diff --git a/python/google/__init__.py b/python/google/__init__.py deleted file mode 100644 index 558561412299..000000000000 --- a/python/google/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -try: - __import__('pkg_resources').declare_namespace(__name__) -except ImportError: - __path__ = __import__('pkgutil').extend_path(__path__, __name__) diff --git a/python/pyproject.toml b/python/pyproject.toml new file mode 100644 index 000000000000..0b91242b9cb3 --- /dev/null +++ b/python/pyproject.toml @@ -0,0 +1,43 @@ +[build-system] +requires = ["packaging", "setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "protobuf" +description = "Protocol Buffers are Google's data interchange format" +readme = "README.md" +requires-python = ">=3.8" +maintainers= [ + { email = "protobuf@googlegroups.com" } +] +license = { text = "BSD-3-Clause" } +classifiers = [ + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "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" +] +dependencies = [ + "numpy<=1.26.1", + "setuptools<=68.2.2" +] +dynamic = ["version"] + +[project.urls] +homepage = "https://developers.google.com/protocol-buffers/" +repository = "https://github.com/protocolbuffers/protobuf" +download = "https://github.com/protocolbuffers/protobuf/releases" + +[tool.setuptools.dynamic] +version = { attr = "google.protobuf.__init__.__version__" } + +[tool.setuptools.packages.find] +include = ["../src/google/protobuf.*"] +exclude = [ + "import_test_package", + "protobuf_distutils" +] diff --git a/python/requirements.txt b/python/requirements.txt deleted file mode 100644 index d568cc581e63..000000000000 --- a/python/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -numpy<=1.26.1 -setuptools<=68.2.2 diff --git a/python/setup.cfg b/python/setup.cfg deleted file mode 100644 index 2a9acf13daa9..000000000000 --- a/python/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[bdist_wheel] -universal = 1 diff --git a/python/setup.py b/python/setup.py index 329dece30655..6d6a5b847540 100755 --- a/python/setup.py +++ b/python/setup.py @@ -13,7 +13,6 @@ import fnmatch import glob import os -import pkg_resources import re import shutil import subprocess @@ -23,10 +22,11 @@ # pylint:disable=g-importing-member # pylint:disable=g-multiple-import -from setuptools import setup, Extension, find_packages - +from setuptools import setup, Extension from setuptools.command.build_ext import build_ext as _build_ext from setuptools.command.build_py import build_py as _build_py +from packaging import version + # Find the Protocol Compiler. if 'PROTOC' in os.environ and os.path.exists(os.environ['PROTOC']): @@ -47,21 +47,6 @@ protoc = shutil.which('protoc') -def GetVersion(): - """Reads and returns the version from google/protobuf/__init__.py. - - Do not import google.protobuf.__init__ directly, because an installed - protobuf library may be loaded instead. - - Returns: - The version. - """ - - with open(os.path.join('google', 'protobuf', '__init__.py')) as version_file: - exec(version_file.read(), globals()) # pylint:disable=exec-used - return __version__ # pylint:disable=undefined-variable - - def GenProto(source, require=True): """Generates a _pb2.py from the given .proto file. @@ -339,8 +324,7 @@ def HasLibraryDirsOpt(): # deployment target of macOS 10.9 or later, or iOS 7 or later. if sys.platform == 'darwin': mac_target = str(sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')) - if mac_target and (pkg_resources.parse_version(mac_target) < - pkg_resources.parse_version('10.9.0')): + if mac_target and (version.parse(mac_target) < version.parse('10.9.0')): os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.9' os.environ['_PYTHON_HOST_PLATFORM'] = re.sub( r'macosx-[0-9]+\.[0-9]+-(.+)', @@ -389,47 +373,12 @@ def HasLibraryDirsOpt(): ]) os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'cpp' - install_requires = [] - setup( - name='protobuf', - version=GetVersion(), - description='Protocol Buffers', - download_url='https://github.com/protocolbuffers/protobuf/releases', - long_description="Protocol Buffers are Google's data interchange format", - url='https://developers.google.com/protocol-buffers/', - project_urls={ - 'Source': 'https://github.com/protocolbuffers/protobuf', - }, - maintainer='protobuf@googlegroups.com', - maintainer_email='protobuf@googlegroups.com', - license='BSD-3-Clause', - classifiers=[ - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - # LINT.IfChange - # Remove importlib fallback path when we drop Python 3.8 support. - 'Programming Language :: Python :: 3.8', - # LINT.ThenChange(//depot/google3/google/protobuf/internal/test_util.py) - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Programming Language :: Python :: 3.12', - ], - namespace_packages=['google'], - packages=find_packages( - exclude=[ - 'import_test_package', - 'protobuf_distutils', - ], - ), test_suite='google.protobuf.internal', cmdclass={ 'build_py': BuildPyCmd, 'build_ext': BuildExtCmd, 'test_conformance': TestConformanceCmd, }, - install_requires=install_requires, ext_modules=ext_module_list, - python_requires='>=3.8', )