Skip to content

Commit

Permalink
Merge pull request #58 from stigok/pypi-preps
Browse files Browse the repository at this point in the history
Forberedelser for publisering til PyPi
  • Loading branch information
stigok authored Mar 16, 2020
2 parents df0650f + 1e6af9c commit 7cfd07c
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 50 deletions.
11 changes: 11 additions & 0 deletions .docker/Dockerfile.matrix-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ARG PYVER
FROM python:${PYVER}-alpine3.10

RUN apk update && \
apk add --no-cache ca-certificates
RUN pip install --upgrade pip

WORKDIR /usr/src/app
ENV PYTHONUNBUFFERED=1

COPY . .
File renamed without changes.
45 changes: 14 additions & 31 deletions .docker/run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,22 @@
#!/bin/bash

# Build and run a Docker image based on a specific Python version
set -eu

# Change working directory to repository root,
# expecting this script to reside at :/.docker/<script>
# Change working directory to repo root (if this script's in .docker)
src="$(dirname "$(readlink -f "$0")")"
cd "$src/.."

dockerfile="$src/Dockerfile"

function run() {
pyver=$1
echo $pyver
tag=ruterstop:python${pyver}

echo "*** Building ${tag} ***"
docker build -f ${dockerfile} \
--build-arg PYVER=$pyver \
--tag ${tag} \
.

echo "*** Running ${tag} ***"
runcmd="docker run --network=host $tag"

$runcmd sh -c "python setup.py test"
$runcmd sh -c "ruterstop --stop-id 6013 --direction outbound --min-eta 2"
}
pyver=$1
shift
test_name=${1}
shift
tag=ruterstop:${test_name}-${pyver}

set -x
docker build --network host \
--file ${src}/Dockerfile.${test_name} \
--build-arg PYVER="$pyver" \
--tag ${tag} \
. > /dev/null

if [ -n ${1:-''} ]
then
run $1
else
for pyver in 3.5 3.6 3.7 3.8
do
run $pyver
done
fi
docker run --network host $tag $@
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.*
**/__pycache__
*.egg-info
venv
Makefile
18 changes: 18 additions & 0 deletions .github/workflows/python-pypi-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Publish to PyPI

on:
release:
types: [published]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Publish Python Package
uses: mariamrf/[email protected]
with:
python_version: '3.8.0'
env:
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
22 changes: 22 additions & 0 deletions .github/workflows/python-pypi-test-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Publish to PyPI

on:
release:
types: [published]
push:
branches:
- pypi-preps

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Publish Python Package
uses: mariamrf/[email protected]
with:
python_version: '3.8.0'
env:
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: Python package
name: Python tests

on: [push]

jobs:
build:

test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -22,6 +21,6 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Test with pytest
- name: Run tests
run: |
python setup.py test
24 changes: 17 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
init:
pip install -r requirements.txt

.PHONY: test
test:
python setup.py test
python3 setup.py test

.PHONY: matrix-unit-tests
matrix-unit-tests:
.docker/run-tests.sh 3.5 matrix-unit-tests python setup.py test
.docker/run-tests.sh 3.6 matrix-unit-tests python setup.py test
.docker/run-tests.sh 3.7 matrix-unit-tests python setup.py test
.docker/run-tests.sh 3.8 matrix-unit-tests python setup.py test

test-e2e: test
python ruterstop/ --stop-id=6013 --min-eta=2 --direction=outbound
.PHONY: matrix-install
matrix-install:
.docker/run-tests.sh 3.5 matrix-install pip install .
.docker/run-tests.sh 3.6 matrix-install pip install .
.docker/run-tests.sh 3.7 matrix-install pip install .
.docker/run-tests.sh 3.8 matrix-install pip install .

.PHONY: init test test-e2e
.PHONY: matrix
matrix: matrix-unit-tests matrix-install
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ Innspill, tanker og feilmeldinger mottas med glede!

![Adafruit Feather HUZZAH ESP8266 med OLED FeatherWing som kjører ruterstop.py][demopic-1]

## Brukerveiledning
## Installasjon

Trenger Python >=3.5 for å kjøre.

### Installer fra PyPi

```
$ pip install ruterstop
```

### Bygg fra kildekode

Last ned kildekoden og installer programmet med avhengigheter fra kildekodemappen

```
Expand All @@ -29,6 +37,8 @@ $ pip install -r requirements.txt
$ python ruterstop/
```

## Brukerveiledning

Søk etter stoppested

```
Expand Down Expand Up @@ -80,7 +90,7 @@ $ curl localhost:4000/6013?direction=outbound

## Utvikling

Kjør tester
### Kjør tester

```
$ python -m venv venv
Expand All @@ -89,16 +99,14 @@ $ pip install -r requirements.txt
$ python setup.py test
```

Eller med Docker
### Kjør multi-versjon tester i Docker

```
$ .docker/run-tests.sh
$ .docker/run-tests.sh 3.5
$ .docker/run-tests.sh 3.6
$ .docker/run-tests.sh 3.7
$ .docker/run-tests.sh 3.8
$ make matrix
```

Se Makefile for detaljer

## Motivasjon

Jeg vil se avganger fra mitt nærmeste stoppested mens jeg sitter ved
Expand Down
17 changes: 17 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,31 @@
version = str(ast.literal_eval(_version_re.search(
f.read().decode('utf-8')).group(1)))

def readme():
with open('README.md') as f:
return f.read()

setup(
name="ruterstop",
description="Et program som viser sanntidsinformasjon for stoppesteder i " +
"Oslo og Akershus.",
version=version,
long_description=readme(),
long_description_content_type="text/markdown",
keywords="entur ruter ruter-api kollektivtransport oslo viken sanntid",
url="https://github.com/stigok/ruterstop",
project_urls={
"Bug Tracker": "http://github.com/stigok/ruterstop/issues",
"Documentation": "http://github.com/stigok/ruterstop/",
"Source Code": "http://github.com/stigok/ruterstop/",
},
classifiers=[
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3 :: Only",
],
author="stigok",
author_email="[email protected]",

packages=["ruterstop"],
entry_points={
"console_scripts": [
Expand Down

0 comments on commit 7cfd07c

Please sign in to comment.