Converting Python Scripts to meet PEP-8 (and bugs)

Announcements and discussion regarding any projects related to Cyan Worlds' Plasma Engine including (but not limited to) CyanWorlds.com Engine, Drizzle, OfflineKI, PyPRP, and libHSPlasma.

Converting Python Scripts to meet PEP-8 (and bugs)

Postby johnsojc » Mon Jul 15, 2013 5:14 am

Just to let everyone know, I took a suggestion from Adam to rework the Python scripts to meet the PEP-8 style standards (which suits me well as I am more a code mechanic than a program developer). In the last two days I have only managed to process 12 files and my initial estimation that this was NOT a trivial task were confirmed. Part of the slow pace is caused by my having to live in the Python language reference docs and being a complete tyro at Python coding.

Some of the difficulties are changing certain code practices (using isinstance() instead of using if type(x) == some type) and removing obsolete usages that will not be in Python3 (has_key..) Some of the deep indenting forces some creative implied continuation lines and seems to defeat the purpose of making the code easily readable. I am looking for input from the community where to break the rules of PEP-8 for the sake of readability.

I have tested the modified code as well as I can but more exhaustive testing will be needed to make sure I don't break something.

Also looking for suggestions as to the best way to submit the modified code. I am not set up to use a git repository and I'm not really familiar with using a version control system (comes from being an obsolete programmer.. ah, the good old days when everything was confusion!).
Last edited by johnsojc on Thu Aug 08, 2013 12:27 pm, edited 1 time in total.
johnsojc
 
Posts: 246
Joined: Sun Dec 07, 2008 10:27 am

Re: Converting Python Scripts to meet PEP-8

Postby Lyrositor » Mon Jul 15, 2013 5:35 am

Heh, I tried to do that with xKI a while back. That was fun.

I think it's not a big problem if your lines are longer than 80 characters; most Uru developers have pretty big screens nowadays. ;) If you need to bend the rules like that from time to time, I hardly think it will be a problem.

Your best bet to submit this is to fork the H'uru/moul-scripts git repository, clone your fork, create a branch on it (called pep8 or something like that), make your changes, then commit your work, push it and submit a pull request to the original repository.
Lyrositor
Explorer #16601888
User avatar
Lyrositor
Director of Wiki Operations
 
Posts: 208
Joined: Tue Feb 07, 2012 6:05 pm

Re: Converting Python Scripts to meet PEP-8

Postby johnsojc » Mon Jul 15, 2013 7:48 am

Lyrositor wrote:Heh, I tried to do that with xKI a while back. That was fun

Plodding through ahnyVogondolaRideV2.py now. I've been working on it over an hour and expect to be at it least another.

Lyrositor wrote:Your best bet to submit this is to fork the H'uru/moul-scripts git repository, clone your fork, create a branch on it (called pep8 or something like that), make your changes, then commit your work, push it and submit a pull request to the original repository.


Probably a good idea. All I have to do is figure out how to set it all up. :roll:
johnsojc
 
Posts: 246
Joined: Sun Dec 07, 2008 10:27 am

Re: Converting Python Scripts to meet PEP-8

Postby Luna » Mon Jul 15, 2013 7:59 am

If you come into the writers' irc channel I'm sure someone can help you to set it up. For basic things like this it's not that hard :) It's also a good place to discuss how to apply pep8 guidelines etc.
Code: Select all
long longestTimeWithoutPlayingMoula = (new Date()) - (new Date(2014, 9, 26));
User avatar
Luna
 
Posts: 204
Joined: Fri Oct 08, 2010 12:21 am
Location: Il y a encore des pommes.

Re: Converting Python Scripts to meet PEP-8

Postby johnsojc » Mon Jul 15, 2013 8:40 am

I have an IRC client all set up for #writers... just never had anything to say before now :)
johnsojc
 
Posts: 246
Joined: Sun Dec 07, 2008 10:27 am

Re: Converting Python Scripts to meet PEP-8

Postby Tsar Hoikas » Mon Jul 15, 2013 6:55 pm

I meant to respond to your PM, but I very quickly got distracted by Ahnoying as well. It looks like I didn't need to though (whew). As Lyrositor said, we don't really care about the 80 columns rule. More troubling are the poor type checking and general C-like nature of Cyan's python. Any and all cleanups of it are highly welcome!

