From d22ae4ba24aa63cf73e7cd38f0ab70eaa9cfb820 Mon Sep 17 00:00:00 2001 From: Vincent Maillol Date: Wed, 14 Jul 2021 07:50:59 +0200 Subject: [PATCH 1/3] Ensure that drone-plugin uses a version of setuptools>=46.4 --- .gitignore | 5 +++++ testdata/drone_pypi_test/__init__.py | 14 ++++++++++++++ testdata/pyproject.toml | 6 ++++++ testdata/setup.cfg | 11 +++++++++++ testdata/setup.py | 11 +---------- 5 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 testdata/pyproject.toml create mode 100644 testdata/setup.cfg diff --git a/.gitignore b/.gitignore index 669c9a0..eacab40 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,8 @@ vendor/ coverage.out drone-pypi + +# Generated testdata folder +testdata/dist/ +testdata/drone_pypi_test/__pycache__/ +testdata/drone_pypi_testbuild.egg-info/ diff --git a/testdata/drone_pypi_test/__init__.py b/testdata/drone_pypi_test/__init__.py index e69de29..472e1d7 100644 --- a/testdata/drone_pypi_test/__init__.py +++ b/testdata/drone_pypi_test/__init__.py @@ -0,0 +1,14 @@ +# Only version of setuptools<45 evaluates the code of module to read the +# __version__ attribute during the build operation. +# setuptools>=45 uses ast (Abstract Syntax Trees) to read the __version__ +# attribute without evaluate the code in order to prevent error with +# third party import + +import setuptools + + +if tuple((int(e) if e.isdigit() else e) for e in setuptools.__version__.split('.')) < (45, 0, 0): + raise Exception("The drone-plugin should use setuptools version >= 45") + + +__version__ = '0.1.0' diff --git a/testdata/pyproject.toml b/testdata/pyproject.toml new file mode 100644 index 0000000..6228f7d --- /dev/null +++ b/testdata/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools >= 46.4.0", + "wheel", +] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/testdata/setup.cfg b/testdata/setup.cfg new file mode 100644 index 0000000..f40df5c --- /dev/null +++ b/testdata/setup.cfg @@ -0,0 +1,11 @@ +[metadata] +name = drone-pypi-testbuild +version = attr: drone_pypi_test.__version__ +description = Testing drone-pypi publishes, no other purpose. +url = https://github.com/xoxys/drone-pypi +packages = find: ['drone_pypi_test'] +maintainer = Robert Kaussow +maintainer_email = xoxys@rknet.org + +[options.packages.find] +where = . diff --git a/testdata/setup.py b/testdata/setup.py index 2e3226f..6068493 100644 --- a/testdata/setup.py +++ b/testdata/setup.py @@ -1,12 +1,3 @@ from setuptools import setup - -setup( - name='drone-pypi-testbuild', - version='0.1.0', - description='Testing drone-pypi publishes, no other purpose.', - url='https://github.com/xoxys/drone-pypi', - packages=['testdata/drone_pypi_test'], - maintainer='Robert Kaussow', - maintainer_email="xoxys@rknet.org", -) +setup() From 640a0ee162dfe6f8d2b12d030d5aef2362939a8c Mon Sep 17 00:00:00 2001 From: Vincent Maillol Date: Wed, 14 Jul 2021 09:58:44 +0200 Subject: [PATCH 2/3] twine requires cryptography and building cryptography requires rust compiler --- .drone.jsonnet | 6 ++++-- .drone.yml | 17 +++++++++-------- docker/Dockerfile.linux.arm | 3 ++- docker/Dockerfile.linux.arm64 | 3 ++- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index 0dd1fd2..555e7a0 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -46,8 +46,10 @@ local PipelineTesting = { PLUGIN_PASSWORD: "demo", }, commands: [ - "apk --no-cache add -U python3 git", - "pip3 install --no-cache-dir --upgrade pip setuptools wheel six twine", + "apk --no-cache add -U python3 python3-dev git gcc libc-dev libffi-dev openssl-dev curl", + // install rust to compile cryptography for twine + "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh /dev/stdin -y -q --profile minimal", + "PATH=$PATH:~/.cargo/bin pip3 install --no-cache-dir --upgrade pip setuptools wheel six twine", "go test -cover ./...", ], }, diff --git a/.drone.yml b/.drone.yml index 4ce4c1c..3557b51 100644 --- a/.drone.yml +++ b/.drone.yml @@ -19,8 +19,9 @@ steps: pull: always image: golang:1.11-alpine commands: - - apk --no-cache add -U python3 python3-dev git gcc libc-dev libffi-dev openssl-dev - - pip3 install --no-cache-dir --upgrade pip setuptools wheel six twine + - apk --no-cache add -U python3 python3-dev git gcc libc-dev libffi-dev openssl-dev curl + - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh /dev/stdin -y -q --profile minimal + - PATH=$PATH:~/.cargo/bin pip3 install --no-cache-dir --upgrade pip setuptools wheel six twine - go test -cover ./... environment: GO111MODULE: on @@ -60,7 +61,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -o release/linux/amd64/drone-pypi" + - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/amd64/drone-pypi environment: CGO_ENABLED: 0 GO111MODULE: on @@ -73,7 +74,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -o release/linux/amd64/drone-pypi" + - go build -v -ldflags "-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/amd64/drone-pypi environment: CGO_ENABLED: 0 GO111MODULE: on @@ -140,7 +141,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -o release/linux/arm64/drone-pypi" + - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/arm64/drone-pypi environment: CGO_ENABLED: 0 GO111MODULE: on @@ -153,7 +154,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -o release/linux/arm64/drone-pypi" + - go build -v -ldflags "-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/arm64/drone-pypi environment: CGO_ENABLED: 0 GO111MODULE: on @@ -220,7 +221,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -o release/linux/arm/drone-pypi" + - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/arm/drone-pypi environment: CGO_ENABLED: 0 GO111MODULE: on @@ -233,7 +234,7 @@ steps: pull: always image: golang:1.11 commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -o release/linux/arm/drone-pypi" + - go build -v -ldflags "-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/arm/drone-pypi environment: CGO_ENABLED: 0 GO111MODULE: on diff --git a/docker/Dockerfile.linux.arm b/docker/Dockerfile.linux.arm index ff16e87..3f80d64 100644 --- a/docker/Dockerfile.linux.arm +++ b/docker/Dockerfile.linux.arm @@ -8,7 +8,8 @@ LABEL maintainer="Drone.IO Community " \ RUN apk add -U ca-certificates python3 \ python3-dev gcc libc-dev libffi-dev openssl-dev git && \ rm -rf /var/cache/apk/* && \ - pip3 install --no-cache-dir --upgrade pip setuptools wheel six twine + python3 -m ensurepip && \ + env CRYPTOGRAPHY_DONT_BUILD_RUST=1 pip3 install --no-cache-dir --upgrade pip setuptools wheel six twine ADD release/linux/arm/drone-pypi /bin/ ENTRYPOINT ["/bin/drone-pypi"] diff --git a/docker/Dockerfile.linux.arm64 b/docker/Dockerfile.linux.arm64 index 78f32e3..fca88d2 100644 --- a/docker/Dockerfile.linux.arm64 +++ b/docker/Dockerfile.linux.arm64 @@ -8,7 +8,8 @@ LABEL maintainer="Drone.IO Community " \ RUN apk add -U ca-certificates python3 \ python3-dev gcc libc-dev libffi-dev openssl-dev git && \ rm -rf /var/cache/apk/* && \ - pip3 install --no-cache-dir --upgrade pip setuptools wheel six twine + python3 -m ensurepip && \ + env CRYPTOGRAPHY_DONT_BUILD_RUST=1 pip3 install --no-cache-dir --upgrade pip setuptools wheel six twine ADD release/linux/arm64/drone-pypi /bin/ ENTRYPOINT ["/bin/drone-pypi"] From 361ad9cac4b9ffd505b798b6032d5bb2f1352049 Mon Sep 17 00:00:00 2001 From: Vincent Maillol Date: Wed, 14 Jul 2021 10:41:07 +0200 Subject: [PATCH 3/3] Python build command must be executed in the dir containing the setup.py file --- docker/Dockerfile.linux.amd64 | 7 +++++-- plugin.go | 12 +++++++++--- plugin_test.go | 4 ++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/docker/Dockerfile.linux.amd64 b/docker/Dockerfile.linux.amd64 index 1b0c950..328037b 100644 --- a/docker/Dockerfile.linux.amd64 +++ b/docker/Dockerfile.linux.amd64 @@ -6,9 +6,12 @@ LABEL maintainer="Drone.IO Community " \ org.label-schema.schema-version="1.0" RUN apk add -U ca-certificates python3 \ - python3-dev gcc libc-dev libffi-dev openssl-dev git && \ + python3-dev gcc libc-dev libffi-dev openssl-dev git curl && \ rm -rf /var/cache/apk/* && \ - pip3 install --no-cache-dir --upgrade pip setuptools wheel six twine + python3 -m ensurepip && \ + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh /dev/stdin -y -q --profile minimal && \ + env PATH=$PATH:$HOME/.cargo/bin pip3 install --no-cache-dir --upgrade pip setuptools wheel six twine && \ + rm -rf $HOME/.cargo/ $HOME/.rustup ADD release/linux/amd64/drone-pypi /bin/ ENTRYPOINT ["/bin/drone-pypi"] diff --git a/plugin.go b/plugin.go index b80474b..784278c 100644 --- a/plugin.go +++ b/plugin.go @@ -3,6 +3,7 @@ package main import ( "log" "os/exec" + "path" "path/filepath" "github.com/pkg/errors" @@ -26,11 +27,14 @@ func (p Plugin) buildCommand() *exec.Cmd { if len(p.Distributions) > 0 { distributions = p.Distributions } - args := []string{p.SetupFile} + dirToWork := path.Dir(p.SetupFile) + args := []string{"setup.py"} for i := range distributions { args = append(args, distributions[i]) } - return exec.Command("python3", args...) + cmd := exec.Command("python3", args...) + cmd.Dir = dirToWork + return cmd } func (p Plugin) uploadCommand() *exec.Cmd { @@ -44,7 +48,9 @@ func (p Plugin) uploadCommand() *exec.Cmd { args = append(args, p.Password) args = append(args, filepath.Join(p.DistDir, "/*")) - return exec.Command("twine", args...) + cmd := exec.Command("twine", args...) + cmd.Dir = path.Dir(p.SetupFile) + return cmd } // Exec runs the plugin - doing the necessary setup.py modifications diff --git a/plugin_test.go b/plugin_test.go index 929ed44..85ec1d2 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -34,11 +34,11 @@ func TestUpload(t *testing.T) { }{ { []string{}, - []string{"python3", "testdata/setup.py", "sdist"}, + []string{"python3", "setup.py", "sdist"}, }, { []string{"sdist", "bdist_wheel"}, - []string{"python3", "testdata/setup.py", "sdist", "bdist_wheel"}, + []string{"python3", "setup.py", "sdist", "bdist_wheel"}, }, } for i, data := range testdata {