Files
tryton/.hooks/update_requirements
T

82 lines
2.4 KiB
Python
Raw Normal View History

2026-03-04 12:36:33 +01:00
#!/usr/bin/env python3
2022-12-16 23:16:08 +01:00
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import importlib.metadata
2022-12-16 23:16:08 +01:00
import io
import json
2022-12-16 23:16:08 +01:00
import os
import subprocess
from multiprocessing.dummy import Pool
from packaging.requirements import Requirement
2022-12-16 23:16:08 +01:00
root = os.path.dirname(os.path.dirname(__file__))
module_path = os.path.join(root, 'modules')
dependencies = set()
build_dependencies = {
'rnc2rng',
'Babel',
'hatchling',
'hatch-tryton',
}
development_dependencies = build_dependencies | {
'Sphinx',
'cookiecutter',
'sphinx-lint',
'tox',
}
2022-12-16 23:16:08 +01:00
FNULL = open(os.devnull, 'w')
_build_deps_installed = True
try:
for requirement in build_dependencies:
importlib.metadata.version(Requirement(requirement).name)
except importlib.metadata.PackageNotFoundError:
_build_deps_installed = False
2022-12-16 23:16:08 +01:00
def add_dependencies(package):
cmd = 'python3 -m build -qq --metadata'
if _build_deps_installed:
cmd += ' --no-isolation'
metadata = subprocess.check_output(
cmd, shell=True, encoding='utf-8', cwd=package).strip()
metadata = json.loads(metadata)
for requirement in metadata.get('requires_dist', []):
requirement = Requirement(requirement)
if (requirement.name.startswith('trytond')
or requirement.name in {'proteus', 'tryton'}):
continue
development = bool(requirement.marker)
requirement.marker = None
if development:
development_dependencies.add(requirement)
else:
dependencies.add(requirement)
2022-12-16 23:16:08 +01:00
pool = Pool()
pool.apply_async(add_dependencies, (os.path.join(root, 'trytond'),))
pool.apply_async(add_dependencies, (os.path.join(root, 'tryton'),))
pool.apply_async(add_dependencies, (os.path.join(root, 'proteus'),))
pool.apply_async(add_dependencies, (os.path.join(root, 'trytond-gis'),))
2022-12-16 23:16:08 +01:00
for module in os.listdir(module_path):
path = os.path.join(module_path, module)
if not os.path.isdir(path):
continue
pool.apply_async(add_dependencies, (path,))
2022-12-16 23:16:08 +01:00
pool.close()
pool.join()
with io.open(os.path.join(root, 'requirements.txt'), 'w') as fp:
fp.writelines(map(lambda d: d + '\n', sorted(map(str, dependencies))))
2022-12-16 23:16:08 +01:00
with io.open(os.path.join(root, 'requirements-dev.txt'), 'w') as fp:
fp.writelines(
map(lambda d: d + '\n', sorted(map(str, development_dependencies))))