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

Rewrite it in Rust: Ruff as alternative Linter #28

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

DavidSchischke
Copy link

Closes #22.

  • Option for choosing linter in cookiecutter setup
  • Automatic removal of unneeded files from other linter
  • Ruff used as non-local hook with according changes in pyproject.toml
  • No disabled options for ruff (tbd). See full list for reference

@@ -10,6 +10,7 @@ repos:
- id: end-of-file-fixer
exclude: '\.ipynb$'
- id: check-toml
exclude: '{{cookiecutter.repo_name}}/pyproject.toml'
Copy link
Member

Choose a reason for hiding this comment

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

I guess you're excluding this, as we now use some templating in the file, correct?

To still make sure that the generated files pass our own quality standards, we should extend the tests with one variation that uses ruff.

Copy link
Author

Choose a reason for hiding this comment

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

From my understanding, the check-toml pre-commit hook tries to parse the toml within the project directory as-is, which leads to a flag because it still contains template strings. This is not necessarily related to ruff/pylint, but to the way the check itself is executed. Let's discuss how to solve this :)

Copy link
Member

Choose a reason for hiding this comment

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

Following up our discussion, I have implemented that the tests now execute the pre-commit hooks. On top of that, I've added the option to specify different configurations to run the tests in. With these changes in place, I'd suggest to:

  1. Exclude everything on "{{cookiecutter.repo_name}}" from the top-level pre-commit configuration, as these are now validated in the tests (after cookiecutter initialized the repo)
  2. Add some configuration with Ruff to our permutations.

Copy link
Member

Choose a reason for hiding this comment

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

I don't really understand what this is good for. Can you explain? I guess it's somehow using one file or the other, but I don't understand how 🙈

Copy link
Author

@DavidSchischke DavidSchischke Nov 17, 2023

Choose a reason for hiding this comment

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

This change is related to a change in post_gen_project:

def remove_unused_linter_files(self):
with open(f"{self.temp_files_dir}/.manifest.yaml", "r", encoding="utf-8") as f:
manifest = yaml.safe_load(f)
for feature in manifest["features"]:
if not feature["enabled"]:
for resource in feature["resources"]:
os.remove(resource)

Basically, after the project is created, the type of linter is determined from manifest.yaml and the config for the other linter is deleted prior to committing. The procedure is taken from this cookiecutter issue.

Copy link
Member

Choose a reason for hiding this comment

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

I think the main confusion here is the name of the folder .temp_ci_cd. I'd instead suggest something like .conditional_files and adjust the post generation script accordingly.

Instead of introducing yet another custom configuration file, we should move both configs (Pylint and Ruff) into that folder and adapt our ConditionalFileManager to only use the appropriate file. While we're at it, we might as well add the option to have no linter at all :)

Copy link
Member

Choose a reason for hiding this comment

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

As discussed, let's do some testing with some existing projects to see if these settings are reasonable.

- pytest=7.2.1
- python=3.10.9
- ruff=0.1.4
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that we need ruff in the top-level environment, as we're only using one linter for the template repository itself. Let's stick with Pylint for now, so I guess you can revert all changes to that file.

{%- if cookiecutter.install_jupyter == 'yes' %}
- jupyter=1.0.0
- nbqa=1.6.1
Copy link
Member

Choose a reason for hiding this comment

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

I think it's a good idea to move "nbqa" into that conditional. However, if we do this, we also need to add a condition to the pre-commit config to avoid that the nbqa-tasks are executed when the dependency is not installed.

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.

Add option to use ruff instead of pylint
2 participants