forked from OCA/maintainer-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pre-commit hook to generate external dependencies
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python3 | ||
"""Generate requirements.txt with external dependencies of Odoo addons.""" | ||
|
||
import os | ||
import subprocess | ||
import sys | ||
from itertools import chain | ||
from pathlib import Path | ||
|
||
|
||
def main(): | ||
projects = chain( | ||
Path.glob(Path.cwd(), "*/pyproject.toml"), | ||
Path.glob(Path.cwd(), "setup/*/setup.py"), | ||
) | ||
|
||
env = os.environ.copy() | ||
env.update( | ||
{ | ||
# for better performance | ||
"WHOOL_POST_VERSION_STRATEGY_OVERRIDE": "none", | ||
"SETUPTOOLS_ODOO_POST_VERSION_STRATEGY_OVERRIDE": "none", | ||
} | ||
) | ||
|
||
result = subprocess.run( | ||
[ | ||
sys.executable, | ||
"-m", | ||
"pyproject_dependencies", | ||
"--no-isolation", # whool and setuptools Odoo must be preinstalled | ||
"--ignore-build-errors", # ignore uninstallable modules etc | ||
"--name-filter", | ||
r"^(odoo$|odoo\d*-addon-)", # filter out odoo and odoo addons | ||
*projects, | ||
], | ||
env=env, | ||
check=False, | ||
stdout=subprocess.PIPE, | ||
text=True, | ||
) | ||
|
||
if result.returncode != 0: | ||
sys.exit(result.returncode) | ||
|
||
requirements = result.stdout | ||
|
||
requirements_path = Path("requirements.txt") | ||
if requirements: | ||
with requirements_path.open("w") as f: | ||
f.write("# generated from manifests external_dependencies\n") | ||
f.write(requirements) | ||
else: | ||
if requirements_path.exists(): | ||
requirements_path.unlink() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |