generated from bazel-contrib/rules-template
-
-
Notifications
You must be signed in to change notification settings - Fork 51
virtualize the trait Reid was stuck on #648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
arrdem
merged 6 commits into
arrdem/tweak-symlink-venvs
from
myrrlyn/tweak-symlink-venvs-2
Sep 25, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bfa3a68
virtualize the trait Reid was stuck on
myrrlyn cce4f2f
forgot to commit the change to the typesig of populate_venv
myrrlyn 7defc64
discard bridge wrapper
myrrlyn 0d2e0d0
simplify a loop
myrrlyn f9302b4
Get to green.
arrdem bc2ba9a
Lint.
arrdem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,76 +115,67 @@ struct VenvArgs { | |
|
||
fn venv_cmd_handler(args: VenvArgs) -> miette::Result<()> { | ||
let pth_file = py::PthFile::new(&args.pth_file, args.pth_entry_prefix); | ||
match args.mode { | ||
// FIXME: Does this need to care about the repo? | ||
VenvMode::DynamicSymlink => py::create_venv( | ||
if let VenvMode::DynamicSymlink = args.mode { | ||
return py::create_venv( | ||
&args.python, | ||
&args.location, | ||
Some(pth_file), | ||
args.collision_strategy.unwrap_or_default().into(), | ||
&args.venv_name, | ||
), | ||
); | ||
} | ||
|
||
it => { | ||
let Some(version) = args.version else { | ||
return Err(miette!("Version must be provided for static venv modes")); | ||
let version = args | ||
.version | ||
.ok_or_else(|| miette!("Version must be provided for static venv modes"))?; | ||
|
||
let venv = py::venv::create_empty_venv( | ||
args.repo | ||
.as_deref() | ||
.ok_or_else(|| miette!("The --repo argument is required for static venvs!"))?, | ||
&args.python, | ||
py::venv::PythonVersionInfo::from_str(&version)?, | ||
&args.location, | ||
args.env_file.as_deref(), | ||
args.venv_shim.as_deref(), | ||
args.debug, | ||
args.include_system_site_packages, | ||
args.include_user_site_packages, | ||
)?; | ||
|
||
let strategy: Box<dyn py::venv::PthEntryHandler> = match args.mode { | ||
VenvMode::DynamicSymlink => unreachable!(), | ||
VenvMode::StaticPth => Box::new(py::venv::PthStrategy), | ||
// TODO: This is much more a "prod" strategy than a "symlink" strategy | ||
// but here we are. Better naming or user-facing extension/strategy | ||
// options would be a good get. | ||
VenvMode::StaticSymlink => { | ||
let thirdparty_strategy = py::venv::StrategyWithBindir { | ||
root_strategy: py::venv::SymlinkStrategy, | ||
bin_strategy: py::venv::CopyAndPatchStrategy, | ||
}; | ||
|
||
let venv = py::venv::create_empty_venv( | ||
args.repo | ||
.as_deref() | ||
.expect("The --repo argument is required for static venvs!"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. quit calling |
||
&args.python, | ||
py::venv::PythonVersionInfo::from_str(&version)?, | ||
&args.location, | ||
args.env_file.as_deref(), | ||
args.venv_shim.as_deref(), | ||
args.debug, | ||
args.include_system_site_packages, | ||
args.include_user_site_packages, | ||
)?; | ||
|
||
// Because the strategy type is dyn-incompatible we have to do this | ||
// so that each call is monomorphic. Oh well. | ||
match it { | ||
VenvMode::DynamicSymlink => unreachable!(), | ||
VenvMode::StaticPth => py::venv::populate_venv( | ||
venv, | ||
pth_file, | ||
args.bin_dir.unwrap(), | ||
py::venv::PthStrategy {}, | ||
args.collision_strategy.unwrap_or_default().into(), | ||
)?, | ||
VenvMode::StaticSymlink => { | ||
let thirdparty_strategy = py::venv::StrategyWithBindir { | ||
root_strategy: py::venv::SymlinkStrategy, | ||
bin_strategy: py::venv::CopyAndPatchStrategy, | ||
}; | ||
|
||
py::venv::populate_venv( | ||
venv, | ||
pth_file, | ||
args.bin_dir.unwrap(), | ||
py::venv::FirstpartyThirdpartyStrategy { | ||
firstparty: py::venv::SrcSiteStrategy { | ||
src_strategy: py::venv::PthStrategy {}, | ||
site_suffixes: vec!["site-packages", "dist-packages"], | ||
site_strategy: thirdparty_strategy.clone(), | ||
}, | ||
thirdparty: py::venv::SrcSiteStrategy { | ||
src_strategy: py::venv::SymlinkStrategy {}, | ||
site_suffixes: vec!["site-packages", "dist-packages"], | ||
site_strategy: thirdparty_strategy.clone(), | ||
}, | ||
}, | ||
args.collision_strategy.unwrap_or_default().into(), | ||
)? | ||
} | ||
} | ||
|
||
Ok(()) | ||
Box::new(py::venv::FirstpartyThirdpartyStrategy { | ||
firstparty: py::venv::SrcSiteStrategy { | ||
src_strategy: py::venv::PthStrategy {}, | ||
site_suffixes: vec!["site-packages", "dist-packages"], | ||
site_strategy: thirdparty_strategy.clone(), | ||
}, | ||
thirdparty: py::venv::SrcSiteStrategy { | ||
src_strategy: py::venv::SymlinkStrategy {}, | ||
site_suffixes: vec!["site-packages", "dist-packages"], | ||
site_strategy: thirdparty_strategy.clone(), | ||
}, | ||
}) | ||
} | ||
} | ||
}; | ||
py::venv::populate_venv( | ||
venv, | ||
pth_file, | ||
args.bin_dir.unwrap(), | ||
&*strategy, | ||
args.collision_strategy.unwrap_or_default().into(), | ||
) | ||
} | ||
|
||
fn main() -> miette::Result<()> { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By switching from a match with one arm acting and the other arm doing-work-then-matching-again to
if let
with areturn
, I took out one level of indentation with no other code changes. The second match still needs theunreachable!
in it because rustc doesn't have the ability to statically strip enum variants in cases like these. Annoying but c'est la vie. Beats writing Haskal