Skip to content

Commit 42594d1

Browse files
committed
First commit
1 parent b6854b2 commit 42594d1

File tree

12 files changed

+305
-0
lines changed

12 files changed

+305
-0
lines changed

.github/workflows/python-package.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Python package
5+
6+
on:
7+
pull_request:
8+
push:
9+
branches:
10+
- main
11+
tags:
12+
- "v*"
13+
14+
jobs:
15+
test:
16+
runs-on: ${{ matrix.os }}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
os: [ubuntu-latest] #, windows-latest, macos-latest]
21+
python-version:
22+
- "3.9"
23+
- "3.10"
24+
- "3.11"
25+
- "3.12"
26+
- "3.13"
27+
- "pypy-3.9"
28+
29+
name: ${{ matrix.os }} - ${{ matrix.python-version }}
30+
steps:
31+
- uses: actions/checkout@v4
32+
- name: Get history and tags for SCM versioning to work
33+
run: |
34+
git fetch --prune --unshallow
35+
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
36+
- name: Install uv
37+
uses: astral-sh/setup-uv@v5
38+
with:
39+
version: "0.5.22"
40+
- name: Set up Python ${{ matrix.python-version }}
41+
uses: actions/setup-python@v5
42+
with:
43+
python-version: ${{ matrix.python-version }}
44+
- name: Install dependencies
45+
run: pip install tox tox-uv
46+
- name: Run tox
47+
# Run tox using the version of Python in `PATH`
48+
run: tox -e py
49+
50+
dist:
51+
runs-on: ubuntu-latest
52+
needs: [test]
53+
name: Build Python packages
54+
steps:
55+
- uses: actions/checkout@v4
56+
- name: Get history and tags for SCM versioning to work
57+
run: |
58+
git fetch --prune --unshallow
59+
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
60+
- uses: actions/setup-python@v5
61+
with:
62+
python-version: "3.9"
63+
- name: Install dependencies
64+
run: |
65+
python -m pip install --upgrade pip
66+
pip install --upgrade wheel setuptools build
67+
- name: Build package
68+
run: python -m build -s -w -o dist/
69+
- uses: actions/upload-artifact@v4
70+
with:
71+
name: dist
72+
path: dist
73+
74+
dist_check:
75+
runs-on: ubuntu-latest
76+
needs: [dist]
77+
name: Twine check
78+
steps:
79+
- uses: actions/setup-python@v5
80+
with:
81+
python-version: "3.9"
82+
- name: Install dependencies
83+
run: pip install twine
84+
- uses: actions/download-artifact@v4
85+
with:
86+
name: dist
87+
path: dist
88+
- run: twine check dist/*
89+
90+
dist_upload:
91+
runs-on: ubuntu-latest
92+
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
93+
needs: [dist_check]
94+
name: PyPI upload
95+
permissions:
96+
id-token: write
97+
steps:
98+
- uses: actions/download-artifact@v4
99+
with:
100+
name: dist
101+
path: dist
102+
- name: Publish package to PyPI
103+
uses: pypa/gh-action-pypi-publish@release/v1

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,6 @@ cython_debug/
169169

170170
# PyPI configuration file
171171
.pypirc
172+
173+
# Generated by setuptools_scm
174+
package/_version.py

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Add files to be included/excluded in the source distribution
2+
#include /path/to/file
3+
#recursive-include directory *.csv

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,39 @@
11
# python-project-starter
2+
23
This is a template repo to act as a reference when starting up a new project in python. It consolidates best practices in regards to minimal level of documentation as well as the CI aspects.
4+
5+
Local installation can be done using [`uv`](https://github.com/astral-sh/uv):
6+
7+
```bash
8+
$ uv venv -p python3.10
9+
$ uv pip install -e .
10+
$ source .venv/bin/activate
11+
$ python
12+
>>> from package import square
13+
>>> square(3)
14+
9
15+
```
16+
17+
After installation a command-line tool is also available:
18+
19+
```bash
20+
$ square 4
21+
Square of 4 is 16
22+
```
23+
24+
Running the tests can be done using [`tox`](https://tox.wiki/):
25+
26+
```bash
27+
$ tox -p
28+
```
29+
30+
Building the packages can also be done using `tox`:
31+
32+
```bash
33+
$ tox -e packages
34+
$ ls dist/
35+
```
36+
37+
Packaging uses [`setuptools-scm`](https://github.com/pypa/setuptools-scm), so the version of the software is based on git tags.
38+
39+
To run the linting, we recommend `ruff`, a standard configuration is in the repo in `pyproject.toml`.

package/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .module import * # noqa
2+
from ._version import __version__ # noqa

package/__main__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from .module import square
2+
from ._version import __version__
3+
4+
5+
def main():
6+
import argparse
7+
8+
parser = argparse.ArgumentParser(prog="Squarer of ints")
9+
parser.add_argument("x", type=int)
10+
parser.add_argument(
11+
"--version",
12+
action="version",
13+
version=f"%(prog)s, version {__version__}",
14+
)
15+
args = parser.parse_args()
16+
print(f"Square of {args.x} is {square(args.x)}")
17+
18+
19+
if __name__ == "__main__":
20+
import sys
21+
22+
sys.exit(main())

package/module.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
__all__ = [
2+
"square",
3+
]
4+
5+
6+
def square(x: int) -> int:
7+
return x**2

pyproject.toml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[build-system]
2+
requires = ["setuptools>=71", "setuptools-scm>=8"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.setuptools_scm]
6+
write_to = "package/_version.py"
7+
write_to_template = "__version__ = \"{version}\"\n"
8+
9+
[tool.pytest.ini_options]
10+
minversion = "6.0"
11+
addopts = "--strict-markers --doctest-modules --doctest-glob='*.rst' --ignore=setup.py"
12+
doctest_optionflags = [
13+
"NORMALIZE_WHITESPACE",
14+
"IGNORE_EXCEPTION_DETAIL",
15+
"ELLIPSIS",
16+
]
17+
norecursedirs = [
18+
".*",
19+
"__pycache__",
20+
"build",
21+
"dist",
22+
"*.egg-info",
23+
"htmlcov",
24+
"doc",
25+
]
26+
filterwarnings = []
27+
28+
[tool.ruff]
29+
line-length = 100
30+
target-version = "py39"
31+
extend-exclude = ["doc"]
32+
33+
[tool.ruff.lint]
34+
select = [
35+
"F", # pyflakes
36+
"E", # pycodestyle
37+
"W", # pycodestyle
38+
"UP", # pyupgrade
39+
"YTT", # flake8-2020
40+
"B", # flake8-bugbear
41+
"T10", # flake8-debugger
42+
"C4", # flake8-comprehensions
43+
"G", # flake8-logging-format
44+
"ISC", # flake8-implicit-str-concat
45+
"ICN", # flake8-import-conventions
46+
]
47+
ignore = []
48+
49+
[tool.black]
50+
line-length = 88
51+
target-version = ["py39"]
52+
extend-exclude = "doc"

setup.cfg

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[metadata]
2+
name = Squarer
3+
description = A package that squares integers
4+
long_description = file: README.md
5+
long_description_content_type = text/markdown
6+
url = https://github.com/AmadeusITGroup/python-project-starter
7+
author = your_name_here
8+
author_email = [email protected]
9+
license_files = LICENSE
10+
classifiers =
11+
Development Status :: 5 - Production/Stable
12+
Programming Language :: Python :: 3
13+
Programming Language :: Python :: 3 :: Only
14+
Programming Language :: Python :: Implementation :: CPython
15+
Programming Language :: Python :: Implementation :: PyPy
16+
17+
[options]
18+
zip_safe = False
19+
include_package_data = True
20+
packages = find:
21+
python_requires = >=3.9
22+
setup_requires =
23+
setuptools_scm
24+
25+
[options.entry_points]
26+
console_scripts =
27+
square = package.__main__:main

setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from setuptools import setup
2+
3+
setup(
4+
use_scm_version=True,
5+
)

0 commit comments

Comments
 (0)