mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
50 lines
1.5 KiB
Python
Executable File
50 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
from os.path import join
|
|
from subprocess import check_call, check_output
|
|
from tempfile import TemporaryDirectory
|
|
|
|
|
|
def print_packages(packages, heading):
|
|
print(f'{heading}:')
|
|
print(' ', end='')
|
|
print('\n '.join(packages))
|
|
|
|
|
|
with TemporaryDirectory() as tmpdir:
|
|
check_call(['python3', '-m', 'venv', tmpdir])
|
|
|
|
# base needs
|
|
check_call([join(tmpdir, 'bin', 'pip'), 'install', '.'])
|
|
frozen = check_output([join(tmpdir, 'bin', 'pip'), 'freeze'])
|
|
frozen = set(frozen.decode('utf-8').strip().split('\n'))
|
|
|
|
# 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').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')
|
|
|
|
with open('requirements.txt', 'w') as fh:
|
|
fh.write('\n'.join(frozen))
|
|
fh.write('\n')
|
|
|
|
with open('requirements-dev.txt', 'w') as fh:
|
|
fh.write('\n'.join(dev_frozen))
|
|
fh.write('\n')
|