Skip to content

Commit

Permalink
Move basic Python configuration to the root of the repo. (#80)
Browse files Browse the repository at this point in the history
After way too much trying to figure stuff out I realized: why not just
put the `pyproject.toml` right at the root of the repo? This eliminates
all the `#subdirectory=...` when doing `pip install`s and also makes
`setuptools-scm` work right again. As a bonus, lots of tools now work
without any additional configuration and we can just run them as-is.

This moves the bare minimum files needed to the repo root:

- `pyproject.toml`
- `MANIFEST.in`

and updates everything else to make that work right.
  • Loading branch information
thetorpedodog authored Jan 14, 2023
1 parent fd6d2c2 commit e935e28
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 108 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/python-somacore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,12 @@ jobs:
cache: pip
cache-dependency-path: python-spec/requirements-py${{ env.PYTHON_VERSION }}-lint.txt
- uses: psf/black@stable
with:
src: "./python-spec"
- uses: isort/isort-action@v1
with:
sort-paths: "./python-spec"
- name: Install typing packages
run: |
pip install -r python-spec/requirements-py${{ env.PYTHON_VERSION }}-lint.txt
- name: Run mypy
working-directory: ./python-spec
run: mypy ./src
run: mypy ./python-spec/src

run-tests:
runs-on: ubuntu-latest
Expand All @@ -41,6 +36,10 @@ jobs:
python-version: ["3.7", "3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
with:
# setuptools-scm needs a deep clone so it can look through history
# to find a relevant tag.
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
Expand All @@ -50,7 +49,7 @@ jobs:
run: |
pip install --upgrade pip wheel pytest pytest-cov setuptools
pip install -r python-spec/requirements-py${{ matrix.python-version }}.txt
pip install ./python-spec
pip install .
- name: Run tests
working-directory: ./python-spec
run: |
Expand All @@ -75,10 +74,9 @@ jobs:
- name: Set up environment
run: |
pip install --upgrade build pip wheel setuptools setuptools-scm
./python-spec/write-version-file
python -m build python-spec
python -m build .
- uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
packages_dir: python-spec/dist
packages_dir: dist
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
temp/
tmp/
**/__pycache__
**/*.egg-info
build/
dist/
python-spec/src/somacore/_version.py
18 changes: 7 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ repos:
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

# Because the built-in pre-commit hooks don't natively support projects
# not at the root of their directory, we have to roll our own hooks.
- repo: local
- repo: https://github.com/psf/black
rev: '22.12.0'
hooks:
- id: format-check
name: Format check
language: python
files: ^python-spec/
types_or: [python, pyi]
entry: ./.pre-commit/format-check.sh
additional_dependencies: [black, isort]
- id: black
- repo: https://github.com/PyCQA/isort
rev: '5.11.4'
hooks:
- id: isort
7 changes: 0 additions & 7 deletions .pre-commit/format-check.sh

This file was deleted.

9 changes: 9 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Python package manifest. We have to do this manually because otherwise
# setuptools-scm will try to include literally everything in the repo
# and we only want to include the Python-specific stuff in our build.

global-exclude *
include pyproject.toml
include MANIFEST.in
recursive-include python-spec/README.md
recursive-include python-spec/src *.py py.typed
17 changes: 13 additions & 4 deletions python-spec/pyproject.toml → pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Build and release configuration for the Python version of core SOMA.
# This lives at the root directory to save us lots of headaches with versioning.

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

[project]
name = "somacore"
description = "Python-language API specification and base utilities for implementation of the SOMA system."
dynamic = ["version"]
readme = "./README.md"
readme = "./python-spec/README.md"
dependencies = [
"anndata",
"attrs>=22.1",
Expand All @@ -22,14 +25,20 @@ classifiers = ["License :: OSI Approved :: MIT License"]
dev = ["black", "isort", "setuptools-scm"]

[tool.setuptools]
packages.find.where = ["src"]
packages.find.where = ["python-spec/src"]
package-data.somacore = ["py.typed"]
dynamic.version.attr = "somacore._version.version"

[tool.setuptools_scm]
write_to = "python-spec/src/somacore/_version.py"
# Keep Python executable package versioning separate from the spec and R impl
# by requiring `python-` at the start of the tag (e.g. `python-v1.2.3`).
tag_regex = '^python-(?P<version>[vV]?\d+(?:\.\d+){0,2}[^\+]*)(?:\+.*)?$'

[tool.isort]
profile = "black"
line_length = 88
force_single_line = true
known_first_party = ["somacore"]
single_line_exclusions = ["typing", "typing_extensions"]

[[tool.mypy.overrides]]
Expand Down
5 changes: 0 additions & 5 deletions python-spec/.gitignore

This file was deleted.

4 changes: 0 additions & 4 deletions python-spec/setup.py

This file was deleted.

9 changes: 0 additions & 9 deletions python-spec/setuptools-scm.toml

This file was deleted.

12 changes: 9 additions & 3 deletions python-spec/src/somacore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@
unified namespace.
"""

from somacore import _version
from somacore import base
from somacore import data
from somacore import ephemeral
from somacore import options
from somacore.query import axis

__version__ = _version.version
__version_tuple__ = _version.version_tuple
try:
# This trips up mypy since it's a generated file:
from somacore import _version # type: ignore[attr-defined]

__version__ = _version.version
__version_tuple__ = _version.version_tuple
except ImportError:
__version__ = "0.0.0.dev+invalid"
__version_tuple__ = (0, 0, 0, "dev", "invalid")

SOMAObject = base.SOMAObject
Collection = base.Collection
Expand Down
36 changes: 0 additions & 36 deletions python-spec/src/somacore/_version.py

This file was deleted.

4 changes: 2 additions & 2 deletions python-spec/update-requirements-txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ LINTVER=3.7
for PYVER in 3.7 3.8 3.9 3.10; do
CONDIR="$TEMPDIR/py-$PYVER"
conda create -y -p "$CONDIR" "python=$PYVER"
conda run -p "$CONDIR" pip install .
conda run -p "$CONDIR" pip install ..
conda run -p "$CONDIR" pip freeze --exclude somacore >"requirements-py$PYVER.txt"
done

CONDIR="$TEMPDIR/py-$LINTVER-lint"
conda create -y -p "$CONDIR" "python=$LINTVER"
conda run -p "$CONDIR" pip install . mypy
conda run -p "$CONDIR" pip install .. mypy
conda run -p "$CONDIR" mypy --install-types --non-interactive ./src
conda run -p "$CONDIR" pip freeze --exclude somacore >"requirements-py$LINTVER-lint.txt"
17 changes: 0 additions & 17 deletions python-spec/write-version-file

This file was deleted.

0 comments on commit e935e28

Please sign in to comment.