Skip to content

Replace linter and formatter with ruff and mypy#392

Merged
lan496 merged 6 commits intospglib:developfrom
lan496:linter
Jan 18, 2024
Merged

Replace linter and formatter with ruff and mypy#392
lan496 merged 6 commits intospglib:developfrom
lan496:linter

Conversation

@lan496
Copy link
Copy Markdown
Member

@lan496 lan496 commented Jan 12, 2024

Closes #364

Copy link
Copy Markdown
Collaborator

@LecrisUT LecrisUT left a comment

Choose a reason for hiding this comment

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

Also, just make sure when you apply pre-commit it's a separate commit, and we don't squash commit for this PR


try:
from spglib import _spglib as spg
from spglib import _spglib as spg # type: ignore
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why the ignore? Also should scope ignores

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Without ignoring, mypy says

error: Module "spglib" has no attribute "_spglib"  [attr-defined]

Copy link
Copy Markdown
Collaborator

@LecrisUT LecrisUT Jan 12, 2024

Choose a reason for hiding this comment

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

Yeah, but that's a genuine issue:

  • We should be using relative paths there
  • We should be providing a _spglib.pyi to type-hint the C interface, even if only internally

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The relative path did not persuade mypy

    from .spglib import _spglib as spg
# -> Module "spglib.spglib" has no attribute "_spglib"  [attr-defined]

@LecrisUT
Copy link
Copy Markdown
Collaborator

Also worth referencing the scienitific-python configuration: https://github.com/scientific-python/cookie/blob/main/pyproject.toml

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jan 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (ba444f4) 83.86% compared to head (a28e63f) 83.86%.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #392   +/-   ##
========================================
  Coverage    83.86%   83.86%           
========================================
  Files           24       24           
  Lines         8180     8180           
========================================
  Hits          6860     6860           
  Misses        1320     1320           
Flag Coverage Δ
c_api 77.59% <ø> (ø)
fortran_api 56.15% <ø> (ø)
python_api 80.38% <ø> (ø)
unit_tests 1.24% <ø> (ø)

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.

@LecrisUT
Copy link
Copy Markdown
Collaborator

LecrisUT commented Jan 13, 2024

Please split the "add mypy/ruff configuration" and "apply mypy/ruff” as separate commits in 31b2842. You can run git commit --no-verify to skip the pre-commit

@lan496 lan496 changed the title Replace linter and formatter with ruff Replace linter and formatter with ruff and mypy Jan 14, 2024
@lan496 lan496 requested a review from LecrisUT January 17, 2024 10:44
Copy link
Copy Markdown
Collaborator

@LecrisUT LecrisUT left a comment

Choose a reason for hiding this comment

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

👍 for the current setup as an initial implementation. Mind if I rebase your commits a bit before merging?

hooks:
- id: mypy
exclude: database
pass_filenames: false
Copy link
Copy Markdown
Collaborator

@LecrisUT LecrisUT Jan 18, 2024

Choose a reason for hiding this comment

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

The size of the python bindings is very small, so might as well run mypy on all sources defined in pyproject.toml, i.e. running

$ mypy --ignore-missing-imports --scripts-are-modules

@lan496
Copy link
Copy Markdown
Member Author

lan496 commented Jan 18, 2024

@LecrisUT No problem. I'll leave the rest to you.

Signed-off-by: Cristian Le <[email protected]>
Signed-off-by: Cristian Le <[email protected]>
Signed-off-by: Cristian Le <[email protected]>
Signed-off-by: Cristian Le <[email protected]>
@LecrisUT
Copy link
Copy Markdown
Collaborator

Sorry, had to change the committer because I've split the commits. Btw, can you add docs/readthedocs.org, and testing-farm:fedora-39 (and later fedora-38 as well) to the required workflows to pass? Otherwise if we use auto-merge now it would keep those checks dangling.

Also make sure to merge this with a merge commit or rebase to keep the history

@lan496
Copy link
Copy Markdown
Member Author

lan496 commented Jan 18, 2024

Thanks to tidy commits. I've updated the branch protection rule. Is it OK?
image

@LecrisUT
Copy link
Copy Markdown
Collaborator

Yep, that looks good. I'll bother you again later when I enable Fedora38

@lan496 lan496 merged commit 5ce87bc into spglib:develop Jan 18, 2024
@lan496 lan496 deleted the linter branch January 18, 2024 22:28
@LecrisUT LecrisUT added this to the 2.3 milestone Jan 25, 2024
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.

ci: Modernize the CI tools

3 participants