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

python3 support #3816

Closed
wants to merge 7 commits into from
Closed

python3 support #3816

wants to merge 7 commits into from

Conversation

samaiyou
Copy link

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.

Copy link
Contributor

@StyXman StyXman left a 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).

@@ -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)
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link

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)

Copy link

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.

@matkoniecz
Copy link
Contributor

Sorry for a long delay!

It seems to me that scripts/generate_road_colours.py used to output elements in constant order and now it is doing in random order.

Though maybe earlier version worked by accident thanks to an undocumented behaviour?

@meased
Copy link
Contributor

meased commented Jul 16, 2019

This behaviour is coming from the YAML loader, which has changed since Python 2:
yaml/pyyaml#110

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".

@Sjord
Copy link
Contributor

Sjord commented Jul 31, 2019

Beside the ordering, the colors are also different for me. I have no explanation for this.

  • python 2: @trunk-low-zoom-casing: #cf6649;
  • python 3: @trunk-low-zoom-casing: #d1684a;

@Sjord
Copy link
Contributor

Sjord commented Aug 1, 2019

I have figured out why the colors are different:

delta_l = (line_colour_info.end_l - line_colour_info.start_l) / colour_divisions

In Python 2, this is an integer division: 20/3 = 6.
In Python 3, this is a float division: 20/3 = 6.667

Copy link
Collaborator

@pnorman pnorman left a 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

@pnorman
Copy link
Collaborator

pnorman commented Aug 1, 2019

Could you also change indexes.py to call python3

@mboeringa
Copy link

I have figured out why the colors are different:

delta_l = (line_colour_info.end_l - line_colour_info.start_l) / colour_divisions

In Python 2, this is an integer division: 20/3 = 6.
In Python 3, this is a float division: 20/3 = 6.667

@Sjord

Have you considered using the decimal module of Python?:
https://docs.python.org/2/library/decimal.html

@pnorman
Copy link
Collaborator

pnorman commented Aug 9, 2019

Have you considered using the decimal module of Python?:
https://docs.python.org/2/library/decimal.html

I don't see that decimal would give us any practical advantages over floats here.

@mboeringa
Copy link

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.

@prmtl
Copy link

prmtl commented Aug 9, 2019

@mboeringa It is not needed to use decimal module to have consistent division. Just use __future__ module and replace / with //:

# python 2 & 3
> from __future__ import division
> 20 // 3
6

@pnorman pnorman force-pushed the feat/python3 branch 3 times, most recently from 274f913 to d30a276 Compare August 10, 2019 17:50
@pnorman
Copy link
Collaborator

pnorman commented Aug 10, 2019

I've addressed the PR comments, but still need to get Travis working with python3

pnorman
pnorman previously approved these changes Aug 10, 2019
@pnorman pnorman self-requested a review August 10, 2019 17:56
@pnorman pnorman force-pushed the feat/python3 branch 3 times, most recently from 2d8a5b5 to 1464d3f Compare August 10, 2019 18:12
@pnorman
Copy link
Collaborator

pnorman commented Aug 10, 2019

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".

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.

@pnorman pnorman dismissed their stale review August 10, 2019 18:45

Failing travis

samaiyou and others added 6 commits August 11, 2019 19:50
lxml tostring returns bytes, so change bytes to utf8,
iteritems had been gone, so cahange to imtes().
change iteritems to items
@pnorman pnorman force-pushed the feat/python3 branch 2 times, most recently from fbb8683 to 088a14e Compare August 12, 2019 03:02
@jeisenbe
Copy link
Collaborator

@pnorman is this nearly ready to release?

@pnorman
Copy link
Collaborator

pnorman commented Sep 17, 2019

@pnorman is this nearly ready to release?

It needs reviewing.

@matkoniecz
Copy link
Contributor

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.

@pnorman
Copy link
Collaborator

pnorman commented Jan 28, 2020

It needs reviewing.

To be clear, it needs reviewing by someone other than me since I took the PR over

@pnorman pnorman mentioned this pull request Jan 31, 2020
Copy link
Contributor

@Sjord Sjord left a 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)
Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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.

@pnorman
Copy link
Collaborator

pnorman commented Feb 13, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

scripts/**.py did not work with python3
9 participants