Skip to content

Commit

Permalink
boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
WT-MM committed Jan 13, 2025
0 parents commit 9daebf5
Show file tree
Hide file tree
Showing 16 changed files with 450 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .darglint
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[darglint]

docstring_style=google
121 changes: 121 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Publish Python Packages

on:
release:
types: [created]
workflow_dispatch:
inputs:
build_wheels:
description: 'Build platform-specific wheels'
required: true
default: 'false'
type: boolean

permissions:
contents: read
id-token: write

concurrency:
group: "publish"
cancel-in-progress: true

jobs:
build-wheels:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
name: Build and publish Python package (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 10
steps:
- name: Skip wheels for pure Python package
if: ${{ !inputs.build_wheels }}
run: |
echo "Skipping wheel build - this is *probably* a pure Python package"
shell: bash

- name: Build real wheels
if: ${{ inputs.build_wheels }}
uses: actions/checkout@v3

- name: Set up Python
if: ${{ inputs.build_wheels }}
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install dependencies
if: ${{ inputs.build_wheels }}
run: |
python -m pip install --upgrade pip
pip install cibuildwheel
shell: bash

- name: Build package
if: ${{ inputs.build_wheels }}
env:
CIBW_SKIP: "pp* *-musllinux*" # Skip PyPy and musllinux builds
run: |
cibuildwheel --output-dir dist
- name: Upload wheel artifacts
if: ${{ inputs.build_wheels }}
uses: actions/upload-artifact@v3
with:
name: wheels-${{ matrix.os }}
path: |
dist/*.whl
build-source-dist:
name: Build and publish Python package (source distribution)
timeout-minutes: 10
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build
shell: bash

- name: Build source distribution
run: |
python -m build --sdist --outdir dist
- name: Upload source distribution
uses: actions/upload-artifact@v3
with:
name: source-dist
path: |
dist/*.tar.gz
publish-wheels:
needs: [build-wheels, build-source-dist]
name: Publish Python wheels
timeout-minutes: 10
runs-on: ubuntu-latest

steps:
- name: Download all wheels
uses: actions/download-artifact@v3
with:
path: dist

- name: Move wheels to dist directory
run: |
mkdir -p final_dist
find dist -name "*.whl" -exec mv {} final_dist/ \;
find dist -name "*.tar.gz" -exec mv {} final_dist/ \;
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: final_dist/
65 changes: 65 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Python Checks

on:
push:
branches:
- master
pull_request:
branches:
- master
types:
- opened
- reopened
- synchronize
- ready_for_review

concurrency:
group: tests-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
run-base-tests:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Restore cache
id: restore-cache
uses: actions/cache/restore@v3
with:
path: |
${{ env.pythonLocation }}
.mypy_cache/
key: python-requirements-${{ env.pythonLocation }}-${{ github.event.pull_request.base.sha || github.sha }}
restore-keys: |
python-requirements-${{ env.pythonLocation }}
python-requirements-
- name: Install package
run: |
pip install --upgrade --upgrade-strategy eager --extra-index-url https://download.pytorch.org/whl/cpu -e '.[dev]'
- name: Run static checks
run: |
mkdir -p .mypy_cache
make static-checks
- name: Run unit tests
run: |
make test
- name: Save cache
uses: actions/cache/save@v3
if: github.ref == 'refs/heads/master'
with:
path: |
${{ env.pythonLocation }}
.mypy_cache/
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# .gitignore

# Python
*.py[oc]
__pycache__/
*.egg-info
.eggs/
.mypy_cache/*
.pyre/
.pytest_cache/
.ruff_cache/
.dmypy.json

# Databases
*.db

# Build artifacts
build/
dist/
*.so
out*/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Wesley Maa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include kos_sim/ *.py *.txt py.typed MANIFEST.in
62 changes: 62 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Makefile

define HELP_MESSAGE
kos-sim

# Installing

1. Create a new Conda environment: `conda create --name kos-sim python=3.11`
2. Activate the environment: `conda activate kos-sim`
3. Install the package: `make install-dev`

# Running Tests

1. Run autoformatting: `make format`
2. Run static checks: `make static-checks`
3. Run unit tests: `make test`

endef
export HELP_MESSAGE

all:
@echo "$$HELP_MESSAGE"
.PHONY: all

# ------------------------ #
# PyPI Build #
# ------------------------ #

build-for-pypi:
@pip install --verbose build wheel twine
@python -m build --sdist --wheel --outdir dist/ .
@twine upload dist/*
.PHONY: build-for-pypi

push-to-pypi: build-for-pypi
@twine upload dist/*
.PHONY: push-to-pypi

# ------------------------ #
# Static Checks #
# ------------------------ #

py-files := $(shell find . -name '*.py')

format:
@black $(py-files)
@ruff format $(py-files)
.PHONY: format

static-checks:
@black --diff --check $(py-files)
@ruff check $(py-files)
@mypy --install-types --non-interactive $(py-files)
.PHONY: lint

# ------------------------ #
# Unit tests #
# ------------------------ #

test:
python -m pytest
.PHONY: test
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# kos-sim

Welcome to the kos-sim project!
1 change: 1 addition & 0 deletions kos-sim/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.0.1"
Empty file added kos-sim/py.typed
Empty file.
7 changes: 7 additions & 0 deletions kos-sim/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# requirements-dev.txt

black
darglint
mypy
pytest
ruff
2 changes: 2 additions & 0 deletions kos-sim/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# requirements.txt

71 changes: 71 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
[tool.black]

line-length = 120
target-version = ["py311"]
include = '\.pyi?$'

[tool.pytest.ini_options]

addopts = "-rx -rf -x -q --full-trace"
testpaths = ["tests"]

markers = [
"slow: Marks test as being slow",
]

[tool.mypy]

pretty = true
show_column_numbers = true
show_error_context = true
show_error_codes = true
show_traceback = true
disallow_untyped_defs = true
strict_equality = true
allow_redefinition = true

warn_unused_ignores = true
warn_redundant_casts = true

incremental = true
namespace_packages = false

# Uncomment to exclude modules from Mypy.
# [[tool.mypy.overrides]]
# module = []
# ignore_missing_imports = true

[tool.isort]

profile = "black"

[tool.ruff]

line-length = 120
target-version = "py310"

[tool.ruff.lint]

select = ["ANN", "D", "E", "F", "G", "I", "N", "PGH", "PLC", "PLE", "PLR", "PLW", "W"]

ignore = [
"D101", "D102", "D103", "D104", "D105", "D106", "D107",
"N812", "N817",
"PLR0911", "PLR0912", "PLR0913", "PLR0915", "PLR2004",
"PLW0603", "PLW2901",
]

dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.lint.per-file-ignores]

"__init__.py" = ["E402", "F401", "F403", "F811"]

[tool.ruff.lint.isort]

known-first-party = ["kos_sim", "tests"]
combine-as-imports = true

[tool.ruff.lint.pydocstyle]

convention = "google"
Loading

0 comments on commit 9daebf5

Please sign in to comment.