Skip to content

Commit

Permalink
chore: move packaging information to pyproject.toml (#97)
Browse files Browse the repository at this point in the history
* build: move packaging metadata to pyproject.toml

* chore: update rtd config

* feat(ci): add pip caching to CI

* build: add build as optional dependencies

* feat(ci): bump python version to 3.8

* fix caching

* set version dynamically

* fix

* show installed packages

* fix build

* check untyped defs by default

---------

Co-authored-by: epwalsh <[email protected]>
  • Loading branch information
SauravMaheshkar and epwalsh authored Apr 11, 2023
1 parent e4c6be6 commit add262f
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 110 deletions.
4 changes: 3 additions & 1 deletion .github/actions/setup-venv/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ runs:
id: virtualenv-cache
with:
path: .venv
key: ${{ inputs.cache-prefix }}-${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('requirements.txt', 'dev-requirements.txt') }}
key: ${{ inputs.cache-prefix }}-${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('pyproject.toml') }}

- if: steps.virtualenv-cache.outputs.cache-hit != 'true'
shell: bash
Expand All @@ -52,3 +52,5 @@ runs:
# Show environment info.
. .venv/bin/activate
echo "✓ Installed $(python --version) virtual environment to $(which python)"
echo "Packages:"
pip freeze
21 changes: 10 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
branches:
- main
tags:
- 'v*.*.*'
- "v*.*.*"

env:
# Change this to invalidate existing cache.
Expand All @@ -27,38 +27,37 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ['3.8', '3.10']
python: ["3.8", "3.10"]
task:
- name: Test
run: |
pytest -v --color=yes tests/
include:
- python: '3.10'
- python: "3.10"
task:
name: Lint
run: flake8 .

- python: '3.10'
- python: "3.10"
task:
name: Type check
run: mypy .

- python: '3.10'
- python: "3.10"
task:
name: Build
run: |
python setup.py check
python setup.py bdist_wheel sdist
python -m build
- python: '3.10'
- python: "3.10"
task:
name: Style
run: |
isort --check .
black --check .
- python: '3.10'
- python: "3.10"
task:
name: Docs
run: cd docs && make html
Expand Down Expand Up @@ -113,12 +112,12 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: "3.10"

- name: Install requirements
run: |
pip install --upgrade pip setuptools wheel
pip install -r dev-requirements.txt
pip install -e .[dev]
- name: Prepare environment
run: |
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.7'
python-version: "3.8"
cache: "pip"
cache-dependency-path: "setup-requirements.txt"

- name: Install prerequisites
run: |
Expand All @@ -38,9 +40,9 @@ jobs:
run: |
set -eo pipefail
# Check that 'new-package' replaced 'my-package' in some files.
grep -q 'new-package' setup.py .github/workflows/main.yml CONTRIBUTING.md
grep -q 'new-package' pyproject.toml .github/workflows/main.yml CONTRIBUTING.md
# Check that the new repo URL replaced the old one in some files.
grep -q 'https://github.com/epwalsh/new-repo' setup.py CONTRIBUTING.md
grep -q 'https://github.com/epwalsh/new-repo' pyproject.toml CONTRIBUTING.md
# Double check that there are no lingering mentions of old names.
for pattern in 'my[-_]package' 'https://github.com/allenai/python-package-template'; do
if find . -type f -not -path './.git/*' | xargs grep "$pattern"; then
Expand Down
7 changes: 5 additions & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ sphinx:
python:
version: "3.8"
install:
- requirements: requirements.txt
- requirements: dev-requirements.txt
- method: pip
path: .
extra_requirements:
- dev

42 changes: 0 additions & 42 deletions dev-requirements.txt

This file was deleted.

71 changes: 67 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,69 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "my-package"
dynamic = ["version"]
readme = "README.md"
classifiers = [
"Intended Audience :: Science/Research",
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
]
authors = [
{name = "Allen Institute for Artificial Intelligence", email = "[email protected]"}
]
requires-python = ">=3.8"
dependencies = [
# Add your own dependencies here
]
license = {file = "LICENSE"}

[project.urls]
homepage = "https://github.com/allenai/python-package-template"
repository = "https://github.com/allenai/python-package-template"

[project.optional-dependencies]
dev = [
"flake8",
"mypy>=1.0,<1.1",
"black>=23.0,<24.0",
"isort>=5.12,<5.13",
"pytest",
"pytest-sphinx",
"pytest-cov",
"twine>=1.11.0",
"build",
"setuptools",
"wheel",
"Sphinx>=4.3.0,<6.2.0",
"furo==2022.12.7",
"myst-parser>=0.15.2,<0.19.0",
"sphinx-copybutton==0.5.1",
"sphinx-autobuild==2021.3.14",
"sphinx-autodoc-typehints",
"packaging"
]

[tool.setuptools.packages.find]
exclude = [
"*.tests",
"*.tests.*",
"tests.*",
"tests",
"docs*",
"scripts*"
]

[tool.setuptools.package-data]
my_package = ["py.typed"]

[tool.setuptools.dynamic]
version = {attr = "my_package.VERSION"}

[tool.black]
line-length = 100

Expand All @@ -23,13 +89,10 @@ multi_line_output = 3
[tool.pyright]
reportPrivateImportUsage = false

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[tool.mypy]
ignore_missing_imports = true
no_site_packages = true
check_untyped_defs = true

[[tool.mypy.overrides]]
module = "tests.*"
Expand Down
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

46 changes: 0 additions & 46 deletions setup.py

This file was deleted.

0 comments on commit add262f

Please sign in to comment.