Skip to content
Snippets Groups Projects
Commit 3276896e authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

Resolve "Why is poetry.lock mandatory?"

parent 6548ed80
No related branches found
No related tags found
No related merge requests found
...@@ -35,12 +35,14 @@ Default configuration follows [this Python project structure](https://docs.pytho ...@@ -35,12 +35,14 @@ Default configuration follows [this Python project structure](https://docs.pytho
The Python template supports [Poetry](https://python-poetry.org/) as packaging and dependency management tool. The Python template supports [Poetry](https://python-poetry.org/) as packaging and dependency management tool.
If a `pyproject.toml` and `poetry.lock` file is detected at the root of your project structure, requirements will automatically be generated from Poetry. If a `pyproject.toml` file is detected at the root of your Python project, requirements will automatically be generated from Poetry.
Poetry support is disabled if `PYTHON_POETRY_DISABLED` is set to `true`. Poetry support can be explicitly disabled by setting `PYTHON_POETRY_DISABLED` to `true`.
:warning: as stated in [Poetry documentation](https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control), _You should commit the `poetry.lock` file to your project repo so that all people working on the project are locked to the same versions of dependencies_. :warning: If no `poetry.lock` file is found, the template will emit a (non-blocking) warning message, to enforce [Poetry recommendation](https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control):
It uses the following variables: > You should commit the `poetry.lock` file to your project repo so that all people working on the project are locked to the same versions of dependencies.
Poetry support uses the following variables:
| Name | description | default value | | Name | description | default value |
| ------------------------ | ---------------------------------------------------------- | ----------------- | | ------------------------ | ---------------------------------------------------------- | ----------------- |
......
...@@ -69,10 +69,6 @@ variables: ...@@ -69,10 +69,6 @@ variables:
fi fi
} }
function install_ca_certs() { function install_ca_certs() {
certs=$1 certs=$1
if [[ -z "$certs" ]] if [[ -z "$certs" ]]
...@@ -213,9 +209,8 @@ variables: ...@@ -213,9 +209,8 @@ variables:
function install_requirements() { function install_requirements() {
target=$1 target=$1
if [[ -f "pyproject.toml" ]] && [[ "${PYTHON_POETRY_DISABLED}" != "true" ]]; then if [[ -f "pyproject.toml" ]] && [[ "${PYTHON_POETRY_DISABLED}" != "true" ]]; then
if [[ ! -f "poetry.lock" ]]; then if [[ ! -f "poetry.lock" ]]; then
log_error "Poetry detected but \\e[33;1mpoetry.lock\\e[0m file not found: you shall commit it with your project files" log_warn "Poetry detected but \\e[33;1mpoetry.lock\\e[0m file not found: you shall commit it with your project files"
exit 1
fi fi
pip install -U poetry pip install -U poetry
if [[ "$target" == "build" ]]; then if [[ "$target" == "build" ]]; then
...@@ -244,7 +239,7 @@ variables: ...@@ -244,7 +239,7 @@ variables:
} }
function _run() { function _run() {
if [[ -f "poetry.lock" ]] && [[ "${PYTHON_POETRY_DISABLED}" != "true" ]]; then if [[ -f "pyproject.toml" ]] && [[ "${PYTHON_POETRY_DISABLED}" != "true" ]]; then
if ! command -v poetry > /dev/null if ! command -v poetry > /dev/null
then then
pip install -U poetry pip install -U poetry
...@@ -264,15 +259,16 @@ variables: ...@@ -264,15 +259,16 @@ variables:
} }
function _package(){ function _package(){
if [[ -f "poetry.lock" ]] && [[ "${PYTHON_POETRY_DISABLED}" != "true" ]]; then if [[ -f "pyproject.toml" ]] && [[ "${PYTHON_POETRY_DISABLED}" != "true" ]]; then
pip install -U poetry pip install -U poetry
poetry build poetry build
else else
python setup.py sdist bdist_wheel python setup.py sdist bdist_wheel
fi fi
} }
function _publish() { function _publish() {
if [[ -f "poetry.lock" ]] && [[ "${PYTHON_POETRY_DISABLED}" != "true" ]]; then if [[ -f "pyproject.toml" ]] && [[ "${PYTHON_POETRY_DISABLED}" != "true" ]]; then
pip install -U poetry pip install -U poetry
poetry config repositories.user_defined "$TWINE_REPOSITORY_URL" poetry config repositories.user_defined "$TWINE_REPOSITORY_URL"
poetry publish --username "$TWINE_USERNAME" --password "$TWINE_PASSWORD" --repository user_defined poetry publish --username "$TWINE_USERNAME" --password "$TWINE_PASSWORD" --repository user_defined
...@@ -286,7 +282,7 @@ variables: ...@@ -286,7 +282,7 @@ variables:
} }
function _release() { function _release() {
if [[ -f "poetry.lock" ]] && [[ "${PYTHON_POETRY_DISABLED}" != "true" ]]; then if [[ -f "pyproject.toml" ]] && [[ "${PYTHON_POETRY_DISABLED}" != "true" ]]; then
pip install -U poetry pip install -U poetry
poetry version "${RELEASE_VERSION_PART}" poetry version "${RELEASE_VERSION_PART}"
else else
...@@ -381,12 +377,10 @@ py-lint: ...@@ -381,12 +377,10 @@ py-lint:
if ! _run pylint --ignore=.cache --output-format=text ${PYLINT_ARGS} ${PYLINT_FILES:-$(find -type f -name "*.py")} if ! _run pylint --ignore=.cache --output-format=text ${PYLINT_ARGS} ${PYLINT_FILES:-$(find -type f -name "*.py")}
then then
# failed: also generate codeclimate report # failed: also generate codeclimate report
_run pylint --ignore=.cache --output-format=pylint_gitlab.GitlabCodeClimateReporter ${PYLINT_ARGS} ${PYLINT_FILES:-$(find -type f -name "*.py")} > reports/pylint-codeclimate.json _run pylint --ignore=.cache --output-format=pylint_gitlab.GitlabCodeClimateReporter ${PYLINT_ARGS} ${PYLINT_FILES:-$(find -type f -name "*.py")} > reports/pylint-codeclimate.json
exit 1 exit 1
else else
# success: generate empty codeclimate report (required by GitLab :( ) # success: generate empty codeclimate report (required by GitLab :( )
echo "[]" > reports/pylint-codeclimate.json echo "[]" > reports/pylint-codeclimate.json
fi fi
artifacts: artifacts:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment