From e3205184be08bd3365e12eb782f8a2de1d4e624c Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Thu, 5 Sep 2024 05:04:57 +0200 Subject: [PATCH] Add namespaces to tasks (#7904) * Namespaces for invoke tasks Fixes #7852 * adjust various places that call re-namespaced tasks * use full invoke command easier for future refactors * fix call name * move worker to int * adapt calls in tasks * fix changed path * ignore localhost links * Avoid using internal names --- .devcontainer/postCreateCommand.sh | 4 +- .github/actions/migration/action.yaml | 2 +- .github/workflows/check_translations.yaml | 2 +- .github/workflows/docker.yaml | 6 +-- .github/workflows/qc_checks.yaml | 26 +++++------ .github/workflows/translations.yaml | 2 +- .vscode/tasks.json | 20 ++++---- contrib/container/Dockerfile | 2 +- contrib/container/dev-docker-compose.yml | 2 +- contrib/container/docker-compose.yml | 2 +- contrib/packager.io/functions.sh | 2 +- contrib/packager.io/preinstall.sh | 4 +- docs/docs/api/api.md | 4 +- docs/docs/develop/contributing.md | 2 +- docs/docs/develop/react-frontend.md | 8 ++-- docs/docs/faq.md | 2 +- docs/docs/start/bare_dev.md | 8 ++-- docs/docs/start/docker_install.md | 6 +-- docs/mlc_config.json | 3 ++ readthedocs.yml | 4 +- src/frontend/playwright.config.ts | 2 +- tasks.py | 57 +++++++++++++++++++++-- 22 files changed, 112 insertions(+), 58 deletions(-) diff --git a/.devcontainer/postCreateCommand.sh b/.devcontainer/postCreateCommand.sh index 9cf0b9c3a0..50e03c60c7 100755 --- a/.devcontainer/postCreateCommand.sh +++ b/.devcontainer/postCreateCommand.sh @@ -11,10 +11,10 @@ python3 -m venv /home/inventree/dev/venv --system-site-packages --upgrade-deps invoke update -s # Configure dev environment -invoke setup-dev +invoke dev.setup-dev # Install required frontend packages -invoke frontend-install +invoke dev.frontend-install # remove existing gitconfig created by "Avoiding Dubious Ownership" step # so that it gets copied from host to the container to have your global diff --git a/.github/actions/migration/action.yaml b/.github/actions/migration/action.yaml index 22c5d45864..eddec9a9da 100644 --- a/.github/actions/migration/action.yaml +++ b/.github/actions/migration/action.yaml @@ -9,7 +9,7 @@ runs: shell: bash run: | invoke migrate - invoke import-fixtures + invoke dev.import-fixtures invoke export-records -f data.json python3 ./src/backend/InvenTree/manage.py flush --noinput invoke migrate diff --git a/.github/workflows/check_translations.yaml b/.github/workflows/check_translations.yaml index 3377460f6e..fb21065b53 100644 --- a/.github/workflows/check_translations.yaml +++ b/.github/workflows/check_translations.yaml @@ -37,6 +37,6 @@ jobs: install: true apt-dependency: gettext - name: Test Translations - run: invoke translate + run: invoke dev.translate - name: Check Migration Files run: python3 .github/scripts/check_migration_files.py diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 4145b2dc60..a96c9523bc 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -97,7 +97,7 @@ jobs: run: | docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run inventree-dev-server invoke install docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run inventree-dev-server invoke update - docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run inventree-dev-server invoke setup-dev + docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run inventree-dev-server invoke dev.setup-dev docker compose --project-directory . -f contrib/container/dev-docker-compose.yml up -d docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run inventree-dev-server invoke wait - name: Check Data Directory @@ -115,10 +115,10 @@ jobs: - name: Run Unit Tests run: | echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> contrib/container/docker.dev.env - docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run --rm inventree-dev-server invoke test --disable-pty + docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run --rm inventree-dev-server invoke dev.test --disable-pty - name: Run Migration Tests run: | - docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run --rm inventree-dev-server invoke test --migrations + docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run --rm inventree-dev-server invoke dev.test --migrations - name: Clean up test folder run: | rm -rf InvenTree/_testfolder diff --git a/.github/workflows/qc_checks.yaml b/.github/workflows/qc_checks.yaml index 7aac3da4a2..2d98aacd98 100644 --- a/.github/workflows/qc_checks.yaml +++ b/.github/workflows/qc_checks.yaml @@ -157,7 +157,7 @@ jobs: dev-install: true update: true - name: Export API Documentation - run: invoke schema --ignore-warnings --filename src/backend/InvenTree/schema.yml + run: invoke dev.schema --ignore-warnings --filename src/backend/InvenTree/schema.yml - name: Upload schema uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # pin@v4.4.0 with: @@ -191,7 +191,7 @@ jobs: diff --color -u src/backend/InvenTree/schema.yml api.yaml diff -u src/backend/InvenTree/schema.yml api.yaml && echo "no difference in API schema " || exit 2 - name: Check schema - including warnings - run: invoke schema + run: invoke dev.schema continue-on-error: true - name: Extract version for publishing id: version @@ -262,9 +262,9 @@ jobs: run: git clone --depth 1 https://github.com/inventree/${{ env.wrapper_name }} ./${{ env.wrapper_name }} - name: Start InvenTree Server run: | - invoke delete-data -f - invoke import-fixtures - invoke server -a 127.0.0.1:12345 & + invoke dev.delete-data -f + invoke dev.import-fixtures + invoke dev.server -a 127.0.0.1:12345 & invoke wait - name: Run Tests For `${{ env.wrapper_name }}` run: | @@ -302,11 +302,11 @@ jobs: - name: Data Export Test uses: ./.github/actions/migration - name: Test Translations - run: invoke translate + run: invoke dev.translate - name: Check Migration Files run: python3 .github/scripts/check_migration_files.py - name: Coverage Tests - run: invoke test --coverage + run: invoke dev.test --coverage - name: Upload coverage reports to Codecov uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # pin@v4.5.0 if: always() @@ -355,7 +355,7 @@ jobs: dev-install: true update: true - name: Run Tests - run: invoke test + run: invoke dev.test - name: Data Export Test uses: ./.github/actions/migration @@ -399,7 +399,7 @@ jobs: dev-install: true update: true - name: Run Tests - run: invoke test + run: invoke dev.test - name: Data Export Test uses: ./.github/actions/migration @@ -438,7 +438,7 @@ jobs: dev-install: true update: true - name: Run Tests - run: invoke test --migrations --report --coverage + run: invoke dev.test --migrations --report --coverage - name: Upload coverage reports to Codecov uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # pin@v4.5.0 if: always() @@ -525,11 +525,11 @@ jobs: install: true update: true - name: Set up test data - run: invoke setup-test -i + run: invoke dev.setup-test -i - name: Rebuild thumbnails - run: invoke rebuild-thumbnails + run: invoke int.rebuild-thumbnails - name: Install dependencies - run: inv frontend-compile + run: invoke int.frontend-compile - name: Install Playwright Browsers run: cd src/frontend && npx playwright install --with-deps - name: Run Playwright tests diff --git a/.github/workflows/translations.yaml b/.github/workflows/translations.yaml index 2657d22715..5fcdf05431 100644 --- a/.github/workflows/translations.yaml +++ b/.github/workflows/translations.yaml @@ -39,7 +39,7 @@ jobs: npm: true apt-dependency: gettext - name: Make Translations - run: invoke translate + run: invoke dev.translate - name: Remove compiled static files run: rm -rf src/backend/InvenTree/static - name: Remove all local changes that are not *.po files diff --git a/.vscode/tasks.json b/.vscode/tasks.json index ffa8d8d36b..335cc9a673 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -9,61 +9,61 @@ { "label": "worker", "type": "shell", - "command": "inv worker", + "command": "invoke int.worker", "problemMatcher": [], }, { "label": "clean-settings", "type": "shell", - "command": "inv clean-settings", + "command": "invoke int.clean-settings", "problemMatcher": [], }, { "label": "delete-data", "type": "shell", - "command": "inv delete-data", + "command": "invoke dev.delete-data", "problemMatcher": [], }, { "label": "migrate", "type": "shell", - "command": "inv migrate", + "command": "invoke migrate", "problemMatcher": [], }, { "label": "server", "type": "shell", - "command": "inv server", + "command": "invoke dev.server", "problemMatcher": [], }, { "label": "setup-dev", "type": "shell", - "command": "inv setup-dev", + "command": "invoke dev.setup-dev", "problemMatcher": [], }, { "label": "setup-test", "type": "shell", - "command": "inv setup-test -i --path dev/inventree-demo-dataset", + "command": "invoke dev.setup-test -i --path dev/inventree-demo-dataset", "problemMatcher": [], }, { "label": "superuser", "type": "shell", - "command": "inv superuser", + "command": "invoke superuser", "problemMatcher": [], }, { "label": "test", "type": "shell", - "command": "inv test", + "command": "invoke dev.test", "problemMatcher": [], }, { "label": "update", "type": "shell", - "command": "inv update", + "command": "invoke update", "problemMatcher": [], }, ] diff --git a/contrib/container/Dockerfile b/contrib/container/Dockerfile index eee14b92e8..27a452f858 100644 --- a/contrib/container/Dockerfile +++ b/contrib/container/Dockerfile @@ -115,7 +115,7 @@ RUN apk add --no-cache --update nodejs npm yarn RUN yarn config set network-timeout 600000 -g COPY src ${INVENTREE_HOME}/src COPY tasks.py ${INVENTREE_HOME}/tasks.py -RUN cd ${INVENTREE_HOME} && inv frontend-compile +RUN cd ${INVENTREE_HOME} && invoke int.frontend-compile # InvenTree production image: # - Copies required files from local directory diff --git a/contrib/container/dev-docker-compose.yml b/contrib/container/dev-docker-compose.yml index 54636da3d5..94e72abfc3 100644 --- a/contrib/container/dev-docker-compose.yml +++ b/contrib/container/dev-docker-compose.yml @@ -56,7 +56,7 @@ services: inventree-dev-worker: image: inventree-dev-image build: *build_config - command: invoke worker + command: invoke int.worker depends_on: - inventree-dev-server volumes: diff --git a/contrib/container/docker-compose.yml b/contrib/container/docker-compose.yml index 6a0b001f8b..93440934db 100644 --- a/contrib/container/docker-compose.yml +++ b/contrib/container/docker-compose.yml @@ -83,7 +83,7 @@ services: # If you wish to specify a particular InvenTree version, do so here image: inventree/inventree:${INVENTREE_TAG:-stable} container_name: inventree-worker - command: invoke worker + command: invoke int.worker depends_on: - inventree-server env_file: diff --git a/contrib/packager.io/functions.sh b/contrib/packager.io/functions.sh index 29c9d53ff4..33886a3946 100755 --- a/contrib/packager.io/functions.sh +++ b/contrib/packager.io/functions.sh @@ -287,7 +287,7 @@ function update_or_install() { # Run update as app user echo "# Updating InvenTree" sudo -u ${APP_USER} --preserve-env=$SETUP_ENVS bash -c "cd ${APP_HOME} && pip install wheel" - sudo -u ${APP_USER} --preserve-env=$SETUP_ENVS bash -c "cd ${APP_HOME} && invoke update | sed -e 's/^/# inv update| /;'" + sudo -u ${APP_USER} --preserve-env=$SETUP_ENVS bash -c "cd ${APP_HOME} && invoke update | sed -e 's/^/# invoke update| /;'" # Make sure permissions are correct again echo "# Set permissions for data dir and media: ${DATA_DIR}" diff --git a/contrib/packager.io/preinstall.sh b/contrib/packager.io/preinstall.sh index 5306184b09..f40a271e36 100755 --- a/contrib/packager.io/preinstall.sh +++ b/contrib/packager.io/preinstall.sh @@ -9,9 +9,9 @@ export SETUP_ENVS=PATH,APP_HOME,INVENTREE_MEDIA_ROOT,INVENTREE_STATIC_ROOT,INVEN if test -f "${APP_HOME}/env/bin/pip"; then # Check if clear-generated is available - if sudo -u ${APP_USER} --preserve-env=$SETUP_ENVS bash -c "cd ${APP_HOME} && invoke clear-generated --help" > /dev/null 2>&1; then + if sudo -u ${APP_USER} --preserve-env=$SETUP_ENVS bash -c "cd ${APP_HOME} && invoke int.clear-generated --help" > /dev/null 2>&1; then echo "# Clearing precompiled files" - sudo -u ${APP_USER} --preserve-env=$SETUP_ENVS bash -c "cd ${APP_HOME} && invoke clear-generated" + sudo -u ${APP_USER} --preserve-env=$SETUP_ENVS bash -c "cd ${APP_HOME} && invoke int.clear-generated" else echo "# Clearing precompiled files - skipping" fi diff --git a/docs/docs/api/api.md b/docs/docs/api/api.md index 7f2c9328d0..0ac6366b47 100644 --- a/docs/docs/api/api.md +++ b/docs/docs/api/api.md @@ -22,10 +22,10 @@ The API is self-documenting, and the documentation is provided alongside any Inv ### Generating Schema File -If you want to generate the API schema file yourself (for example to use with an external client, use the `invoke schema` command. Run with the `-help` command to see available options. +If you want to generate the API schema file yourself (for example to use with an external client, use the `invoke dev.schema` command. Run with the `-help` command to see available options. ``` -invoke schema -help +invoke dev.schema -help ``` ## Authentication diff --git a/docs/docs/develop/contributing.md b/docs/docs/develop/contributing.md index 931d8111fe..fde8f909c7 100644 --- a/docs/docs/develop/contributing.md +++ b/docs/docs/develop/contributing.md @@ -52,7 +52,7 @@ invoke setup-dev ## Branches and Versioning -InvenTree roughly follow the [GitLab flow](https://docs.gitlab.com/ee/topics/gitlab_flow.html) branching style, to allow simple management of multiple tagged releases, short-lived branches, and development on the main branch. +InvenTree roughly follow the [GitLab flow](https://about.gitlab.com/topics/version-control/what-are-gitlab-flow-best-practices/) branching style, to allow simple management of multiple tagged releases, short-lived branches, and development on the main branch. There are nominally 5 active branches: - `master` - The main development branch diff --git a/docs/docs/develop/react-frontend.md b/docs/docs/develop/react-frontend.md index ead305c912..4536372e31 100644 --- a/docs/docs/develop/react-frontend.md +++ b/docs/docs/develop/react-frontend.md @@ -14,7 +14,7 @@ The React frontend requires its own packages that aren't installed via the usual #### Docker Run the following command: -`docker compose run inventree-dev-server invoke frontend-compile` +`docker compose run inventree-dev-server invoke int.frontend-compile` This will install the required packages for running the React frontend on your InvenTree dev server. #### Devcontainer @@ -24,14 +24,14 @@ This will install the required packages for running the React frontend on your I Open a new terminal from the top menu by clicking `Terminal > New Terminal` Make sure this terminal is running within the virtual env. The start of the last line should display `(venv)` -Run the command `invoke frontend-compile`. Wait for this to finish +Run the command `invoke int.frontend-compile`. Wait for this to finish ### Running After finishing the install, you need to launch a frontend server to be able to view the new UI. Using the previously described ways of running commands, execute the following: -`invoke frontend-dev` in your environment +`invoke dev.frontend-dev` in your environment This command does not run as a background daemon, and will occupy the window it's ran in. ### Accessing @@ -40,7 +40,7 @@ When the frontend server is running, it will be available on port 5173. i.e: https://localhost:5173/ !!! note "Backend Server" - The InvenTree backend server must also be running, for the frontend interface to have something to connect to! To launch a backend server, use the `invoke server` command. + The InvenTree backend server must also be running, for the frontend interface to have something to connect to! To launch a backend server, use the `invoke dev.server` command. ### Debugging diff --git a/docs/docs/faq.md b/docs/docs/faq.md index d8b51ecac6..17cfdf84fe 100644 --- a/docs/docs/faq.md +++ b/docs/docs/faq.md @@ -107,7 +107,7 @@ The background worker process must be started separately to the web-server appli From the top-level source directory, run the following command from a separate terminal, while the server is already running: ``` -invoke worker +invoke int.worker ``` !!! info "Supervisor" diff --git a/docs/docs/start/bare_dev.md b/docs/docs/start/bare_dev.md index fdfb02b4cc..1e02469c63 100644 --- a/docs/docs/start/bare_dev.md +++ b/docs/docs/start/bare_dev.md @@ -17,7 +17,7 @@ InvenTree includes a simple server application, suitable for use in a developmen To run the development server on a local machine, run the command: ``` -(env) invoke server +(env) invoke dev.server ``` This will launch the InvenTree web interface at `http://127.0.0.1:8000`. @@ -25,7 +25,7 @@ This will launch the InvenTree web interface at `http://127.0.0.1:8000`. A different port can be specified using the `-a` flag: ``` -(env) invoke server -a 127.0.0.1:8123 +(env) invoke dev.server -a 127.0.0.1:8123 ``` Serving on the address `127.0.0.1` means that InvenTree will only be available *on that computer*. The server will be accessible from a web browser on the same computer, but not from any other computers on the local network. @@ -35,7 +35,7 @@ Serving on the address `127.0.0.1` means that InvenTree will only be available * To enable access to the InvenTree server from other computers on a local network, you need to know the IP of the computer running the server. For example, if the server IP address is `192.168.120.1`: ``` -(env) invoke server -a 192.168.120.1:8000 +(env) invoke dev.server -a 192.168.120.1:8000 ``` ## Background Worker @@ -52,7 +52,7 @@ source ./env/bin/activate ### Start Background Worker ``` -(env) invoke worker +(env) invoke int.worker ``` This will start the background process manager in the current shell. diff --git a/docs/docs/start/docker_install.md b/docs/docs/start/docker_install.md index e2c6d16b26..489e904898 100644 --- a/docs/docs/start/docker_install.md +++ b/docs/docs/start/docker_install.md @@ -202,7 +202,7 @@ Any persistent files generated by the Caddy container (such as certificates, etc To quickly get started with a [demo dataset](../demo.md), you can run the following command: ``` -docker compose run --rm inventree-server invoke setup-test -i +docker compose run --rm inventree-server invoke dev.setup-test -i ``` This will install the InvenTree demo dataset into your instance. @@ -210,7 +210,7 @@ This will install the InvenTree demo dataset into your instance. To start afresh (and completely remove the existing database), run the following command: ``` -docker compose run --rm inventree-server invoke delete-data +docker compose run --rm inventree-server invoke dev.delete-data ``` ## Install custom packages @@ -247,7 +247,7 @@ index 8adee63..dc3993c 100644 - image: inventree/inventree:${INVENTREE_TAG:-stable} + image: inventree/inventree:${INVENTREE_TAG:-stable}-custom + pull_policy: never - command: invoke worker + command: invoke int.worker depends_on: - inventree-server ``` diff --git a/docs/mlc_config.json b/docs/mlc_config.json index 4146cd4cb2..9de13b7050 100644 --- a/docs/mlc_config.json +++ b/docs/mlc_config.json @@ -6,6 +6,9 @@ { "pattern": "http://localhost" }, + { + "pattern": "https://localhost:5173/" + }, { "pattern": "http://127.0.0.1" }, diff --git a/readthedocs.yml b/readthedocs.yml index f9a08ce2a9..f9f48ec0e2 100644 --- a/readthedocs.yml +++ b/readthedocs.yml @@ -17,6 +17,6 @@ build: - echo "Generating API schema file" - pip install -U invoke - invoke migrate - - invoke export-settings-definitions --filename docs/inventree_settings.json --overwrite - - invoke schema --filename docs/schema.yml --ignore-warnings + - invoke int.export-settings-definitions --filename docs/inventree_settings.json --overwrite + - invoke dev.schema --filename docs/schema.yml --ignore-warnings - python docs/extract_schema.py docs/schema.yml diff --git a/src/frontend/playwright.config.ts b/src/frontend/playwright.config.ts index 2914f54f5a..2a48cd0288 100644 --- a/src/frontend/playwright.config.ts +++ b/src/frontend/playwright.config.ts @@ -36,7 +36,7 @@ export default defineConfig({ timeout: 120 * 1000 }, { - command: 'invoke server -a 127.0.0.1:8000', + command: 'invoke dev.server -a 127.0.0.1:8000', env: { INVENTREE_DEBUG: 'True' }, diff --git a/tasks.py b/tasks.py index 4a345b46f5..eb766c8601 100644 --- a/tasks.py +++ b/tasks.py @@ -11,7 +11,7 @@ from pathlib import Path from platform import python_version from typing import Optional -from invoke import task +from invoke import Collection, task def checkPythonVersion(): @@ -367,7 +367,7 @@ def translate_stats(c): The file generated from this is needed for the UI. """ # Recompile the translation files (.mo) - # We do not run 'invoke translate' here, as that will touch the source (.po) files too! + # We do not run 'invoke dev.translate' here, as that will touch the source (.po) files too! try: manage(c, 'compilemessages', pty=True) except Exception: @@ -1431,7 +1431,7 @@ def docs_server(c, address='localhost:8080', compile_schema=False): @task def clear_generated(c): - """Clear generated files from `inv update`.""" + """Clear generated files from `invoke update`.""" # pyc/pyo files run(c, 'find . -name "*.pyc" -exec rm -f {} +') run(c, 'find . -name "*.pyo" -exec rm -f {} +') @@ -1441,3 +1441,54 @@ def clear_generated(c): # Generated translations run(c, 'find . -name "django.mo" -exec rm -f {} +') run(c, 'find . -name "messages.mo" -exec rm -f {} +') + + +# Collection sorting +development = Collection( + delete_data, + docs_server, + frontend_dev, + gunicorn, + import_fixtures, + schema, + server, + setup_dev, + setup_test, + test, + test_translations, + translate, +) +internal = Collection( + clean_settings, + clear_generated, + export_settings_definitions, + frontend_build, + frontend_check, + frontend_compile, + frontend_install, + frontend_trans, + render_js_files, + rebuild_models, + rebuild_thumbnails, + showmigrations, + translate_stats, + worker, +) +ns = Collection( + backup, + export_records, + frontend_download, + import_records, + install, + migrate, + plugins, + remove_mfa, + restore, + static, + superuser, + update, + version, + wait, +) +ns.add_collection(development, 'dev') +ns.add_collection(internal, 'int')