Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
UNRELEASED
----------

* Support `pixi-devenv 0.1.0` or later.


1.5.1 (2025-08-26)
------------------

Expand Down
3 changes: 2 additions & 1 deletion src/deps/_tests/test_deps_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def create_devenv_file(
toml_path = root_dir / get_devenv_filename(flavor)
env_content = []
if relative_paths_to_root is not None:
env_content.append("includes = [")
env_content.append("[devenv]")
env_content.append("upstream = [")
# Use the extended version for half of the includes:
# includes = [
# { path = "../core" },
Expand Down
23 changes: 12 additions & 11 deletions src/deps/deps_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,10 @@ def get_shallow_dependencies(dev_env_file: Path) -> Sequence[Path]:
case ".toml":
import tomli

data = tomli.loads(dev_env_file.read_text(encoding="UTF-8"))
if not data.get("includes"):
return []

def get_relative_path(entry: str | dict[str, str]) -> str:
"""Include entries have two possible formats:
"""pixi-devenv entries have two possible formats:

includes = [
devenv.upstream = [
"../core",
{ path = "../calc" },
]
Expand All @@ -109,11 +105,16 @@ def get_relative_path(entry: str | dict[str, str]) -> str:
else:
return entry

return [
Path(os.path.abspath(dev_env_file.parent / get_relative_path(p)))
/ "pixi.devenv.toml"
for p in data["includes"]
]
data = tomli.loads(dev_env_file.read_text(encoding="UTF-8"))
match data:
case {"devenv": {"upstream": upstream}} if upstream:
return [
Path(os.path.abspath(dev_env_file.parent / get_relative_path(p)))
/ "pixi.devenv.toml"
for p in upstream
]
case _:
return []
Comment on lines +109 to +117
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like to avoid those conditionals (case ... if ...:) in match/case constructs =)

>>> def what_is(v):
...   match v:
...     case [*a]:
...       print(f'{a=}')
...     case set(b):
...       print(f'{b=}')
...     case c:
...       print(f'{c=}')
...
>>> what_is([1,2,3])
a=[1, 2, 3]
>>> what_is((1,2,3))
a=[1, 2, 3]
>>> what_is({1,2,3})
b={1, 2, 3}
>>> what_is({1:11,2:22,3:33})
c={1: 11, 2: 22, 3: 33}
>>> what_is([])
a=[]
Suggested change
match data:
case {"devenv": {"upstream": upstream}} if upstream:
return [
Path(os.path.abspath(dev_env_file.parent / get_relative_path(p)))
/ "pixi.devenv.toml"
for p in upstream
]
case _:
return []
match data:
case {"devenv": {"upstream": [*upstream]}}:
return [
Path(os.path.abspath(dev_env_file.parent / get_relative_path(p)))
/ "pixi.devenv.toml"
for p in upstream
]
case _:
return []

Looks better to me.
And what if that upstream is bound to some other thing like a string?

Copy link
Contributor

@prusse-martin prusse-martin Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it could even be

Suggested change
match data:
case {"devenv": {"upstream": upstream}} if upstream:
return [
Path(os.path.abspath(dev_env_file.parent / get_relative_path(p)))
/ "pixi.devenv.toml"
for p in upstream
]
case _:
return []
match data:
case {"devenv": {"upstream": [*upstream]}}:
return [
(dev_env_file.parent / get_relative_path(p)).absolute()
/ "pixi.devenv.toml"
for p in upstream
]
case {"devenv": {"upstream": invalid_upstream}}:
raise RuntimeError(
f'Invalid upstream declaration: {invalid_upstream!r}\nThe expected value should be a list.'
)
case _:
return []

or even

Maybe it could even be

Suggested change
match data:
case {"devenv": {"upstream": upstream}} if upstream:
return [
Path(os.path.abspath(dev_env_file.parent / get_relative_path(p)))
/ "pixi.devenv.toml"
for p in upstream
]
case _:
return []
match data:
case {"devenv": {"upstream": [*upstream]}}:
return [
(dev_env_file.parent / get_relative_path(p)).absolute()
/ "pixi.devenv.toml"
for p in upstream
]
case {"devenv": {"upstream": str(upstream)}}:
return [
(
dev_env_file.parent / get_relative_path(upstream)
).absolute() / "pixi.devenv.toml"
]
case {"devenv": {"upstream": invalid_upstream}}:
raise RuntimeError(
f'Invalid upstream declaration: {invalid_upstream!r}\nThe expected value should be a list.'
)
case _:
return []

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a matter of taste, and TBH my version looks better to me, so I will keep my version if you don't mind.

case ext: # pragma: no cover
msg = f"Cannot parse files with extension {ext}"
echo_error(msg)
Expand Down