Repository: inventree/InvenTree

Issue:
FR: Reduce tasks
At least the task 'style' is redundant with pre-commit. I think we should clean up the tasks and remove everything we do not need to make it easier to keep an overview.
FR: Reduce tasks
At least the task 'style' is redundant with pre-commit. I think we should clean up the tasks and remove everything we do not need to make it easier to keep an overview.


Discussion:
@SchrodingersGat what is your opinion regarding this?
It is worth looking at, it has been quite a while since we assessed this file. We can look at each task and determine whether it is worth keeping.
@SchrodingersGat what is your opinion regarding this?
It is worth looking at, it has been quite a while since we assessed this file. We can look at each task and determine whether it is worth keeping.

Resolving patch:
diff --git a/tasks.py b/tasks.py
--- a/tasks.py
+++ b/tasks.py
@@ -26,6 +26,32 @@ def apps():
     ]
 
 
+def content_excludes():
+    """Returns a list of content types to exclude from import/export."""
+    excludes = [
+        "contenttypes",
+        "auth.permission",
+        "authtoken.token",
+        "error_report.error",
+        "admin.logentry",
+        "django_q.schedule",
+        "django_q.task",
+        "django_q.ormq",
+        "users.owner",
+        "exchange.rate",
+        "exchange.exchangebackend",
+        "common.notificationentry",
+        "user_sessions.session",
+    ]
+
+    output = ""
+
+    for e in excludes:
+        output += f"--exclude {e} "
+
+    return output
+
+
 def localDir():
     """Returns the directory of *THIS* file.
 
@@ -36,12 +62,12 @@ def localDir():
 
 
 def managePyDir():
-    """Returns the directory of the manage.py file"""
+    """Returns the directory of the manage.py file."""
     return os.path.join(localDir(), 'InvenTree')
 
 
 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')
 
 
@@ -59,9 +85,10 @@ def manage(c, cmd, pty: bool = False):
     ), pty=pty)
 
 
+# Install tasks
 @task
 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
 
     plugin_file = get_plugin_file()
@@ -74,7 +101,7 @@ def plugins(c):
 
 @task(post=[plugins])
 def install(c):
-    """Installs required python packages"""
+    """Installs required python packages."""
     print("Installing required python packages from 'requirements.txt'")
 
     # Install required Python packages with PIP
@@ -83,7 +110,7 @@ def install(c):
 
 @task
 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'")
 
     # Install required Python packages with PIP
@@ -96,81 +123,40 @@ def setup_dev(c):
     c.run('pre-commit autoupdate')
 
 
-@task
-def shell(c):
-    """Open a python shell with access to the InvenTree database models."""
-    manage(c, 'shell', pty=True)
-
-
+# Setup / maintenance tasks
 @task
 def superuser(c):
     """Create a superuser/admin account for the database."""
     manage(c, 'createsuperuser', pty=True)
 
 
-@task
-def check(c):
-    """Check validity of django codebase"""
-    manage(c, "check")
-
-
-@task
-def wait(c):
-    """Wait until the database connection is ready"""
-    return manage(c, "wait_for_db")
-
-
-@task(pre=[wait])
-def worker(c):
-    """Run the InvenTree background worker process"""
-    manage(c, 'qcluster', pty=True)
-
-
 @task
 def rebuild_models(c):
-    """Rebuild database models with MPTT structures"""
+    """Rebuild database models with MPTT structures."""
     manage(c, "rebuild_models", pty=True)
 
 
 @task
 def rebuild_thumbnails(c):
-    """Rebuild missing image thumbnails"""
+    """Rebuild missing image thumbnails."""
     manage(c, "rebuild_thumbnails", pty=True)
 
 
 @task
 def clean_settings(c):
-    """Clean the setting tables of old settings"""
+    """Clean the setting tables of old settings."""
     manage(c, "clean_settings")
 
 
 @task(help={'mail': 'mail of the user whos MFA should be disabled'})
 def remove_mfa(c, mail=''):
-    """Remove MFA for a user"""
+    """Remove MFA for a user."""
     if not mail:
         print('You must provide a users mail')
 
     manage(c, f"remove_mfa {mail}")
 
 
-@task(post=[rebuild_models, rebuild_thumbnails])
-def migrate(c):
-    """Performs database migrations.
-
-    This is a critical step if the database schema have been altered!
-    """
-    print("Running InvenTree database migrations...")
-    print("========================================")
-
-    manage(c, "makemigrations")
-    manage(c, "migrate --noinput")
-    manage(c, "migrate --run-syncdb")
-    manage(c, "check")
-
-    print("========================================")
-    print("InvenTree database migrations completed!")
-
-
 @task
 def static(c):
     """Copies required static files to the STATIC_ROOT directory, as per Django requirements."""
@@ -190,7 +176,7 @@ def translate_stats(c):
 
 @task(post=[translate_stats, static])
 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,
     it is performed as part of the InvenTree translation toolchain.
@@ -200,7 +186,25 @@ def translate(c):
     manage(c, "compilemessages")
 
 
-@task(pre=[install, migrate, static, clean_settings])
+@task(post=[rebuild_models, rebuild_thumbnails])
+def migrate(c):
+    """Performs database migrations.
+
+    This is a critical step if the database schema have been altered!
+    """
+    print("Running InvenTree database migrations...")
+    print("========================================")
+
+    manage(c, "makemigrations")
+    manage(c, "migrate --noinput")
+    manage(c, "migrate --run-syncdb")
+    manage(c, "check")
+
+    print("========================================")
+    print("InvenTree database migrations completed!")
+
+
+@task(pre=[install, migrate, static, clean_settings, translate_stats])
 def update(c):
     """Update InvenTree installation.
 
