mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 03:26:45 +00:00
fix task helper names (#9533)
This commit is contained in:
parent
35150e3bd3
commit
058aa190d9
77
tasks.py
77
tasks.py
@ -40,6 +40,7 @@ def is_deb_environment():
|
||||
)
|
||||
|
||||
|
||||
# region execution logging helpers
|
||||
def task_exception_handler(t, v, tb):
|
||||
"""Handle exceptions raised by tasks.
|
||||
|
||||
@ -116,7 +117,11 @@ def state_logger(fn=None, method_name=None):
|
||||
return decorator
|
||||
|
||||
|
||||
def checkInvokeVersion():
|
||||
# endregion
|
||||
|
||||
|
||||
# region environment checks
|
||||
def check_invoke_version():
|
||||
"""Check that the installed invoke version meets minimum requirements."""
|
||||
MIN_INVOKE_VERSION = '2.0.0'
|
||||
|
||||
@ -129,7 +134,7 @@ def checkInvokeVersion():
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def chceckInvokePath():
|
||||
def check_invoke_path():
|
||||
"""Check that the path of the used invoke is correct."""
|
||||
if is_docker_environment() or is_rtd_environment():
|
||||
return
|
||||
@ -147,7 +152,7 @@ def chceckInvokePath():
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def checkPythonVersion():
|
||||
def check_python_version():
|
||||
"""Check that the installed python version meets minimum requirements.
|
||||
|
||||
If the python version is not sufficient, exits with a non-zero exit code.
|
||||
@ -171,9 +176,10 @@ def checkPythonVersion():
|
||||
|
||||
|
||||
if __name__ in ['__main__', 'tasks']:
|
||||
checkInvokeVersion()
|
||||
chceckInvokePath()
|
||||
checkPythonVersion()
|
||||
check_invoke_version()
|
||||
check_invoke_path()
|
||||
check_python_version()
|
||||
# endregion
|
||||
|
||||
|
||||
def apps():
|
||||
@ -251,7 +257,8 @@ def content_excludes(
|
||||
return ' '.join([f'--exclude {e}' for e in excludes])
|
||||
|
||||
|
||||
def localDir() -> Path:
|
||||
# region file helpers
|
||||
def local_dir() -> Path:
|
||||
"""Returns the directory of *THIS* file.
|
||||
|
||||
Used to ensure that the various scripts always run
|
||||
@ -260,14 +267,17 @@ def localDir() -> Path:
|
||||
return Path(__file__).parent.resolve()
|
||||
|
||||
|
||||
def managePyDir():
|
||||
def manage_py_dir():
|
||||
"""Returns the directory of the manage.py file."""
|
||||
return localDir().joinpath('src', 'backend', 'InvenTree')
|
||||
return local_dir().joinpath('src', 'backend', 'InvenTree')
|
||||
|
||||
|
||||
def managePyPath():
|
||||
def manage_py_path():
|
||||
"""Return the path of the manage.py file."""
|
||||
return managePyDir().joinpath('manage.py')
|
||||
return manage_py_dir().joinpath('manage.py')
|
||||
|
||||
|
||||
# endregion
|
||||
|
||||
|
||||
def run(c, cmd, path: Optional[Path] = None, pty=False, env=None):
|
||||
@ -281,7 +291,7 @@ def run(c, cmd, path: Optional[Path] = None, pty=False, env=None):
|
||||
env (dict, optional): Environment variables to pass to the command. Defaults to None.
|
||||
"""
|
||||
env = env or {}
|
||||
path = path or localDir()
|
||||
path = path or local_dir()
|
||||
|
||||
try:
|
||||
c.run(f'cd "{path}" && {cmd}', pty=pty, env=env)
|
||||
@ -300,7 +310,7 @@ def manage(c, cmd, pty: bool = False, env=None):
|
||||
pty (bool, optional): Run an interactive session. Defaults to False.
|
||||
env (dict, optional): Environment variables to pass to the command. Defaults to None.
|
||||
"""
|
||||
run(c, f'python3 manage.py {cmd}', managePyDir(), pty, env)
|
||||
run(c, f'python3 manage.py {cmd}', manage_py_dir(), pty, env)
|
||||
|
||||
|
||||
def yarn(c, cmd):
|
||||
@ -310,7 +320,7 @@ def yarn(c, cmd):
|
||||
c: Command line context.
|
||||
cmd: Yarn command to run.
|
||||
"""
|
||||
path = localDir().joinpath('src', 'frontend')
|
||||
path = local_dir().joinpath('src', 'frontend')
|
||||
run(c, cmd, path, False)
|
||||
|
||||
|
||||
@ -369,6 +379,7 @@ def check_file_existence(filename: Path, overwrite: bool = False):
|
||||
|
||||
|
||||
# Install tasks
|
||||
# region tasks
|
||||
@task(help={'uv': 'Use UV (experimental package manager)'})
|
||||
@state_logger('TSK01')
|
||||
def plugins(c, uv=False):
|
||||
@ -400,7 +411,7 @@ def plugins(c, uv=False):
|
||||
def install(c, uv=False, skip_plugins=False):
|
||||
"""Installs required python packages."""
|
||||
# Ensure path is relative to *this* directory
|
||||
INSTALL_FILE = localDir().joinpath('src/backend/requirements.txt')
|
||||
INSTALL_FILE = local_dir().joinpath('src/backend/requirements.txt')
|
||||
|
||||
info(f"Installing required python packages from '{INSTALL_FILE}'")
|
||||
|
||||
@ -429,7 +440,7 @@ def install(c, uv=False, skip_plugins=False):
|
||||
plugins(c, uv=uv)
|
||||
|
||||
# Compile license information
|
||||
lic_path = managePyDir().joinpath('InvenTree', 'licenses.txt')
|
||||
lic_path = manage_py_dir().joinpath('InvenTree', 'licenses.txt')
|
||||
run(
|
||||
c,
|
||||
f'pip-licenses --format=json --with-license-file --no-license-path > {lic_path}',
|
||||
@ -571,7 +582,7 @@ def backup(c, clean=False, path=None):
|
||||
# Resolve the provided path
|
||||
path = Path(path)
|
||||
if not os.path.isabs(path):
|
||||
path = localDir().joinpath(path).resolve()
|
||||
path = local_dir().joinpath(path).resolve()
|
||||
|
||||
cmd += f' -O {path}'
|
||||
|
||||
@ -609,7 +620,7 @@ def restore(
|
||||
# Resolve the provided path
|
||||
path = Path(path)
|
||||
if not os.path.isabs(path):
|
||||
path = localDir().joinpath(path).resolve()
|
||||
path = local_dir().joinpath(path).resolve()
|
||||
|
||||
base_cmd += f' -I {path}'
|
||||
|
||||
@ -774,7 +785,7 @@ def export_records(
|
||||
# Get an absolute path to the file
|
||||
target = Path(filename)
|
||||
if not target.is_absolute():
|
||||
target = localDir().joinpath(filename).resolve()
|
||||
target = local_dir().joinpath(filename).resolve()
|
||||
|
||||
info(f"Exporting database records to file '{target}'")
|
||||
|
||||
@ -844,7 +855,7 @@ def import_records(
|
||||
# Get an absolute path to the supplied filename
|
||||
target = Path(filename)
|
||||
if not target.is_absolute():
|
||||
target = localDir().joinpath(filename)
|
||||
target = local_dir().joinpath(filename)
|
||||
|
||||
if not target.exists():
|
||||
error(f"ERROR: File '{target}' does not exist")
|
||||
@ -996,10 +1007,8 @@ def gunicorn(c, address='0.0.0.0:8000', workers=None):
|
||||
|
||||
Note: This server will not auto-reload in response to code changes.
|
||||
"""
|
||||
config_file = localDir().joinpath('contrib', 'container', 'gunicorn.conf.py')
|
||||
cmd = (
|
||||
f'gunicorn -c {config_file} InvenTree.wsgi -b {address} --chdir {managePyDir()}'
|
||||
)
|
||||
config_file = local_dir().joinpath('contrib', 'container', 'gunicorn.conf.py')
|
||||
cmd = f'gunicorn -c {config_file} InvenTree.wsgi -b {address} --chdir {manage_py_dir()}'
|
||||
|
||||
if workers:
|
||||
cmd += f' --workers={workers}'
|
||||
@ -1175,7 +1184,7 @@ def test(
|
||||
|
||||
if coverage:
|
||||
# Run tests within coverage environment, and generate report
|
||||
run(c, f'coverage run {managePyPath()} {cmd}')
|
||||
run(c, f'coverage run {manage_py_path()} {cmd}')
|
||||
run(c, 'coverage xml -i')
|
||||
else:
|
||||
# Run simple test runner, without coverage
|
||||
@ -1201,7 +1210,7 @@ def setup_test(
|
||||
if not ignore_update:
|
||||
update(c)
|
||||
|
||||
template_dir = localDir().joinpath(path)
|
||||
template_dir = local_dir().joinpath(path)
|
||||
|
||||
# Remove old data directory
|
||||
if template_dir.exists():
|
||||
@ -1371,7 +1380,7 @@ Environment {sys.prefix}
|
||||
Invoke Tool {invoke_path}
|
||||
|
||||
Installation paths:
|
||||
Base {localDir()}
|
||||
Base {local_dir()}
|
||||
Config {get_config_file()}
|
||||
Plugin File {get_plugin_file() or NOT_SPECIFIED}
|
||||
Media {get_media_dir(error=False) or NOT_SPECIFIED}
|
||||
@ -1529,7 +1538,7 @@ def frontend_download(
|
||||
if not extract:
|
||||
return
|
||||
|
||||
dest_path = managePyDir().joinpath('web', 'static', 'web')
|
||||
dest_path = manage_py_dir().joinpath('web', 'static', 'web')
|
||||
|
||||
# if clean, delete static/web directory
|
||||
if clean:
|
||||
@ -1568,9 +1577,13 @@ def frontend_download(
|
||||
ref = 'tag' if tag else 'commit'
|
||||
|
||||
if tag:
|
||||
current = managePyDir().joinpath('web', 'static', 'web', '.vite', 'tag.txt')
|
||||
current = manage_py_dir().joinpath(
|
||||
'web', 'static', 'web', '.vite', 'tag.txt'
|
||||
)
|
||||
elif sha:
|
||||
current = managePyDir().joinpath('web', 'static', 'web', '.vite', 'sha.txt')
|
||||
current = manage_py_dir().joinpath(
|
||||
'web', 'static', 'web', '.vite', 'sha.txt'
|
||||
)
|
||||
else:
|
||||
raise ValueError('Either tag or sha needs to be set')
|
||||
|
||||
@ -1608,7 +1621,7 @@ def frontend_download(
|
||||
).strip()
|
||||
except Exception:
|
||||
# .deb Packages contain extra information in the VERSION file
|
||||
version_file = localDir().joinpath('VERSION')
|
||||
version_file = local_dir().joinpath('VERSION')
|
||||
if not version_file.exists():
|
||||
return
|
||||
from dotenv import dotenv_values
|
||||
@ -1725,6 +1738,8 @@ def clear_generated(c):
|
||||
run(c, 'find src -name "messages.mo" -exec rm -f {} +')
|
||||
|
||||
|
||||
# endregion tasks
|
||||
|
||||
# Collection sorting
|
||||
development = Collection(
|
||||
delete_data,
|
||||
|
Loading…
x
Reference in New Issue
Block a user