Skip to content

Commit

Permalink
Add Initial Package Structure
Browse files Browse the repository at this point in the history
* Add poetry package structure for SCC1 driver
* Add initial github action for build and test
* Add flake8 and pytest configuration
* Add test and coverage reporting
  • Loading branch information
psachs committed Feb 9, 2024
1 parent 5562450 commit 92ee784
Show file tree
Hide file tree
Showing 18 changed files with 1,202 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[flake8]
exclude =
.git,
.venv,
.tox,
__pycache__,
docs,
build,
dist,
.eggs,
.pytest_cache
tests/conftest.py
max-line-length = 120
statistics = true
49 changes: 49 additions & 0 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Publish Documentation
on:
push:
branches:
- main
tags:
- "^[0-9]+.[0-9]+.[0-9]+"

jobs:
build_pages:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Install Poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: 1.7.1
- uses: actions/cache@v3
name: Define a cache for the virtual environment based on the dependencies lock file
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}
- name: Install the project dependencies
run: poetry install --with docs
- name: Build documentation
run: cd docs && poetry run make html
- name: Upload html
uses: actions/upload-pages-artifact@v1
with:
path: ./docs/_build/html
deploy_pages:
runs-on: ubuntu-latest
needs: build_pages
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
with:
token: ${{secrets.GITHUB_TOKEN}}
90 changes: 90 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Build and Publish Package to pypi.org
on:
push:
tags:
- "^[0-9]+.[0-9]+.[0-9]+"

jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: 1.7.1
- uses: actions/cache@v3
name: Define a cache for the virtual environment based on the dependencies lock file
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}
- name: Install the project dependencies
run: poetry install
- name: Build Packages
run: poetry install
- name: Build Python packages
run: poetry build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/
publish-pypi:
environment:
name: release
url: https://pypi.org/p/sensirion-uart-scc1
permissions:
id-token: write
runs-on: ubuntu-22.04
needs:
- build
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
github-release:
name: Sign Pyhon distribution and upload it as GitHub Release
needs:
- build
- publish-pypi
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/gh-action-sigstore-python@v1.2.3
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
53 changes: 53 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Test Python Package
on: push

jobs:
test:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-22.04, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
permissions:
id-token: write
contents: read
issues: read
checks: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: 1.7.1
- uses: actions/cache@v3
name: Define a cache for the virtual environment based on the dependencies lock file
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}
- name: Install the project dependencies
run: poetry install --with test
- name: Verify style with flake8
run: poetry run flake8
- name: Run tests
run: poetry run pytest
- name: Setup LCOV
if: runner.os == 'Linux'
uses: hrishikesh-kadam/setup-lcov@v1
- name: Report code coverage
if: runner.os == 'Linux'
uses: zgosalvez/github-actions-report-lcov@v3
with:
coverage-files: coverage.lcov
artifact-name: code-coverage-report
github-token: ${{ secrets.GITHUB_TOKEN }}
update-comment: true
- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
if: success() || failure() # always run even if the previous step fails
with:
report_paths: 'test-report*.xml'
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ htmlcov/
.nox/
.coverage
.coverage.*
coverage.lcov
.cache
nosetests.xml
coverage.xml
Expand Down Expand Up @@ -158,3 +159,10 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Pytest
.pytest_cache/
test-report*.xml

# PyCharm
.idea
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/_build/
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
19 changes: 19 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
API Documentation
=================

This is an example for auto-documenting code of the module
<sensirion_package_name>.<my_module>. If you are viewing this in the browser
click on **View page source** in the upper right corner to see the markup from
which this page has been generated.

Just replace <sensirion_package_name>.<my_module> below with the actual values
in your project and remove the two dots in the beginning of the same line.

You can also auto-document classes, methods and many more. You can find
additional information on auto-documenation on
https://www.sphinx-doc.org/en/master/usage/quickstart.html#autodoc


.. .. automodule:: sensirion_uart_scc1.device
:members:
:undoc-members:
46 changes: 46 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import os
import sys
from datetime import datetime

import pkg_resources

# Add project directory such that sphinx can detect the package.
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

# -- Project information -----------------------------------------------------
distribution = pkg_resources.get_distribution('sensirion_uart_scc1')

project = distribution.project_name
copyright = u'{} Sensirion AG, Switzerland'.format(datetime.now().year)
author = 'Sensirion AG'
version = distribution.version


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
21 changes: 21 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Welcome to sensirion_uart_scc1's documentation!
====================================================

This is the documentation template for sensirion_uart_scc1. If you are
viewing this in the browser click on **View page source** in the upper right
corner to see the markup from which this page has been generated.

Read more on how to document your code (even automatically) on
https://www.sphinx-doc.org/en/master/usage/quickstart.html#defining-document-structure

.. toctree::
:maxdepth: 2
:caption: Contents:

api

Indices and tables
==================

* :ref:`genindex`
* :ref:`search`
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
Loading

0 comments on commit 92ee784

Please sign in to comment.