Skip to content

Commit

Permalink
Merge branch 'moneymeets:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
djm authored Sep 8, 2023
2 parents c2b3c2a + 22a02ea commit 3103c2d
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 28 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ jobs:
shellcheck -P SCRIPTDIR -x test/utils test/test-*
- run: ./run_tests.sh

test-macos:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: macos-latest
timeout-minutes: 5

steps:
- uses: actions/checkout@v3

- run: ./run_tests.sh
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ heroku buildpacks:add https://github.com/moneymeets/python-poetry-buildpack.git
heroku buildpacks:add heroku/python
```

**Note:** this buildpack is _only_ for generating `requirements.txt` and `runtime.txt` for subsequent use by the official `heroku/python` buildpack. Do not depend on the installed Poetry's location, or its venv remaining functional at app runtime. If you need Poetry for other purposes (for example CI checks), make your own separate Poetry installation accordingly.
**Note:** this buildpack is _only_ for generating `requirements.txt` and `runtime.txt` for subsequent use by the official `heroku/python` buildpack. Do not depend on the installed Poetry's location, or its virtual environment remaining functional at app runtime. If you need Poetry for other purposes (for example CI checks), make your own separate Poetry installation accordingly.

## Configuration

Expand All @@ -26,16 +26,28 @@ Python version can be forced by setting the `PYTHON_RUNTIME_VERSION` variable. O
heroku config:set PYTHON_RUNTIME_VERSION=3.9.1
```

### `runtime.txt`

Generation of the `runtime.txt` can be skipped by setting `DISABLE_POETRY_CREATE_RUNTIME_FILE` to `1`:

```
heroku config:set DISABLE_POETRY_CREATE_RUNTIME_FILE=1
```

If `DISABLE_POETRY_CREATE_RUNTIME_FILE` is set, the required Python version can be specified in `runtime.txt`. Otherwise, if `runtime.txt` is present in the repository, the buildpack will prevent the app from being deployed in order to avoid possible ambiguities.

### Poetry

Poetry version can be specified by setting `POETRY_VERSION` in Heroku config vars. Otherwise, it will default to a hardcoded version.
Poetry version can be specified by setting `POETRY_VERSION` in Heroku config vars. Otherwise, it will attempt to be inferred from `poetry.lock` or default to the latest version.

```
heroku config:set POETRY_VERSION=1.1.13
```

