From d2c0eceba5d5d1e469ae9bb3eb931d833806adf9 Mon Sep 17 00:00:00 2001 From: Ben Jeffery Date: Thu, 7 Sep 2023 13:55:32 +0100 Subject: [PATCH] Update packaging --- .circleci/config.yml | 15 +++--- .github/workflows/docker/buildwheel.sh | 21 --------- .github/workflows/docker/shared.env | 6 --- .github/workflows/wheels.yml | 45 +++++++++--------- .pre-commit-config.yaml | 12 ++--- pyproject.toml | 12 +++++ pytest.ini | 4 -- requirements.txt | 3 ++ setup.cfg | 63 ++++++++++++++++++++++++++ setup.py | 37 +-------------- tests/test_accuracy.py | 2 +- tsdate/prior.py | 1 - 12 files changed, 117 insertions(+), 104 deletions(-) delete mode 100644 .github/workflows/docker/buildwheel.sh delete mode 100644 .github/workflows/docker/shared.env create mode 100644 pyproject.toml delete mode 100644 pytest.ini create mode 100644 setup.cfg diff --git a/.circleci/config.yml b/.circleci/config.yml index 4384fa33..44caaab3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,7 +6,7 @@ orbs: jobs: build: docker: - - image: cimg/python:3.7 + - image: cimg/python:3.10.13 steps: - checkout - run: @@ -17,10 +17,6 @@ jobs: sudo apt-get install libgsl-dev # way to set path persistently https://circleci.com/docs/2.0/env-vars/#setting-path echo 'export PATH=/home/circleci/.local/bin:$PATH' >> $BASH_ENV - - run: - name: Compile Python - command: | - python setup.py build_ext --inplace - run: name: install dependencies command: | @@ -44,6 +40,13 @@ jobs: python -m pytest -vv -n0 --cov=tsdate --cov-report=xml --cov-branch tests environment: NUMBA_DISABLE_JIT: 1 - - codecov/upload: token: CODECOV_TOKEN + - run: + name: Build the distribution tarball. + command: | + python -m build + + + + diff --git a/.github/workflows/docker/buildwheel.sh b/.github/workflows/docker/buildwheel.sh deleted file mode 100644 index 8f2be044..00000000 --- a/.github/workflows/docker/buildwheel.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -DOCKER_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "$DOCKER_DIR/shared.env" - -set -e -x - -ARCH=`uname -p` -echo "arch=$ARCH" - -# We're running as root in the docker container so git commands issued by -# setuptools_scm will fail without this: -git config --global --add safe.directory /project -# Fetch the full history as we'll be missing tags otherwise. -git fetch --unshallow -for V in "${PYTHON_VERSIONS[@]}"; do - PYBIN=/opt/python/$V/bin - rm -rf build/ # Avoid lib build by narrow Python is used by wide python - $PYBIN/python setup.py bdist_wheel -done - -rm dist/*.tar.gz \ No newline at end of file diff --git a/.github/workflows/docker/shared.env b/.github/workflows/docker/shared.env deleted file mode 100644 index 6f613fb8..00000000 --- a/.github/workflows/docker/shared.env +++ /dev/null @@ -1,6 +0,0 @@ -PYTHON_VERSIONS=( - cp310-cp310 - cp39-cp39 - cp38-cp38 - cp37-cp37m -) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 337e1ca2..a1f64723 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -15,33 +15,29 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: true - - name: Set up Python 3.8 - uses: actions/setup-python@v2 + - name: Set up Python 3.10 + uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: "3.10" - name: Build sdist shell: bash run: | - python setup.py sdist + python -m pip install --upgrade build + python -m build - name: Upload sdist - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: sdist path: dist - - name: Build wheels in docker - shell: bash - run: | - docker run --rm -v `pwd`:/project -w /project quay.io/pypa/manylinux2010_x86_64 bash .github/workflows/docker/buildwheel.sh - - name: Upload Wheels - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: wheels path: dist @@ -54,11 +50,11 @@ jobs: python: [3.7, 3.8, 3.9, "3.10"] steps: - name: Download wheels - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: wheels - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python }} - name: Install wheel and test @@ -80,11 +76,11 @@ jobs: wordsize: [64] steps: - name: Download wheels - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: wheels - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python }} - name: Install wheel and test @@ -105,11 +101,11 @@ jobs: python: [3.7, 3.8, 3.9, "3.10"] steps: - name: Download wheels - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: wheels - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python }} - name: Install wheel and test @@ -126,21 +122,22 @@ jobs: PyPI_Upload: runs-on: ubuntu-latest needs: ['windows-test', 'OSX-test', 'manylinux-test'] + environment: release + permissions: + id-token: write steps: - name: Download all - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 - name: Move to dist run: | mkdir dist cp */*.{whl,gz} dist/. - name: Publish distribution to Test PyPI if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') - uses: pypa/gh-action-pypi-publish@master + uses: pypa/gh-action-pypi-publish@release/v1 with: - password: ${{ secrets.test_pypi_password }} repository_url: https://test.pypi.org/legacy/ - name: Publish distribution to PRODUCTION PyPI if: github.event_name == 'release' - uses: pypa/gh-action-pypi-publish@master - with: - password: ${{ secrets.pypi_password }} + uses: pypa/gh-action-pypi-publish@release/v1 + diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7119827c..3f717626 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.1.0 + rev: v4.4.0 hooks: - id: check-merge-conflict - id: debug-statements @@ -8,22 +8,22 @@ repos: - id: check-case-conflict - id: check-yaml - repo: https://github.com/asottile/reorder_python_imports - rev: v3.0.1 + rev: v3.10.0 hooks: - id: reorder-python-imports - repo: https://github.com/asottile/pyupgrade - rev: v2.31.1 + rev: v3.10.1 hooks: - id: pyupgrade args: [--py3-plus, --py37-plus] - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 23.7.0 hooks: - id: black language_version: python3 - repo: https://github.com/pycqa/flake8 - rev: 3.9.2 + rev: 6.1.0 hooks: - id: flake8 args: [--config=.flake8] - additional_dependencies: ["flake8-bugbear==22.3.23", "flake8-builtins==1.5.3"] + additional_dependencies: ["flake8-bugbear==23.7.10", "flake8-builtins==2.1.0"] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..6c6e4526 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,12 @@ +[build-system] +requires = [ + "setuptools>=42", + "setuptools_scm", + "wheel", + "oldest-supported-numpy" +] + +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +write_to = "tsdate/_version.py" \ No newline at end of file diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index 50b8418b..00000000 --- a/pytest.ini +++ /dev/null @@ -1,4 +0,0 @@ -[pytest] -addopts = -n 4 -testpaths = - tests diff --git a/requirements.txt b/requirements.txt index 92931223..73c66ced 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,3 +14,6 @@ pytest-xdist pytest-cov mpmath numdifftools +setuptools>=45 +twine +build diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..bcb28a0b --- /dev/null +++ b/setup.cfg @@ -0,0 +1,63 @@ +[metadata] +name = tsdate +author = Tskit Developers +author_email = admin@tskit.dev +license = MIT +description = Infer node ages from a tree sequence topology. +long_description = file: README.md +long_description_content_type = text/markdown +url = http://pypi.python.org/pypi/tsdate +project_urls = + Documentation = https://tsdate.readthedocs.io/en/latest/ + Changelog = https://github.com/tskit-dev/tsdate/blob/main/CHANGELOG.rst + Bug Tracker = https://github.com/tskit-dev/tsdate/issues + GitHub = https://github.com/tskit-dev/tsdate +classifiers = + Programming Language :: Python + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3 :: Only + License :: OSI Approved :: MIT License + Development Status :: 3 - Alpha + Environment :: Other Environment + Intended Audience :: Science/Research + Operating System :: POSIX + Operating System :: MacOS :: MacOS X + Operating System :: Microsoft :: Windows + Topic :: Scientific/Engineering + Topic :: Scientific/Engineering :: Bio-Informatics +keywords = + population genetics + tree sequence + ancestral recombination graph + evolutionary tree + inference + dating + tsdate +platforms = + POSIX + Windows + MacOS X + +[options] +packages = tsdate +python_requires = >=3.7 +include_package_data = True +install_requires = + numpy + tskit>=0.2.3 + scipy>1.2.3 + numba>=0.46.0 + tqdm + appdirs + +[options.entry_points] +console_scripts = + tsdate=tsdate.__main__:main + +[tool:pytest] +testpaths = + tests diff --git a/setup.py b/setup.py index 69b87657..19eaf782 100644 --- a/setup.py +++ b/setup.py @@ -1,41 +1,8 @@ from setuptools import setup -with open("README.md") as fh: - long_description = fh.read() - setup( + # The package name along with all the other metadata is specified in setup.cfg + # However, GitHub's dependency graph can't see the package unless we put this here. name="tsdate", - author="Anthony Wilder Wohns and Yan Wong", - author_email="awohns@gmail.com", - description="Infer node ages from a tree sequence topology", - long_description=long_description, packages=["tsdate"], - long_description_content_type="text/markdown", - url="http://pypi.python.org/pypi/tsdate", - python_requires=">=3.7", - entry_points={ - "console_scripts": [ - "tsdate=tsdate.__main__:main", - ] - }, - setup_requires=["setuptools_scm"], - install_requires=[ - "numpy", - "tskit>=0.2.3", - "scipy>1.2.3", - "numba>=0.46.0", - "tqdm", - "appdirs", - ], - project_urls={ - "Source": "https://github.com/awohns/tsdate", - "Bug Reports": "https://github.com/awohns/tsdate/issues", - }, - classifiers=[ - "Programming Language :: Python :: 3.7", - "License :: OSI Approved :: MIT License", - "Operating System :: MacOS :: MacOS X", - "Operating System :: POSIX", - ], - use_scm_version={"write_to": "tsdate/_version.py"}, ) diff --git a/tests/test_accuracy.py b/tests/test_accuracy.py index bd30ca55..b3a2563b 100644 --- a/tests/test_accuracy.py +++ b/tests/test_accuracy.py @@ -122,7 +122,7 @@ def test_basic( } expected = ts.nodes_time[nonsamples] - for (observed, src) in [ + for observed, src in [ (dts.nodes_time[nonsamples], "ts"), ([dts.node(i).metadata["mn"] for i in np.where(nonsamples)[0]], "unconstr"), ]: diff --git a/tsdate/prior.py b/tsdate/prior.py index 30370e67..f0ad2f9d 100644 --- a/tsdate/prior.py +++ b/tsdate/prior.py @@ -1044,7 +1044,6 @@ def __init__( allow_unary=False, progress=False, ): - if approximate_priors: if not approx_prior_size: approx_prior_size = 1000