Skip to content

Commit 1d8b94a

Browse files
committed
[NEW] Python Pacakge Generator v1.7.4
2 parents bd99cf5 + 07d74d4 commit 1d8b94a

File tree

11 files changed

+192
-38
lines changed

11 files changed

+192
-38
lines changed

.github/workflows/test.yaml

Lines changed: 124 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,80 @@
1-
name: Test Python Package
2-
# Stress Test against different platforms and python versions
1+
name: Continuous Integration / Continuous Delivery
2+
# Stress Test and Build Docker Image
3+
4+
# dev has feature/bug-branch and writes code
5+
# dev wants on each push, 'small' Matrix Tests to trigger
6+
# all feature/bug branches "have" to merge to 'dev' branch
7+
# 'dev' branch automatically triggers 'full' Matrix Tests
8+
9+
# it is time to make a new release
10+
# 'dev' branch merges into 'release' branch
11+
# a couple of commits (ie version bump, changelog update) are pushed to 'release'
12+
# a PR opens to merge 'release' into master/main
13+
# the PR triggers ALL TESTS:
14+
# - Full Matrix Stress Tests
15+
# - Doc tests
16+
# - build/release
17+
18+
# if all OK then PR merges
19+
# then a new tag (release) is pushed to github
20+
21+
22+
# full Matrix Stress Test on
23+
# - push to master/main
24+
# - push to stress-test branch
25+
# we want small Matrix Test on each pushed commit
326

427
on:
528
push:
629
branches:
7-
- master
8-
- dev
9-
- ci
10-
- windows-ci
11-
pull_request:
12-
branches:
13-
- master
14-
- dev
15-
- develop
30+
- "*"
1631
tags:
1732
- v*
1833

34+
env:
35+
# ability to define the Job Matrix as an env var !
36+
FULL_MATRIX_STRATEGY: "{\"platform\": [\"ubuntu-latest\", \"macos-latest\", \"windows-latest\"], \"python-version\": [\"3.9\", \"3.10\"]}"
37+
UBUNTU_PY310_STRATEGY: "{\"platform\":[\"ubuntu-latest\"], \"python-version\":[\"3.10\"]}"
38+
RUN_UNIT_TESTS: "true"
39+
BUILD_DOCKER: "true"
1940

