Skip to content

Commit 919582d

Browse files
build: add poetry, add CI, drop support for Python 3.3 and 3.4
1 parent c971daf commit 919582d

14 files changed

+1273
-313
lines changed

.github/workflows/ci.yaml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: CI
2+
3+
on: push
4+
5+
jobs:
6+
ci:
7+
name: CI ${{ matrix.os }} / Python ${{ matrix.python-version }}
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
os: [ubuntu-18.04]
13+
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9]
14+
poetry-version: [1.1.5]
15+
env:
16+
PYTHONDONTWRITEBYTECODE: 1
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v2
21+
22+
- name: Setup python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
27+
- name: Setup poetry ${{ matrix.poetry-version }}
28+
run: |
29+
curl -fsS -o get-poetry.py https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py
30+
POETRY_VERSION=${{ matrix.poetry-version }} python get-poetry.py -y
31+
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
32+
rm -rf get-poetry.py
33+
34+
- name: Configure poetry
35+
run: |
36+
poetry config virtualenvs.in-project true
37+
38+
- name: Set up poetry cache
39+
uses: actions/cache@v2
40+
with:
41+
path: .venv
42+
key: venv-${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
43+
restore-keys: venv-${{ matrix.os }}-${{ matrix.python-version }}-
44+
45+
- name: Install dependencies
46+
run: |
47+
poetry install --remove-untracked --no-root
48+
49+
- name: Lint
50+
run: |
51+
./bin/lint.sh
52+
53+
- name: Create config
54+
env:
55+
SDK_TEST_CREDENTIALS: ${{ secrets.SDK_TEST_CREDENTIALS }}
56+
run: |
57+
echo "USERNAME = \"$(jq -r .username <<< ${SDK_TEST_CREDENTIALS})\"" > tests/config.py
58+
echo "PASSWORD = \"$(jq -r .password <<< ${SDK_TEST_CREDENTIALS})\"" >> tests/config.py
59+
60+
- name: Test
61+
run: |
62+
./bin/test.sh

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# v7.1.0
2+
Update build tooling, added poetry
3+
Apply lint fixes
4+
Drop support for Python 3.3 and Python 3.4
5+
6+
17
# v7.0.0
28
Remove `get_dpa_creatives` function
39

Dockerfile

+27-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
1-
FROM python:3.7.1-stretch
1+
FROM python:3.9.2-slim-buster
22

33
ARG UNAME=apps
44
ARG UID=1000
55
ARG GID=1000
6-
ENV HOME="/home/$UNAME"
7-
ENV WORKDIR="$HOME/code"
6+
ENV POETRY_HOME=/opt/poetry
7+
ENV WORKDIR=/home/$UNAME/code
88
ENV PATH=$PATH:/home/$UNAME/.local/bin/
99

10-
RUN groupadd -g $GID $UNAME && useradd -m -u $UID -g $GID -s /bin/bash $UNAME
11-
RUN mkdir -p $WORKDIR && chown $UNAME:$UNAME $WORKDIR
10+
RUN apt-get update \
11+
&& apt-get install -y --no-install-recommends curl \
12+
&& rm -fr /var/lib/apt/lists/*
13+
14+
RUN python -m pip install --upgrade --no-cache-dir pip==21.0.1
15+
16+
# Install Poetry
17+
RUN export POETRY_VERSION=1.1.5 \
18+
&& curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python \
19+
&& chmod a+x ${POETRY_HOME}/bin/poetry \
20+
&& ln -s ${POETRY_HOME}/bin/poetry /usr/local/bin/poetry \
21+
&& poetry config virtualenvs.create false \
22+
&& cp -r ~/.config/ /etc/skel/
23+
24+
RUN groupadd -g $GID $UNAME \
25+
&& useradd -m -u $UID -g $GID -s /bin/bash $UNAME \
26+
&& mkdir -p $HOMEDIR/.local/lib/python3.8/site-packages \
27+
&& mkdir -p $HOMEDIR/.local/bin \
28+
&& chown -R $UID:$GID $HOMEDIR/.local \
29+
&& mkdir -p $WORKDIR \
30+
&& chown $UNAME:$UNAME $WORKDIR
1231

1332
USER $UNAME
1433
WORKDIR $WORKDIR
1534

1635
COPY --chown=apps ./ $WORKDIR
17-
RUN pip install --user -e .[dev]
18-
CMD ["py.test", "--junitxml=./results/results.xml", "--color=no", "--cov-report=term-missing", "--cov=rtbhouse_sdk", "tests/"]
36+
RUN poetry install --no-root
37+
CMD ["poetry", "run", "python", "-m", "pytest", "--junitxml=./results/results.xml", "--color=no", \
38+
"--cov-report=term-missing", "--cov=rtbhouse_sdk", "tests/"]

bin/install_env.sh

+3-8
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@
33
set -e
44
set -o pipefail
55

6-
cd "`dirname $0`"
7-
cd ..
6+
cd "`dirname $0`/.."
87

9-
rm -rf ./venv
10-
python3 -m venv venv
11-
export PATH="./venv/bin:$PATH"
8+
rm -rf ./.venv
129

13-
pip install -U pip setuptools wheel
14-
pip install -e .[dev]
15-
pip list --outdated
10+
poetry install

bin/lint.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -o pipefail
5+
6+
cd "`dirname $0`/.."
7+
8+
exit_code=0
9+
10+
if poetry show | cut -f 1 -d ' ' | grep \^black\$ > /dev/null; then
11+
echo -e "\nRunning black..."
12+
poetry run black --check . || exit_code=1
13+
fi
14+
15+
if poetry show | cut -f 1 -d ' ' | grep \^isort\$ > /dev/null; then
16+
echo -e "\nRunning isort..."
17+
poetry run isort -c -q . || exit_code=1
18+
fi
19+
20+
if poetry show | cut -f 1 -d ' ' | grep \^flake8\$ > /dev/null; then
21+
echo -e "\nRunning flake8..."
22+
poetry run flake8 || exit_code=1
23+
fi
24+
25+
exit $exit_code

bin/publish.sh

+4-8
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@
33
set -e
44
set -o pipefail
55

6-
cd "`dirname $0`"
7-
cd ..
6+
cd "`dirname $0`/.."
87

9-
if ! [ -x "$(command -v twine)" ]; then
10-
echo "Missing twine binary, run \"pip install --user --upgrade twine\"" >&2
8+
if [[ -z $PYPI_TOKEN ]]; then
9+
echo -e "Error: please provide PYPI_TOKEN env var"
1110
exit 1
1211
fi
1312

14-
15-
rm -rf dist
16-
./venv/bin/python setup.py sdist
17-
twine upload dist/*
13+
poetry publish --build --no-interaction -u __token__ -p $PYPI_TOKEN

bin/test.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
set -e
44
set -o pipefail
55

6-
cd "`dirname $0`"
7-
cd ..
6+
cd "`dirname $0`/.."
87

98

10-
./venv/bin/py.test tests/
9+
poetry run python -m pytest --junitxml=./results/results.xml --color=no --cov-report=term-missing --cov=rtbhouse_sdk/ tests/

0 commit comments

Comments
 (0)