Skip to content

Commit

Permalink
build: add ability to build against all targeted Python versions
Browse files Browse the repository at this point in the history
Signed-off-by: Emilio Reyes <soda480@gmail.com>
  • Loading branch information
soda480 committed Jul 11, 2022
1 parent ed603a9 commit 7957cae
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 33 deletions.
62 changes: 43 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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.
Expand All @@ -267,7 +267,7 @@ docker container run \
-e https_proxy \
-v $PWD:/code \
rest3client:latest \
/bin/bash
bash
```
Execute the build:
Expand Down
5 changes: 2 additions & 3 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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)
5 changes: 5 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["pybuilder>=0.12.0"]
build-backend = "pybuilder.pep517"

0 comments on commit 7957cae

Please sign in to comment.