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

chore: add pre-commit config, type hints, badges, and lint codebase #57

Merged

Conversation

filipchristiansen
Copy link
Collaborator

Summary

This PR introduces a variety of improvements to enhance code quality and consistency:

  • Pre-commit Hooks: Adds .pre-commit-config.yaml and pyproject.toml with black, isort, and djlint.
  • Type Hints: Adds missing type hints across the codebase, standardized to Dict[...] for Python 3.8 compatibility.
  • Badge Conversion: Adds badges and converts all badges to HTML <a><img> format for uniform styling.
  • Linting: Lints Markdown files and Jinja templates to maintain a tidy code structure.

Future Considerations

  • Adding function documentation (docstrings) and darglint to automate docstring checks.
  • Integrating pylint into the pre-commit workflow for deeper static analysis.

- Add .pre-commit-config.yaml and pyproject.toml for Black and isort
- Add missing type hints throughout the code (Dict[...] for Python 3.8 compatibility)
- Added badges and convert existing badges to use <a><img></a> format
- Lint Markdown files
- Lint Jinja templates with djlint
@filipchristiansen
Copy link
Collaborator Author

filipchristiansen commented Dec 27, 2024

I have now resolved the errors and fixed additional type hint violations.
Update: There still seems to be some issue... debugging.

@cyclotruc
Copy link
Owner

Wow first thank you so much for this invaluable PR

It was very needed and I'm wiling to merge ASAP
I will review this properly and let you know if I have any questions/think of any changes

@filipchristiansen
Copy link
Collaborator Author

filipchristiansen commented Dec 27, 2024

Wow first thank you so much for this invaluable PR

It was very needed and I'm wiling to merge ASAP I will review this properly and let you know if I have any questions/think of any changes

@cyclotruc
Happy to contribute!

I identified the root cause of the issue in test_clone.py. Initially, I changed the import statement from a relative import:

from clone import clone_repo

to an absolute import:

from gitingest.clone import clone_repo

This modification caused two tests to fail, and I began investigating the reason behind this.

Update:
The problem stemmed from how the mocking was implemented. I adjusted the patch target from:

patch('clone.check_repo_exists', ...)

to:

patch('gitingest.clone.check_repo_exists', ...)

After making this change, the tests passed successfully.

I will make another commit and update my PR.

@filipchristiansen
Copy link
Collaborator Author

@cyclotruc
The tests should pass now!

@filipchristiansen
Copy link
Collaborator Author

I realize that my initial commit would have been more effective if it had been divided into smaller, more focused commits. I hope this is still acceptable.

@filipchristiansen
Copy link
Collaborator Author

Failed because of dotenv in requirements.txt. Changing to python-dotenvand pushing again.

@filipchristiansen
Copy link
Collaborator Author

Wow first thank you so much for this invaluable PR

It was very needed and I'm wiling to merge ASAP I will review this properly and let you know if I have any questions/think of any changes

@cyclotruc
Let me know if you want support with anything else. I think this is a cool project. It might benefit from some code cleanup in certain areas, as well as additional docstrings and comments to enhance clarity and maintainability.

@filipchristiansen filipchristiansen force-pushed the chore/precommit-lint-typehints branch from cb10135 to 2655278 Compare December 27, 2024 22:12
Copy link
Owner

@cyclotruc cyclotruc 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 wonderful, I can't thank you enough for those much needed improvements

I read through every change and felt your attention to details

src/routers/download.py Show resolved Hide resolved
@cyclotruc
Copy link
Owner

ParamSpec only exists from python 3.9
Honestly I'm just going to drop the testing bellow 3.9 in favor of 3.10 and up

@cyclotruc cyclotruc merged commit eb73a0c into cyclotruc:main Dec 28, 2024
2 checks passed
@cyclotruc
Copy link
Owner

k this is a cool project. It might benefit from some code cleanup in certain areas, as well as additional docstrings and comment

Please feel welcomed to contribute again
I have to admit the popularity of this project quickly outgrows what I'm able to manage myself
And those changes will help us build faster in a more reliable way in the future

About your future considerations:

I don't know much about a pylint integration, but stronger static analysis could be helpful

As for the docstring this is indeed a good idea that will benefit the API and the python package as well

Feel free to reach out on Discord (or mail) if you want to discuss in more details the possible improvements we could work on

@cyclotruc
Copy link
Owner

Oh and Btw, shouldn't we trigger those actions via a github action as well?

Unless I understood wrong, it's currently up to the user to run
pre-commit install before they can benefit from the pre-commid checks?

So I guess running those automatically in outstanding PRs could hint the contributors to run those

@filipchristiansen
Copy link
Collaborator Author

ParamSpec only exists from python 3.9 Honestly I'm just going to drop the testing bellow 3.9 in favor of 3.10 and up

Apologies. I can switch from ParamSpec to Callable[..., T] to retain support for Python versions below 3.10. It might not be worth it to discontinue support for Python 3.9 and earlier just for type hinting. Let me know your preference, and I can add it back in a new PR, along with adding back the CI tests.

@cyclotruc
Copy link
Owner

To be honest I think it should be fine for a new project like this one but thank you for offering

@filipchristiansen
Copy link
Collaborator Author

Oh and Btw, shouldn't we trigger those actions via a github action as well?

Unless I understood wrong, it's currently up to the user to run pre-commit install before they can benefit from the pre-commid checks?

So I guess running those automatically in outstanding PRs could hint the contributors to run those

Of course, that's a valid suggestion. I preferred not to modify the CI testing setup without first coordinating with you. I'm happy to open a new pull request to integrate GitHub Actions for triggering those checks if you’d like. Additionally, encouraging contributors to run the pre-commit hooks locally before submitting a PR remains beneficial, as there may always be code that violates the hooks.

@cyclotruc
Copy link
Owner

Sure, please do!

As for encouraging the contributors all I can think about is to improve the "contributions" part of the readme, do you think of anything else?

@filipchristiansen
Copy link
Collaborator Author

filipchristiansen commented Dec 28, 2024

To be honest I think it should be fine for a new project like this one but thank you for offering

Then we could also move over to use the new style type hints, e.g., list[str] instad of List[str]. I can add the --py39-plus and --py310-plus flags to the pyupgrade pre-commit hook in a new PR which will do this automatically. Let me know.

@filipchristiansen
Copy link
Collaborator Author

Sure, please do!

As for encouraging the contributors all I can think about is to improve the "contributions" part of the readme, do you think of anything else?

You could also add a Makefile. I can do that if you want. I always have a file like this one in my repos. https://github.com/filipchristiansen/adnex/blob/main/Makefile. That way I can just run make hooks and make tests. Let me know if you want me to add something like that.

@cyclotruc
Copy link
Owner

Then we could also move over to use the new style type hints, e.g., list[str] instad of List[string]. I can add the --py39-plus and --py310-plus flags to the pyupgrade pre-commit hook in a new PR which will do this automatically. Let me know.

This sounds like a good idea please go ahead
I didn't know about those details, but let's have modern syntax!

@cyclotruc
Copy link
Owner

You could also add a Makefile. I can do that if you want. I always have a file like this one in my repos. https://github.com/filipchristiansen/adnex/blob/main/Makefile. That way I can just run make hooks and make tests. Let me know if you want me to add something like that.

For this one I think I'll prefer to wait

I want to have more experience with the eventual pains in the dev flow to see if a makefile is the best way to address them

@filipchristiansen filipchristiansen deleted the chore/precommit-lint-typehints branch December 29, 2024 09:21
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