Skip to content

Replace pycodestyle with ruff #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/lint-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ jobs:
pip install .[test]
- name: Build documentation
run: mkdocs build
- name: Run pycodestyle
run: |
pycodestyle --ignore=W504,E501 netbox_branching/
- name: Run ruff
run: ruff check
tests:
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down
2 changes: 1 addition & 1 deletion netbox_branching/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AppConfig(PluginConfig):

def ready(self):
super().ready()
from . import constants, events, search, signal_receivers
from . import constants, events, search, signal_receivers # noqa: F401
from .utilities import DynamicSchemaDict

# Validate required settings
Expand Down
2 changes: 1 addition & 1 deletion netbox_branching/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.http import HttpResponseBadRequest

from .constants import COOKIE_NAME, QUERY_PARAM
from .utilities import activate_branch, is_api_request, get_active_branch
from .utilities import is_api_request, get_active_branch

__all__ = (
'BranchMiddleware',
Expand Down
84 changes: 71 additions & 13 deletions netbox_branching/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand All @@ -20,8 +19,7 @@ class Migration(migrations.Migration):
operations = [
migrations.CreateModel(
name='ObjectChange',
fields=[
],
fields=[],
options={
'proxy': True,
'indexes': [],
Expand All @@ -35,16 +33,37 @@ class Migration(migrations.Migration):
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True, null=True)),
('last_updated', models.DateTimeField(auto_now=True, null=True)),
('custom_field_data', models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder)),
(
'custom_field_data',
models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
),
('description', models.CharField(blank=True, max_length=200)),
('comments', models.TextField(blank=True)),
('name', models.CharField(max_length=100, unique=True)),
('schema_id', models.CharField(editable=False, max_length=8)),
('status', models.CharField(default='new', editable=False, max_length=50)),
('last_sync', models.DateTimeField(blank=True, editable=False, null=True)),
('merged_time', models.DateTimeField(blank=True, null=True)),
('merged_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('owner', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='branches', to=settings.AUTH_USER_MODEL)),
(
'merged_by',
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name='+',
to=settings.AUTH_USER_MODEL,
),
),
(
'owner',
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name='branches',
to=settings.AUTH_USER_MODEL,
),
),
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
],
options={
Expand All @@ -57,8 +76,20 @@ class Migration(migrations.Migration):
name='AppliedChange',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
('change', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='application', to='core.objectchange')),
('branch', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='applied_changes', to='netbox_branching.branch')),
(
'change',
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE, related_name='application', to='core.objectchange'
),
),
(
'branch',
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name='applied_changes',
to='netbox_branching.branch',
),
),
],
options={
'verbose_name': 'applied change',
Expand All @@ -72,8 +103,22 @@ class Migration(migrations.Migration):
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
('time', models.DateTimeField(auto_now_add=True)),
('type', models.CharField(editable=False, max_length=50)),
('branch', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='events', to='netbox_branching.branch')),
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='branch_events', to=settings.AUTH_USER_MODEL)),
(
'branch',
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, related_name='events', to='netbox_branching.branch'
),
),
(
'user',
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name='branch_events',
to=settings.AUTH_USER_MODEL,
),
),
],
options={
'verbose_name': 'branch event',
Expand All @@ -92,9 +137,22 @@ class Migration(migrations.Migration):
('original', models.JSONField(blank=True, null=True)),
('modified', models.JSONField(blank=True, null=True)),
('current', models.JSONField(blank=True, null=True)),
('conflicts', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), blank=True, editable=False, null=True, size=None)),
('branch', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='netbox_branching.branch')),
('object_type', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='contenttypes.contenttype')),
(
'conflicts',
django.contrib.postgres.fields.ArrayField(
base_field=models.CharField(max_length=100), blank=True, editable=False, null=True, size=None
),
),
(
'branch',
models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='netbox_branching.branch'),
),
(
'object_type',
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT, related_name='+', to='contenttypes.contenttype'
),
),
],
options={
'verbose_name': 'change diff',
Expand Down
8 changes: 4 additions & 4 deletions netbox_branching/models/branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def sync(self, user, commit=True):
if changes := self.get_unsynced_changes().order_by('time'):
logger.info(f"Found {len(changes)} changes to sync")
else:
logger.info(f"No changes found; aborting.")
logger.info("No changes found; aborting.")
return

# Update Branch status
Expand Down Expand Up @@ -329,7 +329,7 @@ def merge(self, user, commit=True):
if changes := self.get_unmerged_changes().order_by('time'):
logger.info(f"Found {len(changes)} changes to merge")
else:
logger.info(f"No changes found; aborting.")
logger.info("No changes found; aborting.")
return

# Update Branch status
Expand Down Expand Up @@ -392,7 +392,7 @@ def revert(self, user, commit=True):
logger.info(f'Reverting branch {self} ({self.schema_name})')

if not self.merged:
raise Exception(f"Only merged branches can be reverted.")
raise Exception("Only merged branches can be reverted.")

# Emit pre-revert signal
pre_revert.send(sender=self.__class__, branch=self, user=user)
Expand All @@ -401,7 +401,7 @@ def revert(self, user, commit=True):
if changes := self.get_changes().order_by('-time'):
logger.info(f"Found {len(changes)} changes to revert")
else:
logger.info(f"No changes found; aborting.")
logger.info("No changes found; aborting.")
return

# Update Branch status
Expand Down
2 changes: 1 addition & 1 deletion netbox_branching/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_with_branch_header(self):
# Branch-aware API query
header = {
**self.header,
f'HTTP_X_NETBOX_BRANCH': branch.schema_id,
'HTTP_X_NETBOX_BRANCH': branch.schema_id,
}
response = self.client.get(url, **header)
results = self.get_results(response)
Expand Down
2 changes: 1 addition & 1 deletion netbox_branching/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def get_active_branch(request):
messages.error(request, f"Branch {branch} is not ready for use (status: {branch.status})")
return None
else:
messages.success(request, f"Deactivated branch")
messages.success(request, "Deactivated branch")
request.COOKIES.pop(COOKIE_NAME, None) # Delete cookie if set
return None

Expand Down
2 changes: 1 addition & 1 deletion netbox_branching/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class BranchArchiveView(generic.ObjectView):
template_name = 'netbox_branching/branch_archive.html'

def get_required_permission(self):
return f'netbox_branching.archive_branch'
return 'netbox_branching.archive_branch'

@staticmethod
def _enforce_status(request, branch):
Expand Down
13 changes: 12 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies = [
]

[project.optional-dependencies]
dev = ["check-manifest", "mkdocs", "mkdocs-material", "pycodestyle"]
dev = ["check-manifest", "mkdocs", "mkdocs-material", "ruff"]
test = ["coverage", "pytest", "pytest-cov"]

[project.urls]
Expand All @@ -44,6 +44,17 @@ package-data = { "netbox_branching" = ["**/*", "templates/**"] }
exclude-package-data = { netbox_branching = ["tests/*"] }
license-files = ["LICENSE.md"]

[tool.ruff]
line-length = 120

[tool.ruff.lint]
extend-select = ["E1", "E2", "E3", "E501", "W"]
ignore = ["F403", "F405"]
preview = true

[tool.ruff.format]
quote-style = "single"

[build-system]
requires = ["setuptools>=43.0.0", "wheel"]
build-backend = "setuptools.build_meta"