Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit f5cf7b2
Author: Matthias Mair <code@mjmair.com>
Date:   Sun Jan 7 20:36:57 2024 +0100

    fixed reqs

commit 9d845be
Author: Matthias Mair <code@mjmair.com>
Date:   Sun Jan 7 20:32:35 2024 +0100

    disable autofix/format

commit aff5f27
Author: Matthias Mair <code@mjmair.com>
Date:   Sun Jan 7 20:28:50 2024 +0100

    adjust checks

commit 47271cf
Author: Matthias Mair <code@mjmair.com>
Date:   Sun Jan 7 20:28:22 2024 +0100

    reorder order of operations

commit e1bf178
Author: Matthias Mair <code@mjmair.com>
Date:   Sun Jan 7 20:01:09 2024 +0100

    adapted ruff settings to better fit code base

commit ad7d88a
Author: Matthias Mair <code@mjmair.com>
Date:   Sun Jan 7 19:59:45 2024 +0100

    auto fixed docstring

commit a2e54a7
Author: Matthias Mair <code@mjmair.com>
Date:   Sun Jan 7 19:46:35 2024 +0100

    fix getattr useage

commit cb80c73
Author: Matthias Mair <code@mjmair.com>
Date:   Sun Jan 7 19:25:09 2024 +0100

    fix requirements file

commit b7780bb
Author: Matthias Mair <code@mjmair.com>
Date:   Sun Jan 7 18:42:28 2024 +0100

    fix removed sections

commit 71f1681
Author: Matthias Mair <code@mjmair.com>
Date:   Sun Jan 7 18:41:21 2024 +0100

    fix djlint syntax

commit a0bcf1b
Author: Matthias Mair <code@mjmair.com>
Date:   Sun Jan 7 18:35:28 2024 +0100

    remove flake8 from code base

commit 22475b3
Author: Matthias Mair <code@mjmair.com>
Date:   Sun Jan 7 18:34:56 2024 +0100

    remove flake8 from code base

commit 0413350
Author: Matthias Mair <code@mjmair.com>
Date:   Sun Jan 7 18:24:39 2024 +0100

    moved ruff section

commit d90c48a
Author: Matthias Mair <code@mjmair.com>
Date:   Sun Jan 7 18:24:24 2024 +0100

    move djlint config to pyproject

commit c5ce55d
Author: Matthias Mair <code@mjmair.com>
Date:   Sun Jan 7 18:20:39 2024 +0100

    added isort again

commit 42a41d2
Author: Matthias Mair <code@mjmair.com>
Date:   Sun Jan 7 18:19:02 2024 +0100

    move config section

commit 8569233
Author: Matthias Mair <code@mjmair.com>
Date:   Sun Jan 7 18:17:52 2024 +0100

    fix codespell error

commit 2897c67
Author: Matthias Mair <code@mjmair.com>
Date:   Sun Jan 7 17:29:21 2024 +0100

    replaced flake8 with ruff
    mostly for speed improvements
  • Loading branch information
matmair committed Jan 7, 2024
1 parent dfaee0e commit 1f34360
Show file tree
Hide file tree
Showing 18 changed files with 114 additions and 110 deletions.
2 changes: 0 additions & 2 deletions .devcontainer/devcontainer.json
Expand Up @@ -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",
Expand Down
3 changes: 0 additions & 3 deletions .djlintrc

This file was deleted.

40 changes: 4 additions & 36 deletions .github/workflows/qc_checks.yaml
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 12 additions & 14 deletions .pre-commit-config.yaml
Expand Up @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion InvenTree/common/models.py
Expand Up @@ -2472,7 +2472,7 @@ class ColorTheme(models.Model):
def get_color_themes_choices(cls):
"""Get all color themes from static folder."""
if not settings.STATIC_COLOR_THEMES_DIR.exists():
logger.error('Theme directory does not exsist')
logger.error('Theme directory does not exists')
return []

# Get files list from css/color-themes/ folder
Expand Down
4 changes: 2 additions & 2 deletions InvenTree/common/notifications.py
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion InvenTree/part/stocktake.py
Expand Up @@ -24,7 +24,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion InvenTree/part/test_api.py
Expand Up @@ -80,7 +80,7 @@ def test_category_list(self):
({'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'),
Expand Down
2 changes: 1 addition & 1 deletion InvenTree/plugin/base/integration/APICallMixin.py
Expand Up @@ -93,7 +93,7 @@ def api_headers(self):
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:
Expand Down
2 changes: 1 addition & 1 deletion InvenTree/plugin/base/label/mixins.py
Expand Up @@ -82,7 +82,7 @@ def print_labels(self, label: LabelTemplate, items: list, request: Request, prin
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:
Expand Down
2 changes: 1 addition & 1 deletion InvenTree/plugin/models.py
Expand Up @@ -189,7 +189,7 @@ def get_setting_definition(cls, key, **kwargs):
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, {})

Expand Down
3 changes: 1 addition & 2 deletions InvenTree/plugins/__init__.py
@@ -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
"""
2 changes: 1 addition & 1 deletion InvenTree/stock/test_api.py
Expand Up @@ -77,7 +77,7 @@ def test_list(self):
({'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'),
]
Expand Down
81 changes: 81 additions & 0 deletions pyproject.toml
@@ -0,0 +1,81 @@

[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"
3 changes: 0 additions & 3 deletions requirements-dev.in
Expand Up @@ -5,10 +5,7 @@ coveralls==2.1.2 # Coveralls linking (for tracking covera
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
Expand Down
19 changes: 0 additions & 19 deletions requirements-dev.txt
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -115,8 +98,6 @@ requests==2.31.0
# via
# -c requirements.txt
# coveralls
snowballstemmer==2.2.0
# via pydocstyle
sqlparse==0.4.4
# via
# -c requirements.txt
Expand Down
9 changes: 7 additions & 2 deletions requirements.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1f34360

Please sign in to comment.