From e45901064ced9d5010c4637d220afa0a93ba4ffa Mon Sep 17 00:00:00 2001 From: nicoco Date: Wed, 19 Jul 2023 20:25:47 +0200 Subject: [PATCH] replace setup.py and mypy.ini with pyproject.toml --- _custom_build.py | 50 +++++++++++++++++++++++ mypy.ini | 15 ------- pyproject.toml | 67 ++++++++++++++++++++++++++++++ setup.py | 103 ----------------------------------------------- 4 files changed, 117 insertions(+), 118 deletions(-) create mode 100644 _custom_build.py delete mode 100644 mypy.ini create mode 100644 pyproject.toml delete mode 100755 setup.py diff --git a/_custom_build.py b/_custom_build.py new file mode 100644 index 00000000..47f24904 --- /dev/null +++ b/_custom_build.py @@ -0,0 +1,50 @@ +""" +Cythonize the .pyx file for sdist, and compile it for wheels. +NB: produced wheels are not valid, but the sdist should be. +""" + +import os +from Cython.Build import cythonize +from subprocess import check_output, CalledProcessError, DEVNULL, call +from tempfile import TemporaryFile + +from setuptools.command.build_py import build_py + + +def check_include(library_name, header): + command = [os.environ.get("PKG_CONFIG", "pkg-config"), "--cflags", library_name] + try: + cflags = check_output(command).decode("utf-8").split() + except FileNotFoundError: + print("pkg-config not found.") + return False + except CalledProcessError: + # pkg-config already prints the missing libraries on stderr. + return False + command = [os.environ.get("CC", "cc")] + cflags + ["-E", "-"] + with TemporaryFile("w+") as c_file: + c_file.write("#include <%s>" % header) + c_file.seek(0) + try: + return call(command, stdin=c_file, stdout=DEVNULL, stderr=DEVNULL) == 0 + except FileNotFoundError: + print("%s headers not found." % library_name) + return False + + +class Build(build_py): + def run(self): + self.run_command("build_ext") + return super().run() + + def initialize_options(self): + super().initialize_options() + + has_python_headers = check_include("python3", "Python.h") + has_stringprep_headers = check_include("libidn", "stringprep.h") + + if has_python_headers and has_stringprep_headers: + self.distribution.ext_modules = cythonize("slixmpp/stringprep.pyx") + + else: + print("Falling back to the slow stringprep module.") diff --git a/mypy.ini b/mypy.ini deleted file mode 100644 index edf0d65f..00000000 --- a/mypy.ini +++ /dev/null @@ -1,15 +0,0 @@ -[mypy] -check_untyped_defs = False -ignore_missing_imports = True - -[mypy-slixmpp.types] -ignore_errors = True - -[mypy-slixmpp.thirdparty.*] -ignore_errors = True - -[mypy-slixmpp.plugins.*] -ignore_errors = True - -[mypy-slixmpp.plugins.base] -ignore_errors = False diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..82250841 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,67 @@ +[project] +name = "slixmpp" +version = "1.8.4" +description = 'Slixmpp is an elegant Python library for XMPP (aka Jabber).' +requires-python = ">=3.7" +dependencies = [ + "aiodns >= 1.0", + "pyasn1", + "pyasn1_modules", + "typing_extensions; python_version < '3.8.0'", +] +classifiers = [ + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Topic :: Internet :: XMPP', + 'Topic :: Software Development :: Libraries :: Python Modules', +] +readme = "README.rst" +license = { file = "LICENSE" } + +[[project.authors]] +name = "Florent Le Coz" +email = "louiz@louiz.org" + +[project.urls] +Repository = 'https://codeberg.org/poezio/slixmpp' + +[project.optional-dependencies] +XEP-0363 = ['aiohttp'] +XEP-0444 = ['emoji'] +XEP-0454 = ['cryptography'] +Safer-XML-parsing = ['defusedxml'] + +[build-system] +requires = ["setuptools", "cython"] +build-backend = "setuptools.build_meta" + +[tool.setuptools] +packages = ["slixmpp"] +py-modules = ["_custom_build"] + +[tool.setuptools.cmdclass] +build_py = "_custom_build.Build" + +[tool.mypy] +check_untyped_defs = false +ignore_missing_imports = true + +[[tool.mypy.overrides]] +module = 'slixmpp.types' +ignore_errors = true + +[[tool.mypy.overrides]] +module = 'slixmpp.thirdparty.*' +ignore_errors = true + +[[tool.mypy.overrides]] +module = 'slixmpp.plugins.*' +ignore_errors = true + +[[tool.mypy.overrides]] +module = 'slixmpp.plugins.base' +ignore_errors = false \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100755 index 1b32cba4..00000000 --- a/setup.py +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# Copyright (C) 2007-2011 Nathanael C. Fritz -# All Rights Reserved -# -# This software is licensed as described in the README.rst and LICENSE -# file, which you should have received as part of this distribution. - -import runpy -import os -from pathlib import Path -from subprocess import call, DEVNULL, check_output, CalledProcessError -from tempfile import TemporaryFile -try: - from setuptools import setup -except ImportError: - from distutils.core import setup - -from run_tests import TestCommand - -version_mod = runpy.run_path('slixmpp/version.py') -VERSION = version_mod['__version__'] - -DESCRIPTION = ('Slixmpp is an elegant Python library for XMPP (aka Jabber).') -with open('README.rst', encoding='utf8') as readme: - LONG_DESCRIPTION = readme.read() - -CLASSIFIERS = [ - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Topic :: Internet :: XMPP', - 'Topic :: Software Development :: Libraries :: Python Modules', -] - -packages = [str(mod.parent) for mod in Path('slixmpp').rglob('__init__.py')] - -def check_include(library_name, header): - command = [os.environ.get('PKG_CONFIG', 'pkg-config'), '--cflags', library_name] - try: - cflags = check_output(command).decode('utf-8').split() - except FileNotFoundError: - print('pkg-config not found.') - return False - except CalledProcessError: - # pkg-config already prints the missing libraries on stderr. - return False - command = [os.environ.get('CC', 'cc')] + cflags + ['-E', '-'] - with TemporaryFile('w+') as c_file: - c_file.write('#include <%s>' % header) - c_file.seek(0) - try: - return call(command, stdin=c_file, stdout=DEVNULL, stderr=DEVNULL) == 0 - except FileNotFoundError: - print('%s headers not found.' % library_name) - return False - -HAS_PYTHON_HEADERS = check_include('python3', 'Python.h') -HAS_STRINGPREP_HEADERS = check_include('libidn', 'stringprep.h') - -ext_modules = None -if HAS_PYTHON_HEADERS and HAS_STRINGPREP_HEADERS: - try: - from Cython.Build import cythonize - except ImportError: - print('Cython not found, falling back to the slow stringprep module.') - else: - ext_modules = cythonize('slixmpp/stringprep.pyx') -else: - print('Falling back to the slow stringprep module.') - -setup( - name="slixmpp", - version=VERSION, - description=DESCRIPTION, - long_description=LONG_DESCRIPTION, - author='Florent Le Coz', - author_email='louiz@louiz.org', - url='https://codeberg.org/poezio/slixmpp', - license='MIT', - platforms=['any'], - package_data={'slixmpp': ['py.typed']}, - packages=packages, - ext_modules=ext_modules, - install_requires=[ - 'aiodns>=1.0', - 'pyasn1', - 'pyasn1_modules', - 'typing_extensions; python_version < "3.8.0"', - ], - extras_require={ - 'XEP-0363': ['aiohttp'], - 'XEP-0444 compliance': ['emoji'], - 'XEP-0454': ['cryptography'], - 'Safer XML parsing': ['defusedxml'], - }, - classifiers=CLASSIFIERS, - cmdclass={'test': TestCommand} -)