2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-16 12:05:53 +00:00

update support files for docstrings

This commit is contained in:
Matthias
2022-05-28 19:06:07 +02:00
parent e4d9fcdb30
commit ff9873f92c
5 changed files with 40 additions and 132 deletions

View File

@ -1,6 +1,4 @@
""" """Test that the root API endpoint is available."""
Test that the root API endpoint is available.
"""
import json import json

View File

@ -1,9 +1,6 @@
""" """Test that the "translated" javascript files to not contain template tags which need to be determined at "run time".
Test that the "translated" javascript files to not contain template tags
which need to be determined at "run time".
This is because the "translated" javascript files are compiled into the "static" directory. This is because the "translated" javascript files are compiled into the "static" directory.
They should only contain template tags that render static information. They should only contain template tags that render static information.
""" """

View File

@ -1,4 +1,4 @@
""" Check that there are no database migration files which have not been committed. """ """Check that there are no database migration files which have not been committed."""
import subprocess import subprocess
import sys import sys

View File

@ -1,4 +1,4 @@
""" Check that there are no database migration files which have not been committed. """ """Check that there are no database migration files which have not been committed."""
import subprocess import subprocess
import sys import sys

159
tasks.py
View File

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
import json import json
import os import os
import pathlib import pathlib
@ -10,10 +8,7 @@ from invoke import task
def apps(): def apps():
""" """Returns a list of installed apps"""
Returns a list of installed apps
"""
return [ return [
'build', 'build',
'common', 'common',
@ -30,8 +25,8 @@ def apps():
def localDir(): def localDir():
""" """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
in the correct directory. in the correct directory.
""" """
@ -39,30 +34,22 @@ def localDir():
def managePyDir(): def managePyDir():
""" """Returns the directory of the manage.py file"""
Returns the directory of the manage.py file
"""
return os.path.join(localDir(), 'InvenTree') return os.path.join(localDir(), 'InvenTree')
def managePyPath(): def managePyPath():
""" """Return the path of the manage.py file"""
Return the path of the manage.py file
"""
return os.path.join(managePyDir(), 'manage.py') return os.path.join(managePyDir(), 'manage.py')
def manage(c, cmd, pty=False): def manage(c, cmd, pty=False):
""" """Runs a given command against django's "manage.py" script.
Runs a given command against django's "manage.py" script.
Args: Args:
c - Command line context c - Command line context
cmd - django command to run cmd - django command to run
""" """
c.run('cd "{path}" && python3 manage.py {cmd}'.format( c.run('cd "{path}" && python3 manage.py {cmd}'.format(
path=managePyDir(), path=managePyDir(),
cmd=cmd cmd=cmd
@ -71,10 +58,7 @@ def manage(c, cmd, pty=False):
@task @task
def plugins(c): def plugins(c):
""" """Installs all plugins as specified in 'plugins.txt'"""
Installs all plugins as specified in 'plugins.txt'
"""
from InvenTree.InvenTree.config import get_plugin_file from InvenTree.InvenTree.config import get_plugin_file
plugin_file = get_plugin_file() plugin_file = get_plugin_file()
@ -87,10 +71,7 @@ def plugins(c):
@task(post=[plugins]) @task(post=[plugins])
def install(c): def install(c):
""" """Installs required python packages"""
Installs required python packages
"""
print("Installing required python packages from 'requirements.txt'") print("Installing required python packages from 'requirements.txt'")
# Install required Python packages with PIP # Install required Python packages with PIP
@ -99,10 +80,7 @@ def install(c):
@task @task
def setup_dev(c): def setup_dev(c):
""" """Sets up everything needed for the dev enviroment"""
Sets up everything needed for the dev enviroment
"""
print("Installing required python packages from 'requirements.txt'") print("Installing required python packages from 'requirements.txt'")
# Install required Python packages with PIP # Install required Python packages with PIP
@ -117,82 +95,55 @@ def setup_dev(c):
@task @task
def shell(c): def shell(c):
""" """Open a python shell with access to the InvenTree database models."""
Open a python shell with access to the InvenTree database models.
"""
manage(c, 'shell', pty=True) manage(c, 'shell', pty=True)
@task @task
def superuser(c): def superuser(c):
""" """Create a superuser/admin account for the database."""
Create a superuser (admin) account for the database.
"""
manage(c, 'createsuperuser', pty=True) manage(c, 'createsuperuser', pty=True)
@task @task
def check(c): def check(c):
""" """Check validity of django codebase"""
Check validity of django codebase
"""
manage(c, "check") manage(c, "check")
@task @task
def wait(c): def wait(c):
""" """Wait until the database connection is ready"""
Wait until the database connection is ready
"""
return manage(c, "wait_for_db") return manage(c, "wait_for_db")
@task(pre=[wait]) @task(pre=[wait])
def worker(c): def worker(c):
""" """Run the InvenTree background worker process"""
Run the InvenTree background worker process
"""
manage(c, 'qcluster', pty=True) manage(c, 'qcluster', pty=True)
@task @task
def rebuild_models(c): def rebuild_models(c):
""" """Rebuild database models with MPTT structures"""
Rebuild database models with MPTT structures
"""
manage(c, "rebuild_models", pty=True) manage(c, "rebuild_models", pty=True)
@task @task
def rebuild_thumbnails(c): def rebuild_thumbnails(c):
""" """Rebuild missing image thumbnails"""
Rebuild missing image thumbnails
"""
manage(c, "rebuild_thumbnails", pty=True) manage(c, "rebuild_thumbnails", pty=True)
@task @task
def clean_settings(c): def clean_settings(c):
""" """Clean the setting tables of old settings"""
Clean the setting tables of old settings
"""
manage(c, "clean_settings") manage(c, "clean_settings")
@task(help={'mail': 'mail of the user whos MFA should be disabled'}) @task(help={'mail': 'mail of the user whos MFA should be disabled'})
def remove_mfa(c, mail=''): def remove_mfa(c, mail=''):
""" """Remove MFA for a user"""
Remove MFA for a user
"""
if not mail: if not mail:
print('You must provide a users mail') print('You must provide a users mail')
@ -201,11 +152,10 @@ def remove_mfa(c, mail=''):
@task(post=[rebuild_models, rebuild_thumbnails]) @task(post=[rebuild_models, rebuild_thumbnails])
def migrate(c): def migrate(c):
""" """Performs database migrations.
Performs database migrations.
This is a critical step if the database schema have been altered! This is a critical step if the database schema have been altered!
""" """
print("Running InvenTree database migrations...") print("Running InvenTree database migrations...")
print("========================================") print("========================================")
@ -220,35 +170,28 @@ def migrate(c):
@task @task
def static(c): def static(c):
""" """Copies required static files to the STATIC_ROOT directory, as per Django requirements."""
Copies required static files to the STATIC_ROOT directory,
as per Django requirements.
"""
manage(c, "prerender") manage(c, "prerender")
manage(c, "collectstatic --no-input") manage(c, "collectstatic --no-input")
@task @task
def translate_stats(c): def translate_stats(c):
""" """Collect translation stats.
Collect translation stats.
The file generated from this is needed for the UI. The file generated from this is needed for the UI.
""" """
path = os.path.join('InvenTree', 'script', 'translation_stats.py') path = os.path.join('InvenTree', 'script', 'translation_stats.py')
c.run(f'python3 {path}') c.run(f'python3 {path}')
@task(post=[translate_stats, static]) @task(post=[translate_stats, static])
def translate(c): def translate(c):
""" """Rebuild translation source files. (Advanced use only!)
Rebuild translation source files. (Advanced use only!)
Note: This command should not be used on a local install, Note: This command should not be used on a local install,
it is performed as part of the InvenTree translation toolchain. it is performed as part of the InvenTree translation toolchain.
""" """
# Translate applicable .py / .html / .js files # Translate applicable .py / .html / .js files
manage(c, "makemessages --all -e py,html,js --no-wrap") manage(c, "makemessages --all -e py,html,js --no-wrap")
manage(c, "compilemessages") manage(c, "compilemessages")
@ -256,8 +199,7 @@ def translate(c):
@task(pre=[install, migrate, static, clean_settings]) @task(pre=[install, migrate, static, clean_settings])
def update(c): def update(c):
""" """Update InvenTree installation.
Update InvenTree installation.
This command should be invoked after source code has been updated, This command should be invoked after source code has been updated,
e.g. downloading new code from GitHub. e.g. downloading new code from GitHub.
@ -270,7 +212,6 @@ def update(c):
- static - static
- clean_settings - clean_settings
""" """
# Recompile the translation files (.mo) # 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 translate' here, as that will touch the source (.po) files too!
manage(c, 'compilemessages', pty=True) manage(c, 'compilemessages', pty=True)
@ -278,19 +219,14 @@ def update(c):
@task @task
def style(c): def style(c):
""" """Run PEP style checks against InvenTree sourcecode"""
Run PEP style checks against InvenTree sourcecode
"""
print("Running PEP style checks...") print("Running PEP style checks...")
c.run('flake8 InvenTree') c.run('flake8 InvenTree')
@task @task
def test(c, database=None): def test(c, database=None):
""" """Run unit-tests for InvenTree codebase."""
Run unit-tests for InvenTree codebase.
"""
# Run sanity check on the django install # Run sanity check on the django install
manage(c, 'check') manage(c, 'check')
@ -300,13 +236,10 @@ def test(c, database=None):
@task @task
def coverage(c): def coverage(c):
""" """Run code-coverage of the InvenTree codebase, using the 'coverage' code-analysis tools.
Run code-coverage of the InvenTree codebase,
using the 'coverage' code-analysis tools.
Generates a code coverage report (available in the htmlcov directory) Generates a code coverage report (available in the htmlcov directory)
""" """
# Run sanity check on the django install # Run sanity check on the django install
manage(c, 'check') manage(c, 'check')
@ -321,10 +254,7 @@ def coverage(c):
def content_excludes(): def content_excludes():
""" """Returns a list of content types to exclude from import/export"""
Returns a list of content types to exclude from import/export
"""
excludes = [ excludes = [
"contenttypes", "contenttypes",
"auth.permission", "auth.permission",
@ -351,10 +281,7 @@ def content_excludes():
@task(help={'filename': "Output filename (default = 'data.json')"}) @task(help={'filename': "Output filename (default = 'data.json')"})
def export_records(c, filename='data.json'): def export_records(c, filename='data.json'):
""" """Export all database records to a file"""
Export all database records to a file
"""
# Get an absolute path to the file # Get an absolute path to the file
if not os.path.isabs(filename): if not os.path.isabs(filename):
filename = os.path.join(localDir(), filename) filename = os.path.join(localDir(), filename)
@ -403,10 +330,7 @@ def export_records(c, filename='data.json'):
@task(help={'filename': 'Input filename', 'clear': 'Clear existing data before import'}, post=[rebuild_models, rebuild_thumbnails]) @task(help={'filename': 'Input filename', 'clear': 'Clear existing data before import'}, post=[rebuild_models, rebuild_thumbnails])
def import_records(c, filename='data.json', clear=False): def import_records(c, filename='data.json', clear=False):
""" """Import database records from a file"""
Import database records from a file
"""
# Get an absolute path to the supplied filename # Get an absolute path to the supplied filename
if not os.path.isabs(filename): if not os.path.isabs(filename):
filename = os.path.join(localDir(), filename) filename = os.path.join(localDir(), filename)
@ -450,12 +374,10 @@ def import_records(c, filename='data.json', clear=False):
@task @task
def delete_data(c, force=False): def delete_data(c, force=False):
""" """Delete all database records!
Delete all database records!
Warning: This will REALLY delete all records in the database!! Warning: This will REALLY delete all records in the database!!
""" """
print("Deleting all data from InvenTree database...") print("Deleting all data from InvenTree database...")
if force: if force:
@ -466,8 +388,7 @@ def delete_data(c, force=False):
@task(post=[rebuild_models, rebuild_thumbnails]) @task(post=[rebuild_models, rebuild_thumbnails])
def import_fixtures(c): def import_fixtures(c):
""" """Import fixture data into the database.
Import fixture data into the database.
This command imports all existing test fixture data into the database. This command imports all existing test fixture data into the database.
@ -476,7 +397,6 @@ def import_fixtures(c):
- Running this command may overwrite existing database data!! - Running this command may overwrite existing database data!!
- Don't say you were not warned... - Don't say you were not warned...
""" """
fixtures = [ fixtures = [
# Build model # Build model
'build', 'build',
@ -515,20 +435,16 @@ def import_fixtures(c):
@task(help={'address': 'Server address:port (default=127.0.0.1:8000)'}) @task(help={'address': 'Server address:port (default=127.0.0.1:8000)'})
def server(c, address="127.0.0.1:8000"): def server(c, address="127.0.0.1:8000"):
""" """Launch a (deveopment) server using Django's in-built webserver.
Launch a (deveopment) server using Django's in-built webserver.
Note: This is *not* sufficient for a production installation. Note: This is *not* sufficient for a production installation.
""" """
manage(c, "runserver {address}".format(address=address), pty=True) manage(c, "runserver {address}".format(address=address), pty=True)
@task(post=[translate_stats, static, server]) @task(post=[translate_stats, static, server])
def test_translations(c): def test_translations(c):
""" """Add a fictional language to test if each component is ready for translations"""
Add a fictional language to test if each component is ready for translations
"""
import django import django
from django.conf import settings from django.conf import settings
@ -595,8 +511,5 @@ def test_translations(c):
@task @task
def render_js_files(c): def render_js_files(c):
""" """Render templated javascript files (used for static testing)."""
Render templated javascript files (used for static testing).
"""
manage(c, "test InvenTree.ci_render_js") manage(c, "test InvenTree.ci_render_js")