Skip to content

Commit 417e799

Browse files
authored
Merge pull request #195 from lociii/main
Install ruff from github releases instead of pipx, refs #194
2 parents e66a270 + 4051391 commit 417e799

4 files changed

Lines changed: 46 additions & 50 deletions

File tree

src/ruff/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# Ruff (via pipx) (ruff)
2+
# Ruff (via Github Releases)
33

44
Ruff is an extremely fast Python linter, written in Rust.
55

src/ruff/devcontainer-feature.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "ruff",
3-
"version": "1.1.1",
4-
"name": "Ruff (via pipx)",
3+
"version": "2.0.0",
4+
"name": "Ruff (via Github Releases)",
55
"documentationURL": "http://github.com/devcontainers-extra/features/tree/main/src/ruff",
66
"description": "Ruff is an extremely fast Python linter, written in Rust.",
77
"options": {
@@ -21,8 +21,5 @@
2121
]
2222
}
2323
},
24-
"installsAfter": [
25-
"ghcr.io/devcontainers-extra/features/pipx-package",
26-
"ghcr.io/devcontainers/features/python"
27-
]
24+
"installsAfter": []
2825
}

src/ruff/install.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1+
#!/usr/bin/env bash
12

23
set -e
34

4-
. ./library_scripts.sh
5+
source ./library_scripts.sh
56

67
# nanolayer is a cli utility which keeps container layers as small as possible
78
# source code: https://github.com/devcontainers-extra/nanolayer
89
# `ensure_nanolayer` is a bash function that will find any existing nanolayer installations,
910
# and if missing - will download a temporary copy that automatically get deleted at the end
1011
# of the script
11-
ensure_nanolayer nanolayer_location "v0.5.0"
12-
12+
ensure_nanolayer nanolayer_location "v0.5.6"
1313

14+
# Example nanolayer installation via devcontainer-feature
1415
$nanolayer_location \
1516
install \
1617
devcontainer-feature \
17-
"ghcr.io/devcontainers-extra/features/pipx-package:1.1.8" \
18-
--option package='ruff' --option version="$VERSION"
19-
20-
18+
"ghcr.io/devcontainers-extra/features/gh-release:1" \
19+
--option repo='astral-sh/ruff' --option binaryNames='ruff' --option version="$VERSION"
2120

2221
echo 'Done!'
23-

src/ruff/library_scripts.sh

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
#!/usr/bin/env bash
22

