Skip to content
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

refactor: Enhance installation script with custom destination and update documentation #2606

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
17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ pixi run test-all-fast
pixi run install # only works on unix systems as on windows you can't overwrite the binary while it's running
```

### Installing the target binaries to a custom location

Use the pixi task `install-as` which invokes a python script to build the project and copy the executable to a custom location.
```shell
$ pixi run install-as
usage: install.py [-h] [--dest DEST] name

Build pixi and copy the executable to ~/.pixi/bin or a custom destination

positional arguments:
name Name of the executable (e.g. pixid)

options:
-h, --help show this help message and exit
--dest DEST Destination directory for the executable, default: $PIXI_HOME/bin (or ~/.pixi/bin if $PIXI_HOME isn't set)
```

## Get your code ready for a PR
We use [`pre-commit`](https://pre-commit.com/) to run all the formatters and linters that we use.
If you have `pre-commit` installed on your system you can run `pre-commit install` to run the tools before you commit or push.
Expand Down
15 changes: 11 additions & 4 deletions scripts/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import platform
import os

DEFAULT_DESTINATION_DIR = Path(os.getenv("PIXI_HOME", Path.home() / ".pixi")) / "bin"


def executable_extension(name: str) -> str:
if platform.system() == "Windows":
Expand All @@ -14,22 +16,27 @@ def executable_extension(name: str) -> str:

def main() -> None:
parser = argparse.ArgumentParser(
description="Build pixi and copy the executable to ~/.pixi/bin/"
description=f"Build pixi and copy the executable to {DEFAULT_DESTINATION_DIR} or a custom destination specified by --dest"
)
parser.add_argument("name", type=str, help="Name of the executable (e.g. pixid)")
parser.add_argument(
"--dest",
type=Path,
default=DEFAULT_DESTINATION_DIR,
help=f"Destination directory for the executable, default: {DEFAULT_DESTINATION_DIR}",
)

args = parser.parse_args()

built_executable_path = Path(os.environ["CARGO_TARGET_DIR"]).joinpath(
"release", executable_extension("pixi")
)
destination_path = Path.home().joinpath(".pixi", "bin", executable_extension(args.name))
destination_path = args.dest.joinpath(executable_extension(args.name))

print(f"Copying the executable to {destination_path}")
destination_path.parent.mkdir(parents=True, exist_ok=True)
shutil.copy(built_executable_path, destination_path)

print("Done!")


if __name__ == "__main__":
main()
Loading