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

feat: ✨ bring pre-commit and tests from supervision #188

Merged
merged 7 commits into from
Dec 21, 2023

Conversation

onuralpszr
Copy link
Contributor

I guess headline pretty much tells everything, We already made successful in supervision. Maybe we can automate here to as well. No more manual linting if that is acceptable.

@onuralpszr onuralpszr marked this pull request as draft September 13, 2023 20:36
@onuralpszr
Copy link
Contributor Author

onuralpszr commented Sep 13, 2023

This changes also require to lock python version to "py38" before merge this please consider this too. Saying "python 3" is very wide and 3.X(1-7) already EOL as well.

Signed-off-by: Onuralp SEZER <[email protected]>
@capjamesg
Copy link
Collaborator

@onuralpszr Is there a way for you to submit this PR without all of the linting changes? I am happy to add a precommit, but this PR has a lot of merge conflicts in its current state.

@capjamesg capjamesg requested review from capjamesg and tonylampada and removed request for tonylampada December 4, 2023 10:14
@onuralpszr
Copy link
Contributor Author

@onuralpszr Is there a way for you to submit this PR without all of the linting changes? I am happy to add a precommit, but this PR has a lot of merge conflicts in its current state.

Let me revision and ping you

@onuralpszr onuralpszr marked this pull request as ready for review December 12, 2023 23:31
@onuralpszr onuralpszr changed the title feat: ✨ bring pre-commit from supervision feat: ✨ bring pre-commit and tests from supervision Dec 12, 2023
@onuralpszr
Copy link
Contributor Author

@capjamesg pre-commits are fixed and more tests added for make sure code is fine as well.

Copy link
Collaborator

@capjamesg capjamesg left a comment

Choose a reason for hiding this comment

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

Looks good. I left one comment. It looks like this has formatted our long print statements to have multiple strings. Do the new strings appear as expected? My inline comment corresponds to one example.

roboflow/core/version.py Show resolved Hide resolved
@onuralpszr
Copy link
Contributor Author

Looks good. I left one comment. It looks like this has formatted our long print statements to have multiple strings. Do the new strings appear as expected? My inline comment corresponds to one example.

That multiple string formatting not create "new line unless we add \n" so it is fine.

@capjamesg
Copy link
Collaborator

Thank you for the clarification. I have approved these changes and asked another team member to review, too.

@onuralpszr
Copy link
Contributor Author

onuralpszr commented Dec 19, 2023

Thank you for the clarification. I have approved these changes and asked another team member to review, too.

