Skip to content

Commit 58c4637

Browse files
authored
Add initial structure to repository (#1)
* Add actions/setup-python * More updates * Add coverage report
1 parent 65539b7 commit 58c4637

File tree

7 files changed

+168
-1
lines changed

7 files changed

+168
-1
lines changed

.github/workflows/test_package.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Test package
2+
3+
on:
4+
push:
5+
# The CI is executed on every push on every branch
6+
branches:
7+
- "**"
8+
pull_request:
9+
# The CI is executed on every pull request to the main branch
10+
branches:
11+
- main
12+
13+
schedule:
14+
# The CI is executed every day at 8am
15+
- cron: "0 8 * * *"
16+
jobs:
17+
check-code:
18+
# This skips running the test if '[ci skip]' or '[skip ci]' is in the commit message
19+
# if: "!(contains(github.event.head_commit.message, '[ci skip]') || contains(github.event.head_commit.message, '[skip ci]'))"
20+
21+
# Choose which operating system to run on, for more options see:
22+
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
23+
runs-on: ubuntu-22.04
24+
25+
steps:
26+
# This action sets the current path to the root of your github repo
27+
- uses: actions/checkout@v3
28+
29+
- uses: actions/setup-python@v4
30+
with:
31+
python-version: '3.10'
32+
33+
- name: "Install code"
34+
run: pip install .[test,docs]
35+
36+
- name: Flake8 code
37+
run: flake8 .
38+
39+
- name: Mypy check
40+
run: |
41+
pip install mypy
42+
python -m mypy . --exclude=build
43+
44+
- name: Generate coverage report
45+
run: python -m pytest --cov=mypackage test
46+
47+
- name: Generate html report
48+
run: python -m coverage html
49+
50+
- name: Upload coverage report as artifact
51+
uses: actions/upload-artifact@v3
52+
with:
53+
name: code-coverage-report
54+
path: htmlcov
55+
if-no-files-found: error
56+
57+
test-code:
58+
# This code depends on the result of check-code
59+
needs: check-code
60+
runs-on: ${{ matrix.os }}
61+
62+
strategy:
63+
matrix:
64+
os: [ubuntu-22.04, windows-latest, macos-12]
65+
66+
steps:
67+
- uses: actions/setup-python@v4
68+
with:
69+
python-version: '3.10'
70+
71+
- uses: actions/checkout@v3
72+
73+
- name: "Install mypackage"
74+
run: pip install .[test]
75+
76+
- name: Run tests
77+
run: |
78+
python -m pytest test/

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
# reproducibility
1+
# reproducibility
2+
3+
This repository is a template for how to set up a reproducible python environment with GitHub.
4+
5+
## Python-packaging
6+
7+
To be able to create a python package, we need a folder with the name of the package (in this repository `mypackage`), and a `pyproject.toml` file.

mypackage/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
# Copyright (C) 2022 Jørgen Schartum Dokken
3+
#
4+
# This file is part of my_package
5+
# SPDX-License-Identifier: MIT
6+
7+
from .functions import addition
8+
9+
__all__ = ["addition"]

mypackage/functions.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
3+
# Copyright (C) 2022 Jørgen Schartum Dokken
4+
#
5+
# This file is part of mypackage
6+
# SPDX-License-Identifier: MIT
7+
8+
def addition(a: int, b: int) -> int:
9+
""" Computes a+b """
10+
return a + b
11+
12+
13+
def print_add(a: int, b: int) -> int:
14+
c = a + b
15+
print(c)
16+
return c

pyproject.toml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[build-system]
2+
requires = ["setuptools>=62.1.0", "wheel"]
3+
4+
5+
[project]
6+
name = "mypackage"
7+
authors = [
8+
{name = "Jørgen S. Dokken", email = "dokken@simula.no"}
9+
]
10+
version = "0.1.0"
11+
description = "Minimal package for adding two numbers"
12+
readme = "README.md"
13+
requires-python = ">=3.8"
14+
license = {file = "LICENSE"}
15+
dependencies = [
16+
'numpy'
17+
]
18+
19+
20+
[project.optional-dependencies]
21+
test = [
22+
"flake8",
23+
"mypy",
24+
"pytest",
25+
"pytest-cov"
26+
]
27+
28+
docs = [
29+
"Sphinx",
30+
"jupyter-book",
31+
"pandoc"
32+
]
33+
34+
[tool.mypy]
35+
ignore_missing_imports = true
36+
exclude = [
37+
"docs/",
38+
"build/"
39+
]

setup.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# flake8 does not support, see:
2+
# https://github.com/PyCQA/flake8/issues/234
3+
[flake8]
4+
exclude = docs
5+
max-line-length = 100
6+
7+

test/test_code.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (C) 2022 Jørgen Schartum Dokken
2+
#
3+
# This file is part of my_package
4+
# SPDX-License-Identifier: MIT
5+
6+
from mypackage import addition
7+
8+
9+
def test_addition():
10+
a = 5
11+
b = 3
12+
assert addition(a, b) == a + b

0 commit comments

Comments
 (0)