Development improvements (#3413)

* rename .env to make sure it is not loaded by default

* make sure migrations are run before import

* Add more messaget to setup_test

* add comments to setup-dev

* Add flag to setup-dev for setting up test data

* add flag to setup-test to also run development setup

* extend contributing with the flags

* change flag to tests

* Add option helptexts

* A nicer starter

* add 3 liner

* Revert "rename .env to make sure it is not loaded by default"

This reverts commit 95fa0bbc53.
This commit is contained in:
Matthias Mair 2022-07-29 06:58:54 +02:00 committed by GitHub
parent 4d5e267753
commit e461a2c1ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 5 deletions

View File

@ -1,8 +1,27 @@
Hi there, thank you for your intrest in contributing!
Please read the contribution guidelines below, before submitting your first pull request to the InvenTree codebase. Please read the contribution guidelines below, before submitting your first pull request to the InvenTree codebase.
Up an running in 3 LOC:
```bash
git clone https://github.com/inventree/InvenTree.git && cd InvenTree
python3 -m venv env && source env/bin/activate
pip install invoke && invoke setup-dev --tests
```
## Setup ## Setup
Please run `invoke setup-dev` in the root directory of your InvenTree code base to set up your development setup before starting to contribute. This will install and set up pre-commit to run some checks before each commit and help reduce the style errors. Run the following command to set up all toolsets for development.
```bash
invoke setup-dev
```
With the flag `tests` the database will additionally be populated with the [offical](https://github.com/inventree/demo-dataset) test dataset.
```bash
invoke setup-dev --tests
```
Run either command to set up your development setup before starting to contribute. This will install and set up `pre-commit` to run some checks before each commit and help reduce the style errors.
## Branches and Versioning ## Branches and Versioning

View File

@ -110,8 +110,8 @@ def install(c):
c.run('pip3 install --no-cache-dir --disable-pip-version-check -U -r requirements.txt') c.run('pip3 install --no-cache-dir --disable-pip-version-check -U -r requirements.txt')
@task @task(help={'tests': 'Set up test dataset at the end'})
def setup_dev(c): def setup_dev(c, tests=False):
"""Sets up everything needed for the dev enviroment.""" """Sets up everything needed for the dev enviroment."""
print("Installing required python packages from 'requirements-dev.txt'") print("Installing required python packages from 'requirements-dev.txt'")
@ -119,10 +119,16 @@ def setup_dev(c):
c.run('pip3 install -U -r requirements-dev.txt') c.run('pip3 install -U -r requirements-dev.txt')
# Install pre-commit hook # Install pre-commit hook
print("Installing pre-commit for checks before git commits...")
c.run('pre-commit install') c.run('pre-commit install')
# Update all the hooks # Update all the hooks
c.run('pre-commit autoupdate') c.run('pre-commit autoupdate')
print("pre-commit set up is done...")
# Set up test-data if flag is set
if tests:
setup_test(c)
# Setup / maintenance tasks # Setup / maintenance tasks
@ -512,17 +518,31 @@ def test(c, database=None):
manage(c, 'test', pty=True) manage(c, 'test', pty=True)
@task(pre=[update]) @task(pre=[update], help={'dev': 'Set up development enviroment at the end'})
def setup_test(c): def setup_test(c, dev=False):
"""Setup a testing enviroment.""" """Setup a testing enviroment."""
# Remove old data directory # Remove old data directory
print("Removing old data ...")
c.run('rm inventree-data -r') c.run('rm inventree-data -r')
# Get test data # Get test data
print("Starting to clone demo dataset ...")
c.run('git clone https://github.com/inventree/demo-dataset inventree-data') c.run('git clone https://github.com/inventree/demo-dataset inventree-data')
print("========================================")
# Make sure migrations are done - might have just deleted sqlite database
print("Running migrations ...")
migrate(c)
# Load data # Load data
print("Loading data ...")
import_records(c, filename='inventree-data/inventree_data.json', clear=True) import_records(c, filename='inventree-data/inventree_data.json', clear=True)
print("Done setting up test enviroment...")
print("========================================")
# Set up development setup if flag is set
if dev:
setup_dev(c)
@task @task