From 169750d061bcdf267d6ccf27b97e153c0eee62aa Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Tue, 9 Jul 2024 20:11:37 +0300 Subject: [PATCH 1/4] pyproject: move project metadata and remove setup.py --- pyproject.toml | 114 ++++++++++++++++++++++++++++++++++++++++--------- setup.py | 53 ----------------------- 2 files changed, 93 insertions(+), 74 deletions(-) delete mode 100644 setup.py diff --git a/pyproject.toml b/pyproject.toml index 37727dab..10dba60a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,77 @@ +[build-system] +build-backend = "setuptools.build_meta" +requires = [ + "setuptools>=63", +] + +[project] +name = "arraycontext" +version = "2021.1" +description = "Choose your favorite numpy-workalike" +readme = "README.rst" +license = { text = "MIT" } +authors = [ + { name = "Andreas Kloeckner", email = "inform@tiker.net" }, +] +requires-python = ">=3.8" +classifiers = [ + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Intended Audience :: Other Audience", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: MIT License", + "Natural Language :: English", + "Programming Language :: Python", + "Programming Language :: Python :: 3 :: Only", + "Topic :: Scientific/Engineering", + "Topic :: Scientific/Engineering :: Information Analysis", + "Topic :: Scientific/Engineering :: Mathematics", + "Topic :: Software Development :: Libraries", + "Topic :: Utilities", +] +dependencies = [ + "immutabledict>=4.1", + "numpy", + "pytools>=2024.1.3", +] + +[project.optional-dependencies] +jax = [ + "jax>=0.4", +] +pyopencl = [ + "islpy>=2024.1", + "loopy>=2024.1", + "pyopencl>=2024.1", +] +pytato = [ + "pytato>=2021.1", +] +test = [ + "mypy", + "pytest", + "ruff", +] + +[project.urls] +Documentation = "https://documen.tician.de/arraycontext" +Homepage = "https://github.com/inducer/arraycontext" + +[tool.setuptools.packages.find] +include = [ + "arraycontext*", +] + +[tool.setuptools.package-dir] +# https://github.com/Infleqtion/client-superstaq/pull/715 +"" = "." + +[tool.setuptools.package-data] +pytools = [ + "py.typed", +] + [tool.ruff] -target-version = "py38" preview = true [tool.ruff.lint] @@ -13,15 +85,15 @@ extend-select = [ "N", # pep8-naming "NPY", # numpy "Q", # flake8-quotes - "UP", # pyupgrade "RUF", # ruff + "UP", # pyupgrade "W", # pycodestyle ] extend-ignore = [ - "C90", # McCabe complexity - "E221", # multiple spaces before operator - "E226", # missing whitespace around arithmetic operator - "E402", # module-level import not at top of file + "C90", # McCabe complexity + "E221", # multiple spaces before operator + "E226", # missing whitespace around arithmetic operator + "E402", # module-level import not at top of file "UP006", # updated annotations due to __future__ import "UP007", # updated annotations due to __future__ import ] @@ -33,15 +105,17 @@ multiline-quotes = "double" [tool.ruff.lint.isort] combine-as-imports = true +known-first-party = [ + "jax", + "loopy", + "pymbolic", + "pyopencl", + "pytato", + "pytools", +] known-local-folder = [ "arraycontext", ] -known-first-party = [ - "pytools", - "pyopencl", - "pytato", - "loopy", -] lines-after-imports = 2 [tool.mypy] @@ -51,15 +125,13 @@ warn_unused_ignores = true # check_untyped_defs = true [[tool.mypy.overrides]] - module = [ - "islpy", - "loopy.*", - "meshmode.*", - "pymbolic", - "pymbolic.*", - "pyopencl.*", - "jax.*", + "islpy.*", + "loopy.*", + "meshmode.*", + "pymbolic", + "pymbolic.*", + "pyopencl.*", + "jax.*", ] - ignore_missing_imports = true diff --git a/setup.py b/setup.py deleted file mode 100644 index 65905265..00000000 --- a/setup.py +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env python - - -def main(): - from setuptools import find_packages, setup - - version_dict = {} - init_filename = "arraycontext/version.py" - exec( - compile(open(init_filename).read(), init_filename, "exec"), version_dict - ) - - setup( - name="arraycontext", - version=version_dict["VERSION_TEXT"], - description="Choose your favorite numpy-workalike", - long_description=open("README.rst").read(), - author="Andreas Kloeckner", - author_email="inform@tiker.net", - license="MIT", - url="https://documen.tician.de/arraycontext", - classifiers=[ - "Development Status :: 3 - Alpha", - "Intended Audience :: Developers", - "Intended Audience :: Other Audience", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: MIT License", - "Natural Language :: English", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Topic :: Scientific/Engineering", - "Topic :: Scientific/Engineering :: Information Analysis", - "Topic :: Scientific/Engineering :: Mathematics", - "Topic :: Software Development :: Libraries", - "Topic :: Utilities", - ], - packages=find_packages(), - python_requires="~=3.8", - install_requires=[ - "numpy", - "pytools>=2024.1.3", - "immutabledict", - "loopy>=2019.1", - ], - extras_require={ - "test": ["pytest>=2.3"], - }, - package_data={"arraycontext": ["py.typed"]}, - ) - - -if __name__ == "__main__": - main() From 94df62c43ca143f55a144efd55fb8f4ebc189eb8 Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Tue, 9 Jul 2024 20:15:54 +0300 Subject: [PATCH 2/4] version: use importlib --- arraycontext/version.py | 17 +++++++++++++++-- doc/conf.py | 9 +++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/arraycontext/version.py b/arraycontext/version.py index 30c96291..a1da82c1 100644 --- a/arraycontext/version.py +++ b/arraycontext/version.py @@ -1,2 +1,15 @@ -VERSION = (2021, 1) -VERSION_TEXT = ".".join(str(i) for i in VERSION) +from importlib import metadata +from typing import Tuple + + +def _parse_version(version: str) -> Tuple[Tuple[int, ...], str]: + import re + + m = re.match("^([0-9.]+)([a-z0-9]*?)$", VERSION_TEXT) + assert m is not None + + return tuple([int(nr) for nr in m.group(1).split(".")]), m.group(2) + + +VERSION_TEXT = metadata.version("arraycontext") +VERSION, VERSION_STATUS = _parse_version(VERSION_TEXT) diff --git a/doc/conf.py b/doc/conf.py index 13c8dd20..0ba49301 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -1,3 +1,4 @@ +from importlib import metadata from urllib.request import urlopen @@ -8,12 +9,8 @@ copyright = "2021, University of Illinois Board of Trustees" author = "Arraycontext Contributors" - -ver_dic = {} -exec(compile(open("../arraycontext/version.py").read(), "../arraycontext/version.py", - "exec"), ver_dic) -version = ".".join(str(x) for x in ver_dic["VERSION"]) -release = ver_dic["VERSION_TEXT"] +release = metadata.version("arraycontext") +version = ".".join(release.split(".")[:2]) intersphinx_mapping = { "jax": ("https://jax.readthedocs.io/en/latest/", None), From 691541f2ea00090ec4c6dcf54bfa729feaa371b6 Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Tue, 9 Jul 2024 20:20:05 +0300 Subject: [PATCH 3/4] update MANIFEST.in --- MANIFEST.in | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index 5ced3216..1cd7e74e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,5 +2,9 @@ include doc/*.rst include doc/conf.py include doc/make.bat include doc/Makefile +prune doc/_* -include examples/*.py +prune .github +exclude .gitignore +exclude .gitlab-ci.yml +exclude .test-conda-env-py3.yml From 97805349054eb82e67eb9758c50f59771d1b2ad9 Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Tue, 9 Jul 2024 20:26:24 +0300 Subject: [PATCH 4/4] isort: add jax as a first-party --- arraycontext/impl/jax/fake_numpy.py | 3 ++- arraycontext/impl/pytato/__init__.py | 3 --- arraycontext/pytest.py | 1 - 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/arraycontext/impl/jax/fake_numpy.py b/arraycontext/impl/jax/fake_numpy.py index 662b86c0..6c9192ba 100644 --- a/arraycontext/impl/jax/fake_numpy.py +++ b/arraycontext/impl/jax/fake_numpy.py @@ -23,9 +23,10 @@ """ from functools import partial, reduce -import jax.numpy as jnp import numpy as np +import jax.numpy as jnp + from arraycontext.container import NotAnArrayContainerError, serialize_container from arraycontext.container.traversal import ( rec_map_array_container, diff --git a/arraycontext/impl/pytato/__init__.py b/arraycontext/impl/pytato/__init__.py index 6e04bdcd..c030de71 100644 --- a/arraycontext/impl/pytato/__init__.py +++ b/arraycontext/impl/pytato/__init__.py @@ -720,7 +720,6 @@ def __init__(self, unstable. """ import jax.numpy as jnp - import pytato as pt super().__init__(compile_trace_callback=compile_trace_callback) self.array_types = (pt.Array, jnp.ndarray) @@ -766,7 +765,6 @@ def zeros_like(self, ary): def from_numpy(self, array): import jax - import pytato as pt def _from_numpy(ary): @@ -791,7 +789,6 @@ def freeze(self, array): return array import jax.numpy as jnp - import pytato as pt from arraycontext.container.traversal import rec_keyed_map_array_container diff --git a/arraycontext/pytest.py b/arraycontext/pytest.py index 3ea7d065..d3d719e5 100644 --- a/arraycontext/pytest.py +++ b/arraycontext/pytest.py @@ -206,7 +206,6 @@ def __init__(self, *args, **kwargs): def is_available(cls) -> bool: try: import jax # noqa: F401 - import pytato # noqa: F401 return True except ImportError: