Skip to content

Commit

Permalink
Move to ruff (#147)
Browse files Browse the repository at this point in the history
* Upgrade test urlconf
  • Loading branch information
yakky committed Apr 18, 2023
1 parent 71caa0b commit 235fa13
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 113 deletions.
25 changes: 25 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[bumpversion]
current_version = 2.1.1.dev0
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.?)(?P<release>[a-z]*)(?P<relver>\d*)
serialize =
{major}.{minor}.{patch}.{release}{relver}
{major}.{minor}.{patch}
commit = True
tag = True
sign_tags = True
tag_name = {new_version}
message = Release {new_version}

[bumpversion:part:release]
optional_value = gamma
values =
dev
a
b
rc
gamma

[bumpversion:part:relver]
first_value = 1

[bumpversion:file:knocker/__init__.py]
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
python-version: [3.9]
toxenv: [pep8, isort, black, pypi-description, docs, towncrier]
toxenv: [ruff, isort, black, pypi-description, docs, towncrier]
steps:
- uses: actions/checkout@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
run: |
tox -e$TOX_ENV
.tox/$TOX_ENV/bin/coverage xml
.tox/$TOX_ENV/bin/coveralls
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,4 @@ $RECYCLE.BIN/

*.sqlite
data
!/.ruff_cache/
25 changes: 10 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
rev: v4.4.0
hooks:
- id: trailing-whitespace
exclude: "setup.cfg"
exclude: .bumpversion.cfg
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
Expand All @@ -25,21 +25,10 @@ repos:
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 5.0.2
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.261'
hooks:
- id: flake8
additional_dependencies:
- flake8-broken-line
- flake8-bugbear
- flake8-builtins
- flake8-coding
- flake8-commas
- flake8-comprehensions
- flake8-eradicate
- flake8-quotes
- flake8-tidy-imports
- pep8-naming
- id: ruff
- repo: https://github.com/econchick/interrogate
rev: 1.5.0
hooks:
Expand All @@ -53,6 +42,11 @@ repos:
- id: pyupgrade
args:
- --py3-plus
- repo: https://github.com/adamchainz/django-upgrade
rev: "1.13.0"
hooks:
- id: django-upgrade
args: [--target-version, "3.2"]
- repo: local
hooks:
- id: towncrier
Expand All @@ -61,6 +55,7 @@ repos:
language: system
pass_filenames: false
always_run: true

ci:
skip:
- towncrier
1 change: 1 addition & 0 deletions changes/138.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move to ruff
21 changes: 20 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,28 @@ build-backend = "setuptools.build_meta"

[tool.black]
line-length = 119
target-version = ["py36"]
target-version = ["py310"]
include = 'meta/*py'

[tool.isort]
profile = "black"
combine_as_imports = true
default_section = "THIRDPARTY"
force_grid_wrap = 0
include_trailing_comma = true
known_first_party = "knocker"
line_length = 119
multi_line_output = 3
use_parentheses = true

[tool.ruff]
ignore = []
line-length = 119
target-version = "py310"

[tool.ruff.mccabe]
max-complexity = 10

[tool.towncrier]
package = "meta"
directory = "changes"
Expand Down
30 changes: 1 addition & 29 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
[bumpversion]
current_version = 2.1.1.dev0
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.?)(?P<release>[a-z]*)(?P<relver>\d*)
serialize =
{major}.{minor}.{patch}.{release}{relver}
{major}.{minor}.{patch}
commit = True
tag = True
sign_tags = True
tag_name = {new_version}
message = Release {new_version}

[bumpversion:part:release]
optional_value = gamma
values =
dev
a
b
rc
gamma

[bumpversion:file:meta/__init__.py]

[metadata]
name = django-meta
version = attr: meta.__version__
Expand Down Expand Up @@ -53,8 +30,6 @@ classifiers =

[options]
include_package_data = True
install_requires =
six
setup_requires =
setuptools
packages = meta
Expand All @@ -68,10 +43,7 @@ meta = *.html *.png *.gif *js *jpg *jpeg *svg *py *mo *po

[options.extras_require]
docs =
django<4.0

[upload]
repository = https://upload.pypi.org/legacy/
django<5.0

[sdist]
formats = zip
Expand Down
2 changes: 1 addition & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def clean(c):
@task
def lint(c):
"""Run linting tox environments."""
c.run("tox -epep8,isort,black,pypi-description")
c.run("tox -eruff,isort,black,pypi-description")


