Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sDNA can work in Python 3! time.clock = time.perf_counter #13

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

JamesParrott
Copy link
Contributor

@JamesParrott JamesParrott commented Sep 22, 2022

The latest two commits are only a 6 line change so (as admin) I tracked my sDNA+ installation folder with git locally (*) and copied the only two changed files in. I was able to run integral, prepare, learn and predict to work with Python 3.9 with few problems. The other commits from Pylint from my previous PR weren't even required, probably because a lot of them are in testing code.

(*)Top tip - ignore everything that's not a Python file:

.gitignore

#ignore all kind of files
*
*.*
#except Python files
!*.py

inpect -> inspect
…env in method

Otherwise the wrong error occurs when using a zone file with an empty zone
unicode is only a built-in in Python 2.  str in Python 3 supports unicode natively.
Fixes NameError that would otherwise occur in path = os.path.dirname(unicode(__file__, encoding)) in Python 3
StandardError is deprecated in Python 3.  Replaced with AttributeError, ValueError and Exception
Replaced deprecated StandardErrors with AttributeError and Exception
Switch the order of these imports so we can change the code as little as possible: runcalculation imports time, but other than _parentdit the common logic across sdnaintegral, sdnaprepare as well as sdnalearn and sdnapredict is in sdnaenvironment
…n del ing them.

Fixes fiftysevendegreesofrad#11

File writer objects were being relied on to close themselves.
In Iron Python relying on del to call .close()
or some other error meant Shapefile headers were
not being written properly - this should happen in the __exit__ of the
context manager but can be called in .close() if preferred.  del is
known to result in wierd behaviour in cPython, and it's certainly no
better in Iron Python, so ought not be relied on to call .close()

The curious number 960051513 that made its way into the shapefile type
in the header, is 39393939 in base 16.  39 happens to be b'9'.hex().  In
shapefile.Writer.__init__ long before the header is constructed
properly (as the length of the file is not yet known) is the following line
of code:
if self.shp: self.shp.write(b'9'*100)
This just reserves the 100 bytes of space required at the start of the file
according to the ESRI shapefile spec.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant