Skip to content

Commit

Permalink
feat: Setup dev-dependencies defined via pyproject
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gavindsouza committed Jun 16, 2022
1 parent ffae670 commit 75957a5
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions bench/utils/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 75957a5

Please sign in to comment.