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

Replace flake with ruff #154

Merged
merged 9 commits into from
Apr 5, 2023
Merged

Replace flake with ruff #154

merged 9 commits into from
Apr 5, 2023

Conversation

thejaminator
Copy link
Collaborator

@thejaminator thejaminator commented Mar 25, 2023

Yep, ruff is pretty fast and nice

Still evaluating the docstrings feature
I don't think enforcing rules "D" for docs everywhere is a good idea. There's still quite alot of false positives.

E.g. Ruff will complain about child override methods not having a docstring when the parent has it.
astral-sh/ruff#970 (comment)

Closes #143

- id: flake8
args: ["--ignore=E203,F401,W503", --max-line-length=88]
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this makes ruff automatically remove unused imports

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

see the remove imports here f337f74

"EigenReporterConfig",
"RunConfig",
"OptimConfig",
]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this makes ruff automatically remove unused imports

but that also means that you need to explicitly export imports

Copy link
Member

Choose a reason for hiding this comment

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

Oh this is a bit annoying actually...

ChatGPT suggests that you can automate this like so:

# Automatically fill the __all__ field
__all__ = [name for name, value in globals().items() if not name.startswith('__') and callable(value)]

appending this to the end of the __init__ files

Copy link
Collaborator Author

@thejaminator thejaminator Apr 4, 2023

Choose a reason for hiding this comment

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

ruff itself (and the user's own linters) wouldn't be able to understand that. That you've reeexported everything inside.
So whoever uses the elk pacakge will still get warnings, and ruff itself will warn us too. (False positive but annoying for everyone)

I've added

ignore-init-module-imports = true

to the pyproject.toml. So what ruff will do is to tell us that we've imported something in __init__.py but didn't add it to__all__. That should fix future mistakes when we forget to declare it.

An example of a message

elk/extraction/__init__.py:1:31: F401 .balanced_sampler.BalancedSampler imported but unused; consider adding to __all__ or using a redundant alias

Copy link
Collaborator Author

@thejaminator thejaminator Apr 4, 2023

Choose a reason for hiding this comment

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

the alternative to this would be to ignore all the import warnings in __init__.py files with ruff. I think thats a worse option. because the user's linters/ ide / typecheckers all complain

thejaminator and others added 6 commits March 25, 2023 16:25
# Conflicts:
#	elk/__init__.py
#	elk/evaluation/evaluate.py
#	elk/extraction/__init__.py
#	elk/extraction/prompt_dataset.py
#	elk/training/__init__.py
#	elk/utils/__init__.py
Dataset,
Features,
IterableDataset,
Sequence,
)
from datasets.distributed import split_dataset_by_node
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

unused imports

Copy link
Member

@norabelrose norabelrose left a comment

Choose a reason for hiding this comment

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

LGTM

@norabelrose norabelrose merged commit 90755b6 into main Apr 5, 2023
@norabelrose norabelrose deleted the add-ruff branch April 5, 2023 07:22
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.

Switch to ruff for linting
2 participants