mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
CI updates (#6167)
* replaced flake8 with ruff mostly for speed improvements * fix codespell error * move config section * added isort again * move djlint config to pyproject * moved ruff section * remove flake8 from code base * remove flake8 from code base * fix djlint syntax * fix removed sections * fix requirements file * fix getattr useage * auto fixed docstring * adapted ruff settings to better fit code base * reorder order of operations * adjust checks * disable autofix/format * fixed reqs * remove flake8 section from setup.cfg * moved isort config * added missing toml req * fixed req * fixed source path
This commit is contained in:
parent
73cc39bb68
commit
e1b670ba57
@ -21,12 +21,10 @@
|
||||
"python.defaultInterpreterPath": "${containerWorkspaceFolder}/dev/venv/bin/python",
|
||||
"python.linting.enabled": true,
|
||||
"python.linting.pylintEnabled": false,
|
||||
"python.linting.flake8Enabled": true,
|
||||
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
|
||||
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
|
||||
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
|
||||
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
|
||||
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
|
||||
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
|
||||
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
|
||||
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
|
||||
|
@ -1,3 +0,0 @@
|
||||
{
|
||||
"ignore": "D018,H006,H008,H020,H021,H023,H025,H030,H031,T002"
|
||||
}
|
40
.github/workflows/qc_checks.yaml
vendored
40
.github/workflows/qc_checks.yaml
vendored
@ -47,27 +47,11 @@ jobs:
|
||||
frontend:
|
||||
- 'src/frontend/**'
|
||||
|
||||
pep_style:
|
||||
name: Style [Python]
|
||||
runs-on: ubuntu-20.04
|
||||
|
||||
needs: paths-filter
|
||||
if: needs.paths-filter.outputs.server == 'true'
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # pin@v4.1.1
|
||||
- name: Environment Setup
|
||||
uses: ./.github/actions/setup
|
||||
with:
|
||||
dev-install: true
|
||||
- name: Run flake8
|
||||
run: flake8 InvenTree --extend-ignore=D
|
||||
|
||||
javascript:
|
||||
name: Style - Classic UI [JS]
|
||||
runs-on: ubuntu-20.04
|
||||
|
||||
needs: [ 'pep_style', 'pre-commit' ]
|
||||
needs: [ 'pre-commit' ]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # pin@v4.1.1
|
||||
@ -167,27 +151,11 @@ jobs:
|
||||
invoke check-server
|
||||
coverage run -m unittest discover -s test/
|
||||
|
||||
docstyle:
|
||||
name: Style [Python Docstrings]
|
||||
runs-on: ubuntu-20.04
|
||||
|
||||
needs: pre-commit
|
||||
continue-on-error: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # pin@v4.1.1
|
||||
- name: Environment Setup
|
||||
uses: ./.github/actions/setup
|
||||
with:
|
||||
install: true
|
||||
- name: Run flake8
|
||||
run: flake8 InvenTree --statistics
|
||||
|
||||
coverage:
|
||||
name: Tests - DB [SQLite] + Coverage
|
||||
runs-on: ubuntu-20.04
|
||||
|
||||
needs: [ 'pep_style', 'pre-commit' ]
|
||||
needs: [ 'pre-commit' ]
|
||||
continue-on-error: true # continue if a step fails so that coverage gets pushed
|
||||
|
||||
env:
|
||||
@ -220,7 +188,7 @@ jobs:
|
||||
postgres:
|
||||
name: Tests - DB [PostgreSQL]
|
||||
runs-on: ubuntu-20.04
|
||||
needs: [ 'pep_style', 'pre-commit' ]
|
||||
needs: [ 'pre-commit' ]
|
||||
|
||||
env:
|
||||
INVENTREE_DB_ENGINE: django.db.backends.postgresql
|
||||
@ -264,7 +232,7 @@ jobs:
|
||||
name: Tests - DB [MySQL]
|
||||
runs-on: ubuntu-20.04
|
||||
|
||||
needs: [ 'pep_style', 'pre-commit' ]
|
||||
needs: [ 'pre-commit' ]
|
||||
|
||||
env:
|
||||
# Database backend configuration
|
||||
|
@ -4,7 +4,8 @@ exclude: |
|
||||
(?x)^(
|
||||
InvenTree/InvenTree/static/.*|
|
||||
InvenTree/locale/.*|
|
||||
src/frontend/src/locales/.*
|
||||
src/frontend/src/locales/.*|
|
||||
.*/migrations/.*
|
||||
)$
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
@ -14,23 +15,20 @@ repos:
|
||||
- id: end-of-file-fixer
|
||||
- id: check-yaml
|
||||
- id: mixed-line-ending
|
||||
- repo: https://github.com/pycqa/flake8
|
||||
rev: '6.1.0'
|
||||
hooks:
|
||||
- id: flake8
|
||||
additional_dependencies: [
|
||||
'flake8-bugbear',
|
||||
'flake8-comprehensions',
|
||||
'flake8-docstrings',
|
||||
'flake8-string-format',
|
||||
'flake8-tidy-imports',
|
||||
'pep8-naming',
|
||||
'flake8-logging'
|
||||
]
|
||||
- repo: https://github.com/pycqa/isort
|
||||
rev: '5.12.0'
|
||||
hooks:
|
||||
- id: isort
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.1.11
|
||||
hooks:
|
||||
# - id: ruff-format
|
||||
# args: [--preview]
|
||||
- id: ruff
|
||||
args: [
|
||||
#--fix,
|
||||
--preview
|
||||
]
|
||||
- repo: https://github.com/jazzband/pip-tools
|
||||
rev: 7.3.0
|
||||
hooks:
|
||||
|
@ -336,9 +336,9 @@ def trigger_notification(obj, category=None, obj_ref='pk', **kwargs):
|
||||
|
||||
# Try with some defaults
|
||||
if not obj_ref_value:
|
||||
obj_ref_value = getattr(obj, 'pk')
|
||||
obj_ref_value = getattr(obj, 'pk', None)
|
||||
if not obj_ref_value:
|
||||
obj_ref_value = getattr(obj, 'id')
|
||||
obj_ref_value = getattr(obj, 'id', None)
|
||||
if not obj_ref_value:
|
||||
raise KeyError(f"Could not resolve an object reference for '{str(obj)}' with {obj_ref}, pk, id")
|
||||
|
||||
|
@ -24,7 +24,7 @@ logger = logging.getLogger('inventree')
|
||||
def perform_stocktake(target: part.models.Part, user: User, note: str = '', commit=True, **kwargs):
|
||||
"""Perform stocktake action on a single part.
|
||||
|
||||
arguments:
|
||||
Arguments:
|
||||
target: A single Part model instance
|
||||
commit: If True (default) save the result to the database
|
||||
user: User who requested this stocktake
|
||||
|
@ -80,7 +80,7 @@ class PartCategoryAPITest(InvenTreeAPITestCase):
|
||||
({'parent': 1, 'cascade': False, 'depth': 1}, 3, 'Dont cascade even with depth=1 specified with parent'),
|
||||
({'parent': 1, 'cascade': True, 'depth': 1}, 5, 'Cascade with depth=1 with parent'),
|
||||
({'parent': 1, 'cascade': True, 'depth': 'abcdefg'}, 5, 'Cascade with invalid depth and parent'),
|
||||
({'parent': 42}, 8, 'Should return everything if parent_pk is not vaild'),
|
||||
({'parent': 42}, 8, 'Should return everything if parent_pk is not valid'),
|
||||
({'parent': 'null', 'exclude_tree': 1, 'cascade': True}, 2, 'Should return everything from except tree with pk=1'),
|
||||
({'parent': 'null', 'exclude_tree': 42, 'cascade': True}, 8, 'Should return everything because exclude_tree=42 is no valid pk'),
|
||||
({'parent': 1, 'starred': True, 'cascade': True}, 2, 'Should return the starred categories for the current user within the pk=1 tree'),
|
||||
|
@ -93,7 +93,7 @@ class APICallMixin:
|
||||
Check the mixin class docstring for a full example.
|
||||
"""
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
if getattr(self, 'API_TOKEN_SETTING'):
|
||||
if getattr(self, 'API_TOKEN_SETTING', None):
|
||||
token = self.get_setting(self.API_TOKEN_SETTING)
|
||||
|
||||
if token:
|
||||
|
@ -82,7 +82,7 @@ class LabelPrintingMixin:
|
||||
items: The list of database items to print (e.g. StockItem instances)
|
||||
request: The HTTP request object which triggered this print job
|
||||
|
||||
Keyword arguments:
|
||||
Keyword Arguments:
|
||||
printing_options: The printing options set for this print job defined in the PrintingOptionsSerializer
|
||||
|
||||
Returns:
|
||||
|
@ -189,7 +189,7 @@ class PluginSetting(common.models.BaseInvenTreeSetting):
|
||||
plugin = kwargs.pop('plugin', None)
|
||||
|
||||
if plugin:
|
||||
mixin_settings = getattr(registry, 'mixins_settings')
|
||||
mixin_settings = getattr(registry, 'mixins_settings', None)
|
||||
if mixin_settings:
|
||||
kwargs['settings'] = mixin_settings.get(plugin.key, {})
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
"""
|
||||
Directory for custom plugin development.
|
||||
"""Directory for custom plugin development.
|
||||
|
||||
Please read the docs for more information https://docs.inventree.org/en/latest/extend/plugins/#local-directory
|
||||
"""
|
||||
|
@ -77,7 +77,7 @@ class StockLocationTest(StockAPITestCase):
|
||||
({'parent': 1, 'cascade': False, 'depth': 1}, 2, 'Dont cascade even with depth=1 specified with parent'),
|
||||
({'parent': 1, 'cascade': True, 'depth': 1}, 2, 'Cascade with depth=1 with parent'),
|
||||
({'parent': 1, 'cascade': True, 'depth': 'abcdefg'}, 2, 'Cascade with invalid depth and parent'),
|
||||
({'parent': 42}, 8, 'Should return everything if parent_pk is not vaild'),
|
||||
({'parent': 42}, 8, 'Should return everything if parent_pk is not valid'),
|
||||
({'parent': 'null', 'exclude_tree': 1, 'cascade': True}, 5, 'Should return everything except tree with pk=1'),
|
||||
({'parent': 'null', 'exclude_tree': 42, 'cascade': True}, 8, 'Should return everything because exclude_tree=42 is no valid pk'),
|
||||
]
|
||||
|
87
pyproject.toml
Normal file
87
pyproject.toml
Normal file
@ -0,0 +1,87 @@
|
||||
|
||||
[tool.ruff]
|
||||
exclude = [
|
||||
".git",
|
||||
"__pycache__",
|
||||
"dist",
|
||||
"build",
|
||||
"test.py",
|
||||
"tests",
|
||||
"venv",
|
||||
"env",
|
||||
".venv",
|
||||
".env",
|
||||
]
|
||||
src = ["../InvenTree"]
|
||||
# line-length = 120
|
||||
|
||||
[tool.ruff.extend-per-file-ignores]
|
||||
"__init__.py" = ["D104"]
|
||||
|
||||
[tool.ruff.lint]
|
||||
select = ["A", "B", "C4", "D", "N"]
|
||||
# Things that should be enabled in the future:
|
||||
# - LOG
|
||||
# - I
|
||||
# - DJ # for Django stuff
|
||||
# - S # for security stuff (bandit)
|
||||
|
||||
ignore = [
|
||||
"N999",
|
||||
# - N802 - function name should be lowercase
|
||||
"N802",
|
||||
# - N806 - variable should be lowercase
|
||||
"N806",
|
||||
# - N812 - lowercase imported as non-lowercase
|
||||
"N812",
|
||||
# - D202 - No blank lines allowed after function docstring
|
||||
"D202",
|
||||
# - D415 - First line should end with a period, question mark, or exclamation point
|
||||
"D415",
|
||||
# - D417 Missing argument descriptions in the docstring
|
||||
"D417",
|
||||
|
||||
# TODO These should be followed up and fixed
|
||||
# - B904 Within an `except` clause, raise exceptions
|
||||
"B904",
|
||||
|
||||
# Remove fast
|
||||
"A001", "A002","A003","B018"
|
||||
]
|
||||
|
||||
[tool.ruff.lint.pydocstyle]
|
||||
convention = "google"
|
||||
|
||||
[tool.ruff.lint.isort]
|
||||
split-on-trailing-comma = false
|
||||
combine-as-imports = false
|
||||
section-order = [
|
||||
"future",
|
||||
"standard-library",
|
||||
"django",
|
||||
"third-party",
|
||||
"first-party",
|
||||
"local-folder",
|
||||
]
|
||||
known-first-party = ["src", "plugin", "InvenTree", "common"]
|
||||
|
||||
[tool.ruff.lint.isort.sections]
|
||||
"django" = ["django"]
|
||||
|
||||
[tool.ruff.format]
|
||||
quote-style = "preserve"
|
||||
indent-style = "space"
|
||||
skip-magic-trailing-comma = true
|
||||
line-ending = "auto"
|
||||
|
||||
[tool.coverage.run]
|
||||
source = ["InvenTree", ]
|
||||
|
||||
[tool.djlint]
|
||||
ignore = "D018,H006,H008,H020,H021,H023,H025,H030,H031,T002"
|
||||
|
||||
[tool.isort]
|
||||
src_paths=["InvenTree", ]
|
||||
skip_glob ="*/migrations/*.py"
|
||||
known_django="django"
|
||||
sections=["FUTURE","STDLIB","DJANGO","THIRDPARTY","FIRSTPARTY","LOCALFOLDER"]
|
@ -1,14 +1,11 @@
|
||||
# Dev requirements for InvenTree
|
||||
-c requirements.txt
|
||||
coverage # Unit test coverage
|
||||
coverage[toml] # Unit test coverage
|
||||
coveralls==2.1.2 # Coveralls linking (for tracking coverage) # PINNED 2022-06-28 - Old version needed for correct upload
|
||||
django-debug-toolbar # Debug / profiling toolbar
|
||||
django-slowtests # Show which unit tests are running slowly
|
||||
django-test-migrations # Unit testing for database migrations
|
||||
flake8 # PEP checking
|
||||
flake8-docstrings # docstring format testing
|
||||
isort # python import sorting
|
||||
pep8-naming # PEP naming convention extension
|
||||
pip-tools # Compile pip requirements
|
||||
pre-commit # Git pre-commit
|
||||
setuptools # Standard dependency
|
||||
|
@ -27,7 +27,7 @@ charset-normalizer==3.3.2
|
||||
# requests
|
||||
click==8.1.7
|
||||
# via pip-tools
|
||||
coverage==5.5
|
||||
coverage[toml]==5.5
|
||||
# via
|
||||
# -r requirements-dev.in
|
||||
# coveralls
|
||||
@ -54,13 +54,6 @@ docopt==0.6.2
|
||||
# via coveralls
|
||||
filelock==3.13.1
|
||||
# via virtualenv
|
||||
flake8==6.1.0
|
||||
# via
|
||||
# -r requirements-dev.in
|
||||
# flake8-docstrings
|
||||
# pep8-naming
|
||||
flake8-docstrings==1.7.0
|
||||
# via -r requirements-dev.in
|
||||
identify==2.5.31
|
||||
# via pre-commit
|
||||
idna==3.4
|
||||
@ -73,8 +66,6 @@ importlib-metadata==6.8.0
|
||||
# build
|
||||
isort==5.12.0
|
||||
# via -r requirements-dev.in
|
||||
mccabe==0.7.0
|
||||
# via flake8
|
||||
nodeenv==1.8.0
|
||||
# via pre-commit
|
||||
packaging==23.2
|
||||
@ -83,24 +74,16 @@ packaging==23.2
|
||||
# build
|
||||
pdfminer-six==20221105
|
||||
# via -r requirements-dev.in
|
||||
pep8-naming==0.13.3
|
||||
# via -r requirements-dev.in
|
||||
pip-tools==7.3.0
|
||||
# via -r requirements-dev.in
|
||||
platformdirs==3.11.0
|
||||
# via virtualenv
|
||||
pre-commit==3.5.0
|
||||
# via -r requirements-dev.in
|
||||
pycodestyle==2.11.1
|
||||
# via flake8
|
||||
pycparser==2.21
|
||||
# via
|
||||
# -c requirements.txt
|
||||
# cffi
|
||||
pydocstyle==6.3.0
|
||||
# via flake8-docstrings
|
||||
pyflakes==3.1.0
|
||||
# via flake8
|
||||
pyproject-hooks==1.0.0
|
||||
# via build
|
||||
pytz==2023.3.post1
|
||||
@ -115,13 +98,13 @@ requests==2.31.0
|
||||
# via
|
||||
# -c requirements.txt
|
||||
# coveralls
|
||||
snowballstemmer==2.2.0
|
||||
# via pydocstyle
|
||||
sqlparse==0.4.4
|
||||
# via
|
||||
# -c requirements.txt
|
||||
# django
|
||||
# django-debug-toolbar
|
||||
toml==0.10.2
|
||||
# via coverage
|
||||
tomli==2.0.1
|
||||
# via
|
||||
# build
|
||||
|
@ -15,7 +15,9 @@ attrs==23.1.0
|
||||
babel==2.13.1
|
||||
# via py-moneyed
|
||||
bleach[css]==6.1.0
|
||||
# via django-markdownify
|
||||
# via
|
||||
# bleach
|
||||
# django-markdownify
|
||||
brotli==1.1.0
|
||||
# via fonttools
|
||||
certifi==2023.7.22
|
||||
@ -162,7 +164,9 @@ et-xmlfile==1.1.0
|
||||
feedparser==6.0.10
|
||||
# via -r requirements.in
|
||||
fonttools[woff]==4.44.0
|
||||
# via weasyprint
|
||||
# via
|
||||
# fonttools
|
||||
# weasyprint
|
||||
gunicorn==21.2.0
|
||||
# via -r requirements.in
|
||||
html5lib==1.1
|
||||
@ -221,6 +225,7 @@ pyjwt[crypto]==2.8.0
|
||||
# via
|
||||
# django-allauth
|
||||
# djangorestframework-simplejwt
|
||||
# pyjwt
|
||||
pyphen==0.14.0
|
||||
# via weasyprint
|
||||
pypng==0.20220715.0
|
||||
|
39
setup.cfg
39
setup.cfg
@ -1,39 +0,0 @@
|
||||
[flake8]
|
||||
ignore =
|
||||
# - W605 - invalid escape sequence
|
||||
W605,
|
||||
# - E501 - line too long (82 characters)
|
||||
E501,
|
||||
# - E722 - do not use bare except
|
||||
E722,
|
||||
# - C901 - function is too complex
|
||||
C901,
|
||||
# - N802 - function name should be lowercase
|
||||
# TODO (In the future, we should conform to this!)
|
||||
N802,
|
||||
# - N806 - variable should be lowercase
|
||||
N806,
|
||||
# - N812 - lowercase imported as non-lowercase
|
||||
N812,
|
||||
# - D202 - No blank lines allowed after function docstring
|
||||
D202,
|
||||
# - D415 - First line should end with a period, question mark, or exclamation point
|
||||
D415,
|
||||
# - B009 - Do not call getattr with a constant attribute value
|
||||
B009
|
||||
exclude = .git,__pycache__,*/migrations/*,*/lib/*,*/bin/*,*/media/*,*/static/*,InvenTree/plugins/*
|
||||
per-file-ignores =
|
||||
# Do not enforce docstring on __init__
|
||||
__init__.py: D104
|
||||
max-complexity = 20
|
||||
docstring-convention=google
|
||||
ban-relative-imports = parents
|
||||
|
||||
[coverage:run]
|
||||
source = ./InvenTree
|
||||
|
||||
[isort]
|
||||
src_paths=InvenTree
|
||||
skip_glob =*/migrations/*.py
|
||||
known_django=django
|
||||
sections=FUTURE, STDLIB, DJANGO, THIRDPARTY, FIRSTPARTY, LOCALFOLDER
|
Loading…
Reference in New Issue
Block a user