Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python example with linting #3

Merged
merged 28 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/python-tox.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Python Tox

on:
push:
branches:
# Run on our main branch
- main
paths:
- example-python/**
pull_request:
# Run for any pull requests
paths:
- example-python/**
jobs:
tox:
runs-on: ubuntu-latest
strategy:
matrix:
# Run on Python versions that are stable and not EOL
python-version: ["3.10", "3.11", "3.12", "3.13"]
tox-job: ["test", "build", "lint", "type"]
steps:
- uses: actions/checkout@v4 # Checkout the current branch/merge state
- name: Set up Python ${{ matrix.python-version }} # Get Python ready to use
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies # Get Tox and Poetry ready
working-directory: ./example-python
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
curl -sSL https://install.python-poetry.org | python -
tox depends --recreate
# Run Tox jobs
- name: Tox (${{ matrix.tox-job }})
working-directory: ./example-python
run: |
poetry config virtualenvs.create false
poetry install --no-root --with ${{ matrix.tox-job }}
tox -e ${{ matrix.tox-job }}
10 changes: 10 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/amrit-repos.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/git_toolbox_blame.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/git_toolbox_prj.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/runConfigurations/Build_Example_Python_Image.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions .idea/runConfigurations/Example_Python__Main_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions .idea/runConfigurations/Example_Python__Tox_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions example-python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# Distribution / packaging
build/
dist/
public/
*.egg-info/
.eggs/
docs/source/generated

# Test artifacts=

.coverage
coverage.xml
coverage_reports
junit.xml

# Developer Environments
venv/
.tox/
.env
secrets.env
24 changes: 24 additions & 0 deletions example-python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM python:3.12 AS base
ENV POETRY_HOME=/opt/poetry
ENV PATH="/opt/poetry/bin:${PATH}"

RUN mkdir -p /opt/poetry/project /opt/poetry/bin
RUN curl -sSL https://install.python-poetry.org | python -

COPY pyproject.toml poetry*.lock README.md /opt/poetry/project/
RUN \
cd /opt/poetry/project && \
poetry config virtualenvs.create false && \
if [ ! -f poetry.lock ]; then poetry lock; fi && \
poetry install --no-root && \
poetry env info

RUN useradd -ms /bin/bash developer
USER developer
WORKDIR /home/developer


FROM base as dev
USER root
RUN cd /opt/poetry/project && poetry install --no-root --with build,lint,test
USER developer
Empty file added example-python/README.md
Empty file.
6 changes: 6 additions & 0 deletions example-python/example/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Example Python package."""

from . import main
from .example import hello

__all__: list[str] = ["main", "hello"]
13 changes: 13 additions & 0 deletions example-python/example/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Example importable module."""

__all__: list[str] = ["hello"]


def hello() -> str:
"""Return a Hello World string that can be printed.

Returns:
A printable string with the content of "Hello World!".

"""
return "Hello World!"
21 changes: 21 additions & 0 deletions example-python/example/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""An example application entry-point module."""

from .example import hello

__all__: list[str] = ["main"]


def main() -> None:
"""Print a Hello World message to the console.

Obtains a Hello World string and prints it.

Note the use of "Google-style" docstrings:
https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html
"""
message = hello()
print(message)


if __name__ == "__main__":
main()
Loading