abichinger / semantic-release-pypi

semantic-release plugin to publish a python package to PyPI
MIT License
26 stars 11 forks source link

Error: version in ./setup.py #23

Closed skwde closed 1 year ago

skwde commented 1 year ago

I get

Error: version in ./setup.py

even though I have a similar setup as in the example: https://github.com/abichinger/semantic-release-pypi-example

setup.cfg is the generated and looks the same as in the example.

Here is my .releaserc

{
  "branches": [
    "master"
  ],
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/changelog",
    [
      "semantic-release-pypi",
      {
        "repoUrl": "https://gitlab.com/api/v4/projects/<my package>/packages/pypi"
      }
    ],
    [
      "@semantic-release/gitlab",
      {
        "assets": [
          {
            "path": "dist/*.whl",
            "label": ".whl"
          },
          {
            "path": "dist/*.tar.gz",
            "label": ".tar.gz"
          }
        ]
      }
    ],
    [
      "@semantic-release/git",
      {
        "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}",
        "assets": [
          "CHANGELOG.md",
          "setup.py",
          "setup.cfg",
          "dist"
        ]
      }
    ]
  ]
}

Weirdly, when running via

 PYPI_TOKEN=<my pypi token> GITLAB_TOKEN=<my gl token> semantic-release --no-ci

it works, but the GitLab CI pipeline fails with the mentioned error.

In both cases I use the same major node version, 18.

Any ideas?

abichinger commented 1 year ago

Hey,

can you post the contents of setup.py.

This error indicates that version is specified inside setup.py. semantic-release-pypi requires that the version is not set in setup.py

skwde commented 1 year ago

Sure, here is my setup.py

import setuptools

with open("README.md", "r", encoding="utf-8") as fh:
    long_description = fh.read()

setuptools.setup(
    name="mkdocs-macros-loadsource",
    packages=["mkdocs_macros_loadsource"],
    license="MIT",
    description="Load source files from other (possibly private) git repositories",
    author="<name>",
    author_email="<email>",
    url="<gitlab url>",
    long_description=long_description,
    long_description_content_type="text/markdown",
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: GNU Affero General Public License",
        "Operating System :: OS Independent",
    ],
    install_requires=[
        "mkdocs-material",
        "mkdocs-macros-plugin",
        "python-gitlab;python_version>='3.7'",
        "importlib-metadata",
        "termcolor",
    ],
)

Yes, I know that the version should not be set in this file. There is no version argument in my setup.py.

version only appears in setup.cfg which is generated by the semantic-release-pypi.

Here is the setup.cfg

[metadata]
version = 1.0.0
abichinger commented 1 year ago

Your setup.py looks good. I suspect that the error message is incorrect.

I just published semantic-release-pypi@2.5.1, which should give you a better error message. Please try the latest version and let me know what error you get.

skwde commented 1 year ago

Thanks for the new release, unfortunately it is still the same error. Here is the error message:

