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

pre-commit setup #238

Merged
merged 14 commits into from
Dec 13, 2024
Merged

pre-commit setup #238

merged 14 commits into from
Dec 13, 2024

Conversation

ulgens
Copy link
Contributor

@ulgens ulgens commented Dec 6, 2024

Resolves #237

Trying to import pre-commit config from https://github.com/django/djangoproject.com/blob/ede018f69a7ae5ecacb99978d067f53613d05353/.pre-commit-config.yaml

Differences:

Missing

  • file-contents-sorter: requirements.txt files already have a different and special ordering.
  • isort: Not being used by the repo
  • flake8: Not being used by the repo
  • djhtml: The repository doesn't have any Django templates
  • checkmake: Fixes don't seem useful for the repo

Changed

  • black doesn't exclude migration files
  • prettier excludes javascript and css files, in addition to already excluded file types

@ulgens
Copy link
Contributor Author

ulgens commented Dec 6, 2024

@bmispelon This is still WIP but please let me know if there is something to update / change / fix.

@bmispelon
Copy link
Member

This is looking very good so far, thanks for tackling it! 🎸

One thing I noted is that the template formatting doesn't seem to understand Trac's weird jinja configuration. See for example the changes proposed in trac-env/templates/site_head.html: I would argue that the indentation was correct since it reflects that we're inside an if "tag".

- id: end-of-file-fixer
exclude_types: [json, sql]
- id: file-contents-sorter
files: ^(requirements/\w*.txt)$
Copy link
Member

Choose a reason for hiding this comment

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

In this project there's only a single requirements.txt file

Suggested change
files: ^(requirements/\w*.txt)$
files: ^requirements\.txt$

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 updated the related commit, should be okay now.

Copy link
Member

Choose a reason for hiding this comment

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

I still see the old line

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 guess I messed up the rebase, sorry. Double checked this time, looks okay.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems this hook doesn't add value to this repo. The requirements.txt file has a special organization, which gets destroyed when package names are ordered alphabetically. I removed it.

@ulgens ulgens force-pushed the pre-commit-setup branch 2 times, most recently from 147388a to 23c9516 Compare December 6, 2024 19:10
@ulgens
Copy link
Contributor Author

ulgens commented Dec 6, 2024

I would argue that the indentation was correct since it reflects that we're inside an if "tag".

I agree with this. Since the files are Jinja templates for Trac, and the checker was looking for Django templates, I removed djhtml hook from teh config.

@ulgens ulgens marked this pull request as ready for review December 6, 2024 19:15
@ulgens ulgens requested a review from bmispelon December 6, 2024 19:15
Copy link
Member

@bmispelon bmispelon left a comment

Choose a reason for hiding this comment

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

Excellent changes, thanks for working on this! 🎸

I found a few minor things, but overall this is very good 👍🏻

@@ -0,0 +1,63 @@
default_language_version:
python: python3
Copy link
Member

Choose a reason for hiding this comment

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

While comparing this configuration file to the one from djangoproject.com I noticed you're using 2 spaces for indentation while the other file has 4.

Could you change this file to 4 as well, it will make it easier for me to review this PR, and will also make it easier to integrate changes between the two files in the future.

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 missed the .editorconfig file, sorry. Once it was in place, the indentation for yaml files became 4 spaces.

Comment on lines 43 to 46
# Trac needs psycopg2
# https://github.com/adamchainz/django-upgrade?tab=readme-ov-file#databases
--skip,
"settings_database_postgresql",
Copy link
Member

Choose a reason for hiding this comment

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

I might be misunderstanding what the settings_database_postgresql fixer does, but I don't think it has to do with psycopg2 vs. psycopg3. It's just a naming alias change and you can use django.db.backends.postgresql with psycopg2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed this under #243

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be okay now.

- id: end-of-file-fixer
exclude_types: [json, sql]
- id: file-contents-sorter
files: ^(requirements/\w*.txt)$
Copy link
Member

Choose a reason for hiding this comment

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

I still see the old line

@ulgens ulgens force-pushed the pre-commit-setup branch 2 times, most recently from 738aa7c to b7e0746 Compare December 9, 2024 09:51
@ulgens ulgens marked this pull request as draft December 9, 2024 09:52
@ulgens ulgens force-pushed the pre-commit-setup branch 2 times, most recently from 885d5bf to 7504d6d Compare December 11, 2024 18:41
@ulgens ulgens force-pushed the pre-commit-setup branch 2 times, most recently from ff90427 to af783e9 Compare December 11, 2024 19:09
@ulgens ulgens requested a review from bmispelon December 11, 2024 19:12
@ulgens ulgens marked this pull request as ready for review December 11, 2024 19:12
Copy link
Member

@bmispelon bmispelon left a comment

Choose a reason for hiding this comment

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

This is looking great now, we're almost there! 🏁

I have one last question about the prettier commit hook: does it makes sense to keep it in this project (see comment above exclude_types).

Once that's clarified, I think we're good to go.

Thanks again for working on this!

.pre-commit-config.yaml Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
Copy link
Member

@bmispelon bmispelon left a comment

Choose a reason for hiding this comment

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

I think we're good to go, very nice work 👍🏻

@bmispelon bmispelon merged commit 8c24455 into django:main Dec 13, 2024
5 checks passed
@ulgens ulgens deleted the pre-commit-setup branch December 13, 2024 13:36
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.

pre-commit config
2 participants