Commit b878ba83 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

Merge branch '17-why-is-poetry-lock-mandatory' into 'master'

Resolve "Why is poetry.lock mandatory?"

Closes #17

See merge request to-be-continuous/python!25
parents 6548ed80 3276896e
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -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.

If a `pyproject.toml` and `poetry.lock` file is detected at the root of your project structure, requirements will automatically be generated from Poetry.
Poetry support is disabled  if `PYTHON_POETRY_DISABLED` is set to `true`.
If a `pyproject.toml` file is detected at the root of your Python project, requirements will automatically be generated from Poetry.
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     |
| ------------------------ | ---------------------------------------------------------- | ----------------- |
+7 −13
Original line number Diff line number Diff line
@@ -69,10 +69,6 @@ variables:
    fi
  }





  function install_ca_certs() {
    certs=$1
    if [[ -z "$certs" ]]
@@ -214,8 +210,7 @@ variables:
    target=$1
    if  [[ -f "pyproject.toml" ]] && [[ "${PYTHON_POETRY_DISABLED}" != "true" ]]; 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"
        exit 1
        log_warn "Poetry detected but \\e[33;1mpoetry.lock\\e[0m file not found: you shall commit it with your project files"
      fi
      pip install -U poetry
      if [[ "$target" == "build" ]]; then
@@ -244,7 +239,7 @@ variables:
  }

  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
      then
        pip install -U poetry
@@ -264,15 +259,16 @@ variables:
  }

  function _package(){
     if [[ -f "poetry.lock" ]] && [[ "${PYTHON_POETRY_DISABLED}" != "true" ]]; then
     if [[ -f "pyproject.toml" ]] && [[ "${PYTHON_POETRY_DISABLED}" != "true" ]]; then
      pip install -U poetry
      poetry build
    else
      python setup.py sdist bdist_wheel
    fi
  }

  function _publish() {
    if [[ -f "poetry.lock" ]] && [[ "${PYTHON_POETRY_DISABLED}" != "true" ]]; then
    if [[ -f "pyproject.toml" ]] && [[ "${PYTHON_POETRY_DISABLED}" != "true" ]]; then
      pip install -U poetry
      poetry config repositories.user_defined  "$TWINE_REPOSITORY_URL"
      poetry publish --username "$TWINE_USERNAME" --password "$TWINE_PASSWORD" --repository user_defined
@@ -286,7 +282,7 @@ variables:
  }

  function _release() {
    if [[ -f "poetry.lock" ]] && [[ "${PYTHON_POETRY_DISABLED}" != "true" ]]; then
    if [[ -f "pyproject.toml" ]] && [[ "${PYTHON_POETRY_DISABLED}" != "true" ]]; then
      pip install -U poetry
      poetry version "${RELEASE_VERSION_PART}"
    else
@@ -381,12 +377,10 @@ py-lint:
      if ! _run pylint --ignore=.cache --output-format=text  ${PYLINT_ARGS}  ${PYLINT_FILES:-$(find -type f -name "*.py")}
      then
        # 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
        exit 1
      else
        # success: generate empty codeclimate report (required by GitLab :( )

        echo "[]" > reports/pylint-codeclimate.json
      fi
  artifacts: