From be28903be7e91e0819a93b7fe57474cbfdbcd47c Mon Sep 17 00:00:00 2001 From: gnzng Date: Mon, 10 Nov 2025 12:23:09 -0800 Subject: [PATCH] refactor: CI installation process to use 'uv' for faster dependency management --- .github/workflows/main.yml | 21 ++++++++------- .github/workflows/publish.yml | 12 +++++---- pyproject.toml | 50 +++++++++++++++++++++++++++++++++- requirements.txt | 11 -------- setup.py | 51 ----------------------------------- 5 files changed, 67 insertions(+), 78 deletions(-) delete mode 100644 requirements.txt delete mode 100644 setup.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5cc6d9b..84f4a00 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,14 +22,15 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Install dependencies + - name: Install uv run: | - pip install --upgrade pip - pip install -r requirements.txt - pip install -e . --no-deps + pip install uv + - name: Install dependencies with uv + run: | + uv pip install ."[tests]" - name: Run tests - run: pytest + run: python -m pytest build-docs: if: github.event_name == 'push' && github.ref == 'refs/heads/master' @@ -52,12 +53,12 @@ jobs: with: python-version: '3.9' - - name: Install dependencies + - name: Install uv run: | - pip install --upgrade pip - pip install -r requirements.txt - pip install sphinx sphinx_rtd_theme sphinx-argparse - pip install -e . --no-deps + pip install uv + - name: Install dependencies with uv + run: | + uv pip install ."[docs]"" - name: Build docs working-directory: docs diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8ff3518..dbb1a1a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -19,12 +19,14 @@ jobs: uses: actions/setup-python@v4 with: python-version: "3.x" - - name: Install dependencies + - name: Install uv run: | - python -m pip install --upgrade pip - pip install setuptools wheel - - name: Build package (setup.py) + pip install uv + - name: Install project with uv run: | - python setup.py sdist bdist_wheel + uv pip install -e . + - name: Build package with uv + run: | + uv build - name: Publish package distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index b7fd46a..703942e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,51 @@ +[build-system] +requires = ["setuptools>=61.0", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "cdtools-py" +description = "Tools for coherent diffractive imaging and ptychography" +readme = "README.md" +requires-python = ">=3.8" +license = { file = "LICENSE.txt" } +authors = [ + { name = "Abe Levitan", email = "abraham.levitan@psi.ch" }, + { name = "Madelyn Cain" }, + { name = "Anastasiia Kutakh" } +] +maintainers = [ + { name = "Abe Levitan", email = "abraham.levitan@psi.ch" } +] +keywords = ["ptychography", "CDI", "imaging", "torch", "differentiable"] +classifiers = [ + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", + "License :: OSI Approved :: MIT License" +] +urls = { "Homepage" = "https://github.com/cdtools-developers/cdtools", "Documentation" = "https://cdtools-developers.github.io/cdtools/" } +dependencies = [ + "numpy>=1.0", + "scipy>=1.0", + "matplotlib>=2.0", + "torch>=2.3.0", + "h5py>=2.1", + "python-dateutil", +] +dynamic = ["version"] + +[tool.setuptools.dynamic] +version = {attr = "cdtools._version.__version__"} + +[project.optional-dependencies] +tests = [ + "pytest", + "pooch" +] +docs = [ + "sphinx>=4.3.0", + "sphinx-argparse", + "sphinx_rtd_theme>=0.5.1" +] + [tool.ruff] -# Decrease the maximum line length to 79 characters. line-length = 79 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 1c584c8..0000000 --- a/requirements.txt +++ /dev/null @@ -1,11 +0,0 @@ -numpy>=1.0 -scipy>=1.0 -matplotlib>=2.0 # 2.0 introduces better colormaps which are used by default -torch>=1.9.0 #1.9.0 implements support for autograd on indexed complex tensors -h5py>=2.1 -python-dateutil -pytest -pooch -sphinx>=4.3.0 # Fixes a bug with bulleted lists -sphinx-argparse -sphinx_rtd_theme>=0.5.1 # Fixes a bug with bulleted lists diff --git a/setup.py b/setup.py deleted file mode 100644 index ae710d7..0000000 --- a/setup.py +++ /dev/null @@ -1,51 +0,0 @@ -import setuptools -import os -import re - -with open("README.md", "r") as fh: - long_description = fh.read() - -# read version from src/cdtools/_version.py -version_file = os.path.join("src/cdtools", "_version.py") -with open(version_file) as f: - version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", f.read(), re.M) -if not version_match: - raise RuntimeError("Unable to find version string.") -version = version_match.group(1) - -setuptools.setup( - name="cdtools-py", - version=version, - python_requires='>3.8', # recommended minimum version for pytorch 2.3.0 - author="Abe Levitan", - author_email="abraham.levitan@psi.ch", - description="Tools for coherent diffractive imaging and ptychography", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/cdtools-developers/cdtools", - install_requires=[ - "numpy>=1.0", - "scipy>=1.0", - "matplotlib>=2.0", # 2.0 has better colormaps which are used by default - "python-dateutil", - "torch>=2.3.0", #2.3.0 is the earliest release for which L-BFGS works directly on complex-valued leaf tensors - "h5py>=2.1"], - extras_require={ - 'tests': [ - "pytest", - "pooch", - ], - 'docs': [ - "sphinx>=4.3.0", - "sphinx-argparse", - "sphinx_rtd_theme>=0.5.1" - ] - }, - package_dir={"": "src"}, - packages=setuptools.find_packages("src"), - classifiers=[ - "Programming Language :: Python :: 3", - "Operating System :: OS Independent", - ], -) -