Skip to content

Conversation

to-sta
Copy link
Collaborator

@to-sta to-sta commented May 31, 2025

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 on ziggy-pydust. During my research I found a similar project on GitHub that uses a zig 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:

spdx-license-checker.....................................................Failed
- hook id: spdx-license-checker
- exit code: 1

File 'backend/without_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 (688000ns) 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\repondit329p\py_env-python3.13\Scripts\spdx_checker_pre_commit.EXE\__main__.py", line 10, in <module>
    sys.exit(main())
             ~~~~^^
  File "C:\Users\<removed>\.cache\pre-commit\repondit329p\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.

Related issue

Copy link

netlify bot commented May 31, 2025

Deploy Preview for activist-org ready!

Name Link
🔨 Latest commit 13b7f28
🔍 Latest deploy log https://app.netlify.com/projects/activist-org/deploys/683ca3526ad02b00081fc4b6
😎 Deploy Preview https://deploy-preview-1298--activist-org.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

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 General and Development rooms once you're in. Also consider attending our bi-weekly Saturday developer syncs! It'd be great to meet you 😊

Copy link
Contributor

github-actions bot commented May 31, 2025

Maintainer Checklist

The 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 :)

  • The TypeScript, pytest and formatting workflows within the PR checks do not indicate new errors in the files changed

  • The Playwright end to end and Zap penetration tests have been ran and are passing (if necessary)

  • The changelog has been updated with a description of the changes for the upcoming release and the corresponding issue (if necessary)

@andrewtavis andrewtavis self-requested a review May 31, 2025 18:55
@to-sta
Copy link
Collaborator Author

to-sta commented May 31, 2025

I will try to add support for >=python3.11.

@to-sta
Copy link
Collaborator Author

to-sta commented May 31, 2025

Added wheels for python versions 3.11, 3.12 and 3.13, for windows, linux and MacOS. @andrewtavis feel to give it a test again. You might have to uninstall your pre-commit hooks and clean the cache before using it:

pre-commit uninstall
pre-commit gc
pre-commit install

@andrewtavis
Copy link
Member

Run the above commands and am still getting the following, @to-sta:

run spdx-checker license check...........................................Failed
- hook id: spdx-license-checker
- exit code: -11

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? :)

@to-sta
Copy link
Collaborator Author

to-sta commented Jun 1, 2025

Run the above commands and am still getting the following, @to-sta:

run spdx-checker license check...........................................Failed
- hook id: spdx-license-checker
- exit code: -11

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 😄:

  • OS specific wheel
  • Your Python version
  • Python version requirements inside spdx_checker
  • Python version requirements and the python package version requirements for spdx-checker-pre-commit hook
  • And caching

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.

@to-sta
Copy link
Collaborator Author

to-sta commented Jun 1, 2025

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

@to-sta
Copy link
Collaborator Author

to-sta commented Jun 9, 2025

I narrowed down the problem to the process of repairing of the wheel. Might take a bit longer till I figure this out 😄

@andrewtavis
Copy link
Member

Thanks for keeping at this, @to-sta!

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