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
python3 support #3816
python3 support #3816
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me besides my comment. Maybe later we could give it another pass trying to make everything consistent (I still see some extra spaces that were in the original).
scripts/generate_road_colours.py
Outdated
@@ -32,7 +32,10 @@ def rgb_error(self): | |||
|
|||
def load_settings(): | |||
"""Read the settings from YAML.""" | |||
return yaml.load(open('road-colors.yaml', 'r')) | |||
with open('road-colors.yaml', 'r') as fd: | |||
y=yaml.load(fd, Loader=yaml.SafeLoader) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: could you add spaces around =
like in the rest of the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
autopep8
should catch such formatting, and fix most of them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to enforce pep8 (any codestyle), check should be added to CI (.travis.yml)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But of course this should not be part of this PR.
Sorry for a long delay! It seems to me that Though maybe earlier version worked by accident thanks to an undocumented behaviour? |
This behaviour is coming from the YAML loader, which has changed since Python 2: This Python 3 version is listing out items in the order they are listed in the YAML file. The Python 2 version was essentially randomized (I believe it would hash the keys and then sort the hashes, but don't quote me on that). I would argue that this version is correct and the previous Python 2 version is "wrong". |
Beside the ordering, the colors are also different for me. I have no explanation for this.
|
I have figured out why the colors are different:
In Python 2, this is an integer division: 20/3 = 6. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After changing the scripts the files they generate need to be regenerated
Could you also change indexes.py to call python3 |
Have you considered using the decimal module of Python?: |
I don't see that decimal would give us any practical advantages over floats here. |
The calculations would be consistent between Python 2 and 3. But of course, if you are dropping Python 2 support entirely, which is logical given the end of life status, then yes, there isn't much to gain. |
@mboeringa It is not needed to use # python 2 & 3
> from __future__ import division
> 20 // 3
6 |
274f913
to
d30a276
Compare
I've addressed the PR comments, but still need to get Travis working with python3 |
2d8a5b5
to
1464d3f
Compare
Either would be correct, but the problem is that Python 3 prior to Python 3.7 doesn't have a fixed ordering. I think the options here are to require Python 3.7 or load into an OrderedDict. |
lxml tostring returns bytes, so change bytes to utf8, iteritems had been gone, so cahange to imtes().
change iteritems to items
fbb8683
to
088a14e
Compare
@pnorman is this nearly ready to release? |
It needs reviewing. |
This PR changes 665 files due to removal of ".0" in generated SVGs. I am considering adding special additional code to preserve it for now, to avoid changing so many files and potentially drowning other changes. |
To be clear, it needs reviewing by someone other than me since I took the PR over |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script get-shapefiles.py wasn't changed in this PR, but it seems that it already supported Python 3. I have made some comments, but otherwise this PR looks good to me.
@@ -32,7 +32,10 @@ def rgb_error(self): | |||
|
|||
def load_settings(): | |||
"""Read the settings from YAML.""" | |||
return yaml.load(open('road-colors.yaml', 'r')) | |||
with open('road-colors.yaml', 'r') as fd: | |||
y = yaml.load(fd, Loader = yaml.SafeLoader) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't you return immediately here, without assigning to y
in between?
@@ -1,4 +1,4 @@ | |||
#!/usr/bin/env python | |||
#!/usr/bin/env python3 | |||
|
|||
# Generate highway shields as SVG files in symbols/shields. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 5 says:
from __future__ import print_function
but this can be removed now. In other files as well.
env: | ||
- CARTO=0.18.0 MAPNIK='3.0.0 3.0.12' | ||
install: | ||
- npm install carto@$CARTO | ||
- pip install --user colormath | ||
- pip3 install --user colormath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this also install PyYAML and lxml?
- python-yaml | ||
- postgresql-9.4-postgis-2.3 | ||
- python3-yaml | ||
- postgresql-9.4-postgis-2.4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this package exist? In bionic there seems to be postgresql-10-postgis-2.4
.
I'm going to close this. The original author never addressed the comments, and while I attempted to do some of them, there are still some left. I'd rather split the python 3 upgrade to multiple PRs, and have been doing so. |
Fixes #3815
Changes proposed in this pull request:
python3 support.
changed from iteritems to items on dict(), lxml.etree.tostring returns to bytes, so convert to utf-8.