Skip to content

Commit

Permalink
feat: completes basic pipx via asdf setup
Browse files Browse the repository at this point in the history
  • Loading branch information
yozachar committed Apr 18, 2023
1 parent d154e63 commit 5f37115
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
- name: asdf_plugin_test
uses: asdf-vm/actions/plugin-test@v2
with:
command: pipx --version
command: alias python3='python'; pipx --version
4 changes: 1 addition & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
TODO: INSERT YOUR NAME COPYRIGHT YEAR

MIT License

Copyright (c) [year] [fullname]
Copyright (c) MIT Jovial Joe Jayarson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@

# asdf-pipx [![Build](https://github.com/joe733/asdf-pipx/actions/workflows/build.yml/badge.svg)](https://github.com/joe733/asdf-pipx/actions/workflows/build.yml) [![Lint](https://github.com/joe733/asdf-pipx/actions/workflows/lint.yml/badge.svg)](https://github.com/joe733/asdf-pipx/actions/workflows/lint.yml)


[pipx](https://pypa.github.io/pipx/) plugin for the [asdf version manager](https://asdf-vm.com).

</div>

# Contents

- [Contents](#contents)
- [Dependencies](#dependencies)
- [Install](#install)
- [Contributing](#contributing)
- [License](#license)

# Dependencies

**TODO: adapt this section**

- `bash`, `curl`, `tar`: generic POSIX utilities.
- `SOME_ENV_VAR`: set this environment variable in your shell config to load the correct version of tool x.
- `bash`, `curl`: generic POSIX utilities.
- `python>=3.7`: Python and some dependencies
- `argcomplete>=1.9.4`
- `colorama>=0.4.4; sys_platform == 'win32'`
- `importlib-metadata>=3.3.0; python_version < '3.8'`
- `packaging>=20.0`
- `platformdirs>=2.1.0`
- `userpath>=1.6.0`

# Install

Expand Down
10 changes: 1 addition & 9 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ source "${plugin_dir}/lib/utils.bash"

mkdir -p "$ASDF_DOWNLOAD_PATH"

# TODO: Adapt this to proper extension and adapt extracting strategy.
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tar.gz"
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME"

# Download tar.gz file to the download directory
download_release "$ASDF_INSTALL_VERSION" "$release_file"

# Extract contents of tar.gz file into the download directory
tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" --strip-components=1 || fail "Could not extract $release_file"

# Remove the tar.gz file since we don't need to keep it
rm "$release_file"
3 changes: 3 additions & 0 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ plugin_dir=$(dirname "$(dirname "$current_script_path")")
source "${plugin_dir}/lib/utils.bash"

install_version "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"

# Removing $release_file
rm "$ASDF_DOWNLOAD_PATH/$TOOL_NAME"
11 changes: 3 additions & 8 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

set -euo pipefail

# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for pipx.
GH_REPO="https://github.com/pypa/pipx"
TOOL_NAME="pipx"
TOOL_TEST="pipx --version"
Expand All @@ -14,7 +13,6 @@ fail() {

curl_opts=(-fsSL)

# NOTE: You might want to remove this if pipx is not hosted on GitHub releases.
if [ -n "${GITHUB_API_TOKEN:-}" ]; then
curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN")
fi
Expand All @@ -27,12 +25,10 @@ sort_versions() {
list_github_tags() {
git ls-remote --tags --refs "$GH_REPO" |
grep -o 'refs/tags/.*' | cut -d/ -f3- |
sed 's/^v//' # NOTE: You might want to adapt this sed to remove non-version strings from tags
sed 's/^v//'
}

list_all_versions() {
# TODO: Adapt this. By default we simply list the tag names from GitHub releases.
# Change this function if pipx has other means of determining installable versions.
list_github_tags
}

Expand All @@ -41,8 +37,7 @@ download_release() {
version="$1"
filename="$2"

# TODO: Adapt the release URL convention for pipx
url="$GH_REPO/archive/v${version}.tar.gz"
url="$GH_REPO/releases/download/${version}/pipx.pyz"

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
Expand All @@ -60,8 +55,8 @@ install_version() {
(
mkdir -p "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path"
chmod +x "$install_path/$TOOL_NAME"

# TODO: Assert pipx executable exists.
local tool_cmd
tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)"
test -x "$install_path/$tool_cmd" || fail "Expected $install_path/$tool_cmd to be executable."
Expand Down

0 comments on commit 5f37115

Please sign in to comment.