-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add asdf support to python + poetry * feat: initial asdf poetry and python extraction * fix: remove old poetry version code * style: formatting * style: more linting fixes * log if tool-versions does not match expectations * tests for asdf * fmt * fmt * fmt * fixing badly merged changes * adding snapshot
- Loading branch information
1 parent
9fae921
commit d927e08
Showing
9 changed files
with
306 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
python 3.12.3 | ||
poetry 1.8.2 |
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,9 @@ | ||
import sys | ||
import subprocess | ||
|
||
print(sys.version) | ||
|
||
poetry_version = subprocess.run( | ||
["poetry", "--version"], capture_output=True, text=True | ||
).stdout.strip() | ||
print(poetry_version) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,15 @@ | ||
[tool.poetry] | ||
name = "python-asdf-poetry" | ||
version = "0.1.0" | ||
description = "" | ||
authors = ["iloveitaly"] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.10" | ||
|
||
[tool.poetry.dev-dependencies] | ||
pytest = "^5.2" | ||
|
||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend = "poetry.core.masonry.api" |
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 @@ | ||
use regex::Regex; | ||
use std::collections::HashMap; | ||
|
||
pub fn parse_tool_versions_content(file_content: &str) -> HashMap<String, String> { | ||
let re = Regex::new(r"\s+").unwrap(); | ||
file_content | ||
.lines() | ||
.map(str::trim) | ||
.filter(|line| !line.starts_with('#')) | ||
.filter_map(|line| { | ||
let parts: Vec<&str> = re.splitn(line, 2).collect(); | ||
if parts.len() == 2 { | ||
Some((parts[0].to_string(), parts[1].to_string())) | ||
} else { | ||
None | ||
} | ||
}) | ||
.collect() | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_parse_tool_versions_content() { | ||
let file_content = "\ | ||
# This is a comment | ||
python 3.10.4 | ||
poetry 1.7.1 | ||
# exact ruby version required for homebrew | ||
ruby\t3.1.4 | ||
direnv 2.32.3 "; | ||
let versions = parse_tool_versions_content(file_content); | ||
|
||
let expected = HashMap::from([ | ||
("direnv".to_string(), "2.32.3".to_string()), | ||
("python".to_string(), "3.10.4".to_string()), | ||
("ruby".to_string(), "3.1.4".to_string()), | ||
("poetry".to_string(), "1.7.1".to_string()), | ||
]); | ||
|
||
assert_eq!(versions, expected); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod app; | ||
pub mod asdf; | ||
pub mod builder; | ||
pub mod environment; | ||
mod files; | ||
|
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
52 changes: 52 additions & 0 deletions
52
tests/snapshots/generate_plan_tests__python_asdf_poetry.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,52 @@ | ||
--- | ||
source: tests/generate_plan_tests.rs | ||
expression: plan | ||
--- | ||
{ | ||
"providers": [], | ||
"buildImage": "[build_image]", | ||
"variables": { | ||
"NIXPACKS_METADATA": "python,poetry", | ||
"NIXPACKS_POETRY_VERSION": "1.8.2", | ||
"PIP_DEFAULT_TIMEOUT": "100", | ||
"PIP_DISABLE_PIP_VERSION_CHECK": "1", | ||
"PIP_NO_CACHE_DIR": "1", | ||
"PYTHONDONTWRITEBYTECODE": "1", | ||
"PYTHONFAULTHANDLER": "1", | ||
"PYTHONHASHSEED": "random", | ||
"PYTHONUNBUFFERED": "1" | ||
}, | ||
"phases": { | ||
"install": { | ||
"name": "install", | ||
"dependsOn": [ | ||
"setup" | ||
], | ||
"cmds": [ | ||
"python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install poetry==$NIXPACKS_POETRY_VERSION && poetry install --no-dev --no-interaction --no-ansi" | ||
], | ||
"cacheDirectories": [ | ||
"/root/.cache/pip" | ||
], | ||
"paths": [ | ||
"/opt/venv/bin" | ||
] | ||
}, | ||
"setup": { | ||
"name": "setup", | ||
"nixPkgs": [ | ||
"python312", | ||
"gcc" | ||
], | ||
"nixLibs": [ | ||
"zlib", | ||
"stdenv.cc.cc.lib" | ||
], | ||
"nixOverlays": [], | ||
"nixpkgsArchive": "[archive]" | ||
} | ||
}, | ||
"start": { | ||
"cmd": "python main.py" | ||
} | ||
} |