We don't always talk about Plasma in the IRC channel either ;) (code and tech tend to be the hot topics though)
Image
User avatar
Tsar Hoikas
Councilor of Technical Direction
 
Posts: 1891
Joined: Fri Nov 16, 2007 9:45 pm
Location: South Georgia

Re: Converting Python Scripts to meet PEP-8

Postby johnsojc » Tue Jul 16, 2013 5:56 am

No problem. My limited skill set suits me perfectly for the boring clean up tasks that most developers cringe to think about.

I've been happily banging on the code (brutally relearning the perils of a misplaced parenthesis). I managed to break not one, but three of the Ahnonay scripts which I just now managed to fix so they work. Happily, DIRTSAND reports client Tracebacks so I know where to look for broken code.

One of the comments about PEP-8 I've read was "Know when to break the rules...". I have kept to the 80 column rule so far but some of the more involved scripts have many levels of indent so the right side of the code gets a bit crowded with continuation lines.

Yesterday I suddenly realized where this 72/80 character lines must have come from (and not the excuse that a programmer needs to put two files side by side for editing)... the 72/80 char format exactly matches the old IBM 80 column punch card! :evil:
johnsojc
 
Posts: 246
Joined: Sun Dec 07, 2008 10:27 am

Re: Converting Python Scripts to meet PEP-8

Postby tachzusamm » Tue Jul 16, 2013 6:47 am

User avatar
tachzusamm
 
Posts: 575
Joined: Thu May 29, 2008 2:03 am
Location: Germany

Re: Converting Python Scripts to meet PEP-8

Postby johnsojc » Tue Jul 16, 2013 8:20 am

:lol:
johnsojc
 
Posts: 246
Joined: Sun Dec 07, 2008 10:27 am

Re: Converting Python Scripts to meet PEP-8

Postby johnsojc » Tue Jul 16, 2013 2:04 pm

I've started noticing traceback errors in DIRTSAND while testing the cleaned up Python scripts and noticed some errors. At first I thought I had messed up formatting the Python but after restoring the original Python scripts, I'm no longer sure. The problem seems to be in reading some SDL values.

On entering my Neighborhood I get:
Code: Select all
{Auth} Got client python traceback:
PythonFileReaderVis_13 - Traceback (most recent call last):
  File ".\python\xAgeSDLBoolShowHide.py, Line 81, in OnServerInitComplete
    self._Setup()
  File ".\python\xAgeSDLBoolShowHide.py, Line 107, in _Setup()
    self.sdl_value = ageSDL[sdlName.value][0]
KeyError: 'SDL key nb01ReaderBoardVis  not found'

On entering the city:
Code: Select all
{Auth} Got client python traceback:
cPythonReaderBoardSDLvar_1- Traceback (most recent call last):
  File ".\python\xAgeSDLBoolShowHide.py, Line 81, in OnServerInitComplete
    self._Setup()
  File ".\python\xAgeSDLBoolShowHide.py, Line 107, in _Setup()
    self.sdl_value = ageSDL[sdlName.value][0]
KeyError: 'SDL key nb01ReaderBoardVis  not found'

Entering the Watcher's Pub:
Code: Select all
{Auth} Got client python traceback:
cPythDayNight2- Traceback (most recent call last):
  File ".\python\xAgeSDLBoolRespond.py, Line 95, in OnServerInitComplete
    self._Setup()
  File ".\python\xAgeSDLBoolRespond.py, Line 121, in _Setup()
    self._Execute(ageSDL[sdlName.value][0], initFastFwd.value)
KeyError: 'SDL key boolTreeDayLights  not found'


The only thing I noticed about these values is that in the .sdl files, these SDL values are at the end of a long list of values and followed by whitespace.

Anyone have a clue?

EDIT: I changed my client to the CWE build client and used the SDL files from that bundle. The error persists so it's either in the Python code, a problem in DIRTSAND, or there's something in the C++ client code common to my own compiled client and the CWE build client.
johnsojc
 
Posts: 246
Joined: Sun Dec 07, 2008 10:27 am

Next

Return to Plasma Development

Who is online

Users browsing this forum: No registered users and 2 guests

cron