findpython icon indicating copy to clipboard operation
findpython copied to clipboard

Add support for `rtx`

Open baggiponte opened this issue 2 years ago • 4 comments

rtx is an asdf compatible runtime executor written in rust. Executables are installed by default under ~/.local/share/rtx (ref here) though it can be changed. Would you be interested in findpython supporting rtx too? I could volunteer to work on the PR too.

baggiponte avatar Aug 07 '23 10:08 baggiponte

Is it possible to make it work by simply setting an environment variable? https://github.com/frostming/findpython/blob/ebe580527fd718abac82993132569c68302a0c4e/src/findpython/providers/asdf.py#L19C1-L21C10

frostming avatar Aug 07 '23 10:08 frostming

Yes!

RTX_DATA_DIR This is the directory where rtx stores plugins and tool installs. The default location is ~/.local/share/rtx.

rtx installs under its RTX_DATA_DIR/installs/python like asdf so nothing else changes. My guess is that you could write a RtxProvider like you did with your AsdfProvider just by changing this:

    def create(cls) -> t.Self | None:
-        asdf_root = os.path.expanduser(
-            os.path.expandvars(os.getenv("ASDF_DATA_DIR", "~/.asdf"))
+       rtx_root = os.path.expanduser(
+            os.path.expandvars(os.getenv("RTX_DATA_DIR", "~/.local/share/rtx"))
        )
-        if not os.path.exists(asdf_root):
+        if not os.path.exists(rtx_root):
            return None
-        return cls(Path(asdf_root))
+        return cls(Path(rtx_root))

If you like it, I could come up with a PR.

baggiponte avatar Aug 08 '23 10:08 baggiponte

I mean to set ASDF_DATA_DIR=$HOME/.local/share/rtx and everything works, you don't ever need a new provider.

frostming avatar Aug 09 '23 01:08 frostming

I guess so, though I don't know whether this could create a conflict with other tools (hopefully none, since rtx strives to be compatible with asdf). I think it might still be the case to refer to this issue or write in the docs/readme about this - what do you think?

One more thing about my use case. I found out about findpython because I saw a python.providers option being added to pdm, and I would like to set it to rtx only, to avoid picking up other python interpreters. From the perspective of a tool that depends on findpython, I think it might quicker overall to add a new provider rather than having the downstream library, or the final user, handle this manually.

Nevertheless, your solution should work so feel free to close the issue! Thanks for your time.

baggiponte avatar Aug 09 '23 10:08 baggiponte