-
Notifications
You must be signed in to change notification settings - Fork 16
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
fix: unfreeze pycountry version #22
fix: unfreeze pycountry version #22
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.
I guess you can bump the component to 1.4.0.
postal_address/territory.py
Outdated
'DG': 'IO', # Diego Garcia is part of the British Indian Ocean Territory | ||
'FX': 'FR', # France, Metropolitan | ||
# European Commision country code exceptions. | ||
# Source: http://publications.europa.eu/code/pdf/370000en.htm#pays |
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.
Link seems down. Tracked it down to: https://web.archive.org/web/20171108144027/http://publications.europa.eu/code/pdf/370000en.htm
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.
http://publications.europa.eu/code/pdf/370000en.htm#pays Doesn't seem to be down for me
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.
Did you tried https://publications.europa.eu/en/code/pdf/370000en.htm#pays ?
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 one you sent here is not working (it is using https
and with /en
at the beginning). But the one in the code seems to work and has the same content as the web.archive.org link you sent me. Do you want to replace it regardless?
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.
Aha! Got it! Just a missing https
redirection! No no, keep the original URL! 😄
postal_address/territory.py
Outdated
'UK': 'GB', # United Kingdom | ||
'EL': 'GR', # Greece | ||
'UK': 'GB', # United Kingdom is known as 'GB' in ISO-3166 | ||
'EL': 'GR', # 'EL' is the european version of Greece, |
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.
Can you point to https://web.archive.org/web/20171108144027/http://publications.europa.eu/code/pdf/370000en.htm as the reference document that led to that decision?
postal_address/territory.py
Outdated
'FX': 'FR', # France, Metropolitan | ||
# European Commision country code exceptions. | ||
# Source: http://publications.europa.eu/code/pdf/370000en.htm#pays | ||
'EA': 'ES', # 'EA' is the union of Ceuta and Melilla, Spanish territory |
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.
OK, agree on this one, let's make things simple.
postal_address/territory.py
Outdated
Map some subdivision aliases representing the same territory, but defined | ||
under different countries. | ||
|
||
.. data:: FOREIGN_TERRITORIES_ALIAS_TO_COUNTRY |
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.
Why not rename that kind RESERVED_COUNTRY_CODES
? As it it supposed to be an exact copy of special cases exposed at https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Reserved_code_elements right?
@@ -140,7 +146,7 @@ def test_alias_normalization(self): | |||
|
|||
# Check country alias to a subdivision. | |||
self.assertEquals( | |||
list(territory_parents_codes('TA')), | |||
list(territory_parents_codes('SH-TA')), |
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.
Just to make sure I really follow you, what's the result of the previous version of the test (a.k.a. territory_parents_codes('TA')
)?
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.
Currently it would fail but I can fix it by adding a resolution against COUNTRY_ALIAS_TO_SUBDIVISION
in territory_parents
. This would send the same result for both queries. Would that be ok ?
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.
Great! Sounds fantastic! Let's do that! :)
# Sub-territories will not change by default | ||
self.assertEqual("BQ", normalize_territory_code("BQ")) | ||
self.assertEqual("GP", normalize_territory_code("FR-GP")) | ||
# TODO: Is it normal to not retrieve alpha2 ? |
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.
I guess this is allowed as the concept of a "territory" is covering both county and subdivisions. So to me, based on its naming normalize_territory_code()
should return the most appropriate territory, be it a country or a subdivision.
self.assertEqual("FR", resolved) | ||
|
||
resolved = normalize_territory_code("NL-BQ1", | ||
resole_foreign_territory=True) |
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.
Seeing the usage of that parameter in the wild, I just realized that maybe resole_foreign_territory
is badly named and should be called resolve_top_country
or something. In which case it will not be allowed to return a subdivision but always a country.
setup.py
Outdated
@@ -31,7 +31,7 @@ | |||
# TODO: subdivision definitions are broken for Czech Republic starting with | |||
# PyCountry 16.11.27. See: | |||
# https://bitbucket.org/flyingcircus/pycountry/issues/13389 | |||
'pycountry >= 16.11.08, < 16.11.27', | |||
'pycountry >= 18.5.26', |
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.
I guess you can remove the TODO statement above then.
Codecov Report
@@ Coverage Diff @@
## develop #22 +/- ##
===========================================
+ Coverage 95.61% 96.01% +0.39%
===========================================
Files 3 2 -1
Lines 342 376 +34
Branches 91 95 +4
===========================================
+ Hits 327 361 +34
Misses 5 5
Partials 10 10
Continue to review full report at Codecov.
|
@@ -140,7 +146,7 @@ def test_alias_normalization(self): | |||
|
|||
# Check country alias to a subdivision. | |||
self.assertEquals( | |||
list(territory_parents_codes('TA')), | |||
list(territory_parents_codes('SH-TA')), |
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.
Great! Sounds fantastic! Let's do that! :)
postal_address/address.py
Outdated
'{}_code'.format(subdiv_type_id): subdivision.code, | ||
# Rename code to slug to avoid overriding 'country_code' in some cases | ||
# See https://github.com/scaleway/postal-address/issues/16 | ||
'{}_slug'.format(subdiv_type_id): subdivision.code, |
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.
Now that I saw the use of that metadata in the wild, _slug
might not be the right word, as it still holds a code. Don't you think _key
, _area_code
will be more appropriate here?
Hey @aveuiller, what's the status of that PR? Do you want me to merge it? |
Hello, yes this pull request is finished on my side. :) |
Let's merge then! Thanks @aveuiller for your patience and huge effort! 👍 |
This PR is mostly to fix the compatibility issue with
pycountry
(country_code
being sometimes overridden). But I also tried to refactor the territory management and add a mapping of foreign territories.I tried to understand and separated as well as possible the concepts you had behind the territories management. It's still far from perfect, but doesn't seem to break the behavior you intended to create. Tell me if it remains understandable on your side.
Please tell me if anything seems off in this PR since it has quite some changes ;)
Closes #16, #11