Skip to content

Commit

Permalink
chore: migrate to hatch/hatchling, drop Python 2 support (#626)
Browse files Browse the repository at this point in the history
* Mark some TODOs; reword Ruff env description

* Hatchling as build backend, add missing metadata

* Mark wheel as py3 and above, support Python 3.8+

* Remove `setuptools`-specific files

* Add hatch and friends, modernise build command

* Drop dependence on `six`

* Drop dependence on `future`

* Pin NumPy <2 to allow the tests to pass

* Bump some GHA tools versions

* Bump to `setup-python` v5.1.1

* Preface command-line `tox` invocation with `python -m`

* Temporarily exclude PyPy3.10-Windows
  • Loading branch information
agriyakhetarpal authored Aug 13, 2024
1 parent c274f8a commit 7832b4b
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 52 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ jobs:
#- ruff
- package
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5.1.1
with:
python-version: '3.10'
- name: Install build tools
run: |
python -m pip install tox wheel
- name: Run ${{ matrix.env }}
run: tox -e ${{ matrix.env }}
run: python -m tox -e ${{ matrix.env }}
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5.1.1
with:
python-version: '3.10'
- name: Install build tools
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ jobs:
- platform: windows-latest
python-version: 'pypy-3.10'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5.1.1
with:
python-version: ${{ matrix.python-version }}
- name: Install Python build tools
run: python -m pip install tox wheel
- name: Run tests
run: tox run -e py
run: python -m tox run -e py
- name: Install Scipy prerequisites for Ubuntu
if: startsWith(matrix.platform, 'ubuntu')
run: sudo apt-get install libopenblas-dev
- name: Run tests with scipy
if: startsWith(matrix.platform, 'ubuntu') || startsWith(matrix.python-version, 'pypy') != true
run: tox run -e py-scipy
run: python -m tox run -e py-scipy
2 changes: 0 additions & 2 deletions MANIFEST.in

This file was deleted.

12 changes: 6 additions & 6 deletions autograd/builtins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from six import with_metaclass
from .util import subvals
from .extend import (Box, primitive, notrace_primitive, VSpace, vspace,
SparseObject, defvjp, defvjp_argnum, defjvp, defjvp_argnum)
Expand Down Expand Up @@ -86,24 +85,25 @@ def fwd_grad_make_sequence(argnum, g, ans, seq_type, *args, **kwargs):
defjvp_argnum(make_sequence, fwd_grad_make_sequence)


class TupleMeta(type_):
class TupleMeta(type(tuple_)):
def __instancecheck__(self, instance):
return isinstance(instance, tuple_)
class tuple(with_metaclass(TupleMeta, tuple_)):

class tuple(tuple_, metaclass=TupleMeta):
def __new__(cls, xs):
return make_sequence(tuple_, *xs)

class ListMeta(type_):
def __instancecheck__(self, instance):
return isinstance(instance, list_)
class list(with_metaclass(ListMeta, list_)):
class list(list_, metaclass=ListMeta):
def __new__(cls, xs):
return make_sequence(list_, *xs)
return make_sequence(list_, *xs)

class DictMeta(type_):
def __instancecheck__(self, instance):
return isinstance(instance, dict_)
class dict(with_metaclass(DictMeta, dict_)):
class dict(dict_, metaclass=DictMeta):
def __new__(cls, *args, **kwargs):
result = dict_(*args, **kwargs)
if result:
Expand Down
3 changes: 1 addition & 2 deletions autograd/numpy/numpy_vjps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import absolute_import
from six import string_types
from functools import partial
import numpy as onp
from ..util import func
Expand Down Expand Up @@ -588,7 +587,7 @@ def grad_einsum(argnum, ans, operands_, kwargs):
result_meta = anp.metadata(operands_[argnum])
def vjp(g):
operands = operands_
if isinstance(operands[0], string_types): # using "ijk" convention.
if isinstance(operands[0], str): # using "ijk" convention.
in_subs, out_subs, _ = anp.parse_einsum_input(*operands)
string, operands = operands[0], operands[1:]

Expand Down
6 changes: 3 additions & 3 deletions autograd/scipy/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from autograd.extend import primitive, defvjp

from numpy.lib.stride_tricks import as_strided
from six import iteritems


@primitive
def convolve(A, B, axes=None, dot_axes=[(),()], mode='full'):
Expand Down Expand Up @@ -79,8 +79,8 @@ def parse_axes(A_shape, B_shape, conv_axes, dot_axes, mode):
'conv' : tuple(range(i2, i3))}
conv_shape = (compute_conv_size(A_shape[i], B_shape[j], mode)
for i, j in zip(axes['A']['conv'], axes['B']['conv']))
shapes = {'A' : {s : (A_shape[i] for i in ax) for s, ax in iteritems(axes['A'])},
'B' : {s : (B_shape[i] for i in ax) for s, ax in iteritems(axes['B'])}}
shapes = {'A': {s: tuple(A_shape[i] for i in ax) for s, ax in axes['A'].items()},
'B': {s: tuple(B_shape[i] for i in ax) for s, ax in axes['B'].items()}}
shapes['out'] = {'ignore_A' : shapes['A']['ignore'],
'ignore_B' : shapes['B']['ignore'],
'conv' : conv_shape}
Expand Down
5 changes: 3 additions & 2 deletions conda_recipe/conda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ source:
requirements:
build:
- python
- setuptools
- hatch
- hatchling
- future
- numpy >=1.9