@task # NOQA
Expand Down
35 changes: 10 additions & 25 deletions tests/example_app/urls.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
import django.views.static
from django.conf import settings
from django.contrib import admin
from django.urls import re_path
from django.urls import path
from django.views.i18n import JavaScriptCatalog
from django.views.static import serve

from .views import PostDetailView, PostListView, PostMixinDetailView, PostMixinImageObjectDetailView

try:
from django.views.i18n import JavaScriptCatalog

javascript_catalog = JavaScriptCatalog.as_view()
except ImportError:
from django.views.i18n import javascript_catalog

admin.autodiscover()

urlpatterns = [
re_path(
r"^media/(?P<path>.*)$",
django.views.static.serve, # NOQA
{"document_root": settings.MEDIA_ROOT, "show_indexes": True},
),
re_path(r"^jsi18n/(?P<packages>\S+?)/$", javascript_catalog), # NOQA
re_path(r"^mixin/(?P<slug>\w[-\w]*)/$", PostMixinDetailView.as_view(), name="post-detail-mixinx"),
re_path(
r"^mixin_image/(?P<slug>\w[-\w]*)/$", PostMixinImageObjectDetailView.as_view(), name="post-detail-image-mixinx"
),
re_path(r"^(?P<slug>\w[-\w]*)/$", PostDetailView.as_view(), name="post-detail"),
re_path(r"^$", PostListView.as_view(), name="post-list"),
path("admin/", admin.site.urls),
path("media/<str:path>", serve, {"document_root": settings.MEDIA_ROOT, "show_indexes": True}),
path("jsi18n/", JavaScriptCatalog.as_view(), name="javascript-catalog"),
path("mixin/<slug:slug>/", PostMixinDetailView.as_view(), name="post-detail-mixinx"),
path("mixin_image/<slug:slug>/", PostMixinImageObjectDetailView.as_view(), name="post-detail-image-mixinx"),
path("<slug:slug>/", PostDetailView.as_view(), name="post-detail"),
path("", PostListView.as_view(), name="post-list"),
]
try:
urlpatterns.insert(0, re_path(r"^admin/", admin.site.urls)), # NOQA
except Exception:
urlpatterns.insert(0, re_path(r"^admin/", include(admin.site.urls))), # NOQA
49 changes: 8 additions & 41 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ envlist =
docs
isort
isort_format
pep8
ruff
pypi-description
towncrier
py{311,310,39}-django{42,32}-{sekizai,nosekizai}
Expand All @@ -22,23 +22,12 @@ passenv =
COMMAND
PYTEST_*

[testenv:pep8]
[testenv:ruff]
commands =
{envpython} -m flake8
{envpython} -minterrogate -c pyproject.toml meta tests
{envpython} -m ruff check meta tests
deps =
interrogate
flake8<6.0.0
flake8-broken-line
flake8-bugbear
flake8-builtins
flake8-coding
flake8-commas
flake8-comprehensions
flake8-eradicate
flake8-quotes
flake8-tidy-imports
pep8-naming
ruff
skip_install = true

[testenv:isort]
Expand Down Expand Up @@ -69,7 +58,7 @@ skip_install = true
commands =
{envpython} -m invoke docbuild
deps =
django==4.2
django~=4.2.0
invoke
sphinx
sphinx-rtd-theme
Expand All @@ -89,48 +78,26 @@ skip_install = true
commands =
{envpython} -m invoke clean
{envpython} -m check_manifest
{envpython} -m pep517.build .
{envpython} -m build .
{envpython} -m twine check dist/*
deps =
invoke
check-manifest
pep517
build
twine
skip_install = true

[testenv:release]
commands =
{envpython} -m invoke clean
{envpython} -m check_manifest
{envpython} -m pep517.build .
{envpython} -m build .
{envpython} -m twine upload {posargs} dist/*
deps = {[testenv:pypi-description]deps}
passenv =
TWINE_*
skip_install = true

[flake8]
exclude = *.egg-info,.git,.settings,.tox,build,dist,docs,requirements,tmp,*migrations*,tests,data
ignore = E800, W503, C812, C813, C815, C818, C819, C408
max-line-length = 119
# flake8-quotes
inline-quotes = double
# flake8-coding
no-accept-encodings = True
# flake8-tidy-imports
banned-modules = __future__ = this project supports python3 only

[isort]
combine_as_imports = true
default_section = THIRDPARTY
force_grid_wrap = 0
include_trailing_comma = true
known_first_party = meta
line_length = 119
multi_line_output = 3
skip = data, .tox
use_parentheses = True

[check-manifest]
ignore =
.*
Expand Down

0 comments on commit 235fa13

Please sign in to comment.