2041
jobs:
42+
# we use the below to read the workflow env vars and be able to use in "- if:" Job conditionals
43+
# now we can do -> if: ${{ needs.set_github_outputs.outputs.TESTS_ENABLED == 'true' }}
44+
# github does not have a way to simply do "- if: ${{ env.RUN_UNIT_TESTS == 'true' }} " !!
45+
set_github_outputs:
46+
name: Read Workflow Env Section Vars and set Github Outputs
47+
runs-on: ubuntu-latest
48+
outputs:
49+
matrix: ${{ steps.pass-env-to-output.outputs.matrix }}
50+
TESTS_ENABLED: ${{ steps.pass-env-to-output.outputs.TESTS_ENABLED }}
51+
DOCKER_ENABLED: ${{ steps.pass-env-to-output.outputs.DOCKER_ENABLED }}
52+
steps:
53+
- name: Pass 'env' section variables to GITHUB_OUTPUT
54+
id: pass-env-to-output
55+
run: |
56+
# set the matrix strategy to Full Matrix Stress Test if on master/main or stress-test branch or any tag
57+
BRANCH_NAME=${GITHUB_REF##*/}
58+
if [[ $BRANCH_NAME == "master" || $BRANCH_NAME == "main" || $BRANCH_NAME == "stress-test" || $GITHUB_REF == refs/tags/* ]]; then
59+
echo "matrix=$FULL_MATRIX_STRATEGY" >> $GITHUB_OUTPUT
60+
else
61+
echo "matrix=$UBUNTU_PY310_STRATEGY" >> $GITHUB_OUTPUT
62+
fi
63+
echo "TESTS_ENABLED=$RUN_UNIT_TESTS" >> $GITHUB_OUTPUT
64+
echo "DOCKER_ENABLED=$BUILD_DOCKER" >> $GITHUB_OUTPUT
65+
2166
test_suite:
2267
runs-on: ${{ matrix.platform }}
68+
needs: set_github_outputs
69+
if: ${{ needs.set_github_outputs.outputs.TESTS_ENABLED == 'true' }}
2370
strategy:
24-
matrix:
25-
# platform: [ubuntu-latest, macos-latest, windows-latest]
26-
platform: [ubuntu-latest]
27-
# python-version: ["3.7", "3.8", "3.9", "3.10"]
28-
python-version: ["3.10"]
71+
# This needs to match the first job's name and output parameter
72+
matrix: ${{fromJSON(needs.set_github_outputs.outputs.matrix)}}
2973

3074
steps:
3175
- uses: actions/checkout@v3
3276
- name: Set up Python ${{ matrix.python-version }}
33-
uses: actions/setup-python@v2
77+
uses: actions/setup-python@v4
3478
with:
3579
python-version: ${{ matrix.python-version }}
3680

@@ -81,6 +125,7 @@ jobs:
81125
run: tox -e coverage --sitepackages -vv -s false
82126

83127
- run: pip install coverage[toml]>=5.1
128+
if: ${{ always() }}
84129

85130
- name: Send Coverage Data to Codecov
86131
uses: codecov/codecov-action@v2
@@ -92,6 +137,7 @@ jobs:
92137
flags: unittests
93138
name: codecov-umbrella
94139
verbose: true
140+
if: ${{ always() }}
95141

96142
- name: Check for compliance with Python Best Practices
97143
shell: bash
@@ -114,7 +160,6 @@ jobs:
114160
- name: Upload Source & Wheel distributions as Artefacts
115161
uses: actions/upload-artifact@v2
116162
with:
117-
# name: dist-${{ env.OS }}-${{ env.PYTHON }} # TODO enable this
118163
name: dist-${{ matrix.platform }}-${{ matrix.python-version }}
119164
path: ${{ env.DIST_DIR }}
120165
if-no-files-found: error
@@ -131,9 +176,41 @@ jobs:
131176
# with:
132177
# name: coverage-xml-data
133178

179+
# DRAW PYTHON DEPENDENCY GRAPHS
180+
check_if_source_code_changed:
181+
runs-on: ubuntu-latest
182+
name: Check for Source Code changes; happened inside the 'src' dir
183+
outputs:
184+
src_dir_changed: ${{ steps.check_files.outputs.src_dir_changed }}
185+
steps:
186+
- name: Checkout code
187+
uses: actions/checkout@v3
188+
with:
189+
fetch-depth: 2
190+
- name: check modified files
191+
id: check_files
192+
run: |
193+
echo "=============== list modified files ==============="
194+
git diff --name-only HEAD^ HEAD
195+
196+
echo "========== check paths of modified files =========="
197+
git diff --name-only HEAD^ HEAD > files.txt
198+
199+
echo "src_dir_changed=false" >> $GITHUB_OUTPUT
200+
while read file; do
201+
echo $file
202+
if [[ $file =~ ^src/ ]]; then
203+
echo "This modified file is under the 'src' folder."
204+
echo "src_dir_changed=true" >> $GITHUB_OUTPUT
205+
break
206+
fi
207+
done < files.txt
208+
134209
draw-dependencies:
135210
runs-on: ubuntu-latest
136-
needs: test_suite
211+
needs: check_if_source_code_changed
212+
if: needs.check_if_source_code_changed.outputs.src_dir_changed == 'true'
213+
name: Draw Python Dependencies as Graphs, in .svg
137214
steps:
138215
- uses: actions/checkout@v3
139216
- name: Set up Python 3.10
@@ -160,3 +237,31 @@ jobs:
160237
name: dependency-graphs
161238
path: pydeps/
162239
if-no-files-found: warn # 'error' or 'ignore' are also available, defaults to `warn`
240+
241+
docker_build:
242+
runs-on: ubuntu-latest
243+
needs: test_suite
244+
if: needs.set_github_outputs.outputs.DOCKER_ENABLED == 'true'
245+
env:
246+
DOCKER_USER: ${{ secrets.DOCKER_USER }}
247+
steps:
248+
- uses: actions/checkout@v3
249+
- name: Build 'n Push Docker Image to DockerHub
250+
run: |
251+
# workflow enabled for branches and v* tags
252+
IMAGE_TAG="${GITHUB_REF_NAME}" # this is branch name or tag name
253+
echo "IMAGE_REF=generate-python:${IMAGE_TAG}" >> $GITHUB_ENV
254+
255+
docker build -t "${DOCKER_USER}/generate-python:${GITHUB_REF_NAME}" .
256+
docker images
257+
258+
- name: Publish Docker Image to DockerHub
259+
env:
260+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
261+
run: |
262+
echo "Sanity check: ${DOCKER_USER}"
263+
echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USER}" --password-stdin
264+
echo "Logged into Docker Hub"
265+
docker push "${DOCKER_USER}/${IMAGE_REF}"
266+
echo "Published in Dockerhub :)"
267+
docker logout

CHANGELOG.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22
Changelog
33
=========
44

5+
1.7.4 (2023-01-26)
6+
==================
7+
8+
| Improvements in the CI/CD pipeline running on Github Actions.
9+
| See the .github/workflows/test.yaml file for the workflow (aka pipeline) details.
10+
11+
12+
Changes
13+
^^^^^^^
14+
15+
documentation
16+
"""""""""""""
17+
- check Web Server Result Interface
18+
19+
ci
20+
""
21+
- 'set_github_outputs' Job to pass 'env' vars to GITHUB_OUTPUT
22+
- add flag to turn on/off docker build+publish
23+
- draw deps job based on changes in src dir
24+
- add disable tests flag
25+
- build and push (docker) image to dockerhub
26+
- define (docker) image, where the 'generate-python' cli is installed
27+
28+
529
1.7.3 (2023-01-15)
630
==================
731

Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM python:3.9.16-slim-bullseye as builder
2+
# See https://github.com/python-poetry/poetry/discussions/1879#discussioncomment-216865
3+
# for inspiration
4+
COPY poetry.lock pyproject.toml ./
5+
6+
# Envrironment Configuration
7+
## See https://github.com/alejandro-angulo/poetry/blob/master/docs/configuration.md
8+
# Determine where to install poetry
9+
ENV POETRY_HOME=/opt/poetry
10+
11+
# Install Poetry & generate a requirements.txt file
12+
RUN python -c 'from urllib.request import urlopen; print(urlopen("https://install.python-poetry.org").read().decode())' | python && \
13+
"$POETRY_HOME/bin/poetry" export -f requirements.txt > requirements.txt
14+
15+
FROM python:3.9.16-slim-bullseye
16+
17+
COPY --from=builder requirements.txt .
18+
19+
# Pre emptively add the user's bin folder to PATH
20+
ENV PATH="/root/.local/bin:$PATH"
21+
22+
RUN apt-get update && \
23+
apt-get install -y --no-install-recommends build-essential && \
24+
pip install -U pip && \
25+
pip install --no-cache-dir --user -r requirements.txt
26+
27+
COPY . .
28+
RUN pip install --no-cache-dir --user .
29+
30+
CMD [ "generate-python" ]

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ For more complex use cases, you can modify the Template and also leverage all of
202202

203203
.. Github Releases & Tags
204204
205-
.. |commits_since_specific_tag_on_master| image:: https://img.shields.io/github/commits-since/boromir674/cookiecutter-python-package/v1.7.3/master?color=blue&logo=github
205+
.. |commits_since_specific_tag_on_master| image:: https://img.shields.io/github/commits-since/boromir674/cookiecutter-python-package/v1.7.4/master?color=blue&logo=github
206206
:alt: GitHub commits since tagged version (branch)
207-
:target: https://github.com/boromir674/cookiecutter-python-package/compare/v1.7.3..master
207+
:target: https://github.com/boromir674/cookiecutter-python-package/compare/v1.7.4..master
208208

209209
.. |commits_since_latest_github_release| image:: https://img.shields.io/github/commits-since/boromir674/cookiecutter-python-package/latest?color=blue&logo=semver&sort=semver
210210
:alt: GitHub commits since latest release (by SemVer)

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
author = 'Konstantinos Lampridis'
3131

3232
# The full version, including alpha/beta/rc tags
33-
release = '1.7.3'
33+
release = '1.7.4'
3434

3535
# -- General configuration ---------------------------------------------------
3636

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ build-backend = "poetry.core.masonry.api"
1010
## Also renders on pypi as 'subtitle'
1111
[tool.poetry]
1212
name = "cookiecutter_python"
13-
version = "1.7.3"
13+
version = "1.7.4"
1414
description = "Yet another modern Python Package (pypi) with emphasis in CI/CD and automation."
1515
authors = ["Konstantinos Lampridis <k.lampridis@hotmail.com>"]
1616
maintainers = ["Konstantinos Lampridis <k.lampridis@hotmail.com>"]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.7.3'
1+
__version__ = '1.7.4'

src/cookiecutter_python/backend/check_server_result.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33

44
class CheckWebServerResult(ABC):
5+
"""Interface for checking the result of a web server request."""
6+
57
@property
68
@abstractmethod
79
def future(self):

src/cookiecutter_python/backend/sanitization/input_sanitization.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ def wrapper(func: SanitizerLike) -> SanitizerLike:
3838
"""Add the decorated callback to the sanitizers' registry.
3939
4040
Args:
41-
func (t.Callable): the callback to add to the registry
41+
func (t.Callable): the callback to add to the registry
4242
43-
Returns:
44-
object: the (sub) class
43+
Returns:
44+
object: the (sub) class
4545
"""
4646
cls.sanitizers_map[sanitizer_identifier] = func
4747
return func

src/cookiecutter_python/backend/sanitization/interpreters_support.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@
66

77

88
# TODO Improvement: use an Enum
9-
# SUPPORTED = {
10-
# 'py35',
11-
# 'py36',
12-
# 'py37',
13-
# 'py38',
14-
# 'py39',
15-
# 'py310',
16-
# 'py311',
17-
# }
189

1910
SUPPORTED = {
2011
'3.5',

0 commit comments

Comments
 (0)