Browse Source

Rework update-requirements and setup.py to use pip's setup.py support

pull/866/head
Ross McFarland 4 years ago
parent
commit
4dff97e8f6
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
2 changed files with 34 additions and 40 deletions
  1. +19
    -36
      script/update-requirements
  2. +15
    -4
      setup.py

+ 19
- 36
script/update-requirements View File

@ -3,30 +3,6 @@
from os.path import join
from subprocess import check_call, check_output
from tempfile import TemporaryDirectory
import re
def parse_setup(lines, which):
match = re.search(fr'{which}\w*=\w*[\(\[](?P<list>[^\)\]]*)', lines,
flags=re.DOTALL)
packages = match.groups('list')[0]
packages = re.sub(r"[\"'\s]+", '', packages, flags=re.MULTILINE)
packages = [p for p in packages.split(',') if p]
return packages
with open('setup.py') as fh:
lines = fh.read()
install_requires = parse_setup(lines, 'install_requires')
tests_require = parse_setup(lines, 'tests_require')
dev_requires = [
'build>=0.7.0',
'pycodestyle>=2.6.0',
'pyflakes>=2.2.0',
'readme_renderer[md]>=26.0',
'twine>=3.4.2',
]
def print_packages(packages, heading):
@ -35,24 +11,31 @@ def print_packages(packages, heading):
print('\n '.join(packages))
print_packages(install_requires, 'install_requires')
print_packages(tests_require, 'tests_require')
print_packages(dev_requires, 'dev_requires')
with TemporaryDirectory() as tmpdir:
check_call(['python3', '-m', 'venv', tmpdir])
check_call([join(tmpdir, 'bin', 'pip'), 'install', *install_requires])
# base needs
check_call([join(tmpdir, 'bin', 'pip'), 'install', '.'])
frozen = check_output([join(tmpdir, 'bin', 'pip'), 'freeze'])
frozen = set(frozen.decode('utf-8').split())
frozen = set(frozen.decode('utf-8').strip().split('\n'))
check_call([join(tmpdir, 'bin', 'pip'), 'install', *tests_require,
*dev_requires])
# dev additions
check_call([join(tmpdir, 'bin', 'pip'), 'install', '.[dev]'])
dev_frozen = check_output([join(tmpdir, 'bin', 'pip'), 'freeze'])
dev_frozen = set(dev_frozen.decode('utf-8').split()) - frozen
frozen = sorted(frozen)
dev_frozen = sorted(dev_frozen)
dev_frozen = set(dev_frozen.decode('utf-8').strip().split('\n')) - frozen
# pip installs the module itself along with deps so we need to get that out of
# our list by finding the thing that was file installed during dev
dev_frozen_sorted = sorted(dev_frozen)
dev_frozen = []
for package in dev_frozen_sorted:
if 'file://' in package:
ours = package.split(' @ ')[0]
else:
dev_frozen.append(package)
# now we can build the list of base requiements w/o ourself
frozen = sorted([p for p in frozen if not p.startswith(ours)])
# we also sorted things while we were at it above
print_packages(frozen, 'frozen')
print_packages(dev_frozen, 'dev_frozen')


+ 15
- 4
setup.py View File

@ -55,6 +55,11 @@ def long_description():
return buf.getvalue()
tests_require = (
'pytest>=6.2.5',
'pytest-network>=0.0.1',
)
setup(
author='Ross McFarland',
author_email='rwmcfa1@gmail.com',
@ -62,6 +67,15 @@ setup(
entry_points={
'console_scripts': console_scripts,
},
extras_require={
'dev': tests_require + (
'build>=0.7.0',
'pycodestyle>=2.6.0',
'pyflakes>=2.2.0',
'readme_renderer[md]>=26.0',
'twine>=3.4.2',
),
},
install_requires=(
'PyYaml>=4.2b1',
'dnspython>=1.15.0',
@ -77,10 +91,7 @@ setup(
name='octodns',
packages=find_packages(),
python_requires='>=3.6',
tests_require=tests_require,
url='https://github.com/octodns/octodns',
version=octodns.__VERSION__,
tests_require=(
'pytest>=6.2.5',
'pytest-network>=0.0.1',
),
)

Loading…
Cancel
Save