[5:34:40 AM] [semantic-release] › ℹ  Start step "verifyConditions" of plugin "semantic-release-pypi"
[5:34:40 AM] [semantic-release] [semantic-release-pypi] › ℹ  Check if setuptools, wheel and twine are installed
[5:34:41 AM] [semantic-release] [semantic-release-pypi] › ℹ  Verify authentication for __token__@https://gitlab.com/api/v4/projects/skwde%2Fmkdocs-macros-loadsource/packages/pypi
[5:34:42 AM] [semantic-release] [semantic-release-pypi] › ℹ  Verify that version is not set in setup.py
[5:34:42 AM] [semantic-release] › ✘  Failed step "verifyConditions" of plugin "semantic-release-pypi"
[5:34:42 AM] [semantic-release] › ℹ  Start step "verifyConditions" of plugin "@semantic-release/gitlab"
[5:34:42 AM] [semantic-release] [@semantic-release/gitlab] › ℹ  Verify GitLab authentication (https://gitlab.com/api/v4)
[5:34:42 AM] [semantic-release] › ✔  Completed step "verifyConditions" of plugin "@semantic-release/gitlab"
[5:34:42 AM] [semantic-release] › ℹ  Start step "verifyConditions" of plugin "@semantic-release/git"
[5:34:42 AM] [semantic-release] › ✔  Completed step "verifyConditions" of plugin "@semantic-release/git"
[5:34:42 AM] [semantic-release] › ✘  An error occurred while running semantic-release: Error
    at verifySetupPy (/usr/local/lib/node_modules/semantic-release-pypi/lib/verify.js:43:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async verify (/usr/local/lib/node_modules/semantic-release-pypi/lib/verify.js:94:5)
    at async validator (file:///usr/local/lib/node_modules/semantic-release/lib/plugins/normalize.js:36:24)
    at async file:///usr/local/lib/node_modules/semantic-release/lib/plugins/pipeline.js:38:36
    at async Promise.all (index 0)
    at async next (file:///usr/local/lib/node_modules/semantic-release/node_modules/p-reduce/index.js:15:44) {
  pluginName: 'semantic-release-pypi'
}
AggregateError: 
    Error
        at verifySetupPy (/usr/local/lib/node_modules/semantic-release-pypi/lib/verify.js:43:15)
        at async verify (/usr/local/lib/node_modules/semantic-release-pypi/lib/verify.js:94:5)
        at async validator (file:///usr/local/lib/node_modules/semantic-release/lib/plugins/normalize.js:36:24)
        at async file:///usr/local/lib/node_modules/semantic-release/lib/plugins/pipeline.js:38:36
        at async Promise.all (index 0)
        at async next (file:///usr/local/lib/node_modules/semantic-release/node_modules/p-reduce/index.js:15:44)
    at file:///usr/local/lib/node_modules/semantic-release/lib/plugins/pipeline.js:55:13
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async pluginsConfigAccumulator.<computed> [as verifyConditions] (file:///usr/local/lib/node_modules/semantic-release/lib/plugins/index.js:87:11)
    at async run (file:///usr/local/lib/node_modules/semantic-release/index.js:106:3)
    at async Module.default (file:///usr/local/lib/node_modules/semantic-release/index.js:275:22)
    at async default (file:///usr/local/lib/node_modules/semantic-release/cli.js:55:5) {
  errors: [
    Error
        at verifySetupPy (/usr/local/lib/node_modules/semantic-release-pypi/lib/verify.js:43:15)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async verify (/usr/local/lib/node_modules/semantic-release-pypi/lib/verify.js:94:5)
        at async validator (file:///usr/local/lib/node_modules/semantic-release/lib/plugins/normalize.js:36:24)
        at async file:///usr/local/lib/node_modules/semantic-release/lib/plugins/pipeline.js:38:36
        at async Promise.all (index 0)
        at async next (file:///usr/local/lib/node_modules/semantic-release/node_modules/p-reduce/index.js:15:44) {
      pluginName: 'semantic-release-pypi'
    }
  ]
}
Cleaning up project directory and file based variables 00:00
ERROR: Job failed: exit code 1
abichinger commented 1 year ago

I was hoping that you would get an error message with more details.

Could you please share your CI setup with me.

Have you made sure that the CI instance has Python installed?

skwde commented 1 year ago

Sure, here it is:

# The release pipeline will run only on the master branch a commit is triggered
stages:
  - release

release:
  image: node:18-buster-slim
  stage: release
  before_script:
    - apt-get update && apt-get install -y --no-install-recommends git-core ca-certificates
    - apt-get install -y python3 python3-pip
    - pip3 install --upgrade pip
    - pip3 install setuptools wheel build twine
    - npm install -g semantic-release @semantic-release/{commit-analyzer,release-notes-generator,changelog,git,gitlab} semantic-release-pypi
    - npm list -g
  script:
    - semantic-release
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
abichinger commented 1 year ago

Thank you for sharing your setup. I think I finally found the problem.

semantic-release-pypi runs a python script to verify, if the version is inside setup.py. The command running the script looks like this:

python verifySetup.py ./setup.py

Running this command on a debian based system leads to the error python: not found, because it is calling python instead of python3.

Dockerfile

FROM node:18-buster-slim

RUN apt-get update && apt-get install -y --no-install-recommends git-core ca-certificates
RUN apt-get install -y python3 python3-pip
RUN pip3 install --upgrade pip
RUN pip3 install setuptools wheel build twine

RUN python --version

Output

Step 6/6 : RUN python --version
 ---> Running in fcd8639dcee1
/bin/sh: 1: python: not found
The command '/bin/sh -c python --version' returned a non-zero code: 127

I thought that all Linux distributions used python as an alias for python3, but I was wrong. I'll publish a fix for it soon.

skwde commented 1 year ago

I can confirm that it is fixed now.