Page 1 of 12

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

PostPosted: Mon Jul 15, 2013 5:14 am
by johnsojc
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!).

Re: Converting Python Scripts to meet PEP-8

PostPosted: Mon Jul 15, 2013 5:35 am
by Lyrositor
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.

Re: Converting Python Scripts to meet PEP-8

PostPosted: Mon Jul 15, 2013 7:48 am
by johnsojc
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:

Re: Converting Python Scripts to meet PEP-8

PostPosted: Mon Jul 15, 2013 7:59 am
by Luna
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.

Re: Converting Python Scripts to meet PEP-8

PostPosted: Mon Jul 15, 2013 8:40 am
by johnsojc
I have an IRC client all set up for #writers... just never had anything to say before now :)

Re: Converting Python Scripts to meet PEP-8

PostPosted: Mon Jul 15, 2013 6:55 pm
by Tsar Hoikas
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)

Re: Converting Python Scripts to meet PEP-8

PostPosted: Tue Jul 16, 2013 5:56 am
by johnsojc
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:

Re: Converting Python Scripts to meet PEP-8

PostPosted: Tue Jul 16, 2013 6:47 am
by tachzusamm

Re: Converting Python Scripts to meet PEP-8

PostPosted: Tue Jul 16, 2013 8:20 am
by johnsojc
:lol:

Re: Converting Python Scripts to meet PEP-8

PostPosted: Tue Jul 16, 2013 2:04 pm
by johnsojc
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.