Skip to content

Commit

Permalink
refactor: Enhance installation script with custom destination and upd…
Browse files Browse the repository at this point in the history
…ate documentation (prefix-dev#2606)

Found this script useful while working on features for other tooling, i
use PIXI_HOME for my binaries so this feature helps write it to the same
location.
+ also wanted to describe how to use it for other devs looking to
contribute

- Refactor the installation script to support specifying a custom
destination for executables and add logging for better visibility.
- Update CONTRIBUTING.md to include instructions for the new
installation method.

---------

Co-authored-by: Julian Hofer <[email protected]>
  • Loading branch information
jjjermiah and Hofer-Julian authored Dec 2, 2024
1 parent 51d9920 commit 0b63796
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
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()

0 comments on commit 0b63796

Please sign in to comment.