From 28314c5335fb9e83b86620751c4f0b94372d184f Mon Sep 17 00:00:00 2001 From: Alexander Saprykin Date: Mon, 14 Oct 2024 16:09:41 +0200 Subject: [PATCH] Incorporate ruff linter into CI pipeline (#2311) The ruff tool is a linting and formatting tool, that replaces most of the functionality of the flake8 including most popular plugins, isort and black. This commit adds ruff into development and CI pipeline with minimal configuration. This enables only basic checks that will be expanded in future aiming to replace flake8 with plugins and isort. Fixed warnings: 11 F401 [*] unused-import 3 F841 [*] unused-variable 2 F811 [*] redefined-while-unused 1 E741 [ ] ambiguous-variable-name --- .ci/scripts/extra_linting.sh | 9 --------- .github/workflows/ci_full.yml | 13 ++++--------- Makefile | 1 + flake8.cfg | 2 +- .../migrations/0003_inbound_repo_per_namespace.py | 2 +- ...mote_containerregistryrepos_containersynctask.py | 1 - .../migrations/0017_populate_repos_and_remotes.py | 11 ++++------- .../app/migrations/0034_remove_inbound_repos.py | 1 - galaxy_ng/app/migrations/0036_repository_labels.py | 1 - galaxy_ng/app/migrations/0038_namespace_sync.py | 4 +--- .../0040_fix_collection_remote_pulp_type.py | 6 ------ galaxy_ng/app/migrations/0053_wait_for_dab_rbac.py | 4 +--- .../migrations/0054_galaxy_role_defs_to_dab_defs.py | 1 - galaxy_ng/app/migrations/_dab_rbac.py | 1 - lint_requirements.txt | 2 +- pyproject.toml | 6 ++++++ 16 files changed, 20 insertions(+), 45 deletions(-) delete mode 100755 .ci/scripts/extra_linting.sh diff --git a/.ci/scripts/extra_linting.sh b/.ci/scripts/extra_linting.sh deleted file mode 100755 index 4bf192d162..0000000000 --- a/.ci/scripts/extra_linting.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -EXIT_CODE=0 - -# Plugin template removed the call to the flake8 linter -# so we need to call it ourselves. -flake8 --config flake8.cfg || EXIT_CODE=1 - -exit $EXIT_CODE diff --git a/.github/workflows/ci_full.yml b/.github/workflows/ci_full.yml index 0ac39900ac..37f556714f 100644 --- a/.github/workflows/ci_full.yml +++ b/.github/workflows/ci_full.yml @@ -1,10 +1,8 @@ --- name: galaxy_ng/ci on: - pull_request: - branches: ['**'] - push: - branches: ['**'] + - push + - pull_request jobs: @@ -44,11 +42,8 @@ jobs: - name: Install requirements run: pip3 install -r lint_requirements.txt - - name: Run extra lint checks - run: "[ ! -x .ci/scripts/extra_linting.sh ] || .ci/scripts/extra_linting.sh" - - - name: Check manifest - run: check-manifest + - name: Run linters + run: make lint - name: Check for pulpcore imports outside of pulpcore.plugin run: sh .ci/scripts/check_pulpcore_imports.sh diff --git a/Makefile b/Makefile index 037aac642b..ed3d8642cd 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,7 @@ requirements/pip-upgrade-all: ## Update based on setup.py and *.in files, an lint: ## Lint the code check-manifest flake8 --config flake8.cfg + ruff check . .PHONY: fmt fmt: ## Format the code using Darker diff --git a/flake8.cfg b/flake8.cfg index 11b8a450aa..efcac4e028 100644 --- a/flake8.cfg +++ b/flake8.cfg @@ -9,7 +9,7 @@ exclude = .ci/scripts/*, .github/workflows/scripts/*, .venv/*, - ./galaxy_ng/_vendor/automated_logging/*, + ./galaxy_ng/_vendor/*, .tox/*, ignore = BLK,W503,Q000,D,D100,D101,D102,D103,D104,D105,D106,D107,D200,D401,D402,E203 diff --git a/galaxy_ng/app/migrations/0003_inbound_repo_per_namespace.py b/galaxy_ng/app/migrations/0003_inbound_repo_per_namespace.py index 2dd9541bd9..84a4e861cf 100644 --- a/galaxy_ng/app/migrations/0003_inbound_repo_per_namespace.py +++ b/galaxy_ng/app/migrations/0003_inbound_repo_per_namespace.py @@ -12,7 +12,7 @@ def create_inbound_repo_per_namespace(apps, schema_editor): name=name, pulp_type='ansible.ansible', ) - distro = AnsibleDistribution.objects.using(db_alias).create( + AnsibleDistribution.objects.using(db_alias).create( name=name, base_path=name, repository=repo, diff --git a/galaxy_ng/app/migrations/0016_containerregistryremote_containerregistryrepos_containersynctask.py b/galaxy_ng/app/migrations/0016_containerregistryremote_containerregistryrepos_containersynctask.py index 21b06fc2d8..c8b28d0d37 100644 --- a/galaxy_ng/app/migrations/0016_containerregistryremote_containerregistryrepos_containersynctask.py +++ b/galaxy_ng/app/migrations/0016_containerregistryremote_containerregistryrepos_containersynctask.py @@ -2,7 +2,6 @@ from django.db import migrations, models import django.db.models.deletion -import django_lifecycle.mixins import galaxy_ng.app.access_control.mixins diff --git a/galaxy_ng/app/migrations/0017_populate_repos_and_remotes.py b/galaxy_ng/app/migrations/0017_populate_repos_and_remotes.py index f5e86b0f5c..5c89973eac 100644 --- a/galaxy_ng/app/migrations/0017_populate_repos_and_remotes.py +++ b/galaxy_ng/app/migrations/0017_populate_repos_and_remotes.py @@ -62,35 +62,32 @@ def populate_initial_repos(apps, schema_editor): db_alias = schema_editor.connection.alias AnsibleRepository = apps.get_model('ansible', 'AnsibleRepository') - AnsibleDistribution = apps.get_model('ansible', 'AnsibleDistribution') - CollectionRemote = apps.get_model('ansible', 'CollectionRemote') - RepositoryVersion = apps.get_model('core', 'RepositoryVersion') for repo_data in REPOSITORIES: remote = repo_data.pop("remote", None) if remote is not None: - remote, _ = CollectionRemote.objects.get_or_create( + remote, _ = CollectionRemote.objects.using(db_alias).get_or_create( name=remote["name"], defaults=remote ) repo_data["remote"] = remote - repository, _ = AnsibleRepository.objects.get_or_create( + repository, _ = AnsibleRepository.objects.using(db_alias).get_or_create( name=repo_data["name"], defaults=repo_data ) if not RepositoryVersion.objects.filter(repository__name=repository.name): - RepositoryVersion.objects.create( + RepositoryVersion.objects.using(db_alias).create( repository=repository, number=0, complete=True ) - AnsibleDistribution.objects.get_or_create( + AnsibleDistribution.objects.using(db_alias).get_or_create( base_path=repository.name, defaults={ "name": repository.name, diff --git a/galaxy_ng/app/migrations/0034_remove_inbound_repos.py b/galaxy_ng/app/migrations/0034_remove_inbound_repos.py index 1888778ce9..109f19eed9 100644 --- a/galaxy_ng/app/migrations/0034_remove_inbound_repos.py +++ b/galaxy_ng/app/migrations/0034_remove_inbound_repos.py @@ -6,7 +6,6 @@ def remove_inbound_repos(apps, schema_editor): AnsibleDistribution = apps.get_model('ansible', 'AnsibleDistribution') AnsibleRepository = apps.get_model('ansible', 'AnsibleRepository') - RepositoryContent = apps.get_model('core', 'RepositoryContent') repos = AnsibleRepository.objects.filter(name__startswith="inbound-") diff --git a/galaxy_ng/app/migrations/0036_repository_labels.py b/galaxy_ng/app/migrations/0036_repository_labels.py index 1fa4eb3b8b..b96d4d3220 100644 --- a/galaxy_ng/app/migrations/0036_repository_labels.py +++ b/galaxy_ng/app/migrations/0036_repository_labels.py @@ -1,6 +1,5 @@ # Generated by Django 3.2.18 on 2023-02-15 13:52 -import django.core.validators from django.db import migrations from django.db.models import Q diff --git a/galaxy_ng/app/migrations/0038_namespace_sync.py b/galaxy_ng/app/migrations/0038_namespace_sync.py index 4a684a3be2..e141f03d0a 100644 --- a/galaxy_ng/app/migrations/0038_namespace_sync.py +++ b/galaxy_ng/app/migrations/0038_namespace_sync.py @@ -1,5 +1,3 @@ -import django.core.validators -from django.db import migrations import hashlib import json @@ -36,7 +34,7 @@ def add_pulp_ansible_namespace_metadata_objects(apps, schema_editor): for old_ns in Namespace.objects.all(): new_ns = AnsibleNamespace.objects.create(name=old_ns.name) - links = {l.name: l.url for l in old_ns.links.all()} + links = {link.name: link.url for link in old_ns.links.all()} metadata = { "company": old_ns.company, diff --git a/galaxy_ng/app/migrations/0040_fix_collection_remote_pulp_type.py b/galaxy_ng/app/migrations/0040_fix_collection_remote_pulp_type.py index e5101212ce..0cc66b96d9 100644 --- a/galaxy_ng/app/migrations/0040_fix_collection_remote_pulp_type.py +++ b/galaxy_ng/app/migrations/0040_fix_collection_remote_pulp_type.py @@ -1,10 +1,4 @@ -import django.core.validators from django.db import migrations -import hashlib -import json - -from django.db import migrations, models -import django.db.models.deletion def set_collection_remote_type(apps, schema_editor): diff --git a/galaxy_ng/app/migrations/0053_wait_for_dab_rbac.py b/galaxy_ng/app/migrations/0053_wait_for_dab_rbac.py index c33968a011..a09853db08 100644 --- a/galaxy_ng/app/migrations/0053_wait_for_dab_rbac.py +++ b/galaxy_ng/app/migrations/0053_wait_for_dab_rbac.py @@ -1,8 +1,6 @@ # Generated by Django 4.2.10 on 2024-02-15 17:33 -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models +from django.db import migrations class Migration(migrations.Migration): diff --git a/galaxy_ng/app/migrations/0054_galaxy_role_defs_to_dab_defs.py b/galaxy_ng/app/migrations/0054_galaxy_role_defs_to_dab_defs.py index 1c1092ee5c..55c5777741 100644 --- a/galaxy_ng/app/migrations/0054_galaxy_role_defs_to_dab_defs.py +++ b/galaxy_ng/app/migrations/0054_galaxy_role_defs_to_dab_defs.py @@ -1,5 +1,4 @@ import logging -import time from django.db import migrations diff --git a/galaxy_ng/app/migrations/_dab_rbac.py b/galaxy_ng/app/migrations/_dab_rbac.py index 8f7fef3ece..4a53edc609 100644 --- a/galaxy_ng/app/migrations/_dab_rbac.py +++ b/galaxy_ng/app/migrations/_dab_rbac.py @@ -1,7 +1,6 @@ import logging from django.apps import apps as global_apps -from django.contrib.contenttypes.models import ContentType from rest_framework.exceptions import ValidationError from ansible_base.rbac.management import create_dab_permissions diff --git a/lint_requirements.txt b/lint_requirements.txt index b76e72e15b..484bef93d5 100644 --- a/lint_requirements.txt +++ b/lint_requirements.txt @@ -1,4 +1,4 @@ -# python packages handy for developers, but not required by pulp check-manifest flake8 yamllint +ruff diff --git a/pyproject.toml b/pyproject.toml index 6fad5d41b3..7965eb0c1c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -92,3 +92,9 @@ omit = [ "galaxy_ng/_vendor/*", "galaxy_ng/tests/*", ] + +[tool.ruff] +line-length = 100 +extend-exclude = [ + "galaxy_ng/_vendor/", +]