Generally all variables starting with `POETRY_` are passed on to Poetry by this buildpack; see the corresponding [Poetry documentation](https://python-poetry.org/docs/configuration/#using-environment-variables) section for possible uses.

### `requirements.txt`

Exporting of development dependencies (e.g. to run tests in CI pipelines) can be optionally enabled by setting `POETRY_EXPORT_DEV_REQUIREMENTS` to `1`:

```
Expand All @@ -48,16 +60,6 @@ If you want to override the default export parameters (`--without-hashes --with-
heroku config:set POETRY_EXPORT_PARAMS=--with-hashes
```

### runtime.txt

Generation of the `runtime.txt` can be skipped by setting `DISABLE_POETRY_CREATE_RUNTIME_FILE` to `1`:

```
heroku config:set DISABLE_POETRY_CREATE_RUNTIME_FILE=1
```

If `DISABLE_POETRY_CREATE_RUNTIME_FILE` is set, the required Python version can be specified in `runtime.txt`. Otherwise, if `runtime.txt` is present in the repository, the buildpack will prevent the app from being deployed in order to avoid possible ambiguities.

## Contributing

To test your changes locally run the (TAP-compatible) test suite:
Expand Down
17 changes: 13 additions & 4 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,18 @@ for env_file in $BUILDPACK_VARIABLES ; do
[ -f "$ENV_DIR/$env_file" ] && export "$(basename "$env_file")=$(cat "$ENV_DIR/$env_file" 2>/dev/null)"
done

if [ -z "${POETRY_VERSION:-}" ] ; then
export POETRY_VERSION=1.5.1
log "No Poetry version specified in POETRY_VERSION config var. Defaulting to $POETRY_VERSION."
POETRY_VERSION="${POETRY_VERSION:-}"

if [ -z "$POETRY_VERSION" ] ; then
if [ -f "$BUILD_DIR/poetry.lock" ] ; then
POETRY_VERSION=$(head --lines=1 "$BUILD_DIR/poetry.lock" | grep --only-matching '[0-9]\+\.[0-9]\+\.[0-9]\+' || true)
fi
if [ -n "$POETRY_VERSION" ] ; then
export POETRY_VERSION
log "Read Poetry version $POETRY_VERSION from poetry.lock"
else
log "No Poetry version specified in POETRY_VERSION config var. Defaulting to latest."
fi
else
log "Using Poetry version from POETRY_VERSION config var: $POETRY_VERSION"
fi
Expand Down Expand Up @@ -88,7 +97,7 @@ fi

if [ -z "${PYTHON_RUNTIME_VERSION:-}" ] ; then
log "Read Python version from poetry.lock"
PYTHON_RUNTIME_VERSION="$(sed -n -e '/^\[metadata\]/,/^\[/p' poetry.lock | sed -n -e 's/^python-versions\s*=\s*//p' | tr -d \"'[:space:]'\')"
PYTHON_RUNTIME_VERSION="$(sed -n -e '/^\[metadata\]/,/^\[/p' poetry.lock | sed -n -e 's/^python-versions[[:space:]]*=[[:space:]]*//p' | tr -d \"'[:space:]'\')"
else
log "Force Python version to $PYTHON_RUNTIME_VERSION, because PYTHON_RUNTIME_VERSION is set!"
fi
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/compile-exact_version_specifier.stdout.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to 1.5.1.
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to latest.
-----> Generate requirements.txt with Poetry
-----> Install Poetry
>>> mocked curl call <<<
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/compile-export_dev.stdout.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to 1.5.1.
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to latest.
-----> Generate requirements.txt with Poetry
-----> Install Poetry
>>> mocked curl call <<<
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/compile-export_params-0.stdout.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to 1.5.1.
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to latest.
-----> Generate requirements.txt with Poetry
-----> Install Poetry
>>> mocked curl call <<<
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/compile-export_params-1.stdout.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to 1.5.1.
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to latest.
-----> Generate requirements.txt with Poetry
-----> Install Poetry
>>> mocked curl call <<<
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/compile-force_python_version.stdout.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to 1.5.1.
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to latest.
-----> Generate requirements.txt with Poetry
-----> Install Poetry
>>> mocked curl call <<<
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/compile-invalid_python_version.stdout.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to 1.5.1.
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to latest.
-----> Generate requirements.txt with Poetry
-----> Install Poetry
>>> mocked curl call <<<
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/compile-no_vars_success.stdout.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to 1.5.1.
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to latest.
-----> Generate requirements.txt with Poetry
-----> Install Poetry
>>> mocked curl call <<<
Expand Down
Empty file.
10 changes: 10 additions & 0 deletions test/fixtures/compile-poetry_version_comment.stdout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-----> Read Poetry version 1.5.1 from poetry.lock
-----> Generate requirements.txt with Poetry
-----> Install Poetry
>>> mocked curl call <<<
-----> Add Poetry to the PATH
-----> Export requirements.txt from Poetry
>>> mocked poetry call <<<
-----> Export Python version from Poetry to Heroku runtime.txt file
-----> Read Python version from poetry.lock
-----> Write 3.8.3 into runtime.txt
2 changes: 1 addition & 1 deletion test/fixtures/compile-skip_runtime_error.stdout.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to 1.5.1.
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to latest.
-----> Generate requirements.txt with Poetry
-----> Install Poetry
>>> mocked curl call <<<
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/compile-skip_runtime_success.stdout.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to 1.5.1.
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to latest.
-----> Generate requirements.txt with Poetry
-----> Install Poetry
>>> mocked curl call <<<
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/compile-trailing_space.stdout.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to 1.5.1.
-----> No Poetry version specified in POETRY_VERSION config var. Defaulting to latest.
-----> Generate requirements.txt with Poetry
-----> Install Poetry
>>> mocked curl call <<<
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/poetry.lock-invalid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/poetry.lock-valid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/poetry.lock-valid_exact_version_specifier

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions test/fixtures/poetry.lock-valid_version_comment

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions test/test-compile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ run_test sanity-2 compile BUILD_DIR CACHE_DIR
cp fixtures/poetry.lock-valid "$INPUT_DIR"/poetry.lock
run_test no_vars_success compile "$INPUT_DIR" CACHE_DIR fixtures/env_dir

cp fixtures/poetry.lock-valid_version_comment "$INPUT_DIR"/poetry.lock
run_test poetry_version_comment compile "$INPUT_DIR" CACHE_DIR fixtures/env_dir

cp fixtures/poetry.lock-valid_exact_version_specifier "$INPUT_DIR"/poetry.lock
run_test exact_version_specifier compile "$INPUT_DIR" CACHE_DIR fixtures/env_dir

cp fixtures/poetry.lock-valid "$INPUT_DIR"/poetry.lock
# add trailing space to python-versions to test if it will be removed
sed -i 's/^python-versions.*/& /g' "$INPUT_DIR"/poetry.lock
sed -e 's/^python-versions.*/& /g' fixtures/poetry.lock-valid > "$INPUT_DIR"/poetry.lock
run_test trailing_space compile "$INPUT_DIR" CACHE_DIR fixtures/env_dir

cp fixtures/poetry.lock-valid "$INPUT_DIR"/poetry.lock
Expand Down

0 comments on commit 3103c2d

Please sign in to comment.