helper function for resolving the site package path across platforms - #23
Conversation
There was a problem hiding this comment.
There error was duplicated.
There was a problem hiding this comment.
The main issue here is path to the site-packages directory differs between Windows and Linux/MacOS
Windows -> .venv/Lib/site-packages (Case sensitive)
Linux/MacOS -> .venv/lib/python {version}/site-packages.
| use std::path::PathBuf; | ||
|
|
||
| #[derive(Debug)] | ||
| pub enum VenvErr { |
There was a problem hiding this comment.
Error structure needs more polish or consolidation with errors.rs
| let site_packages = python_version_dir.path().join("site-packages"); | ||
| // FIXME, properly handle error propagation. | ||
| let site_packages = | ||
| resolve_site_package_path(&venv_path).expect("Failed to resolve site packages"); |
There was a problem hiding this comment.
Currently this code panics and needs to properly return and error string.
| })?; | ||
|
|
||
| let site_packages = python_version_dir.path().join(SITE_PACKAGES); | ||
| let site_packages = resolve_site_package_path(&venv_path).map_err(|e| { |
There was a problem hiding this comment.
Worth thinking about consolidation with BridgeError in errors.rs or differentiate between path related errors vs others.
|
|
||
| Ok(site_packages) | ||
| } | ||
| } |
There was a problem hiding this comment.
I plan on adding a "resolve_interpreter_path" function here as well unless you have an objection.
| shell: bash | ||
| run: ln -sf "$pythonLocation/bin/python" "$pythonLocation/bin/python3.12" | ||
| # Check that files are not equivalent before linking. | ||
| run: | |
There was a problem hiding this comment.
Added checks to make sure files aren't equivalent before creating symlink.
…indows))->cfg(unix)
24ca22f to
2778e42
Compare
This pull request aims to consolidate the cross-platform logic for finding python virtual environment related assets. I think the utils.rs file in r2x-python is a good place to put the platform specific logic for resolving paths to python packages and the python interpreter binary, given that the path structure and binary name is slightly different.
Currently this branch compiles and runs most of the tests. It is currently hanging on the test python virtual environment creation.
There is a small fix for handling and propagating the errors properly. I currently have an Enum of VenvErr which could be polished more, however, they need to be mapped to BridgeError in some cases.