33
clean_download() {
44
# The purpose of this function is to download a file with minimal impact on container layer size
@@ -15,7 +15,7 @@ clean_download() {
1515
tempdir=$(mktemp -d)
1616
downloader_installed=""
1717

18-
_apt_get_install() {
18+
function _apt_get_install() {
1919
tempdir=$1
2020

2121
# copy current state of apt list - in order to revert back later (minimize contianer layer size)
@@ -24,7 +24,7 @@ clean_download() {
2424
apt-get -y install --no-install-recommends wget ca-certificates
2525
}
2626

27-
_apt_get_cleanup() {
27+
function _apt_get_cleanup() {
2828
tempdir=$1
2929

3030
echo "removing wget"
@@ -35,15 +35,15 @@ clean_download() {
3535
rm -r /var/lib/apt/lists && mv $tempdir/lists /var/lib/apt/lists
3636
}
3737

38-
_apk_install() {
38+
function _apk_install() {
3939
tempdir=$1
4040
# copy current state of apk cache - in order to revert back later (minimize contianer layer size)
4141
cp -p -R /var/cache/apk $tempdir
4242

43-
apk add --no-cache wget
43+
apk add --no-cache wget
4444
}
4545

46-
_apk_cleanup() {
46+
function _apk_cleanup() {
4747
tempdir=$1
4848

4949
echo "removing wget"
@@ -59,10 +59,10 @@ clean_download() {
5959
fi
6060

6161
# in case none of them is installed, install wget temporarly
62-
if [ -z $downloader ] ; then
63-
if [ -x "/usr/bin/apt-get" ] ; then
62+
if [ -z $downloader ]; then
63+
if [ -x "/usr/bin/apt-get" ]; then
6464
_apt_get_install $tempdir
65-
elif [ -x "/sbin/apk" ] ; then
65+
elif [ -x "/sbin/apk" ]; then
6666
_apk_install $tempdir
6767
else
6868
echo "distro not supported"
@@ -72,18 +72,18 @@ clean_download() {
7272
downloader_installed="true"
7373
fi
7474

75-
if [ $downloader = "wget" ] ; then
75+
if [ $downloader = "wget" ]; then
7676
wget -q $url -O $output_location
7777
else
7878
curl -sfL $url -o $output_location
7979
fi
8080

8181
# NOTE: the cleanup procedure was not implemented using `trap X RETURN` only because
8282
# alpine lack bash, and RETURN is not a valid signal under sh shell
83-
if ! [ -z $downloader_installed ] ; then
84-
if [ -x "/usr/bin/apt-get" ] ; then
83+
if ! [ -z $downloader_installed ]; then
84+
if [ -x "/usr/bin/apt-get" ]; then
8585
_apt_get_cleanup $tempdir
86-
elif [ -x "/sbin/apk" ] ; then
86+
elif [ -x "/sbin/apk" ]; then
8787
_apk_cleanup $tempdir
8888
else
8989
echo "distro not supported"
@@ -93,56 +93,60 @@ clean_download() {
9393

9494
}
9595

96-
9796
ensure_nanolayer() {
9897
# Ensure existance of the nanolayer cli program
9998
local variable_name=$1
10099

101100
local required_version=$2
101+
# normalize version
102+
if ! [[ $required_version == v* ]]; then
103+
required_version=v$required_version
104+
fi
102105

103-
local __nanolayer_location=""
106+
local nanolayer_location=""
104107

105108
# If possible - try to use an already installed nanolayer
106-
if [ -z "${NANOLAYER_FORCE_CLI_INSTALLATION}" ]; then
107-
if [ -z "${NANOLAYER_CLI_LOCATION}" ]; then
109+
if [[ -z "${NANOLAYER_FORCE_CLI_INSTALLATION}" ]]; then
110+
if [[ -z "${NANOLAYER_CLI_LOCATION}" ]]; then
108111
if type nanolayer >/dev/null 2>&1; then
109112
echo "Found a pre-existing nanolayer in PATH"
110-
__nanolayer_location=nanolayer
113+
nanolayer_location=nanolayer
111114
fi
112-
elif [ -f "${NANOLAYER_CLI_LOCATION}" ] && [ -x "${NANOLAYER_CLI_LOCATION}" ] ; then
113-
__nanolayer_location=${NANOLAYER_CLI_LOCATION}
114-
echo "Found a pre-existing nanolayer which were given in env variable: $__nanolayer_location"
115+
elif [ -f "${NANOLAYER_CLI_LOCATION}" ] && [ -x "${NANOLAYER_CLI_LOCATION}" ]; then
116+
nanolayer_location=${NANOLAYER_CLI_LOCATION}
117+
echo "Found a pre-existing nanolayer which were given in env variable: $nanolayer_location"
115118
fi
116119

117120
# make sure its of the required version
118-
if ! [ -z "${__nanolayer_location}" ]; then
121+
if ! [[ -z "${nanolayer_location}" ]]; then
119122
local current_version
120-
current_version=$($__nanolayer_location --version)
121-
123+
current_version=$($nanolayer_location --version)
124+
if ! [[ $current_version == v* ]]; then
125+
current_version=v$current_version
126+
fi
122127

123128
if ! [ $current_version == $required_version ]; then
124129
echo "skipping usage of pre-existing nanolayer. (required version $required_version does not match existing version $current_version)"
125-
__nanolayer_location=""
130+
nanolayer_location=""
126131
fi
127132
fi
128133

129134
fi
130135

131136
# If not previuse installation found, download it temporarly and delete at the end of the script
132-
if [ -z "${__nanolayer_location}" ]; then
137+
if [[ -z "${nanolayer_location}" ]]; then
133138

134-
if [ "$(uname -sm)" = 'Linux x86_64' ] || [ "$(uname -sm)" = "Linux aarch64" ]; then
139+
if [ "$(uname -sm)" == "Linux x86_64" ] || [ "$(uname -sm)" == "Linux aarch64" ]; then
135140
tmp_dir=$(mktemp -d -t nanolayer-XXXXXXXXXX)
136141

137-
clean_up () {
142+
clean_up() {
138143
ARG=$?
139144
rm -rf $tmp_dir
140145
exit $ARG
141146
}
142147
trap clean_up EXIT
143148

144-
145-
if [ -x "/sbin/apk" ] ; then
149+
if [ -x "/sbin/apk" ]; then
146150
clib_type=musl
147151
else
148152
clib_type=gnu
@@ -155,8 +159,7 @@ ensure_nanolayer() {
155159

156160
tar xfzv $tmp_dir/$tar_filename -C "$tmp_dir"
157161
chmod a+x $tmp_dir/nanolayer
158-
__nanolayer_location=$tmp_dir/nanolayer
159-
162+
nanolayer_location=$tmp_dir/nanolayer
160163

161164
else
162165
echo "No binaries compiled for non-x86-linux architectures yet: $(uname -m)"
@@ -165,8 +168,6 @@ ensure_nanolayer() {
165168
fi
166169

167170
# Expose outside the resolved location
168-
export ${variable_name}=$__nanolayer_location
171+
declare -g ${variable_name}=$nanolayer_location
169172

170173
}
171-
172-

0 commit comments

Comments
 (0)