2
0
mirror of https://github.com/frappe/bench.git synced 2024-09-27 22:39:03 +00:00

feat: Setup dev-dependencies defined via pyproject

Since support for pyproject.toml exists, Frappe has gotten rid of
requirements.txt file. However, dev-requirements.txt file still existed
in Frappe & other apps. With this, we can get rid of the separate
dev-reqs file as well and replace it by defining the deps in pyproject
under [tool.bench.dev-dependencies]

Example:

For Frappe, this transition will look like moving the contents of
dev-requirements.txt as follows:

```
\# dev-requirements.txt
coverage==5.5
Faker~=13.12.1
pyngrok~=5.0.5
unittest-xml-reporting~=3.0.4

```

```
\# pyproject.toml
[tool.bench.dev-dependencies]
coverage = "==5.5"
Faker = "~=13.12.1"
pyngrok = "~=5.0.5"
unittest-xml-reporting = "~=3.0.4"
```

Note: If dev-dependencies are defined in pyproject.toml, and a
dev-dependencies.txt file exists - the txt file will be ignored.
This commit is contained in:
Gavin D'souza 2022-06-16 18:16:57 +05:30
parent ffae670be7
commit 75957a56ee

View File

@ -84,14 +84,38 @@ def install_python_dev_dependencies(bench_path=".", apps=None, verbose=False):
apps = bench.get_installed_apps()
for app in apps:
pyproject_deps = None
app_path = os.path.join(bench_path, "apps", app)
pyproject_path = os.path.join(app_path, "pyproject.toml")
dev_requirements_path = os.path.join(app_path, "dev-requirements.txt")
if os.path.exists(dev_requirements_path):
if os.path.exists(pyproject_path):
pyproject_deps = _generate_dev_deps_pattern(pyproject_path)
if pyproject_deps:
bench.run(f"{bench.python} -m pip install {quiet_flag} --upgrade {pyproject_deps}")
if not pyproject_deps and os.path.exists(dev_requirements_path):
bench.run(f"{bench.python} -m pip install {quiet_flag} --upgrade -r {dev_requirements_path}")
def _generate_dev_deps_pattern(pyproject_path):
try:
from tomli import loads
except ImportError:
from tomllib import loads
requirements_pattern = ""
pyroject_config = loads(open(pyproject_path).read())
try:
for pkg, version in pyroject_config['tool']['bench']['dev-dependencies'].items():
op = "=" if "=" not in version else ""
requirements_pattern += f"{pkg}{op}{version} "
except KeyError:
pass
return requirements_pattern
def update_yarn_packages(bench_path=".", apps=None):
from bench.bench import Bench