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

Use pyproject.toml for tooling, add isort management of imports #14

Merged
merged 3 commits into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Commit that added in black formatting support
c2d88038dab583c26ab94fe888cbbf4c0b06c6c6
# Commit for isort formatting changes
fc02b01b2d3ba1e199b6a6ccadea4b7c5534d477
18 changes: 4 additions & 14 deletions octodns_edgedns/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
#
#

from akamai.edgegrid import EdgeGridAuth
from collections import defaultdict
from logging import getLogger
from requests import Session
from urllib.parse import urljoin

from octodns.record import Record
from akamai.edgegrid import EdgeGridAuth
from requests import Session

from octodns.provider import ProviderException
from octodns.provider.base import BaseProvider
from octodns.record import Record

__VERSION__ = '0.0.2'

Expand All @@ -34,7 +35,6 @@ class AkamaiClient(object):
'''

def __init__(self, client_secret, host, access_token, client_token):

self.base = "https://" + host + "/config-dns/v2/"

sess = Session()
Expand All @@ -46,7 +46,6 @@ def __init__(self, client_secret, host, access_token, client_token):
self._sess = sess

def _request(self, method, path, params=None, data=None, v1=False):

url = urljoin(self.base, path)
resp = self._sess.request(method, url, params=params, json=data)

Expand Down Expand Up @@ -100,7 +99,6 @@ def zone_recordset_get(
sortBy="name",
types=None,
):

params = {
'page': page,
'pageSize': pageSize,
Expand Down Expand Up @@ -149,7 +147,6 @@ def __init__(
*args,
**kwargs,
):

self.log = getLogger(f'AkamaiProvider[{id}]')
self.log.debug('__init__: id=%s, ')
super().__init__(id, *args, **kwargs)
Expand Down Expand Up @@ -182,7 +179,6 @@ def populate(self, zone, target=False, lenient=False):

values = defaultdict(lambda: defaultdict(list))
for record in self.zone_records(zone):

_type = record.get('type')
# Akamai sends down prefix.zonename., while octodns expects prefix
_name = record.get('name').split("." + zone.name[:-1], 1)[0]
Expand Down Expand Up @@ -234,7 +230,6 @@ def _apply(self, plan):
self._zone_records.pop(desired.name, None)

def _apply_Create(self, change):

new = change.new
record_type = new._type

Expand All @@ -257,7 +252,6 @@ def _apply_Create(self, change):
return

def _apply_Delete(self, change):

zone = change.existing.zone.name[:-1]
name = self._set_full_name(change.existing.name, zone)
record_type = change.existing._type
Expand All @@ -267,7 +261,6 @@ def _apply_Delete(self, change):
return

def _apply_Update(self, change):

new = change.new
record_type = new._type

Expand All @@ -290,7 +283,6 @@ def _apply_Update(self, change):
return

def _data_for_multiple(self, _type, records):

return {
'ttl': records['ttl'],
'type': _type,
Expand Down Expand Up @@ -451,7 +443,6 @@ def _params_for_TXT(self, values):
def _build_zone_config(
self, zone, _type="primary", comment=None, masters=[]
):

if self._contractId is None:
raise NameError("contractId not specified to create zone")

Expand All @@ -463,7 +454,6 @@ def _build_zone_config(
}

def _get_values(self, data):

try:
vals = data['values']
except KeyError:
Expand Down
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[tool.black]
line-length=80
skip-string-normalization=true
skip-magic-trailing-comma=true

[tool.isort]
profile = "black"
known_first_party="octodns_edgedns"
known_octodns="octodns"
line_length=80
sections="FUTURE,STDLIB,THIRDPARTY,OCTODNS,FIRSTPARTY,LOCALFOLDER"

[tool.pytest.ini_options]
pythonpath = "."
47 changes: 24 additions & 23 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
# DO NOT EDIT THIS FILE DIRECTLY - use ./script/update-requirements to update
Pygments==2.13.0
attrs==22.1.0
black==22.10.0
bleach==5.0.1
build==0.9.0
Pygments==2.14.0
attrs==22.2.0
black==23.1.0
bleach==6.0.0
build==0.10.0
click==8.1.3
cmarkgfm==2022.10.27
commonmark==0.9.1
coverage==6.5.0
coverage==7.1.0
docutils==0.19
exceptiongroup==1.0.1
importlib-metadata==5.0.0
iniconfig==1.1.1
exceptiongroup==1.1.0
importlib-metadata==6.0.0
iniconfig==2.0.0
isort==5.11.5
jaraco.classes==3.2.3
keyring==23.11.0
keyring==23.13.1
markdown-it-py==2.1.0
mdurl==0.1.2
more-itertools==9.0.0
mypy-extensions==0.4.3
packaging==21.3
pathspec==0.10.1
pep517==0.13.0
pkginfo==1.8.3
platformdirs==2.5.3
mypy-extensions==1.0.0
packaging==23.0
pathspec==0.11.0
pkginfo==1.9.6
platformdirs==2.6.2
pluggy==1.0.0
pyflakes==2.5.0
pyparsing==3.0.9
pyflakes==3.0.1
pyproject_hooks==1.0.0
pytest-cov==4.0.0
pytest-network==0.0.1
pytest==7.2.0
pytest==7.2.1
readme-renderer==37.3
requests-mock==1.10.0
rfc3986==2.0.0
rich==12.6.0
rich==13.3.1
tomli==2.0.1
twine==4.0.1
twine==4.0.2
webencodings==0.5.1
zipp==3.10.0
zipp==3.12.0
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
PyYAML==6.0
certifi==2022.12.7
cffi==1.15.1
charset-normalizer==2.1.1
cryptography==38.0.3
dnspython==2.2.1
charset-normalizer==3.0.1
cryptography==39.0.0
dnspython==2.3.0
edgegrid-python==1.3.1
fqdn==1.5.1
idna==3.4
natsort==8.2.0
ndg-httpsclient==0.5.1
octodns==0.9.21
pyOpenSSL==22.1.0
pyOpenSSL==23.0.0
pyasn1==0.4.8
pycparser==2.21
python-dateutil==2.8.2
requests-toolbelt==0.10.1
requests==2.28.1
requests==2.28.2
six==1.16.0
urllib3==1.26.12
urllib3==1.26.14
2 changes: 0 additions & 2 deletions script/coverage
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ grep -r -I --line-number "# pragma: +no.*cover" $SOURCE_DIR && {
exit 1
}

export PYTHONPATH=.:$PYTHONPATH

pytest \
--disable-network \
--cov-reset \
Expand Down
3 changes: 2 additions & 1 deletion script/format
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ SOURCES=$(find *.py octodns_* tests -name "*.py")

. env/bin/activate

black --line-length=80 --skip-string-normalization --skip-magic-trailing-comma "$@" $SOURCES
isort "$@" $SOURCES
black "$@" $SOURCES
2 changes: 0 additions & 2 deletions script/test
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ if [ ! -f "$ACTIVATE" ]; then
fi
. "$ACTIVATE"

export PYTHONPATH=.:$PYTHONPATH

pytest --disable-network "$@"
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from os import environ
from setuptools import find_packages, setup
from subprocess import CalledProcessError, check_output

from setuptools import find_packages, setup


def descriptions():
with open('README.md') as fh:
Expand Down Expand Up @@ -43,6 +44,8 @@ def version():
+ (
'black>=22.3.0',
'build>=0.7.0',
# >=5.12.0 does not support python 3.7, we still do
'isort==5.11.5',
'pyflakes>=2.2.0',
'readme_renderer[md]>=26.0',
'twine>=3.4.2',
Expand Down
10 changes: 5 additions & 5 deletions tests/test_octodns_provider_edgedns.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
#

from os.path import dirname, join
from requests import HTTPError
from requests_mock import ANY, mock as requests_mock
from unittest import TestCase

from octodns.record import Record
from requests import HTTPError
from requests_mock import ANY
from requests_mock import mock as requests_mock

from octodns.provider.yaml import YamlProvider
from octodns.record import Record
from octodns.zone import Zone

from octodns_edgedns import AkamaiProvider
Expand Down Expand Up @@ -72,7 +74,6 @@ def test_populate(self):

# No diffs == no changes
with requests_mock() as mock:

with open('tests/fixtures/edgedns-records.json') as fh:
mock.get(ANY, text=fh.read())

Expand Down Expand Up @@ -104,7 +105,6 @@ def test_apply(self):

# tests create update delete through previous state config json
with requests_mock() as mock:

with open('tests/fixtures/edgedns-records-prev.json') as fh:
mock.get(ANY, text=fh.read())

Expand Down