diff --git a/Makefile b/Makefile index de709d455..cc3d1491e 100644 --- a/Makefile +++ b/Makefile @@ -66,15 +66,18 @@ lint.install: echo "Installing..." pip install -Iv ruff +# The preferred method (for now) w.r.t. fixable rules is to manually update the makefile +# with --fix and re-run 'make lint.' Since ruff is constantly adding rules this is a slight +# amount of "needed" friction imo. lint.run: - ruff check --select F401 --select I . --fix + ruff check ruff format lint.check: echo "Linting..." + ruff check + echo "Formatting..." ruff format --check - echo "Sorting..." - ruff check --select F401 --select I . build.requirements: # if docker pull succeeds, we have already build this version of diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 000000000..52ad2f14b --- /dev/null +++ b/ruff.toml @@ -0,0 +1,63 @@ +# Exclude a variety of commonly ignored directories. +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".git-rewrite", + ".hg", + ".ipynb_checkpoints", + ".mypy_cache", + ".nox", + ".pants.d", + ".pyenv", + ".pytest_cache", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + ".vscode", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "site-packages", + "venv", +] + +# Same as Black. +line-length = 88 +indent-width = 4 + +# Assume Python 3.12 +target-version = "py312" + +[lint] +# Currently only enabled for most F (Pyflakes) and I (isort) rules: https://docs.astral.sh/ruff/rules/ +select = ["F", "I"] +ignore = ["F841", "F405", "F403"] + +# Allow fix for all enabled rules (when `--fix`) is provided. +# The preferred method (for now) w.r.t. fixable rules is to manually update the makefile +# with --fix and re-run 'make lint' +fixable = ["ALL"] +unfixable = [] + +# Allow unused variables when underscore-prefixed. +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" + +[format] +# Like Black, use double quotes for strings. +quote-style = "double" + +# Like Black, indent with spaces, rather than tabs. +indent-style = "space" + +# Like Black, respect magic trailing commas. +skip-magic-trailing-comma = false + +# Like Black, automatically detect the appropriate line ending. +line-ending = "auto" \ No newline at end of file diff --git a/services/notification/notifiers/tests/unit/test_checks.py b/services/notification/notifiers/tests/unit/test_checks.py index c41ecf4f2..dbdcc4b32 100644 --- a/services/notification/notifiers/tests/unit/test_checks.py +++ b/services/notification/notifiers/tests/unit/test_checks.py @@ -1161,7 +1161,7 @@ async def test_notification_exception( assert result.data_sent is None @pytest.mark.asyncio - async def test_notification_exception(self, sample_comparison, mocker): + async def test_notification_exception_not_fit(self, sample_comparison, mocker): notifier = ChecksNotifier( repository=sample_comparison.head.commit.repository, title="title", diff --git a/services/notification/notifiers/tests/unit/test_comment.py b/services/notification/notifiers/tests/unit/test_comment.py index eb3281d7e..cc1c729f5 100644 --- a/services/notification/notifiers/tests/unit/test_comment.py +++ b/services/notification/notifiers/tests/unit/test_comment.py @@ -4977,7 +4977,7 @@ async def test_build_message_team_plan_customer_all_lines_covered_test_results_e assert result == expected_result @pytest.mark.asyncio - async def test_build_message_team_plan_customer_all_lines_covered( + async def test_build_message_team_plan_customer_all_lines_covered_no_third_line( self, dbsession, mock_configuration, diff --git a/services/report/__init__.py b/services/report/__init__.py index 8e8bc13cb..ec0264b5c 100644 --- a/services/report/__init__.py +++ b/services/report/__init__.py @@ -25,7 +25,6 @@ from shared.utils.sessions import Session, SessionType from shared.yaml import UserYaml -from database.enums import ReportType from database.models import Commit, Repository, Upload, UploadError from database.models.reports import ( AbstractTotals, diff --git a/services/tests/test_flake_detector.py b/services/tests/test_flake_detector.py index eaf3230d6..8825e81e8 100644 --- a/services/tests/test_flake_detector.py +++ b/services/tests/test_flake_detector.py @@ -161,32 +161,6 @@ def test_flake_consecutive_differing_outcomes_no_main_branch_specified(dbsession assert flaky_tests[test_id] == {FlakeSymptomType.CONSECUTIVE_DIFF_OUTCOMES} -def test_flake_consecutive_differing_outcomes_no_main_branch_specified(dbsession): - repoid = create_repo( - dbsession, - ) - commitid = create_commit(dbsession, repoid, "not_main") - reportid = create_report(dbsession, commitid) - reportid2 = create_report(dbsession, commitid) - uploadid = create_upload(dbsession, reportid) - uploadid2 = create_upload(dbsession, reportid2) - test_id = create_test(dbsession, repoid) - ti1 = create_test_instance( - dbsession, test_id, uploadid, str(Outcome.Failure), "failure message" - ) - _ = create_test_instance(dbsession, test_id, uploadid2, str(Outcome.Pass), None) - - dbfd = DefaultBranchFailureDetector(dbsession, repoid) - umd = UnrelatedMatchesDetector() - dod = DiffOutcomeDetector() - - fd = FlakeDetectionEngine(dbsession, repoid, [dbfd, dod, umd]) - flaky_tests = fd.detect_flakes() - - assert test_id in flaky_tests - assert flaky_tests[test_id] == {FlakeSymptomType.CONSECUTIVE_DIFF_OUTCOMES} - - def test_flake_matching_failures_on_unrelated_branches(dbsession): repoid = create_repo( dbsession, diff --git a/services/timeseries.py b/services/timeseries.py index 53779182a..bae4b95f3 100644 --- a/services/timeseries.py +++ b/services/timeseries.py @@ -8,7 +8,6 @@ from database.models import Commit, Dataset, Measurement, MeasurementName from database.models.core import Repository from database.models.reports import RepositoryFlag -from database.models.timeseries import Dataset from helpers.timeseries import backfill_max_batch_size, timeseries_enabled from services.report import ReportService from services.yaml import get_repo_yaml diff --git a/tasks/tests/unit/test_new_user_activated.py b/tasks/tests/unit/test_new_user_activated.py index 6df3d2f9c..4d7becf0d 100644 --- a/tasks/tests/unit/test_new_user_activated.py +++ b/tasks/tests/unit/test_new_user_activated.py @@ -118,18 +118,6 @@ def test_org_not_on_pr_plan(self, mocker, dbsession, pull): "reason": "org not on pr author billing plan", } - def test_org_not_on_pr_plan(self, mocker, dbsession, pull): - pull.repository.owner.plan = "users-inappm" - dbsession.flush() - res = NewUserActivatedTask().run_impl( - dbsession, pull.repository.owner.ownerid, pull.author.ownerid - ) - assert res == { - "notifies_scheduled": False, - "pulls_notified": [], - "reason": "org not on pr author billing plan", - } - def test_no_commit_notifications_found(self, mocker, dbsession, pull): mocked_possibly_resend_notifications = mocker.patch( "tasks.new_user_activated.NewUserActivatedTask.possibly_resend_notifications" diff --git a/tasks/tests/unit/test_notify_task.py b/tasks/tests/unit/test_notify_task.py index 4ce0e1a5a..2068670f3 100644 --- a/tasks/tests/unit/test_notify_task.py +++ b/tasks/tests/unit/test_notify_task.py @@ -278,7 +278,7 @@ def test__possibly_refresh_previous_selection( assert task._possibly_refresh_previous_selection(commit) == True mock_set_gh_app_for_commit.assert_called_with(app_to_save, commit) - def test__possibly_refresh_previous_selection(self, mocker, dbsession): + def test__possibly_refresh_previous_selection_false(self, mocker, dbsession): commit = CommitFactory(repository__owner__service="github") dbsession.add(commit) dbsession.flush() diff --git a/tasks/tests/unit/test_sync_repo_languages.py b/tasks/tests/unit/test_sync_repo_languages.py index d5569800b..bcd4eb3e5 100644 --- a/tasks/tests/unit/test_sync_repo_languages.py +++ b/tasks/tests/unit/test_sync_repo_languages.py @@ -183,7 +183,7 @@ def test_languages_intersection_and_synced_beyond_threshold( task.run_impl(dbsession, repoid=repo.repoid, manual_trigger=False) == None ) - def test_languages_intersection_and_synced_beyond_threshold( + def test_languages_intersection_and_synced_beyond_threshold_with_languages( self, dbsession, setup_with_languages ): mocked_beyond_threshold = MOCKED_NOW + timedelta(days=-10) diff --git a/tasks/upload.py b/tasks/upload.py index 5db7fd854..e45664468 100644 --- a/tasks/upload.py +++ b/tasks/upload.py @@ -35,7 +35,6 @@ from services.archive import ArchiveService from services.bundle_analysis import BundleAnalysisReportService from services.redis import ( - Redis, download_archive_from_redis, get_parallel_upload_processing_session_counter_redis_key, get_redis_connection,