Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that drone-plugin uses a version of setuptools>=45 #35

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .drone.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...",
],
},
Expand Down
17 changes: 9 additions & 8 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
7 changes: 5 additions & 2 deletions docker/Dockerfile.linux.amd64
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
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"]
3 changes: 2 additions & 1 deletion docker/Dockerfile.linux.arm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
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"]
3 changes: 2 additions & 1 deletion docker/Dockerfile.linux.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
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"]
12 changes: 9 additions & 3 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"log"
"os/exec"
"path"
"path/filepath"

"github.com/pkg/errors"
Expand All @@ -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 {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions testdata/drone_pypi_test/__init__.py
Original file line number Diff line number Diff line change
@@ -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'
6 changes: 6 additions & 0 deletions testdata/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = [
"setuptools >= 46.4.0",
"wheel",
]
build-backend = "setuptools.build_meta"
11 changes: 11 additions & 0 deletions testdata/setup.cfg
Original file line number Diff line number Diff line change
@@ -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 = .
11 changes: 1 addition & 10 deletions testdata/setup.py
Original file line number Diff line number Diff line change
@@ -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()