From 2e81a304d17338b299188e6211a7acb468c2bbe9 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 28 Feb 2024 15:04:14 +1100 Subject: [PATCH] Devcontainer postgresql (#6590) * Working on devcontainer with postgresql * Fix for docker-compose.yml * Update postCreateCommand * Tweak docker compose file * Fix Dockerfile - Do not use uv (breaks process) * Update postCreateCommand.sh - Skip database backup * Tweak file * Further improvements - Remove 'devcontainer' Dockerfile target - Fix postCreateCommand * Further cleanup * Reduce SQL errors - Use filter().exists() rather than get() * Set default SITE_URL * Docs updates * Fix hard-coded django version * Update faq.md * Typo fix: PluginObject -> PluginConfig * Docs: strict mode * docs: fix link * docs: fix typo * Fix error message * Revert change to config_template default --- .devcontainer/devcontainer.json | 39 ++-- .devcontainer/docker-compose.yml | 41 ++++ .devcontainer/postCreateCommand.sh | 14 +- .vscode/launch.json | 2 +- .vscode/tasks.json | 2 +- CONTRIBUTING.md | 265 +------------------------- Dockerfile | 15 +- InvenTree/common/models.py | 14 +- InvenTree/plugin/api.py | 4 +- InvenTree/plugin/registry.py | 6 +- docs/docs/develop/contributing.md | 288 ++++++++++++++++++++++++++++- docs/docs/develop/devcontainer.md | 26 ++- docs/docs/develop/starting.md | 27 --- docs/docs/faq.md | 2 +- docs/docs/start/intro.md | 2 +- docs/mkdocs.yml | 1 - 16 files changed, 388 insertions(+), 360 deletions(-) create mode 100644 .devcontainer/docker-compose.yml delete mode 100644 docs/docs/develop/starting.md diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 7aae820122..6c6a62f9f9 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,16 +1,11 @@ // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: // https://github.com/microsoft/vscode-dev-containers/tree/v0.241.1/containers/python-3 { - "name": "InvenTree", - "build": { - "dockerfile": "../Dockerfile", - "context": "..", - "target": "devcontainer", - "args": { - "base_image": "mcr.microsoft.com/vscode/devcontainers/base:alpine-3.18", - "workspace": "${containerWorkspaceFolder}" - } - }, + "name": "InvenTree devcontainer", + "dockerComposeFile": "docker-compose.yml", + "service": "inventree", + "overrideCommand": true, + "workspaceFolder": "/home/inventree/", // Configure tool-specific properties. "customizations": { @@ -42,37 +37,27 @@ }, // Use 'forwardPorts' to make a list of ports inside the container available locally. - "forwardPorts": [5173, 8000], + "forwardPorts": [5173, 8000, 8080], "portsAttributes": { "5173": { - "label": "Vite server" + "label": "Vite Server" }, "8000": { - "label": "InvenTree server" + "label": "InvenTree Server" + }, + "8080": { + "label": "mkdocs server" } }, // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "./.devcontainer/postCreateCommand.sh ${containerWorkspaceFolder}", + "postCreateCommand": ".devcontainer/postCreateCommand.sh", // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. "remoteUser": "vscode", "containerUser": "vscode", "remoteEnv": { - // InvenTree config - "INVENTREE_DEBUG": "True", - "INVENTREE_LOG_LEVEL": "INFO", - "INVENTREE_DB_ENGINE": "sqlite3", - "INVENTREE_DB_NAME": "${containerWorkspaceFolder}/dev/database.sqlite3", - "INVENTREE_MEDIA_ROOT": "${containerWorkspaceFolder}/dev/media", - "INVENTREE_STATIC_ROOT": "${containerWorkspaceFolder}/dev/static", - "INVENTREE_BACKUP_DIR": "${containerWorkspaceFolder}/dev/backup", - "INVENTREE_CONFIG_FILE": "${containerWorkspaceFolder}/dev/config.yaml", - "INVENTREE_SECRET_KEY_FILE": "${containerWorkspaceFolder}/dev/secret_key.txt", - "INVENTREE_PLUGINS_ENABLED": "True", - "INVENTREE_PLUGIN_DIR": "${containerWorkspaceFolder}/dev/plugins", - "INVENTREE_PLUGIN_FILE": "${containerWorkspaceFolder}/dev/plugins.txt", // Python config "PIP_USER": "no", diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000000..ad8faf193f --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,41 @@ +version: "3" + +services: + db: + image: postgres:13 + restart: unless-stopped + expose: + - 5432/tcp + volumes: + - postgresql:/var/lib/postgresql/data:z + environment: + POSTGRES_DB: inventree + POSTGRES_USER: inventree_user + POSTGRES_PASSWORD: inventree_password + + inventree: + build: + context: .. + target: dev + args: + base_image: "mcr.microsoft.com/vscode/devcontainers/base:alpine-3.18" + workspace: "${containerWorkspaceFolder}" + data_dir: "dev" + volumes: + - ../:/home/inventree:z + + environment: + INVENTREE_DEBUG: True + INVENTREE_DB_ENGINE: postgresql + INVENTREE_DB_NAME: inventree + INVENTREE_DB_HOST: db + INVENTREE_DB_USER: inventree_user + INVENTREE_DB_PASSWORD: inventree_password + INVENTREE_PLUGINS_ENABLED: True + INVENTREE_PY_ENV: /home/inventree/dev/venv + + depends_on: + - db + +volumes: + postgresql: diff --git a/.devcontainer/postCreateCommand.sh b/.devcontainer/postCreateCommand.sh index b124007580..04be371ef1 100755 --- a/.devcontainer/postCreateCommand.sh +++ b/.devcontainer/postCreateCommand.sh @@ -1,20 +1,14 @@ #!/bin/bash # Avoiding Dubious Ownership in Dev Containers for setup commands that use git -# Note that the local workspace directory is passed through as the first argument $1 -git config --global --add safe.directory $1 - -# create folders -mkdir -p $1/dev/{commandhistory,plugins} -cd $1 +git config --global --add safe.directory /home/inventree # create venv -python3 -m venv $1/dev/venv -. $1/dev/venv/bin/activate +python3 -m venv /home/inventree/dev/venv --system-site-packages --upgrade-deps +. /home/inventree/dev/venv/bin/activate # setup InvenTree server -pip install invoke -invoke update +invoke update -s invoke setup-dev invoke frontend-install diff --git a/.vscode/launch.json b/.vscode/launch.json index 8d01312e36..a3029a0325 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -14,7 +14,7 @@ "justMyCode": true }, { - "name": "Python: Django - 3rd party", + "name": "InvenTree Server - 3rd party", "type": "python", "request": "launch", "program": "${workspaceFolder}/InvenTree/manage.py", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 35a9d40f84..ffa8d8d36b 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -45,7 +45,7 @@ { "label": "setup-test", "type": "shell", - "command": "inv setup-test --path dev/inventree-demo-dataset", + "command": "inv setup-test -i --path dev/inventree-demo-dataset", "problemMatcher": [], }, { diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b079f12437..aef77cdc3b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,263 +1,6 @@ +### Contributing to InvenTree + Hi there, thank you for your interest in contributing! -Please read the contribution guidelines below, before submitting your first pull request to the InvenTree codebase. +Please read our contribution guidelines, before submitting your first pull request to the InvenTree codebase. -## Quickstart - -The following commands will get you quickly configure and run a development server, complete with a demo dataset to work with: - -### Bare Metal - -```bash -git clone https://github.com/inventree/InvenTree.git && cd InvenTree -python3 -m venv env && source env/bin/activate -pip install invoke && invoke -pip install invoke && invoke setup-dev --tests -``` - -### Docker - -```bash -git clone https://github.com/inventree/InvenTree.git && cd InvenTree -docker compose run inventree-dev-server invoke install -docker compose run inventree-dev-server invoke setup-test --dev -docker compose up -d -``` - -Read the [InvenTree setup documentation](https://docs.inventree.org/en/latest/start/intro/) for a complete installation reference guide. - -### Setup Devtools - -Run the following command to set up all toolsets for development. - -```bash -invoke setup-dev -``` - -*We recommend you run this command before starting to contribute. This will install and set up `pre-commit` to run some checks before each commit and help reduce errors.* - -## 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. - -### Version Numbering - -InvenTree version numbering follows the [semantic versioning](https://semver.org/) specification. - -### Master Branch - -The HEAD of the "main" or "master" branch of InvenTree represents the current "latest" state of code development. - -- All feature branches are merged into master -- All bug fixes are merged into master - -**No pushing to master:** New features must be submitted as a pull request from a separate branch (one branch per feature). - -### Feature Branches - -Feature branches should be branched *from* the *master* branch. - -- One major feature per branch / pull request -- Feature pull requests are merged back *into* the master branch -- Features *may* also be merged into a release candidate branch - -### Stable Branch - -The HEAD of the "stable" branch represents the latest stable release code. - -- Versioned releases are merged into the "stable" branch -- Bug fix branches are made *from* the "stable" branch - -#### Release Candidate Branches - -- Release candidate branches are made from master, and merged into stable. -- RC branches are targeted at a major/minor version e.g. "0.5" -- When a release candidate branch is merged into *stable*, the release is tagged - -#### Bugfix Branches - -- If a bug is discovered in a tagged release version of InvenTree, a "bugfix" or "hotfix" branch should be made *from* that tagged release -- When approved, the branch is merged back *into* stable, with an incremented PATCH number (e.g. 0.4.1 -> 0.4.2) -- The bugfix *must* also be cherry picked into the *master* branch. - -## API versioning - -The [API version](https://github.com/inventree/InvenTree/blob/master/InvenTree/InvenTree/api_version.py) needs to be bumped every time when the API is changed. - -## Environment -### Target version -We are currently targeting: -| Name | Minimum version | Note | -|---|---| --- | -| Python | 3.9 | | -| Django | 3.2 | | -| Node | 18 | Only needed for frontend development | - -### Auto creating updates -The following tools can be used to auto-upgrade syntax that was depreciated in new versions: -```bash -pip install pyupgrade -pip install django-upgrade -``` - -To update the codebase run the following script. -```bash -pyupgrade `find . -name "*.py"` -django-upgrade --target-version 3.2 `find . -name "*.py"` -``` - -## Credits -If you add any new dependencies / libraries, they need to be added to [the docs](https://github.com/inventree/inventree/blob/master/docs/docs/credits.md). Please try to do that as timely as possible. - - -## Migration Files - -Any required migration files **must** be included in the commit, or the pull-request will be rejected. If you change the underlying database schema, make sure you run `invoke migrate` and commit the migration files before submitting the PR. - -*Note: A github action checks for unstaged migration files and will reject the PR if it finds any!* - -## Unit Testing - -Any new code should be covered by unit tests - a submitted PR may not be accepted if the code coverage for any new features is insufficient, or the overall code coverage is decreased. - -The InvenTree code base makes use of [GitHub actions](https://github.com/features/actions) to run a suite of automated tests against the code base every time a new pull request is received. These actions include (but are not limited to): - -- Checking Python and Javascript code against standard style guides -- Running unit test suite -- Automated building and pushing of docker images -- Generating translation files - -The various github actions can be found in the `./github/workflows` directory - -### Run tests locally - -To run test locally, use: -``` -invoke test -``` - -To run only partial tests, for example for a module use: -``` -invoke test --runtest order -``` - -To see all the available options: - -``` -invoke test --help -``` - -## Code Style - -Code style is automatically checked as part of the project's CI pipeline on GitHub. This means that any pull requests which do not conform to the style guidelines will fail CI checks. - -### Backend Code - -Backend code (Python) is checked against the [PEP style guidelines](https://peps.python.org/pep-0008/). Please write docstrings for each function and class - we follow the [google doc-style](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) for python. - -### Frontend Code - -Frontend code (Javascript) is checked using [eslint](https://eslint.org/). While docstrings are not enforced for front-end code, good code documentation is encouraged! - -### Running Checks Locally - -If you have followed the setup devtools procedure, then code style checking is performend automatically whenever you commit changes to the code. - -### Django templates - -Django are checked by [djlint](https://github.com/Riverside-Healthcare/djlint) through pre-commit. - -The following rules out of the [default set](https://djlint.com/docs/linter/) are not applied: -```bash -D018: (Django) Internal links should use the { % url ... % } pattern -H006: Img tag should have height and width attributes -H008: Attributes should be double quoted -H021: Inline styles should be avoided -H023: Do not use entity references -H025: Tag seems to be an orphan -H030: Consider adding a meta description -H031: Consider adding meta keywords -T002: Double quotes should be used in tags -``` - - -## Documentation - -New features or updates to existing features should be accompanied by user documentation. - -## Translations - -Any user-facing strings *must* be passed through the translation engine. - -- InvenTree code is written in English -- User translatable strings are provided in English as the primary language -- Secondary language translations are provided [via Crowdin](https://crowdin.com/project/inventree) - -*Note: Translation files are updated via GitHub actions - you do not need to compile translations files before submitting a pull request!* - -### Python Code - -For strings exposed via Python code, use the following format: - -```python -from django.utils.translation import gettext_lazy as _ - -user_facing_string = _('This string will be exposed to the translation engine!') -``` - -### Templated Strings - -HTML and javascript files are passed through the django templating engine. Translatable strings are implemented as follows: - -```html -{ % load i18n % } - -{ % trans "This string will be translated" % } - this string will not! -``` - -## Github use - -### Tags - -The tags describe issues and PRs in multiple areas: - -| Area | Name | Description | -| --- | --- | --- | -| Triage Labels | | | -| | triage:not-checked | Item was not checked by the core team | -| | triage:not-approved | Item is not green-light by maintainer | -| Type Labels | | | -| | breaking | Indicates a major update or change which breaks compatibility | -| | bug | Identifies a bug which needs to be addressed | -| | dependency | Relates to a project dependency | -| | duplicate | Duplicate of another issue or PR | -| | enhancement | This is an suggested enhancement, extending the functionality of an existing feature | -| | experimental | This is a new *experimental* feature which needs to be enabled manually | -| | feature | This is a new feature, introducing novel functionality | -| | help wanted | Assistance required | -| | invalid | This issue or PR is considered invalid | -| | inactive | Indicates lack of activity | -| | migration | Database migration, requires special attention | -| | question | This is a question | -| | roadmap | This is a roadmap feature with no immediate plans for implementation | -| | security | Relates to a security issue | -| | starter | Good issue for a developer new to the project | -| | wontfix | No work will be done against this issue or PR | -| Feature Labels | | | -| | API | Relates to the API | -| | barcode | Barcode scanning and integration | -| | build | Build orders | -| | importer | Data importing and processing | -| | order | Purchase order and sales orders | -| | part | Parts | -| | plugin | Plugin ecosystem | -| | pricing | Pricing functionality | -| | report | Report generation | -| | stock | Stock item management | -| | user interface | User interface | -| Ecosystem Labels | | | -| | backport | Tags that the issue will be backported to a stable branch as a bug-fix | -| | demo | Relates to the InvenTree demo server or dataset | -| | docker | Docker / docker-compose | -| | CI | CI / unit testing ecosystem | -| | refactor | Refactoring existing code | -| | setup | Relates to the InvenTree setup / installation process | +Refer to our [contribution guidelines](https://docs.inventree.org/en/latest/develop/contributing/) for more information! diff --git a/Dockerfile b/Dockerfile index 1208960886..c87a7dea44 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,8 @@ ARG commit_tag="" ARG commit_hash="" ARG commit_date="" +ARG data_dir="data" + ENV PYTHONUNBUFFERED 1 ENV PIP_DISABLE_PIP_VERSION_CHECK 1 ENV INVOKE_RUN_SHELL="/bin/ash" @@ -27,7 +29,7 @@ ENV INVENTREE_DOCKER="true" # InvenTree paths ENV INVENTREE_HOME="/home/inventree" ENV INVENTREE_MNG_DIR="${INVENTREE_HOME}/InvenTree" -ENV INVENTREE_DATA_DIR="${INVENTREE_HOME}/data" +ENV INVENTREE_DATA_DIR="${INVENTREE_HOME}/${data_dir}" ENV INVENTREE_STATIC_ROOT="${INVENTREE_DATA_DIR}/static" ENV INVENTREE_MEDIA_ROOT="${INVENTREE_DATA_DIR}/media" ENV INVENTREE_BACKUP_DIR="${INVENTREE_DATA_DIR}/backup" @@ -94,7 +96,7 @@ FROM inventree_base as prebuild ENV PATH=/root/.local/bin:$PATH RUN ./install_build_packages.sh --no-cache --virtual .build-deps && \ - pip install --user uv --no-cache-dir && uv pip install -r base_requirements.txt -r requirements.txt --no-cache && \ + pip install --user uv --no-cache-dir && pip install -r base_requirements.txt -r requirements.txt --no-cache && \ apk --purge del .build-deps # Frontend builder image: @@ -139,7 +141,7 @@ EXPOSE 5173 # Install packages required for building python packages RUN ./install_build_packages.sh -RUN pip install uv --no-cache-dir && uv pip install -r base_requirements.txt --no-cache +RUN pip install uv --no-cache-dir && pip install -r base_requirements.txt --no-cache # Install nodejs / npm / yarn @@ -162,10 +164,3 @@ ENTRYPOINT ["/bin/ash", "./docker/init.sh"] # Launch the development server CMD ["invoke", "server", "-a", "${INVENTREE_WEB_ADDR}:${INVENTREE_WEB_PORT}"] - -# Image target for devcontainer -FROM dev as devcontainer - -ARG workspace="/workspaces/InvenTree" - -WORKDIR ${WORKSPACE} diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index f861d30fb3..9ca83c361a 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -675,12 +675,14 @@ class BaseInvenTreeSetting(models.Model): } try: - setting = cls.objects.get(**filters) - except cls.DoesNotExist: - if create: - setting = cls(key=key, **kwargs) - else: - return + setting = cls.objects.filter(**filters).first() + + if not setting: + if create: + setting = cls(key=key, **kwargs) + else: + return + except (OperationalError, ProgrammingError): if not key.startswith('_'): logger.warning("Database is locked, cannot set setting '%s'", key) diff --git a/InvenTree/plugin/api.py b/InvenTree/plugin/api.py index a4cf80d497..be16328c0a 100644 --- a/InvenTree/plugin/api.py +++ b/InvenTree/plugin/api.py @@ -289,13 +289,13 @@ def check_plugin(plugin_slug: str, plugin_pk: int) -> InvenTreePlugin: # Check that the 'plugin' specified is valid try: - plugin_cgf = PluginConfig.objects.get(**filter) + plugin_cgf = PluginConfig.objects.filter(**filter).first() except PluginConfig.DoesNotExist: raise NotFound(detail=f"Plugin '{ref}' not installed") if plugin_cgf is None: # This only occurs if the plugin mechanism broke - raise NotFound(detail=f"Plugin '{ref}' not found") # pragma: no cover + raise NotFound(detail=f"Plugin '{ref}' not installed") # pragma: no cover # Check that the plugin is activated if not plugin_cgf.active: diff --git a/InvenTree/plugin/registry.py b/InvenTree/plugin/registry.py index b51a797b96..ee68b0d04f 100644 --- a/InvenTree/plugin/registry.py +++ b/InvenTree/plugin/registry.py @@ -115,7 +115,11 @@ class PluginsRegistry: return None try: - cfg, _created = PluginConfig.objects.get_or_create(key=slug) + cfg = PluginConfig.objects.filter(key=slug).first() + + if not cfg: + cfg = PluginConfig.objects.create(key=slug) + except PluginConfig.DoesNotExist: return None except (IntegrityError, OperationalError, ProgrammingError): # pragma: no cover diff --git a/docs/docs/develop/contributing.md b/docs/docs/develop/contributing.md index 7aad5d3d27..12ed77faf7 100644 --- a/docs/docs/develop/contributing.md +++ b/docs/docs/develop/contributing.md @@ -1,3 +1,285 @@ -{! - include-markdown "../../../CONTRIBUTING.md" -!} +--- +title: Contribution Guide +--- + + +Please read the contribution guidelines below, before submitting your first pull request to the InvenTree codebase. + +## Quickstart + +The following commands will get you quickly configure and run a development server, complete with a demo dataset to work with: + +### Devcontainer + +The recommended method for getting up and running with an InvenTree development environment is to use our [devcontainer](https://code.visualstudio.com/docs/devcontainers/containers) setup in [vscode](https://code.visualstudio.com/). + +!!! success "Devcontainer Guide" + Refer to the [devcontainer guide](./devcontainer.md) for more information! + +### Docker + +To setup a development environment using [docker](../start/docker.md), run the following instructions: + +```bash +git clone https://github.com/inventree/InvenTree.git && cd InvenTree +docker compose run inventree-dev-server invoke install +docker compose run inventree-dev-server invoke setup-test --dev +docker compose up -d +``` + +### Bare Metal + +A "bare metal" development setup can be installed as follows: + +```bash +git clone https://github.com/inventree/InvenTree.git && cd InvenTree +python3 -m venv env && source env/bin/activate +pip install invoke && invoke +pip install invoke && invoke setup-dev --tests +``` + +Read the [InvenTree setup documentation](../start/intro.md) for a complete installation reference guide. + +### Setup Devtools + +Run the following command to set up all toolsets for development. + +```bash +invoke setup-dev +``` + +*We recommend you run this command before starting to contribute. This will install and set up `pre-commit` to run some checks before each commit and help reduce errors.* + +## 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. + +### Version Numbering + +InvenTree version numbering follows the [semantic versioning](https://semver.org/) specification. + +### Master Branch + +The HEAD of the "main" or "master" branch of InvenTree represents the current "latest" state of code development. + +- All feature branches are merged into master +- All bug fixes are merged into master + +**No pushing to master:** New features must be submitted as a pull request from a separate branch (one branch per feature). + +### Feature Branches + +Feature branches should be branched *from* the *master* branch. + +- One major feature per branch / pull request +- Feature pull requests are merged back *into* the master branch +- Features *may* also be merged into a release candidate branch + +### Stable Branch + +The HEAD of the "stable" branch represents the latest stable release code. + +- Versioned releases are merged into the "stable" branch +- Bug fix branches are made *from* the "stable" branch + +#### Release Candidate Branches + +- Release candidate branches are made from master, and merged into stable. +- RC branches are targeted at a major/minor version e.g. "0.5" +- When a release candidate branch is merged into *stable*, the release is tagged + +#### Bugfix Branches + +- If a bug is discovered in a tagged release version of InvenTree, a "bugfix" or "hotfix" branch should be made *from* that tagged release +- When approved, the branch is merged back *into* stable, with an incremented PATCH number (e.g. 0.4.1 -> 0.4.2) +- The bugfix *must* also be cherry picked into the *master* branch. + +## API versioning + +The [API version](https://github.com/inventree/InvenTree/blob/master/InvenTree/InvenTree/api_version.py) needs to be bumped every time when the API is changed. + +## Environment + +### Software Versions + +The core software modules are targeting the following versions: + +| Name | Minimum version | Note | +|---|---| --- | +| Python | {{ config.extra.min_python_version }} | Minimum required version | +| Invoke | {{ config.extra.min_invoke_version }} | Minimum required version | +| Django | {{ config.extra.django_version }} | Pinned version | +| Node | 18 | Only needed for frontend development | + +Any other software dependencies are handled by the project package config. + +### Auto creating updates + +The following tools can be used to auto-upgrade syntax that was depreciated in new versions: +```bash +pip install pyupgrade +pip install django-upgrade +``` + +To update the codebase run the following script. +```bash +pyupgrade `find . -name "*.py"` +django-upgrade --target-version {{ config.extra.django_version }} `find . -name "*.py"` +``` + +## Credits + +If you add any new dependencies / libraries, they should be added to [the credits page](../credits.md). + +## Migration Files + +Any required migration files **must** be included in the commit, or the pull-request will be rejected. If you change the underlying database schema, make sure you run `invoke migrate` and commit the migration files before submitting the PR. + +*Note: A github action checks for unstaged migration files and will reject the PR if it finds any!* + +## Unit Testing + +Any new code should be covered by unit tests - a submitted PR may not be accepted if the code coverage for any new features is insufficient, or the overall code coverage is decreased. + +The InvenTree code base makes use of [GitHub actions](https://github.com/features/actions) to run a suite of automated tests against the code base every time a new pull request is received. These actions include (but are not limited to): + +- Checking Python and Javascript code against standard style guides +- Running unit test suite +- Automated building and pushing of docker images +- Generating translation files + +The various github actions can be found in the `./github/workflows` directory + +### Run tests locally + +To run test locally, use: +``` +invoke test +``` + +To run only partial tests, for example for a module use: +``` +invoke test --runtest order +``` + +To see all the available options: + +``` +invoke test --help +``` + +## Code Style + +Code style is automatically checked as part of the project's CI pipeline on GitHub. This means that any pull requests which do not conform to the style guidelines will fail CI checks. + +### Backend Code + +Backend code (Python) is checked against the [PEP style guidelines](https://peps.python.org/pep-0008/). Please write docstrings for each function and class - we follow the [google doc-style](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) for python. + +### Frontend Code + +Frontend code (Javascript) is checked using [eslint](https://eslint.org/). While docstrings are not enforced for front-end code, good code documentation is encouraged! + +### Running Checks Locally + +If you have followed the setup devtools procedure, then code style checking is performend automatically whenever you commit changes to the code. + +### Django templates + +Django are checked by [djlint](https://github.com/Riverside-Healthcare/djlint) through pre-commit. + +The following rules out of the [default set](https://djlint.com/docs/linter/) are not applied: +```bash +D018: (Django) Internal links should use the { % url ... % } pattern +H006: Img tag should have height and width attributes +H008: Attributes should be double quoted +H021: Inline styles should be avoided +H023: Do not use entity references +H025: Tag seems to be an orphan +H030: Consider adding a meta description +H031: Consider adding meta keywords +T002: Double quotes should be used in tags +``` + + +## Documentation + +New features or updates to existing features should be accompanied by user documentation. + +## Translations + +Any user-facing strings *must* be passed through the translation engine. + +- InvenTree code is written in English +- User translatable strings are provided in English as the primary language +- Secondary language translations are provided [via Crowdin](https://crowdin.com/project/inventree) + +*Note: Translation files are updated via GitHub actions - you do not need to compile translations files before submitting a pull request!* + +### Python Code + +For strings exposed via Python code, use the following format: + +```python +from django.utils.translation import gettext_lazy as _ + +user_facing_string = _('This string will be exposed to the translation engine!') +``` + +### Templated Strings + +HTML and javascript files are passed through the django templating engine. Translatable strings are implemented as follows: + +```html +{ % load i18n % } + +{ % trans "This string will be translated" % } - this string will not! +``` + +## Github use + +### Tags + +The tags describe issues and PRs in multiple areas: + +| Area | Name | Description | +| --- | --- | --- | +| Triage Labels | | | +| | triage:not-checked | Item was not checked by the core team | +| | triage:not-approved | Item is not green-light by maintainer | +| Type Labels | | | +| | breaking | Indicates a major update or change which breaks compatibility | +| | bug | Identifies a bug which needs to be addressed | +| | dependency | Relates to a project dependency | +| | duplicate | Duplicate of another issue or PR | +| | enhancement | This is an suggested enhancement, extending the functionality of an existing feature | +| | experimental | This is a new *experimental* feature which needs to be enabled manually | +| | feature | This is a new feature, introducing novel functionality | +| | help wanted | Assistance required | +| | invalid | This issue or PR is considered invalid | +| | inactive | Indicates lack of activity | +| | migration | Database migration, requires special attention | +| | question | This is a question | +| | roadmap | This is a roadmap feature with no immediate plans for implementation | +| | security | Relates to a security issue | +| | starter | Good issue for a developer new to the project | +| | wontfix | No work will be done against this issue or PR | +| Feature Labels | | | +| | API | Relates to the API | +| | barcode | Barcode scanning and integration | +| | build | Build orders | +| | importer | Data importing and processing | +| | order | Purchase order and sales orders | +| | part | Parts | +| | plugin | Plugin ecosystem | +| | pricing | Pricing functionality | +| | report | Report generation | +| | stock | Stock item management | +| | user interface | User interface | +| Ecosystem Labels | | | +| | backport | Tags that the issue will be backported to a stable branch as a bug-fix | +| | demo | Relates to the InvenTree demo server or dataset | +| | docker | Docker / docker-compose | +| | CI | CI / unit testing ecosystem | +| | refactor | Refactoring existing code | +| | setup | Relates to the InvenTree setup / installation process | diff --git a/docs/docs/develop/devcontainer.md b/docs/docs/develop/devcontainer.md index 6975c46257..093e36b092 100644 --- a/docs/docs/develop/devcontainer.md +++ b/docs/docs/develop/devcontainer.md @@ -16,22 +16,29 @@ You need to make sure that you have the following tools installed before continu - [docker](https://www.docker.com/products/docker-desktop/) is needed to run the devcontainer - [vscode](https://code.visualstudio.com/Download) is needed to edit and debug code +#### Docker Containers + +The InvenTree devcontainer setup will install two docker containers: + +| Container | Description | +| --- | --- | +| db | InvenTree database (postgresql) | +| inventree | InvenTree server | + #### Setup/Installation 1. Clone the repository (If you want to submit changes fork it and use the url to your fork in the next step) ```bash git clone https://github.com/inventree/InvenTree.git ``` -2. open vscode, navigate to the extensions sidebar and search for `ms-vscode-remote.remote-containers`. Click on install. -3. open the cloned folder from above by clicking on `file > open folder` +2. Open vscode, navigate to the extensions sidebar and search for `ms-vscode-remote.remote-containers`. Click on install. +3. Open the cloned folder from above by clicking on `file > open folder` 4. vscode should now ask you if you'd like to reopen this folder in a devcontainer. Click `Reopen in Container`. If it does not ask you, open the command palette (CTRL/CMD+Shift+P) and search for `Reopen in Container`. This can take a few minutes until the image is downloaded, build and setup with all dependencies. 5. Open a new terminal from the top menu by clicking `Terminal > New Terminal` 6. The last line in your terminal should now show the text `(venv)` at the start of the line -7. From here' we need to setup the InvenTree specific development environment -8. From the newly opened terminal, run: `invoke install` -9. If you want test data on your server, run: `invoke setup-test --dev`. If not, run `invoke setup-dev` +7. You are done! You now should have a functioning InvenTree development installation -### Setup in codespaces +### Setup in Codespaces Open [inventree/InvenTree](https://github.com/inventree/InvenTree) with your browser and click on `Code`, select the `codespaces` tab and click on create codespace on current branch. This may can take a few minutes until your inventree development environment is setup. @@ -52,14 +59,14 @@ If you only need a superuser, run the `superuser` task. It should prompt you for #### Run background workers -If you need to process your queue with background workers, run the `worker` task. +If you need to process your queue with background workers, run the `worker` task. This is a foreground task which will execute in the terminal. ### Running InvenTree You can either only run InvenTree or use the integrated debugger for debugging. Goto the `Run and debug` side panel make sure `InvenTree Server` is selected. Click on the play button on the left. !!! tip "Debug with 3rd party" - Sometimes you need to debug also some 3rd party packages. Just select `python: Django - 3rd party` + Sometimes you need to debug also some 3rd party packages. Just select `InvenTree Servre - 3rd party` You can now set breakpoints and vscode will automatically pause execution if that point is hit. You can see all variables available in that context and evaluate some code with the debugger console at the bottom. Use the play or step buttons to continue execution. @@ -94,12 +101,15 @@ Your plugin should now be activateable from the InvenTree settings. You can also ### Troubleshooting #### Your ssh-keys are not available in the devcontainer but are loaded to the active `ssh-agent` on macOS + Make sure you enabled full disk access on macOS for vscode, otherwise your ssh-keys are not available inside the container (Ref: [Automatically add SSH keys to ssh-agent [comment]](https://github.com/microsoft/vscode-remote-release/issues/4024#issuecomment-831671081)). #### You're not able to use your gpg-keys inside the devcontainer to sign commits on macOS + Make sure you have `gnupg` and `pinentry-mac` installed and set up correctly. Read this [medium post](https://medium.com/@jma/setup-gpg-for-git-on-macos-4ad69e8d3733) for more info on how to set it up correctly. #### Where are the database, media files, ... stored? + Backups, Commandhistory, media/static files, venv, plugin.txt, secret_key.txt, ... are stored in the `dev` folder. If you want to start with a clean setup, you can remove that folder, but be aware that this will delete everything you already setup in InvenTree. ### Performance Improvements diff --git a/docs/docs/develop/starting.md b/docs/docs/develop/starting.md deleted file mode 100644 index f37f9d6ed9..0000000000 --- a/docs/docs/develop/starting.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: Getting started ---- - -InvenTree consists of a Django-based backend server, and a HTML / vanilla JS based frontend that uses Bootstrap. The main languages used are Python and Javascript. -As part of the larger project other languages/techniques are used, such as docker (dev/deployment), bash (installer) and markdown (documentation). - -### Getting started -#### Getting to know the basics - -The Django framework is a powerful tool for creating web applications. It is well documented and has a large community. The [Django documentation]({% include "django.html" %}) is a good place to start. - -In particular the [tutorial]({% include "django.html" %}/intro/tutorial01/) is a good way to get to know the basics of Django. -InvenTree follows the best practies for Django so most of the contents should be applicable to InvenTree as well. The REST API is based on the [Django REST framework](https://www.django-rest-framework.org/). - -#### Setting up a development environment - -The recommended way to set up a development environment is to use VSCode devcontainers. The required files are provided with the repo, the docs are on a [dedicated page](./devcontainer.md). - -It is also possible to use [docker](../start/docker.md) or [bare metal development](../start/bare_dev.md). With these you need to install the required dependencies manually with a dedicated task. -```bash -invoke setup-dev -``` - -#### Following standards - -Before contributing to the project, please read the [contributing guidelines](contributing.md). Pull requests that do not follow the guidelines, do not pass QC checks or lower the test coverage will not be accepted. diff --git a/docs/docs/faq.md b/docs/docs/faq.md index b14acbef10..86bdaa4d7f 100644 --- a/docs/docs/faq.md +++ b/docs/docs/faq.md @@ -60,7 +60,7 @@ Always activate the virtual environment before running server commands! ### 'str' object has no attribute 'removeSuffix' -This error occurs because your installed python version is not up to date. We [require Python v3.9 or newer](./start/intro.md#python-requirements) +This error occurs because your installed python version is not up to date. We [require Python {{ config.extra.min_python_version }} or newer](./start/intro.md#python-requirements) You (or your system administrator) needs to update python to meet the minimum requirements for InvenTree. diff --git a/docs/docs/start/intro.md b/docs/docs/start/intro.md index da035c2d33..5b733cd5a0 100644 --- a/docs/docs/start/intro.md +++ b/docs/docs/start/intro.md @@ -7,7 +7,7 @@ title: Setup Introduction A functional InvenTree server can be hosted with minimal setup requirements. Multiple installation methods and database back-ends are supported, allowing for flexibility where required. !!! info "Production Ready" - InvenTree is designed to be a production-ready application, and can be deployed in a variety of environments. The following instructions are designed to help you get started with a *production* setup. For a development setup, refer to the [development setup guide](../develop/starting.md). + InvenTree is designed to be a production-ready application, and can be deployed in a variety of environments. The following instructions are designed to help you get started with a *production* setup. For a development setup, refer to the [devcontainer setup guide](../develop/devcontainer.md). ## Installation Methods diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 848788aaad..9de602d7ea 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -77,7 +77,6 @@ nav: - Terminology: concepts/terminology.md - Physical Units: concepts/units.md - Development: - - Getting started: develop/starting.md - Contributing: develop/contributing.md - Devcontainer: develop/devcontainer.md - React Frontend: develop/react-frontend.md