diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6338f3bf4..df9814bdf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. diff --git a/scripts/install.py b/scripts/install.py index 14e58aac4..5480a67a0 100644 --- a/scripts/install.py +++ b/scripts/install.py @@ -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": @@ -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()