rust-code-analysis icon indicating copy to clipboard operation
rust-code-analysis copied to clipboard

Create a Python library for using rust-code-analysis

Open marco-c opened this issue 6 years ago • 8 comments

It would be easier for projects using rust-code-analysis to handle their dependency on rust-code-analysis.

marco-c avatar Dec 19 '19 16:12 marco-c

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.

luigig44 avatar May 20 '25 18:05 luigig44

Nice @luigig44! If you are up for it, we could definitely accept a PR to add this upstream.

marco-c avatar May 20 '25 21:05 marco-c

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.

luigig44 avatar Jun 04 '25 21:06 luigig44

@Luni-4 any thoughts?

marco-c avatar Jun 04 '25 22:06 marco-c

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.

luigig44 avatar Jun 17 '25 02:06 luigig44

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

Luni-4 avatar Jun 17 '25 07:06 Luni-4

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.

luigig44 avatar Jun 17 '25 13:06 luigig44

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.

Luni-4 avatar Jun 18 '25 08:06 Luni-4