Skip to content
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

chore: replace pylint and black with ruff #1382

Merged
merged 7 commits into from
Oct 2, 2024

Conversation

Venefilyn
Copy link
Member

Ruff is a drop-in replacement for black and also handles linting
for us in a lot nicer way than pylint. More specifically it is a lot
faster than the alternatives and allows us to enforce PyFormat
for strings rather than percent-format or f-strings.

Jira Issues:

Checklist

  • PR has been tested manually in a VM (either author or reviewer)
  • Jira issue has been made public if possible
  • [RHELC-] or [HMS-] is part of the PR title
  • GitHub label has been added to help with Release notes
  • PR title explains the change from the user's point of view
  • Code and tests are documented properly
  • The commits are squashed to as few commits as possible (without losing data)
  • When merged: Jira issue has been updated to Release Pending if relevant

@Venefilyn Venefilyn requested review from r0x0d and a team as code owners September 23, 2024 13:36
Copy link

codecov bot commented Sep 23, 2024

Codecov Report

Attention: Patch coverage is 95.86466% with 11 lines in your changes missing coverage. Please review.

Project coverage is 96.51%. Comparing base (27e14a4) to head (3a43a0b).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
...ions/system_checks/check_firewalld_availability.py 50.00% 2 Missing ⚠️
convert2rhel/toolopts/config.py 75.00% 2 Missing ⚠️
convert2rhel/applock.py 75.00% 1 Missing ⚠️
convert2rhel/exceptions.py 0.00% 1 Missing ⚠️
convert2rhel/grub.py 94.44% 1 Missing ⚠️
convert2rhel/pkghandler.py 96.55% 1 Missing ⚠️
convert2rhel/redhatrelease.py 80.00% 1 Missing ⚠️
convert2rhel/subscription.py 94.11% 1 Missing ⚠️
convert2rhel/utils/__init__.py 96.42% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1382   +/-   ##
=======================================
  Coverage   96.51%   96.51%           
=======================================
  Files          71       71           
  Lines        5077     5077           
  Branches      883      883           
=======================================
  Hits         4900     4900           
  Misses         98       98           
  Partials       79       79           
Flag Coverage Δ
centos-linux-7 92.01% <89.47%> (ø)
centos-linux-8 92.88% <87.59%> (ø)
centos-linux-9 92.92% <87.59%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Venefilyn
Copy link
Member Author

/packit test --labels sanity

pyproject.toml Outdated

# We technically only support py27 py36 due to el7 and el8 but ruff only
# supports py37 as minimum. This is not a huge issue as any rules we do not
# want we can disablew
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# want we can disablew
# want we can disable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed

@Venefilyn Venefilyn force-pushed the chore/pylint-format branch 7 times, most recently from 3b13167 to b29ecad Compare September 24, 2024 17:51
@kokesak kokesak added the tests-skip This PR does not require integration tests to be run. label Sep 25, 2024
@has-bot
Copy link
Member

has-bot commented Sep 25, 2024

This PR does not require integration tests to be run.


Comment generated by an automation.

@Venefilyn Venefilyn added the no-changelog If it should be excluded from changelog or Release notes. Such as infra, reverted PRs, etc. label Sep 25, 2024
@r0x0d r0x0d added tests-run-sanity PR ready to run the sanity test suit. Equivalent to `/packit test --labels sanity`. and removed tests-skip This PR does not require integration tests to be run. labels Sep 26, 2024
@has-bot
Copy link
Member

has-bot commented Sep 26, 2024

/packit test --labels sanity


Comment generated by an automation.

@r0x0d
Copy link
Member

r0x0d commented Sep 26, 2024

I've added the sanity test label just to be sure that nothing is broken. It will not, but just in case. Doesn't hurt to run the sanity tests suite

@kokesak
Copy link
Member

kokesak commented Sep 27, 2024

/packit test --labels sanity

@Venefilyn
Copy link
Member Author

/packit test --labels sanity

Comment on lines -3 to -4
from test_helpers.common_functions import log_file_data

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not remove this line. It is needed in the test

Copy link
Member Author

@Venefilyn Venefilyn Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we just move it to conftest to have it be available without import? It doesn't feel good to have to import a fixture like this as it is a bit confusing. I'd rather have pytest take care of it in something like conftest

diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py
index bfb0596b..0734bf56 100644
--- a/tests/integration/conftest.py
+++ b/tests/integration/conftest.py
@@ -538,3 +538,20 @@ def backup_directory(shell, request):
     yield backup_path
 
     shell(f"rm -rf {backup_path}")
+
+
+@pytest.fixture()
+def log_file_data():
+    """
+    Helper fixture.
+    Reads and returns data from the convert2rhel.log file.
+    Mainly used for after conversion checks, where we match required strings to the log output.
+    """
+    convert2rhel_log_file = "/var/log/convert2rhel/convert2rhel.log"
+
+    assert os.path.exists(convert2rhel_log_file), "The c2r log file does not exits."
+
+    with open(convert2rhel_log_file, "r") as logfile:
+        log_data = logfile.read()
+
+        return log_data
diff --git a/tests/integration/test_helpers/common_functions.py b/tests/integration/test_helpers/common_functions.py
index 069626b1..c2cd9e07 100644
--- a/tests/integration/test_helpers/common_functions.py
+++ b/tests/integration/test_helpers/common_functions.py
@@ -108,20 +108,3 @@ def get_custom_repos_names():
                 f"rhel-{system_version.major}-for-x86_64-appstream-rpms",
             ]
     return repos
-
-
-@pytest.fixture()
-def log_file_data():
-    """
-    Helper fixture.
-    Reads and returns data from the convert2rhel.log file.
-    Mainly used for after conversion checks, where we match required strings to the log output.
-    """
-    convert2rhel_log_file = "/var/log/convert2rhel/convert2rhel.log"
-
-    assert os.path.exists(convert2rhel_log_file), "The c2r log file does not exits."
-
-    with open(convert2rhel_log_file, "r") as logfile:
-        log_data = logfile.read()
-
-        return log_data

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've moved certain functions to a separate file, so the conftest.py is not that big. It had over 1000 lines, and it was hard for us to navigate in it. The fixture log_file_data is used only in this test, so we moved it from conftest.

@Venefilyn
Copy link
Member Author

/packit test --labels sanity

1 similar comment
@Venefilyn
Copy link
Member Author

/packit test --labels sanity

@Venefilyn
Copy link
Member Author

/packit test --labels sanity

@Venefilyn
Copy link
Member Author

@kokesak All integration tests are passing now with the change I made

# We use pytest_plugins to allow us to use fixtures we define in other files without the need to explicitly import them
# inside each test file.
# LINK - https://docs.pytest.org/en/7.0.x/reference/reference.html#globalvar-pytest_plugins
pytest_plugins = (
    "test_helpers.common_functions",
    "test_helpers.workarounds",
)

As for unit tests failing, it is unclear to me at the moment what the underlying issue is with the encoding tests in el7

But for the failing test relating to restorable file it is unrelated to any change I've made. It is just a unit test previously not being executed due to wrong name. Unsure if the error is the test or implementation atm

@r0x0d you are a code owner as well atm, wanna give a quick review of the devcontainer stuff that's changed?

Copy link
Member

@kokesak kokesak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QE ack, thanks @Venefilyn!

Venefilyn and others added 7 commits October 2, 2024 17:05
Ruff is a drop-in replacement for black and also handles linting
for us in a lot nicer way than pylint. More specifically it is a lot
faster than the alternatives and allows us to enforce PyFormat
for strings rather than percent-format or f-strings.

Signed-off-by: Freya Gustavsson <[email protected]>
Take care of all the errors reported by Ruff with the current
rules that are in place. This also takes care of percent-string
formatting and replaces it with PyFormat.

Signed-off-by: Freya Gustavsson <[email protected]>
Co-authored-by: Rodolfo Olivieri <[email protected]>
@Venefilyn
Copy link
Member Author

/packit test --labels sanity

1 similar comment
@Venefilyn
Copy link
Member Author

/packit test --labels sanity

@Venefilyn Venefilyn merged commit a805f5b into oamg:main Oct 2, 2024
26 of 29 checks passed
@Venefilyn Venefilyn deleted the chore/pylint-format branch October 2, 2024 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog If it should be excluded from changelog or Release notes. Such as infra, reverted PRs, etc. tests-run-sanity PR ready to run the sanity test suit. Equivalent to `/packit test --labels sanity`.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants