mirror of
https://github.com/frappe/bench.git
synced 2024-11-14 17:24:04 +00:00
refactor(minor): Use more readable alternatives
This commit is contained in:
parent
a84239d6ab
commit
af46fedc28
@ -1,4 +1,5 @@
|
|||||||
# imports - standard imports
|
# imports - standard imports
|
||||||
|
import contextlib
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@ -99,12 +100,10 @@ def _generate_dev_deps_pattern(pyproject_path):
|
|||||||
requirements_pattern = ""
|
requirements_pattern = ""
|
||||||
pyroject_config = loads(open(pyproject_path).read())
|
pyroject_config = loads(open(pyproject_path).read())
|
||||||
|
|
||||||
try:
|
with contextlib.suppress(KeyError):
|
||||||
for pkg, version in pyroject_config["tool"]["bench"]["dev-dependencies"].items():
|
for pkg, version in pyroject_config["tool"]["bench"]["dev-dependencies"].items():
|
||||||
op = "==" if "=" not in version else ""
|
op = "==" if "=" not in version else ""
|
||||||
requirements_pattern += f"{pkg}{op}{version} "
|
requirements_pattern += f"{pkg}{op}{version} "
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
return requirements_pattern
|
return requirements_pattern
|
||||||
|
|
||||||
|
|
||||||
@ -222,8 +221,7 @@ def migrate_env(python, backup=False):
|
|||||||
|
|
||||||
|
|
||||||
def validate_upgrade(from_ver, to_ver, bench_path="."):
|
def validate_upgrade(from_ver, to_ver, bench_path="."):
|
||||||
if to_ver >= 6:
|
if to_ver >= 6 and not which("npm") and not which("node") and not which("nodejs"):
|
||||||
if not which("npm") and not (which("node") or which("nodejs")):
|
|
||||||
raise Exception("Please install nodejs and npm")
|
raise Exception("Please install nodejs and npm")
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ class Rendering:
|
|||||||
return
|
return
|
||||||
|
|
||||||
_prefix = click.style("⏼", fg="bright_yellow")
|
_prefix = click.style("⏼", fg="bright_yellow")
|
||||||
_hierarchy = " " if not self.is_parent else ""
|
_hierarchy = "" if self.is_parent else " "
|
||||||
self._title = self.title.format(**self.kw)
|
self._title = self.title.format(**self.kw)
|
||||||
click.secho(f"{_hierarchy}{_prefix} {self._title}")
|
click.secho(f"{_hierarchy}{_prefix} {self._title}")
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ class Rendering:
|
|||||||
if l["message"] == self._title:
|
if l["message"] == self._title:
|
||||||
l["prefix"] = self._prefix
|
l["prefix"] = self._prefix
|
||||||
l["message"] = self._success
|
l["message"] = self._success
|
||||||
_hierarchy = " " if not l["is_parent"] else ""
|
_hierarchy = "" if l.get("is_parent") else " "
|
||||||
click.secho(f'{_hierarchy}{l["prefix"]} {l["message"]}', fg=l["color"])
|
click.secho(f'{_hierarchy}{l["prefix"]} {l["message"]}', fg=l["color"])
|
||||||
|
|
||||||
|
|
||||||
|
@ -113,10 +113,7 @@ def setup_sudoers(user):
|
|||||||
if not os.path.exists("/etc/sudoers.d"):
|
if not os.path.exists("/etc/sudoers.d"):
|
||||||
os.makedirs("/etc/sudoers.d")
|
os.makedirs("/etc/sudoers.d")
|
||||||
|
|
||||||
set_permissions = False
|
set_permissions = not os.path.exists("/etc/sudoers")
|
||||||
if not os.path.exists("/etc/sudoers"):
|
|
||||||
set_permissions = True
|
|
||||||
|
|
||||||
with open("/etc/sudoers", "a") as f:
|
with open("/etc/sudoers", "a") as f:
|
||||||
f.write("\n#includedir /etc/sudoers.d\n")
|
f.write("\n#includedir /etc/sudoers.d\n")
|
||||||
|
|
||||||
@ -142,11 +139,7 @@ def setup_sudoers(user):
|
|||||||
|
|
||||||
|
|
||||||
def start(no_dev=False, concurrency=None, procfile=None, no_prefix=False, procman=None):
|
def start(no_dev=False, concurrency=None, procfile=None, no_prefix=False, procman=None):
|
||||||
if procman:
|
program = which(procman) if procman else get_process_manager()
|
||||||
program = which(procman)
|
|
||||||
else:
|
|
||||||
program = get_process_manager()
|
|
||||||
|
|
||||||
if not program:
|
if not program:
|
||||||
raise Exception("No process manager found")
|
raise Exception("No process manager found")
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ def update_translations(app, lang):
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
translations_dir = os.path.join("apps", app, app, "translations")
|
translations_dir = os.path.join("apps", app, app, "translations")
|
||||||
csv_file = os.path.join(translations_dir, lang + ".csv")
|
csv_file = os.path.join(translations_dir, f"{lang}.csv")
|
||||||
url = f"https://translate.erpnext.com/files/{app}-{lang}.csv"
|
url = f"https://translate.erpnext.com/files/{app}-{lang}.csv"
|
||||||
r = requests.get(url, stream=True)
|
r = requests.get(url, stream=True)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
|
Loading…
Reference in New Issue
Block a user