2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 11:36:44 +00:00

fix task helper names (#9533)

This commit is contained in:
Matthias Mair 2025-04-20 01:57:02 +02:00 committed by GitHub
parent 35150e3bd3
commit 058aa190d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

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