-
Notifications
You must be signed in to change notification settings - Fork 3
Adapt to pixi-devenv 0.1.0 #48
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
Conversation
Initially we envisioned `pixi.devenv.toml` files dependencies to be included as: ```toml includes = ["../core"] ``` However, in the end we went with a different syntax: ```toml [devenv] upstream = ["../core"] ```
| 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 [] |
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.
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=[]| 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?
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.
Maybe it could even be
| 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
| 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 [] |
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.
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.
Initially we envisioned
pixi.devenv.tomlfiles dependencies to be included as:However, in the end we went with a different syntax: