Skip to content

feat: prevent pixi init to be executed in parent of pixi home directory#4168

Merged
lucascolley merged 6 commits intoprefix-dev:mainfrom
ytausch:prevent-pixi-init-home
Jul 29, 2025
Merged

feat: prevent pixi init to be executed in parent of pixi home directory#4168
lucascolley merged 6 commits intoprefix-dev:mainfrom
ytausch:prevent-pixi-init-home

Conversation

@ytausch
Copy link
Contributor

@ytausch ytausch commented Jul 21, 2025

Closes #4166.

@lucascolley I implemented the feature. Can you guide me on how your testing strategy imposes tests for this change?

Copy link
Collaborator

@lucascolley lucascolley left a comment

Choose a reason for hiding this comment

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

nice! Could you add a test next to

def test_pixi_init_non_existing_dir(pixi: Path, tmp_pixi_workspace: Path) -> None:
# Specify project dir
project_dir = tmp_pixi_workspace / "project_dir"
# Create a new project
verify_cli_command([pixi, "init", project_dir], ExitCode.SUCCESS)
# Verify that the manifest file is created
manifest_path = project_dir / "pixi.toml"
assert manifest_path.exists()
# Verify that the manifest file contains expected content
manifest_content = manifest_path.read_text()
assert "[workspace]" in manifest_content
? I think you can use verify_cli_command to attempt the init.
def verify_cli_command(
command: list[Path | str],
expected_exit_code: ExitCode = ExitCode.SUCCESS,
stdout_contains: str | list[str] | None = None,
stdout_excludes: str | list[str] | None = None,
stderr_contains: str | list[str] | None = None,
stderr_excludes: str | list[str] | None = None,
env: dict[str, str] | None = None,
cwd: str | Path | None = None,
reset_env: bool = False,
) -> Output:

Use the env argument to set PIXI_HOME, pass ExitCode.FAILURE, and pass the expected error message to stderr_contains.

@lucascolley lucascolley added area:init Related to pixi init enhancement New features labels Jul 21, 2025
@ytausch
Copy link
Contributor Author

ytausch commented Jul 21, 2025

Thank you! I added the test.

@ytausch ytausch requested a review from lucascolley July 21, 2025 17:33
Copy link
Collaborator

@lucascolley lucascolley left a comment

Choose a reason for hiding this comment

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

thanks!

Copy link
Collaborator

@lucascolley lucascolley left a comment

Choose a reason for hiding this comment

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

@ytausch ytausch requested a review from lucascolley July 22, 2025 12:28
@ytausch
Copy link
Contributor Author

ytausch commented Jul 22, 2025

Fixed!

Copy link
Collaborator

@lucascolley lucascolley left a comment

Choose a reason for hiding this comment

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

LGTM!

@lucascolley
Copy link
Collaborator

@Hofer-Julian can you press the green button :) ?

@Hofer-Julian
Copy link
Contributor

@Hofer-Julian can you press the green button :) ?

Happy to, but you should be able to do that as well, right?

@lucascolley lucascolley merged commit 8d542ed into prefix-dev:main Jul 29, 2025
73 of 74 checks passed
@lucascolley
Copy link
Collaborator

I can now, thanks @ytausch !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:init Related to pixi init enhancement New features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should print error when running pixi init in $PIXI_HOME/..

3 participants