Create a Python library for using rust-code-analysis
It would be easier for projects using rust-code-analysis to handle their dependency on rust-code-analysis.
Hi! I've done just that: https://github.com/luigig44/rust-code-analysis-python (rust-code-analysis-python in PyPI)
It's pretty barebones at the moment, but should work as a pretty much drop-in replacement for anyone using the REST API metrics or comment removal endpoints from Python.
I needed it for another project so it will probably never include much more than those two functionalities, but if someone requests something else in an issue I will look into adding it.
Nice @luigig44! If you are up for it, we could definitely accept a PR to add this upstream.
I've made a cursory pass at this, but I can't get it to work.
I copied my repo into rust-code-analysis/rust-code-analysis-python, added it to the workspace in Cargo.toml, and adjusted its Cargo.toml to include rust-code-analysis from the parent directory (as is done in -web). However, I haven't figured out a way to get Maturin (my build tool) to include the parent directory code in the sdist build.
While I might be able to get it working, it seems like I would need to clutter the main project's directory with some Python-related files, which sounds like a bad idea.
I'll try to set up a documentation website for the project in a few days, and then you can link back to it.
@Luni-4 any thoughts?
I believe there is a bug in how Maturin builds the source distribution (sdist) of the Python package when inside a workspace with a crate at the root of the workspace. Wheels (binary distributions) work fine.
I've reported it here: PyO3/maturin#2654 with this repro: luigig44/rust-code-analysis@broken-sdist
In the meantime, it can be made to work by including the whole workspace in the sdist (i.e. -cli and -web too, which is not many bytes but is pretty inelegant) and moving pyproject.toml to the root: luigig44/rust-code-analysis@master.
I would recommend not merging this solution until that issue is resolved. I will get around to merging the docs together and updating the readme to include testing instructions for Python once that happens.
Thanks a lot @luigig44 for this project! Out of curiosity, since I'm not a Python expert, have you tried https://github.com/astral-sh/uv as package manager? Here is the documentation
have you tried https://github.com/astral-sh/uv as package manager?
I have not. I do not think it would make any difference because what is failing is Cargo due to missing files in the sdist. You can see the exact error in the issue I linked.
But I may end up trying it anyway.
Yep, I have seen the issue, just wondering if that problem might be fixed in another way. Ok, let me know if uv works better for your use-case.