Sure please do, I also want to fix colab bug as well. as soon as this one merge, I will fix other bugs too. (I am holding because I don't wanna create conflicts)

@onuralpszr
Copy link
Contributor Author

@capjamesg also please add this repo to here (https://pre-commit.ci/) for auto fixes and CI actions you can do before merge or after merge but doing before is better so you can also see in action too.

@tonylampada
Copy link
Collaborator

@capjamesg @onuralpszr I went over the file changes and it really looks like this causes no change in runtime behaviour.
I still need to make some local tests anyway.
Also I need to have a better understanding of what the changes in pre-commit config and pyproject.toml mean for the dev env. I'm not too familiar with those tools so if any of you can give a more detailed explanation about that, it might speed me up a bit :-)

@onuralpszr
Copy link
Contributor Author

Pre-commit is a framework for managing Git pre-commit hooks in a project. These hooks are scripts that run automatically before you commit any changes to your codebase. Their purpose is to catch potential issues in your code early on, preventing them from being pushed to the repository and potentially causing problems later.

Advantages of using pre-commit:

  • Improved code quality: By running checks for formatting, linting, security vulnerabilities, and other issues, pre-commit helps ensure that your codebase is always clean and maintainable.

  • Increased developer productivity: Catching issues early saves developers time and effort compared to discovering them later in the development process during code reviews or deployment.

  • Enforced coding standards: Pre-commit allows you to define and enforce coding conventions for your project, leading to a more consistent and readable codebase.

  • Reduced friction in collaboration: When everyone is working with the same coding standards and checks, it makes collaborating on code much smoother and less prone to conflicts.

  • Language and technology agnostic: Pre-commit can be used with any programming language or technology, as long as the checks are available as pre-commit hooks. In our case we use for python and their tooling do automatic checks

Advantages of using pre-commit.ci website:

  • Community-driven hooks: The website offers a library of pre-built hooks for various languages and tools, saving you time and effort in setting up your own checks.

  • Continuous integration (CI) integration: pre-commit.ci can be integrated with your CI/CD pipeline to automatically run pre-commit checks on every pull request, further ensuring code quality before merging and commit to automatically in case of check failure and try to auto-fix but do only once in each commit so no endless loop.

Lastly we do use pre-commit heavily in supervision project and make sure codebase is in same standard.

Usage is also very easy

pip install pre-commit
pre-commit run --all-files

Install as git-hook locally in your clone repo

pre-commit install 

@onuralpszr
Copy link
Contributor Author

Current run and result

pre-commit run --all-files
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
check yaml...............................................................Passed
check docstring is first.................................................Passed
check that executables have shebangs.....................................Passed
check toml...............................................................Passed
check for case conflicts.................................................Passed
check for added large files..............................................Passed
detect private key.......................................................Passed
forbid new submodules................................(no files to check)Skipped
pretty format json.......................................................Passed
mixed line ending........................................................Passed
Sort imports.............................................................Passed
Flake8 Checks............................................................Passed
bandit...................................................................Passed
ruff.....................................................................Passed

@onuralpszr
Copy link
Contributor Author

About pyproject.toml currently I use as for storing parameters of tooling we use like ruff , isort , bandit etc. And previously you already had toml for build-system

[build-system]
requires = ["setuptools>=57", "wheel"]
build-backend = "setuptools.build_meta"

I just added others config for pre-commit tools and it can automatically read from there

@tonylampada
Copy link
Collaborator

So if I understand correctly, the pre-commit change will have no effect for folks that don't have it installed then?

@onuralpszr
Copy link
Contributor Author

onuralpszr commented Dec 19, 2023

So if I understand correctly, the pre-commit change will have no effect for folks that don't have it installed then?

For people who install "pip install roboflow" / users has no effect.(they don't need to install) But for devs and contributors has to install for meet the pre-commit requirements.

@tonylampada
Copy link
Collaborator

But for devs and contributors has to install for meet the pre-commit requirements.

Right. I'm just thinking abou what happens to the dev env of a a dev who just does "git pull" on this and doesn't know about it.
If I understand correctly, the pre-commit rules will never be enforced. Nothing changes in their dev env. Correct?

(and imo, at this time, "nothing changes" is exactly what we want: make it optional first, dogfood on it, and maybe later add it to the devenv setup with the devcontainer)

@onuralpszr
Copy link
Contributor Author

But for devs and contributors has to install for meet the pre-commit requirements.

Right. I'm just thinking abou what happens to the dev env of a a dev who just does "git pull" on this and doesn't know about it. If I understand correctly, the pre-commit rules will never be enforced. Nothing changes in their dev env. Correct?

(and imo, at this time, "nothing changes" is exactly what we want: make it optional first, dogfood on it, and maybe later add it to the devenv setup with the devcontainer)

If person never install yes not gonna enforce it but "CI" will enforce it

@onuralpszr
Copy link
Contributor Author

Right. I'm just thinking abou what happens to the dev env of a a dev who just does "git pull" on this and doesn't know about it.

I mean best we can do write in contribute guide and hopefully checks the toml and config files :) (I assume person is dev)

@onuralpszr
Copy link
Contributor Author

(and imo, at this time, "nothing changes" is exactly what we want: make it optional first, dogfood on it, and maybe later add it to the devenv setup with the devcontainer)

For this change it needs enforce and add dev container upfront and run install hook so it will automatically will exist.

@tonylampada
Copy link
Collaborator

OK I understand now. This doesn't force any change in the dev env, commits will still work. and may get fixed automatically like it did here...

CleanShot 2023-12-21 at 10 20 00@2x

or the build will break if the code doesn't conform with the new rules.

This can go in as is. It's an improvement.
I'm thinking a good next step would be installing and configuring the pre-commit tool (along with helping vscode plugins, maybe) in the project's devcontainer. Then people using the devcontainer would have the advantage of avoiding the potential "code-bouncing" fight with the ci without even having to know the quirks of setting up the pre-commit tool locally. @onuralpszr if you want to do that in another PR I'll definitely take a look.

@tonylampada tonylampada merged commit 811368e into roboflow:main Dec 21, 2023
5 checks passed
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.

3 participants