mirror of
https://github.com/frappe/bench.git
synced 2025-01-09 00:21:23 +00:00
Merge pull request #1323 from gavindsouza/dev-deps-toml
feat: Dev Dependencies via pyproject.toml
This commit is contained in:
commit
28549ff139
@ -155,10 +155,13 @@ class Bench(Base, Validator):
|
|||||||
def get_installed_apps(self) -> List:
|
def get_installed_apps(self) -> List:
|
||||||
"""Returns list of installed apps on bench, not in excluded_apps.txt
|
"""Returns list of installed apps on bench, not in excluded_apps.txt
|
||||||
"""
|
"""
|
||||||
apps = [app for app in self.apps if app not in self.excluded_apps]
|
try:
|
||||||
apps.remove("frappe")
|
installed_packages = get_cmd_output(f"{self.python} -m pip freeze", cwd=self.name)
|
||||||
apps.insert(0, "frappe")
|
except Exception:
|
||||||
return apps
|
installed_packages = []
|
||||||
|
is_installed = lambda app: app in installed_packages
|
||||||
|
|
||||||
|
return [app for app in self.apps if app not in self.excluded_apps and is_installed(app)]
|
||||||
|
|
||||||
|
|
||||||
class BenchApps(MutableSequence):
|
class BenchApps(MutableSequence):
|
||||||
@ -262,23 +265,14 @@ class BenchApps(MutableSequence):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def initialize_apps(self):
|
def initialize_apps(self):
|
||||||
is_installed = lambda app: app in installed_packages
|
|
||||||
|
|
||||||
try:
|
|
||||||
installed_packages = get_cmd_output(f"{self.bench.python} -m pip freeze", cwd=self.bench.name)
|
|
||||||
except Exception:
|
|
||||||
self.apps = []
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.apps = [
|
self.apps = [
|
||||||
x
|
x
|
||||||
for x in os.listdir(os.path.join(self.bench.name, "apps"))
|
for x in os.listdir(os.path.join(self.bench.name, "apps"))
|
||||||
if (
|
if is_frappe_app(os.path.join(self.bench.name, "apps", x))
|
||||||
is_frappe_app(os.path.join(self.bench.name, "apps", x))
|
|
||||||
and is_installed(x)
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
|
self.apps.remove("frappe")
|
||||||
|
self.apps.insert(0, "frappe")
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
self.apps = []
|
self.apps = []
|
||||||
|
|
||||||
@ -438,8 +432,7 @@ class BenchSetup(Base):
|
|||||||
"""
|
"""
|
||||||
from bench.app import App
|
from bench.app import App
|
||||||
|
|
||||||
if not apps:
|
apps = apps or self.bench.apps
|
||||||
apps = self.bench.get_installed_apps()
|
|
||||||
|
|
||||||
self.pip()
|
self.pip()
|
||||||
|
|
||||||
@ -456,8 +449,7 @@ class BenchSetup(Base):
|
|||||||
"""
|
"""
|
||||||
import bench.cli
|
import bench.cli
|
||||||
|
|
||||||
if not apps:
|
apps = apps or self.bench.apps
|
||||||
apps = self.bench.get_installed_apps()
|
|
||||||
|
|
||||||
quiet_flag = "" if bench.cli.verbose else "--quiet"
|
quiet_flag = "" if bench.cli.verbose else "--quiet"
|
||||||
|
|
||||||
|
@ -84,21 +84,44 @@ def install_python_dev_dependencies(bench_path=".", apps=None, verbose=False):
|
|||||||
apps = bench.get_installed_apps()
|
apps = bench.get_installed_apps()
|
||||||
|
|
||||||
for app in apps:
|
for app in apps:
|
||||||
|
pyproject_deps = None
|
||||||
app_path = os.path.join(bench_path, "apps", app)
|
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")
|
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}")
|
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):
|
def update_yarn_packages(bench_path=".", apps=None):
|
||||||
from bench.bench import Bench
|
from bench.bench import Bench
|
||||||
|
|
||||||
bench = Bench(bench_path)
|
bench = Bench(bench_path)
|
||||||
|
|
||||||
if not apps:
|
apps = apps or bench.apps
|
||||||
apps = bench.get_installed_apps()
|
|
||||||
|
|
||||||
apps_dir = os.path.join(bench.name, "apps")
|
apps_dir = os.path.join(bench.name, "apps")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user