Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate to hatch + use hatchling for the build backend, drop Python 2 support #626

Merged
merged 12 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 8 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,22 @@ jobs:
- '3.12'
- pypy-3.9
- pypy-3.10
# TODO: bring this back later
exclude:
- 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 = "j.h.n.townsend@uva.nl"},
{name = "Fabian Joswig", email = "fabian.joswig@uni-muenster.de"},
{name = "Agriya Khetarpal", email = "agriyakhetarpal@outlook.com"},
]
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