Expand All @@ -24,7 +25,7 @@ requirements:
- numpy >=1.9

build:
script: python setup.py build && python setup.py install
script: pip install . --no-deps

test:
# Python imports
Expand Down
3 changes: 0 additions & 3 deletions examples/data_mnist.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from __future__ import absolute_import
from __future__ import print_function
import sys
if sys.version < "3":
from future.standard_library import install_aliases
install_aliases()

import os
import gzip
Expand Down
38 changes: 15 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[build-system]
requires = ["setuptools>=44"]
build-backend = "setuptools.build_meta"
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "autograd"
version = "1.6.3"
description = "Efficiently computes derivatives of numpy code."
requires-python = ">=3.8"
description = "Efficiently computes derivatives of NumPy code."
readme = "README.md"
license = {file = "license.txt"}
authors = [
Expand All @@ -16,22 +17,20 @@ authors = [
]
maintainers = [
{name = "Jamie Townsend", email = "[email protected]"},
{name = "Fabian Joswig", email = "[email protected]"},
{name = "Agriya Khetarpal", email = "[email protected]"},
]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Information Technology",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering",
]
keywords = [
"Automatic differentiation",
Expand All @@ -41,14 +40,16 @@ keywords = [
"optimization",
"neural networks",
"Python",
"Numpy",
"Scipy",
"NumPy",
"SciPy",
]
dependencies = [
"numpy>=1.12",
"six",
"future>=0.15.2; python_version < '3'",
"numpy<2",
]
# dynamic = ["version"]

[project.urls]
Source = "https://github.com/HIPS/autograd"

[project.optional-dependencies]
scipy = [
Expand All @@ -69,12 +70,3 @@ extend-exclude = []
extend-ignore = ["E731"]
extend-select = ["I", "W"]
line-length = 109

[tool.setuptools]
packages=[
"autograd",
"autograd.numpy",
"autograd.scipy",
"autograd.scipy.stats",
"autograd.misc",
]
6 changes: 4 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Tox (https://tox.wiki/) - run tests in isolation using virtualenv.
# Also contains config settings for tools that don't look into pyproject.toml.

# TODO: Migrate to tool.hatch.run or noxfile.py

[tox]
envlist =
ruff
Expand Down Expand Up @@ -33,10 +35,10 @@ deps = pyclean
commands = pyclean {posargs:. --debris --erase junit-report.xml --yes}

[testenv:ruff]
description = Lightening-fast linting for Python
description = Lightning-fast linting for Python
skip_install = true
deps = ruff
commands = ruff {posargs:.}
commands = ruff check {posargs:.} # TODO: Fix style failures

[testenv:package]
description = Build package and check metadata (or upload package)
Expand Down

0 comments on commit 7832b4b

Please sign in to comment.