Skip to content

Commit

Permalink
Migrate to pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Apr 19, 2024
1 parent d0e1752 commit 9b587ec
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 125 deletions.
12 changes: 9 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ binary extension for your Python.

If it is unable to build a binary extension, it will use cffi ABI mode
instead and only needs the libvips shared library. This takes longer to
start up and is typically ~20% slower in execution. You can find out how
pyvips installed with ``pip show pyvips``.
start up and is typically ~20% slower in execution. You can find out if
API mode is being used with:

.. code-block:: python
import pyvips
print(pyvips.API_mode)
This binding passes the vips test suite cleanly and with no leaks under
python3 and pypy3 on Windows, macOS and Linux.
Expand Down Expand Up @@ -246,7 +252,7 @@ Update pypi package:

.. code-block:: shell
$ python3 setup.py sdist
$ python3 -m build --sdist
$ twine upload --repository pyvips dist/*
$ git tag -a v2.2.0 -m "as uploaded to pypi"
$ git push origin v2.2.0
Expand Down
93 changes: 93 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
[build-system]
requires = [
# First version of setuptools to support pyproject.toml configuration
"setuptools>=61.0.0",
"wheel",
# Must be kept in sync with `project.dependencies`
"cffi>=1.0.0",
"pkgconfig>=1.5",
]
build-backend = "setuptools.build_meta"

[project]
name = "pyvips"
authors = [
{name = "John Cupitt", email = "[email protected]"},
]
description = "binding for the libvips image processing library"
readme = "README.rst"
keywords = [
"image processing",
]
license = {text = "MIT"}
requires-python = ">=3.3"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Topic :: Multimedia :: Graphics",
"Topic :: Multimedia :: Graphics :: Graphics Conversion",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"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",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
# Must be kept in sync with `build-system.requires`
"cffi>=1.0.0",
]
dynamic = [
"version",
]

[project.urls]
changelog = "https://github.com/libvips/pyvips/blob/master/CHANGELOG.rst"
documentation = "https://libvips.github.io/pyvips/"
funding = "https://opencollective.com/libvips"
homepage = "https://github.com/libvips/pyvips"
issues = "https://github.com/libvips/pyvips/issues"
source = "https://github.com/libvips/pyvips"

[tool.setuptools]
# We try to compile as part of install, so we can't run in a ZIP
zip-safe = false
include-package-data = false

[tool.setuptools.dynamic]
version = {attr = "pyvips.version.__version__"}

[tool.setuptools.packages.find]
exclude = [
"doc*",
"examples*",
"tests*",
]

[project.optional-dependencies]
# All the following are used for our own testing
tox = ["tox"]
test = [
"pytest",
"pyperf",
]
sdist = ["build"]
doc = [
"sphinx",
"sphinx_rtd_theme",
]

[tool.pytest.ini_options]
norecursedirs = ["tests/helpers"]
2 changes: 1 addition & 1 deletion pyvips/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# user code can override this null handler
logger.addHandler(logging.NullHandler())

# pull in our module version number, see also setup.py
# pull in our module version number
from .version import __version__

# try to import our binary interface ... if that works, we are in API mode
Expand Down
2 changes: 1 addition & 1 deletion pyvips/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# this is execfile()d into setup.py imported into __init__.py
# this is used in pyproject.toml and imported into __init__.py
__version__ = '2.2.3'

__all__ = ['__version__']
5 changes: 0 additions & 5 deletions setup.cfg

This file was deleted.

126 changes: 11 additions & 115 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,126 +1,22 @@
"""a binding for the libvips image processing library
See:
https://github.com/libvips/pyvips
"""

# flake8: noqa

import sys
from codecs import open
from os import path

from setuptools import setup, find_packages
from distutils import log

here = path.abspath(path.dirname(__file__))

info = {}
with open(path.join(here, 'pyvips', 'version.py'), encoding='utf-8') as f:
exec(f.read(), info)

with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
long_description = f.read()

# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
pyvips_classifiers = [
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'Topic :: Multimedia :: Graphics',
'Topic :: Multimedia :: Graphics :: Graphics Conversion',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3'
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'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',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
]

setup_deps = [
'cffi>=1.0.0',
]

install_deps = [
'cffi>=1.0.0',
]

test_deps = [
'cffi>=1.0.0',
'pytest',
'pyperf',
]

extras = {
'test': test_deps,
'doc': ['sphinx', 'sphinx_rtd_theme'],
}

pyvips_packages = find_packages(exclude=['docs', 'tests', 'examples'])

sys.path.append(path.join(here, 'pyvips'))

def setup_API():
setup(
name='pyvips',
version=info['__version__'],
description='binding for the libvips image processing library, API mode',
long_description=long_description,
url='https://github.com/libvips/pyvips',
author='John Cupitt',
author_email='[email protected]',
license='MIT',
classifiers=pyvips_classifiers,
keywords='image processing',

packages=pyvips_packages,
setup_requires=setup_deps + ['pkgconfig>=1.5'],
cffi_modules=['pyvips/pyvips_build.py:ffibuilder'],
install_requires=install_deps + ['pkgconfig>=1.5'],
tests_require=test_deps,
extras_require=extras,

# we will try to compile as part of install, so we can't run in a zip
zip_safe=False,
)
from os import path
from setuptools import setup

def setup_ABI():
setup(
name='pyvips',
version=info['__version__'],
description='binding for the libvips image processing library, ABI mode',
long_description=long_description,
url='https://github.com/libvips/pyvips',
author='John Cupitt',
author_email='[email protected]',
license='MIT',
classifiers=pyvips_classifiers,
keywords='image processing',
base_dir = path.dirname(__file__)
src_dir = path.join(base_dir, 'pyvips')

packages=pyvips_packages,
setup_requires=setup_deps,
install_requires=install_deps,
tests_require=test_deps,
extras_require=extras,
)
# When executing the setup.py, we need to be able to import ourselves, this
# means that we need to add the pyvips/ directory to the sys.path.
sys.path.insert(0, src_dir)

# try to install in API mode first, then if that fails, fall back to ABI
# Try to install in API mode first, then if that fails, fall back to ABI

# API mode requires a working C compiler plus all the libvips headers whereas
# ABI only needs the libvips shared library to be on the system

try:
setup_API()
setup(cffi_modules=['pyvips/pyvips_build.py:ffibuilder'])
except Exception as e:
log.warn('Falling back to ABI mode. Details: {0}'.format(e))
setup_ABI()
print('Falling back to ABI mode. Details: {0}'.format(e))
setup()

0 comments on commit 9b587ec

Please sign in to comment.