-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support resolving for an alternate Python distribution (#364)
## Summary Low-priority but fun thing to end the day. You can now pass `--target-version py37`, and we'll generate a resolution for Python 3.7. See: #183.
- Loading branch information
1 parent
d407bbb
commit cfd84d6
Showing
6 changed files
with
245 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use std::str::FromStr; | ||
|
||
use pep508_rs::{MarkerEnvironment, StringVersion}; | ||
|
||
#[derive(Debug, Clone, Copy, clap::ValueEnum)] | ||
pub(crate) enum PythonVersion { | ||
Py37, | ||
Py38, | ||
Py39, | ||
Py310, | ||
Py311, | ||
Py312, | ||
} | ||
|
||
impl PythonVersion { | ||
/// Return the `python_version` marker for a [`PythonVersion`]. | ||
fn python_version(self) -> &'static str { | ||
match self { | ||
Self::Py37 => "3.7", | ||
Self::Py38 => "3.8", | ||
Self::Py39 => "3.9", | ||
Self::Py310 => "3.10", | ||
Self::Py311 => "3.11", | ||
Self::Py312 => "3.12", | ||
} | ||
} | ||
|
||
/// Return the `python_full_version` marker for a [`PythonVersion`]. | ||
fn python_full_version(self) -> &'static str { | ||
match self { | ||
Self::Py37 => "3.7.0", | ||
Self::Py38 => "3.8.0", | ||
Self::Py39 => "3.9.0", | ||
Self::Py310 => "3.10.0", | ||
Self::Py311 => "3.11.0", | ||
Self::Py312 => "3.12.0", | ||
} | ||
} | ||
|
||
/// Return the `implementation_version` marker for a [`PythonVersion`]. | ||
fn implementation_version(self) -> &'static str { | ||
match self { | ||
Self::Py37 => "3.7.0", | ||
Self::Py38 => "3.8.0", | ||
Self::Py39 => "3.9.0", | ||
Self::Py310 => "3.10.0", | ||
Self::Py311 => "3.11.0", | ||
Self::Py312 => "3.12.0", | ||
} | ||
} | ||
|
||
/// Return a [`MarkerEnvironment`] compatible with the given [`PythonVersion`], based on | ||
/// a base [`MarkerEnvironment`]. | ||
/// | ||
/// The returned [`MarkerEnvironment`] will preserve the base environment's platform markers, | ||
/// but override its Python version markers. | ||
pub(crate) fn markers(self, base: &MarkerEnvironment) -> MarkerEnvironment { | ||
let mut markers = base.clone(); | ||
// Ex) `python_version == "3.12"` | ||
markers.python_version = StringVersion::from_str(self.python_version()).unwrap(); | ||
// Ex) `python_full_version == "3.12.0"` | ||
markers.python_full_version = StringVersion::from_str(self.python_full_version()).unwrap(); | ||
// Ex) `implementation_version == "3.12.0"` | ||
if markers.implementation_name == "cpython" { | ||
markers.implementation_version = | ||
StringVersion::from_str(self.implementation_version()).unwrap(); | ||
} | ||
markers | ||
} | ||
} |
This file contains 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
34 changes: 34 additions & 0 deletions
34
crates/puffin-cli/tests/snapshots/pip_compile__compile_python_312.snap
This file contains 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
source: crates/puffin-cli/tests/pip_compile.rs | ||
info: | ||
program: puffin | ||
args: | ||
- pip-compile | ||
- requirements.in | ||
- "--python-version" | ||
- py312 | ||
- "--cache-dir" | ||
- /var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmpbKzceW | ||
env: | ||
VIRTUAL_ENV: /var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmpZkKRNz/.venv | ||
--- | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
# This file was autogenerated by Puffin v0.0.1 via the following command: | ||
# [BIN_PATH] pip-compile requirements.in --python-version py312 --cache-dir [CACHE_DIR] | ||
black==23.10.1 | ||
click==8.1.7 | ||
# via black | ||
mypy-extensions==1.0.0 | ||
# via black | ||
packaging==23.2 | ||
# via black | ||
pathspec==0.11.2 | ||
# via black | ||
platformdirs==3.11.0 | ||
# via black | ||
|
||
----- stderr ----- | ||
Resolved 6 packages in [TIME] | ||
|
45 changes: 45 additions & 0 deletions
45
crates/puffin-cli/tests/snapshots/pip_compile__compile_python_37.snap
This file contains 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
source: crates/puffin-cli/tests/pip_compile.rs | ||
info: | ||
program: puffin | ||
args: | ||
- pip-compile | ||
- requirements.in | ||
- "--python-version" | ||
- py37 | ||
- "--cache-dir" | ||
- /var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmpQwHoBA | ||
env: | ||
VIRTUAL_ENV: /var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmp1TmUIW/.venv | ||
--- | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
# This file was autogenerated by Puffin v0.0.1 via the following command: | ||
# [BIN_PATH] pip-compile requirements.in --python-version py37 --cache-dir [CACHE_DIR] | ||
black==23.10.1 | ||
click==8.1.7 | ||
# via black | ||
importlib-metadata==6.8.0 | ||
# via click | ||
mypy-extensions==1.0.0 | ||
# via black | ||
packaging==23.2 | ||
# via black | ||
pathspec==0.11.2 | ||
# via black | ||
platformdirs==3.11.0 | ||
# via black | ||
tomli==2.0.1 | ||
# via black | ||
typing-extensions==4.8.0 | ||
# via | ||
# black | ||
# importlib-metadata | ||
# platformdirs | ||
zipp==3.17.0 | ||
# via importlib-metadata | ||
|
||
----- stderr ----- | ||
Resolved 10 packages in [TIME] | ||
|