-
Notifications
You must be signed in to change notification settings - Fork 377
WIP added pre-commit hook for spdx_checker #1298
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for activist-org ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Thank you for the pull request! ❤️The activist team will do our best to address your contribution as soon as we can. If you're not already a member of our public Matrix community, please consider joining! We'd suggest using Element as your Matrix client, and definitely join the |
Maintainer ChecklistThe following is a checklist for maintainers to make sure this process goes as well as possible. Feel free to address the points below yourself in further commits if you realize that actions are needed :)
|
I will try to add support for >=python3.11. |
Added wheels for python versions 3.11, 3.12 and 3.13, for
|
Run the above commands and am still getting the following, @to-sta:
Are you testing it in your activist repo? Just checking if there's maybe something up with that that's not coming through in your tests within the project itself? :) |
I have tested it locally while building the package on Windows and the WSL. Then switch to a test repo to try it with the wheels I have pushed to pypi 😄 also on Windows and the WSL. A lot of things have to fall in place to make this work properly 😄:
I think the problem was that spdx-checker-pre-commit still had requires-python = ">=3.13" and was depending on spdx-checker>=0.1.3. If your pre-commit hook was still using version 0.1.3, it wouldn't have picked up the newer 0.1.4 release. And since both versions required Python 3.13 or higher, that could’ve caused the issue. Right now, spdx_checker is at 0.1.5 and spdx-checker-pre-commit is at 0.1.2. The pre-commit hook now depends on spdx_checker >= 0.1.5, which should fix the versioning problems and makes sure the right dependencies are pulled in. |
I updated the pre-commit hook version in 495b05f and tried it again: File 'backend/withou_license.py' does not match target license 'AGPL-3.0-or-later'.
Files with license 'AGPL-3.0-or-later': 0 / 1 Files
License check completed in (570000ns) 0ms
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\<removed>\.cache\pre-commit\repohyn5pxcw\py_env-python3.13\Scripts\spdx_checker_pre_commit.EXE\__main__.py", line 7, in <module>
sys.exit(main())
~~~~^^
File "C:\Users\<removed>\.cache\pre-commit\repohyn5pxcw\py_env-python3.13\Lib\site-packages\spdx_checker_pre_commit\main.py", line 41, in main
spdx_checker.check_license(args.license, args.filenames)
~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: File does not match target license.
run numpydoc docstring validation........................................Failed
- hook id: numpydoc-validation
- exit code: 1 |
I narrowed down the problem to the process of repairing of the wheel. Might take a bit longer till I figure this out 😄 |
Thanks for keeping at this, @to-sta! |
Contributor checklist
Description
To speed up checking SPDX license headers with our current setup, I built a Python package that uses a compiled Zig extension. It works cross-platform and is available on PyPI as spdx_checker
I also created a separate pre-commit hook repository: spdx-checker-pre-commit. This handles argument passing and keeps the pre-commit hook logic separate from the main package.
The development went through a few iterations. I started with a simple Zig function as a proof-of-concept, then moved on to turning it into a Python package.
Initially, I tried using pydust-ziggy, which is a great project — but unfortunately, it doesn’t support Windows at the moment. I still pushed forward using WSL and got a working version, and even attempted to add Windows support to ziggy-pydust. After some small wins and slow progress, I decided to take a different route.
My next and final approach was to take care of the integration with
zig
by myself instead of relying onziggy-pydust
. During my research I found a similar project on GitHub that uses azig
extension for parsing yaml called zaml. I took some inspiration, espeaclially about form the custom builder.So, for the final version, I handled the Zig integration myself instead of relying on ziggy-pydust. During this process, I came across zaml, which uses a Zig extension for YAML parsing. It gave me some inspiration, especially for the custom build system.
So, I made python wheels and went thru the hell of creating wheel via a GitHub workflow. Actually not that bad but not the most initutive either. cibuildwheel made it alot more convient that setting it up manually.
Cross-platform compilation wasn’t straightforward at first — library paths and naming conventions differ a lot between systems, especially on Windows. At one point, I had a version that required Zig to be installed locally before building the binary, but I wasn’t happy with that setup. You didn't have to install it yourself but still It took sometime and around 70mb.
Eventually, I decided to build and publish Python wheels, and went through the (slightly painful but not terrible) process of setting that up in a GitHub workflow. cibuildwheel made it way easier than doing it manually.
It works on my machine 🙂 — but there should definitely be some testing before considering to merge this in. Right now, it's only compiled for Python 3.13. I ran into issues getting it to work with Python 3.12 on Windows (though it worked fine on the WSL), so I focused on 3.13 for now. I did use the Python limited ABI, which should help make it compatible with more Python versions down the line.
To test the setup, I install the pre-commit hook locally and added a python file without a license. Here are the resuls:
Related issue