@@ -211,77 +215,16 @@ def update(c):
 
     - install
     - migrate
-    - translate_stats
     - static
     - clean_settings
+    - translate_stats
     """
     # Recompile the translation files (.mo)
     # We do not run 'invoke translate' here, as that will touch the source (.po) files too!
     manage(c, 'compilemessages', pty=True)
 
 
-@task
-def style(c):
-    """Run PEP style checks against InvenTree sourcecode"""
-    print("Running PEP style checks...")
-    c.run('flake8 InvenTree tasks.py')
-
-
-@task
-def test(c, database=None):
-    """Run unit-tests for InvenTree codebase."""
-    # Run sanity check on the django install
-    manage(c, 'check')
-
-    # Run coverage tests
-    manage(c, 'test', pty=True)
-
-
-@task
-def coverage(c):
-    """Run code-coverage of the InvenTree codebase, using the 'coverage' code-analysis tools.
-
-    Generates a code coverage report (available in the htmlcov directory)
-    """
-    # Run sanity check on the django install
-    manage(c, 'check')
-
-    # Run coverage tests
-    c.run('coverage run {manage} test {apps}'.format(
-        manage=managePyPath(),
-        apps=' '.join(apps())
-    ))
-
-    # Generate coverage report
-    c.run('coverage html')
-
-
-def content_excludes():
-    """Returns a list of content types to exclude from import/export"""
-    excludes = [
-        "contenttypes",
-        "auth.permission",
-        "authtoken.token",
-        "error_report.error",
-        "admin.logentry",
-        "django_q.schedule",
-        "django_q.task",
-        "django_q.ormq",
-        "users.owner",
-        "exchange.rate",
-        "exchange.exchangebackend",
-        "common.notificationentry",
-        "user_sessions.session",
-    ]
-
-    output = ""
-
-    for e in excludes:
-        output += f"--exclude {e} "
-
-    return output
-
-
+# Data tasks
 @task(help={
     'filename': "Output filename (default = 'data.json')",
     'overwrite': "Overwrite existing files without asking first (default = off/False)",
@@ -359,7 +302,7 @@ def export_records(c, filename='data.json', overwrite=False, include_permissions
 
 @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):
-    """Import database records from a file"""
+    """Import database records from a file."""
     # Get an absolute path to the supplied filename
     if not os.path.isabs(filename):
         filename = os.path.join(localDir(), filename)
@@ -462,6 +405,7 @@ def import_fixtures(c):
     manage(c, command, pty=True)
 
 
+# Execution tasks
 @task(help={'address': 'Server address:port (default=127.0.0.1:8000)'})
 def server(c, address="127.0.0.1:8000"):
     """Launch a (deveopment) server using Django's in-built webserver.
@@ -471,9 +415,28 @@ def server(c, address="127.0.0.1:8000"):
     manage(c, "runserver {address}".format(address=address), pty=True)
 
 
+@task
+def wait(c):
+    """Wait until the database connection is ready."""
+    return manage(c, "wait_for_db")
+
+
+@task(pre=[wait])
+def worker(c):
+    """Run the InvenTree background worker process."""
+    manage(c, 'qcluster', pty=True)
+
+
+# Testing tasks
+@task
+def render_js_files(c):
+    """Render templated javascript files (used for static testing)."""
+    manage(c, "test InvenTree.ci_render_js")
+
+
 @task(post=[translate_stats, static, server])
 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
     from django.conf import settings
 
@@ -539,6 +502,29 @@ def test_translations(c):
 
 
 @task
-def render_js_files(c):
-    """Render templated javascript files (used for static testing)."""
-    manage(c, "test InvenTree.ci_render_js")
+def test(c, database=None):
+    """Run unit-tests for InvenTree codebase."""
+    # Run sanity check on the django install
+    manage(c, 'check')
+
+    # Run coverage tests
+    manage(c, 'test', pty=True)
+
+
+@task
+def coverage(c):
+    """Run code-coverage of the InvenTree codebase, using the 'coverage' code-analysis tools.
+
+    Generates a code coverage report (available in the htmlcov directory)
+    """
+    # Run sanity check on the django install
+    manage(c, 'check')
+
+    # Run coverage tests
+    c.run('coverage run {manage} test {apps}'.format(
+        manage=managePyPath(),
+        apps=' '.join(apps())
+    ))
+
+    # Generate coverage report
+    c.run('coverage html')


Test patch: