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

Use Ruff #566

Merged
merged 6 commits into from
Feb 28, 2024
Merged

Use Ruff #566

merged 6 commits into from
Feb 28, 2024

Conversation

danielhollas
Copy link
Contributor

Besides flake8 plugins that we already had, I've added ruff-specific rules (RUF). Especially the one that detects unnecessary list comprehension is quite useful and made a couple of places more readable.

I've disabled a couple of rules that would take more work to resolve all.

Comment on lines -35 to -36
- flake8-debugger==4.1.2
- flake8-logging-format==0.9.0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not activate these two in ruff. We do not use logging in AWB and the flake8-debugger seems rather niche.

@@ -28,6 +28,7 @@ def find_installed_packages(python_bin: str | None = None) -> dict[str, str]:
[python_bin, "-m", "pip", "list", "--format=json"],
encoding="utf-8",
capture_output=True,
check=True,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a change in behaviour. We had implicitly check=False and we were not checking the return code of the command. So if pip list failed, we would probably blow up below on line 34.

Now instead run throws exception on non-zero command exit. This exception will then be caught on line 204. This seems like a better behaviour. I still need to test this manually. (not sure it's worth adding a test for this)

@@ -376,7 +376,7 @@ def _ssh_keygen(self):
"",
]
if not fpath.exists():
subprocess.run(keygen_cmd, capture_output=True)
subprocess.run(keygen_cmd, capture_output=True, check=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ditto, we were not checking that the command ran correctly. Now we at least fail loudly.

@@ -1028,6 +1028,7 @@ def test(self, _=None):
process_result = subprocess.run(
["verdi", "computer", "test", "--print-traceback", self.label.value],
capture_output=True,
check=False,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No functional change here, since we check the return code below.

@@ -152,8 +152,8 @@ class :class:`aiidalab_widgets_base.structures.StructureManagerWidget`.

def __init__(
self,
embedded: bool = True,
title: str = None,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This type was not correct (missing Optional). We're currently not doing any actual typechecking so it's better to just remove it, wrong types are worse than no types.

Copy link

codecov bot commented Feb 27, 2024

Codecov Report

Attention: Patch coverage is 91.30435% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 87.07%. Comparing base (3bce8e7) to head (fe7f3b9).
Report is 2 commits behind head on master.

Files Patch % Lines
aiidalab_widgets_base/structures.py 71.42% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master     #566   +/-   ##
=======================================
  Coverage   87.07%   87.07%           
=======================================
  Files          27       27           
  Lines        4649     4649           
=======================================
  Hits         4048     4048           
  Misses        601      601           
Flag Coverage Δ
python-3.10 87.07% <91.30%> (ø)
python-3.9 87.10% <91.30%> (ø)

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.

Copy link
Member

@unkcpz unkcpz left a comment

Choose a reason for hiding this comment

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

Thanks @danielhollas. Just to minor requests.

aiidalab_widgets_base/viewers.py Outdated Show resolved Hide resolved
aiidalab_widgets_base/export.py Show resolved Hide resolved
Copy link
Member

@unkcpz unkcpz left a comment

Choose a reason for hiding this comment

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

Thanks, looks all good for me.

@danielhollas danielhollas merged commit 63332a6 into aiidalab:master Feb 28, 2024
12 checks passed
@danielhollas danielhollas deleted the ruff branch February 28, 2024 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants