From 7957caefbd57f86cb0112519ccc60a0dc17defed Mon Sep 17 00:00:00 2001 From: Emilio Reyes Date: Sun, 10 Jul 2022 19:59:22 -0700 Subject: [PATCH] build: add ability to build against all targeted Python versions Signed-off-by: Emilio Reyes --- .github/workflows/main.yml | 62 ++++++++++++++++++++++++++------------ Dockerfile | 9 +++--- README.md | 14 ++++----- build.py | 5 ++- build.sh | 5 +++ pyproject.toml | 3 ++ 6 files changed, 65 insertions(+), 33 deletions(-) create mode 100755 build.sh create mode 100644 pyproject.toml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 384905a..2e8ac4d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,24 +9,48 @@ on: branches: - main jobs: - build: + build-images: + strategy: + matrix: + version: ['3.7', '3.8', '3.9', '3.10'] + name: Build Python Docker images runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - - name: Build Docker image - run: | - docker image build --target build-image -t rest3client:latest . - - - name: Prepare coverage - run: | - ID=$(docker create rest3client) - docker cp $ID:/code/target/reports/rest3client_coverage.xml rest3client_coverage.xml - sed -i -e 's,filename="rest3client/,filename="src/main/python/rest3client/,g' rest3client_coverage.xml - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1 - with: - token: ${{ secrets.CODECOV_TOKEN }} - file: rest3client_coverage.xml + - uses: actions/checkout@v3 + - name: build rest3client ${{ matrix.version }} image + run: + docker image build --target build-image --build-arg PYTHON_VERSION=${{ matrix.version }} -t rest3client:${{ matrix.version }} . + - name: save rest3client ${{ matrix.version }} image + if: ${{ matrix.version == '3.9' }} + run: | + mkdir -p images + docker save --output images/rest3client-${{ matrix.version }}.tar rest3client:${{ matrix.version }} + - name: upload rest3client ${{ matrix.version }} image artifact + if: ${{ matrix.version == '3.9' }} + uses: actions/upload-artifact@v2 + with: + name: image + path: images/rest3client-${{ matrix.version }}.tar + coverage: + name: Publish Code Coverage Report + needs: build-images + runs-on: ubuntu-20.04 + steps: + - name: download image artifact + uses: actions/download-artifact@v2 + with: + name: image + path: images/ + - name: load image + run: + docker load --input images/rest3client-3.9.tar + - name: prepare report + run: | + ID=$(docker create rest3client:3.9) + docker cp $ID:/code/target/reports/rest3client_coverage.xml rest3client_coverage.xml + sed -i -e 's,filename="rest3client/,filename="src/main/python/rest3client/,g' rest3client_coverage.xml + - name: upload report + uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: rest3client_coverage.xml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index ceb0a4c..b87e4b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,14 +13,15 @@ # See the License for the specific language governing permissions and # limitations under the License. # -FROM python:3.9-slim AS build-image +ARG PYTHON_VERSION=3.9 +FROM python:${PYTHON_VERSION}-slim AS build-image ENV PYTHONDONTWRITEBYTECODE 1 WORKDIR /code COPY . /code/ -RUN pip install pybuilder -RUN pyb install +RUN pip install --upgrade pip && pip install pybuilder +RUN pyb -X && pyb install -FROM python:3.9-alpine +FROM python:${PYTHON_VERSION}-slim ENV PYTHONDONTWRITEBYTECODE 1 WORKDIR /opt/rest3client COPY --from=build-image /code/target/dist/rest3client-*/dist/rest3client-*.tar.gz /opt/rest3client diff --git a/README.md b/README.md index ed93002..37ab005 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# rest3client # +# rest3client [![GitHub Workflow Status](https://github.com/soda480/rest3client/workflows/build/badge.svg)](https://github.com/soda480/rest3client/actions) [![Code Coverage](https://codecov.io/gh/soda480/rest3client/branch/master/graph/badge.svg)](https://codecov.io/gh/soda480/rest3client) [![Code Grade](https://api.codiga.io/project/12271/status/svg)](https://app.codiga.io/public/project/12271/rest3client/dashboard) [![vulnerabilities](https://img.shields.io/badge/vulnerabilities-None-brightgreen)](https://pypi.org/project/bandit/) [![PyPI version](https://badge.fury.io/py/rest3client.svg)](https://badge.fury.io/py/rest3client) -[![python](https://img.shields.io/badge/python-3.9-teal)](https://www.python.org/downloads/) +[![python](https://img.shields.io/badge/python-3.7%20%7C%203.8%20%7C%203.9%20%7C%203.10-teal)](https://www.python.org/downloads/) rest3client is an abstraction of the HTTP requests library (https://pypi.org/project/requests/) providing a simpler API for consuming HTTP REST APIs. @@ -23,12 +23,12 @@ The library supports most popular authentication schemes: - Certificate-based authentication - JWT authentication -### Installation ### +### Installation ```bash pip install rest3client ``` -### API Usage ### +### API Usage The examples below show how RESTclient can be used to consume the GitHub REST API. However RESTclient can be used to consume just about any REST API. ```python @@ -158,7 +158,7 @@ export RETRY_CONNECTION_ERROR_WAIT_RANDOM_MAX = 15000 #### Real Eamples See [GitHub3API](https://github.com/soda480/github3api) for an example of how RESTclient can be subclassed to provide further custom functionality for a specific REST API (including retry on exceptions). -### CLI Usage ### +### CLI Usage RESTclient comes packaged with a command line interace (CLI) that can be used to consume REST APIs using the RESTclient class. To consume the CLI simply build and run the Docker container as described below, except when building the image exclude the `--target build-image` argument. ```bash usage: rest [-h] [--address ADDRESS] [--json JSON_DATA] @@ -244,7 +244,7 @@ rest DELETE /repos/soda480/test-repo1 --debug rest GET /rate_limit --raw ``` -### Development ### +### Development Ensure the latest version of Docker is installed on your development server. Fork and clone the repository. @@ -267,7 +267,7 @@ docker container run \ -e https_proxy \ -v $PWD:/code \ rest3client:latest \ -/bin/bash +bash ``` Execute the build: diff --git a/build.py b/build.py index 94e1780..b306434 100644 --- a/build.py +++ b/build.py @@ -30,7 +30,7 @@ authors = [Author('Emilio Reyes', 'emilio.reyes@intel.com')] summary = 'An abstraction of the requests library providing a simpler API for consuming HTTP REST APIs' url = 'https://github.com/soda480/rest3client' -version = '0.5.0' +version = '0.5.1' default_task = [ 'clean', 'analyze', @@ -67,10 +67,10 @@ def set_properties(project): 'License :: OSI Approved :: Apache Software License', 'Operating System :: POSIX :: Linux', 'Programming Language :: Python', - 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', 'Topic :: Software Development :: Libraries', 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: System :: Networking', @@ -79,4 +79,3 @@ def set_properties(project): project.set_property('radon_break_build_complexity_threshold', 14) project.set_property('bandit_break_build', True) project.set_property('anybadge_exclude', 'coverage, complexity') - project.set_property('anybadge_use_shields', True) diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..0da3eeb --- /dev/null +++ b/build.sh @@ -0,0 +1,5 @@ +versions=( '3.7' '3.8' '3.9' '3.10' ) +for version in "${versions[@]}"; +do + docker image build --target build-image --build-arg PYTHON_VERSION=$version -t rest3client:$version . +done \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..950f549 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["pybuilder>=0.12.0"] +build-backend = "pybuilder.pep517"