Skip to content

Commit 80d08dc

Browse files
committed
redo python venv machinery. Allow poetry
Refs #211
1 parent 4c060d3 commit 80d08dc

File tree

28 files changed

+160
-89
lines changed

28 files changed

+160
-89
lines changed

.github/workflows/ci.cli.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ jobs:
1010
integration-tests:
1111
name: ${{matrix.pkg}} (${{matrix.platform.tag}})
1212
strategy:
13+
fail-fast: false
1314
matrix:
1415
platform:
1516
- os: ubuntu-latest
@@ -20,8 +21,8 @@ jobs:
2021
pkg:
2122
- stark.com/foo
2223
- toolchain.com
23-
- pyapp.com/1
24-
- pyapp.com/2
24+
- pyapp.com/pip
25+
- pyapp.com/poetry
2526
- stark.com/[email protected]
2627
- git-clone.com
2728
- pc-cmake.com
@@ -55,6 +56,7 @@ jobs:
5556
- run: test $(pkgx +stark.com/foo -- stark) = not_much_u
5657
- run: bin/bk audit
5758

59+
5860
unit-tests:
5961
runs-on: ubuntu-latest
6062
env:

bin/cmd/build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const { options, args } = await new Command()
1515
.name("build")
1616
.description("Build pkgx pantry pkgs with brewkit")
1717
.option("-C, --clean", "Clean everything first")
18+
.option("-s, --stage", "Stage, do not run build")
1819
.arguments("[pkgspec]")
1920
.parse();
2021

@@ -93,6 +94,10 @@ const script = new Path(`${config.path.build}.sh`)
9394
console.log('writing', script)
9495
script.write({text: script_content, force: true}).chmod(0o755)
9596

97+
if (options.stage) {
98+
Deno.exit(0)
99+
}
100+
96101
/// run script
97102
await gum('build')
98103

lib/porcelain/build-script.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default async function(config: Config, PATH?: Path): Promise<string> {
1717

1818
const brewkitd = new Path(new URL(import.meta.url).pathname).parent().parent().parent()
1919
const brewkit_PATHs = [
20-
brewkitd.join("share/brewkit"),
20+
brewkitd.join("libexec"),
2121
PATH
2222
].compact(x => x?.string).join(':')
2323

@@ -26,6 +26,16 @@ export default async function(config: Config, PATH?: Path): Promise<string> {
2626
FLAGS.push("export MACOSX_DEPLOYMENT_TARGET=11.0")
2727
}
2828

29+
const tmp = (() => {
30+
switch (host().platform) {
31+
case 'darwin':
32+
case 'linux':
33+
return `export TMPDIR="$HOME/tmp"; mkdir -p "$TMPDIR"`
34+
case 'windows':
35+
return `export TMP="$HOME/tmp"; export TEMP="$HOME/tmp"; mkdir -p "$TMP"`
36+
}
37+
})
38+
2939
return undent`
3040
#!/${bash}
3141
@@ -39,8 +49,9 @@ export default async function(config: Config, PATH?: Path): Promise<string> {
3949
set +a
4050
4151
export PKGX="${pkgx}"
42-
export SRCROOT=${config.path.build.string}
4352
export HOME=${config.path.home.string}
53+
export SRCROOT=${config.path.build.string}
54+
${tmp()}
4455
if [ -n "$CI" ]; then
4556
export FORCE_UNSAFE_CONFIGURE=1
4657
fi

libexec/bkpyvenv

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env -S pkgx +git +install bash
2+
3+
set -eo pipefail
4+
5+
cd "$SRCROOT"
6+
7+
d="$(cd "$(dirname "$0")"/.. && pwd)"
8+
9+
CMD=$1
10+
shift
11+
12+
if [ $1 = '--engine=poetry' ]; then
13+
ENGINE=poetry
14+
shift
15+
fi
16+
17+
PREFIX=$1
18+
shift
19+
20+
set -x
21+
22+
case $CMD in
23+
stage)
24+
VERSION=$1
25+
26+
if [ ! -d "$SRCROOT/.git" ]; then
27+
GIT_DIR="$SRCROOT/.git"
28+
git init
29+
git config user.name 'pkgx[bot]'
30+
git config user.email '[email protected]'
31+
git commit -mnil --allow-empty
32+
git tag -a "$VERSION" -m "Version $VERSION" --force
33+
unset GIT_DIR
34+
fi
35+
36+
if [ "$ENGINE" = poetry ]; then
37+
poetry config virtualenvs.create true
38+
poetry config virtualenvs.in-project true
39+
else
40+
python -m venv "$PREFIX"/venv
41+
fi
42+
;;
43+
seal)
44+
PYTHON=$(python --version | sed -n 's/Python \([0-9]\+\.[0-9]\+\).*/\1/p')
45+
46+
if [ "$ENGINE" = poetry ]; then
47+
# FIXME is there a more efficient way to do this?
48+
# FIXME the glob is unfortunate
49+
poetry build -f sdist
50+
tar xzf \
51+
dist/*.tar.gz \
52+
--directory "$SRCROOT"/.venv/lib/python$PYTHON/site-packages \
53+
--strip-components=1
54+
mkdir -p "$PREFIX"
55+
mv "$SRCROOT"/.venv "$PREFIX/venv"
56+
fi
57+
58+
for cmd in $@; do
59+
install -D "$d/share/brewkit/python-venv-stub.py" $PREFIX/bin/$cmd
60+
sed -i "1s|.*|#!/usr/bin/env -S pkgx python@$PYTHON|" $PREFIX/bin/$cmd
61+
done
62+
;;
63+
esac
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)