microsoft / python-environment-tools

MIT License
110 stars 7 forks source link

Workspace Conda, Poetry, Virtual Envs #22

Closed karthiknadig closed 2 weeks ago

karthiknadig commented 1 month ago

Note: Ignore hatch for now

DonJayamanne commented 2 weeks ago

Done

ofek commented 1 week ago

what needs to be done to support Hatch? (I'm the maintainer)

karthiknadig commented 1 week ago

@ofek You can add hatch support here, Don can provide the details. When the extension API for this becomes available, you will likely want to use that as it will allow you to do more than just discovery.

FYI, this is an intermediate bridging tool, with the intent that this will allow us to break out the tightly coupled environment code in the python extension. On the python extension side I will be opening up a set of APIs that allow environment managers to ship support in their own extensions.

For env types supported here like pyenv, poetry, conda, etc, we expect those to be removed (from here) as and when extension for those env managers will ship. The reason we made this tool was to set a baseline expectation for discovery in python extension. So when env managers ship their own extensions there is some benchmark for expected performance. The TS discovery code was outdated and overdue a refresh, hence this re-write.

DonJayamanne commented 1 week ago

@ofek You can have a look at the pet-poetry crate (please ignore the file environment_locations_spawn.rs I am yet to document the code and API (actually will be working on that today/tomorrow). The file lib.rs has the implementation for the trait Locator

Next update the crates/pet/src/locators.rs file to add an entry to the hatch locator just above or below the Poetry locator (this line locators.push(Arc::new(Poetry::from(&environment)));.

Bulk of the code in Poetry is used to locate the directory where Poetry environments are located. I had to get that from the Poetry code, with Hatch you will know very well where they are located, and then for each environment you will need to determine the project it belongs to, thats where the project field needs to be populated.

E.g. for hatch once you find environments, (I think), you will then go through the file ..lib/python3.9/site-packages/_hatch_demo.pth and find the project this belongs to and use that as the value for project field (from what I can tell, i think it needs to be the parent of src folder).

Hope this helps. Will update the docs with contribution guides this week.

Oh yes, please do not spaw hatch or other processes, the goal of this tool is to avoid spawning and favour file I/O to discover Python environments along with the version/prefix information.