Skip to content

Commit

Permalink
pep723: Pass through inputs inline script metadata in the metadata
Browse files Browse the repository at this point in the history
…verbatim
  • Loading branch information
adisbladis committed Jan 11, 2025
1 parent 6251dce commit 64fedca
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/pep723.nix
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ in
{
requires-python = pep440.parseVersionConds (metadata.requires-python or "");
dependencies = map pep508.parseString (metadata.dependencies or [ ]);
inherit metadata;
}
else
default;
Expand Down
2 changes: 1 addition & 1 deletion lib/scripts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fix (self: {
fix (scriptSelf: {
name = normalizePackageName name;
script = script';
metadata = pep723.parseScript script';
metadata = parseScript script';
renderWithPackages =
{
# Python interpreter
Expand Down
54 changes: 54 additions & 0 deletions lib/test_pep723.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ in
print("Hello world")
'';
expected = {
metadata = {
dependencies = [
"requests<3"
"rich"
];
requires-python = ">=3.11";
};
requires-python = requiresPython;
dependencies = [
requests
Expand All @@ -54,6 +61,13 @@ in
requests
rich
];
metadata = {
dependencies = [
"requests<3"
"rich"
];
requires-python = ">=3.11";
};
};
};

Expand All @@ -77,6 +91,9 @@ in
# ///
'';
expected = {
metadata = {
dependencies = [ "rich" ];
};
requires-python = [ ];
dependencies = [ rich ];
};
Expand All @@ -89,11 +106,34 @@ in
# ///
'';
expected = {
metadata = {
requires-python = ">=3.11";
};
requires-python = requiresPython;
dependencies = [ ];
};
};

testTool = {
expr = pep723.parseScript ''
# /// script
# [tool.uv]
# no-binary = true
# ///
'';
expected = {
requires-python = [ ];
dependencies = [ ];
metadata = {
tool = {
uv = {
no-binary = true;
};
};
};
};
};

# A script with a shebang and a script section offset from the initial comment block
testOffsetScript = {
expr = pep723.parseScript ''
Expand All @@ -108,6 +148,13 @@ in
# ///
'';
expected = {
metadata = {
dependencies = [
"requests<3"
"rich"
];
requires-python = ">=3.11";
};
requires-python = requiresPython;
dependencies = [
requests
Expand All @@ -134,6 +181,13 @@ in
requests
rich
];
metadata = {
dependencies = [
"requests<3"
"rich"
];
requires-python = ">=3.11";
};
};
};
};
Expand Down

0 comments on commit 64fedca

Please sign in to comment.