Skip to content

Commit

Permalink
Merge pull request #61 from octodns/drop-pycountry
Browse files Browse the repository at this point in the history
Use native geo_data instead of pycountry
  • Loading branch information
viranch authored Aug 12, 2023
2 parents 2935663 + 2ff57f7 commit 377fa5d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 43 deletions.
20 changes: 5 additions & 15 deletions octodns_ns1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

from ns1 import NS1
from ns1.rest.errors import RateLimitException, ResourceException
from pycountry_convert import country_alpha2_to_continent_code

from octodns.provider import ProviderException
from octodns.provider.base import BaseProvider
from octodns.record import Record, Update
from octodns.record.geo import GeoCodes
from octodns.record.geo_data import geo_data

__VERSION__ = '0.0.5'
Expand Down Expand Up @@ -584,8 +584,7 @@ def _data_for_geo_A(self, _type, record):
us_state = meta.get('us_state', [])
ca_province = meta.get('ca_province', [])
for cntry in country:
con = country_alpha2_to_continent_code(cntry)
key = f'{con}-{cntry}'
key = GeoCodes.country_to_code(cntry)
geo[key].extend(answer['answer'])
for state in us_state:
key = f'NA-US-{state}'
Expand Down Expand Up @@ -694,22 +693,13 @@ def _parse_rule_geos(self, meta, notes):

special_continents = dict()
for country in meta.get('country', []):
# country_alpha2_to_continent_code fails for Pitcairn ('PN'),
# United States Minor Outlying Islands ('UM') and
# Sint Maarten ('SX')
if country == 'TL':
con = 'AS'
elif country == 'SX':
con = 'NA'
elif country in ('PN', 'UM'):
con = 'OC'
else:
con = country_alpha2_to_continent_code(country)
geo_code = GeoCodes.country_to_code(country)
con = GeoCodes.parse(geo_code)['continent_code']

if con in self._CONTINENT_TO_LIST_OF_COUNTRIES:
special_continents.setdefault(con, set()).add(country)
else:
geos.add(f'{con}-{country}')
geos.add(geo_code)

for continent, countries in special_continents.items():
if (
Expand Down
24 changes: 16 additions & 8 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
# DO NOT EDIT THIS FILE DIRECTLY - use ./script/update-requirements to update
Pygments==2.15.1
Pygments==2.16.1
SecretStorage==3.3.3
black==23.7.0
bleach==6.0.0
build==0.10.0
cffi==1.15.1
click==8.1.6
cmarkgfm==2022.10.27
cryptography==41.0.2
coverage==7.2.7
cryptography==41.0.3
docutils==0.20.1
exceptiongroup==1.1.2
importlib-metadata==6.8.0
importlib-resources==6.0.0
importlib-resources==6.0.1
iniconfig==2.0.0
isort==5.12.0
jaraco.classes==3.3.0
jeepney==0.8.0
keyring==24.2.0
markdown-it-py==3.0.0
mdurl==0.1.2
more-itertools==10.0.0
more-itertools==10.1.0
mypy-extensions==1.0.0
pathspec==0.11.1
packaging==23.1
pathspec==0.11.2
pkginfo==1.9.6
platformdirs==3.9.1
platformdirs==3.10.0
pluggy==1.2.0
pycparser==2.21
pyflakes==3.0.1
pyflakes==3.1.0
pyproject_hooks==1.0.0
pytest-cov==4.1.0
pytest-network==0.0.1
pytest==7.4.0
readme-renderer==40.0
requests-toolbelt==1.0.0
rfc3986==2.0.0
rich==13.4.2
rich==13.5.2
tomli==2.0.1
twine==4.0.2
typing_extensions==4.7.1
webencodings==0.5.1
Expand Down
21 changes: 2 additions & 19 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
# DO NOT EDIT THIS FILE DIRECTLY - use ./script/update-requirements to update
PyYAML==6.0.1
anyio==3.7.1
certifi==2023.7.22
charset-normalizer==3.2.0
coverage==7.2.7
dnspython==2.4.0
exceptiongroup==1.1.2
dnspython==2.4.2
fqdn==1.5.1
h11==0.14.0
httpcore==0.17.3
idna==3.4
iniconfig==2.0.0
natsort==8.4.0
ns1-python==0.18.0
octodns==1.0.0rc0
packaging==23.1
pluggy==1.2.0
pprintpp==0.4.0
pycountry-convert==0.7.2
pycountry==22.3.5
pytest-cov==4.1.0
pytest-mock==3.11.1
pytest==7.4.0
octodns==1.0.0
python-dateutil==2.8.2
repoze.lru==0.7
requests==2.31.0
six==1.16.0
sniffio==1.3.0
tomli==2.0.1
urllib3==2.0.4
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def version():
install_requires=(
'octodns>=1.0.0rc0',
'ns1_python>=0.17.1',
'pycountry-convert>=0.7.2',
'requests>=2.27.1',
),
license='MIT',
Expand Down

0 comments on commit 377fa5d

Please sign in to comment.