jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/995443?usp=email )

Change subject: [dist] use pyproject.toml for distribution setup
......................................................................

[dist] use pyproject.toml for distribution setup

- move information fields from setup.py to pyproject.toml
- add tomli to docs requirements and use that package to read the
  pyproject.toml within docs.conf.py
- remove fields from __meta__ which are in pyproject.toml
- only support __copyright__', '__url__', '__version__ with pywikibot
  and drop support for the others
- read the project name within setup.py using ConfigParser
  and add test for this function

Change-Id: Iae9643f3fe49a41e1997790b8c4bec5ef1616b36
---
M docs/conf.py
M docs/requirements.txt
M pyproject.toml
M pywikibot/__init__.py
M pywikibot/__metadata__.py
M setup.py
M tests/setup_tests.py
7 files changed, 197 insertions(+), 164 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved




diff --git a/docs/conf.py b/docs/conf.py
index 5ca8569..395e968 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -1,6 +1,6 @@
 """Configuration file for Sphinx."""
 #
-# (C) Pywikibot team, 2014-2023
+# (C) Pywikibot team, 2014-2024
 #
 # Distributed under the terms of the MIT license.
 #
@@ -24,6 +24,7 @@
 import os
 import re
 import sys
+import tomli
 import warnings
 from pathlib import Path

@@ -78,9 +79,13 @@
 root_doc = 'index'

 # General information about the project.
-project = pywikibot.__name__.title()
+filepath = Path().absolute().parent / 'pyproject.toml'
+with open(filepath, 'rb') as f:
+    meta_data = tomli.load(f)
+
+project = meta_data['project']['name'].title()
 project_copyright = pywikibot.__copyright__  # alias since Python 3.5
-author = 'Pywikibot Team'
+author = meta_data['project']['maintainers'][0]['name']

 # The version info for the project you're documenting, acts as replacement for
 # |version| and |release|, also used in various other places throughout the
diff --git a/docs/requirements.txt b/docs/requirements.txt
index 0052ead..d55a081 100644
--- a/docs/requirements.txt
+++ b/docs/requirements.txt
@@ -6,3 +6,4 @@
 sphinxext-opengraph >= 0.9.0
 sphinx-notfound-page >= 1.0.0
 furo >= 2023.9.10
+tomli
diff --git a/pyproject.toml b/pyproject.toml
index e94bba3..3c8eb7f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,2 +1,127 @@
 [build-system]
-requires = ["packaging", "setuptools", "wheel"]
\ No newline at end of file
+requires = ["packaging", "setuptools", "wheel"]
+build-backend = "setuptools.build_meta"
+
+
+[project]
+name = "pywikibot"
+
+##############################################################
+# Keep this file readable for all entries above this comment #
+##############################################################
+
+authors = [
+    {name = "xqt", email = "[email protected]"},
+]
+maintainers = [
+    {name = "The Pywikibot team", email = "[email protected]"},
+]
+description = "Python MediaWiki Bot Framework"
+requires-python = ">=3.7.0"
+keywords = [
+    "API", "bot", "client", "framework", "mediawiki", "pwb", "pybot", "python",
+    "pywiki", "pywikibase", "pywikibot", "pywikipedia", "pywikipediabot",
+    "wiki", "wikibase", "wikidata", "wikimedia", "wikipedia",
+]
+license = {text = "MIT License"}
+classifiers=[
+    "Development Status :: 5 - Production/Stable",
+    "Environment :: Console",
+    "Intended Audience :: Developers",
+    "License :: OSI Approved :: MIT License",
+    "Natural Language :: Afrikaans",
+    "Natural Language :: Arabic",
+    "Natural Language :: Basque",
+    "Natural Language :: Bengali",
+    "Natural Language :: Bosnian",
+    "Natural Language :: Bulgarian",
+    "Natural Language :: Cantonese",
+    "Natural Language :: Catalan",
+    "Natural Language :: Chinese (Simplified)",
+    "Natural Language :: Chinese (Traditional)",
+    "Natural Language :: Croatian",
+    "Natural Language :: Czech",
+    "Natural Language :: Danish",
+    "Natural Language :: Dutch",
+    "Natural Language :: English",
+    "Natural Language :: Esperanto",
+    "Natural Language :: Finnish",
+    "Natural Language :: French",
+    "Natural Language :: Galician",
+    "Natural Language :: German",
+    "Natural Language :: Greek",
+    "Natural Language :: Hebrew",
+    "Natural Language :: Hindi",
+    "Natural Language :: Hungarian",
+    "Natural Language :: Icelandic",
+    "Natural Language :: Indonesian",
+    "Natural Language :: Irish",
+    "Natural Language :: Italian",
+    "Natural Language :: Japanese",
+    "Natural Language :: Javanese",
+    "Natural Language :: Korean",
+    "Natural Language :: Latin",
+    "Natural Language :: Latvian",
+    "Natural Language :: Lithuanian",
+    "Natural Language :: Macedonian",
+    "Natural Language :: Malay",
+    "Natural Language :: Marathi",
+    "Natural Language :: Nepali",
+    "Natural Language :: Norwegian",
+    "Natural Language :: Panjabi",
+    "Natural Language :: Persian",
+    "Natural Language :: Polish",
+    "Natural Language :: Portuguese",
+    "Natural Language :: Portuguese (Brazilian)",
+    "Natural Language :: Romanian",
+    "Natural Language :: Russian",
+    "Natural Language :: Serbian",
+    "Natural Language :: Slovak",
+    "Natural Language :: Slovenian",
+    "Natural Language :: Spanish",
+    "Natural Language :: Swedish",
+    "Natural Language :: Tamil",
+    "Natural Language :: Telugu",
+    "Natural Language :: Thai",
+    "Natural Language :: Tibetan",
+    "Natural Language :: Turkish",
+    "Natural Language :: Ukrainian",
+    "Natural Language :: Urdu",
+    "Natural Language :: Vietnamese",
+    "Operating System :: OS Independent",
+    "Programming Language :: Python",
+    "Programming Language :: Python :: 3",
+    "Programming Language :: Python :: 3 :: Only",
+    "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 :: 3.13",
+    "Programming Language :: Python :: Implementation :: CPython",
+    "Programming Language :: Python :: Implementation :: PyPy",
+    "Topic :: Internet :: WWW/HTTP :: Dynamic Content :: Wiki",
+    "Topic :: Software Development :: Libraries :: Python Modules",
+    "Topic :: Utilities",
+]
+dynamic = [
+    "dependencies",
+    "optional-dependencies",
+    "readme",
+    "version",
+]
+
+
+[project.scripts]
+pwb = "pywikibot.scripts.wrapper:run"
+
+
+[project.urls]
+Homepage = "https://www.mediawiki.org/wiki/Manual:Pywikibot";
+Documentation = "https://doc.wikimedia.org/pywikibot/stable/";
+Repository = "https://gerrit.wikimedia.org/r/plugins/gitiles/pywikibot/core/";
+"GitHub Mirror" = "https://github.com/wikimedia/pywikibot";
+Download = "https://www.pywikibot.org";
+Changelog = "https://doc.wikimedia.org/pywikibot/master/changelog.html";
+Tracker = "https://phabricator.wikimedia.org/tag/pywikibot/";
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 4fc3a17..0639acd 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -20,17 +20,7 @@

 from pywikibot import config as _config
 from pywikibot import exceptions
-from pywikibot.__metadata__ import (
-    __copyright__,
-    __description__,
-    __download_url__,
-    __license__,
-    __maintainer__,
-    __maintainer_email__,
-    __name__,
-    __url__,
-    __version__,
-)
+from pywikibot.__metadata__ import __copyright__, __url__, __version__
 from pywikibot._wbtypes import (
     Coordinate,
     WbGeoShape,
@@ -77,9 +67,7 @@


 __all__ = (
-    '__copyright__', '__description__', '__download_url__', '__license__',
-    '__maintainer__', '__maintainer_email__', '__name__', '__url__',
-    '__version__',
+    '__copyright__', '__url__', '__version__',
     'async_manager', 'async_request', 'Bot', 'calledModuleName', 'Category',
     'Claim', 'Coordinate', 'critical', 'CurrentPageBot', 'debug', 'error',
     'exception', 'FilePage', 'handle_args', 'html2unicode', 'info', 'input',
diff --git a/pywikibot/__metadata__.py b/pywikibot/__metadata__.py
index 6c5d383..9460e54 100644
--- a/pywikibot/__metadata__.py
+++ b/pywikibot/__metadata__.py
@@ -3,24 +3,13 @@
 .. versionadded:: 4.0
 """
 #
-# (C) Pywikibot team, 2020-2023
+# (C) Pywikibot team, 2020-2024
 #
 # Distributed under the terms of the MIT license.
 #
-from __future__ import annotations
-
 from time import strftime


-__name__ = 'pywikibot'
 __version__ = '9.0.0.dev0'
-__description__ = 'Python MediaWiki Bot Framework'
-__maintainer__ = 'The Pywikibot team'
-__maintainer_email__ = '[email protected]'
-__license__ = 'MIT License'
 __url__ = 'https://www.mediawiki.org/wiki/Manual:Pywikibot'
-__download_url__ = 'https://pywikibot.toolforge.org/'
 __copyright__ = '(C) Pywikibot team, 2003-' + strftime('%Y')
-__keywords__ = 'API bot client framework mediawiki pwb pybot python pywiki ' \
-               'pywikibase pywikibot pywikipedia pywikipediabot wiki ' \
-               'wikibase wikidata wikimedia wikipedia'
diff --git a/setup.py b/setup.py
index 7bbfae2..852b1fe 100755
--- a/setup.py
+++ b/setup.py
@@ -26,10 +26,12 @@
 #
 from __future__ import annotations

+import configparser
 import os
 import re
 import sys
 from contextlib import suppress
+from pathlib import Path


 if sys.version_info[:3] >= (3, 9):
@@ -113,16 +115,31 @@
     __getattr__ = dict.__getitem__


-# import metadata
-metadata = _DottedDict()
-name = 'pywikibot'
-path = os.path.abspath(os.path.dirname(__file__))
-with open(os.path.join(path, name, '__metadata__.py')) as f:
-    exec(f.read(), None, metadata)
-assert metadata.__name__ == name
+path = Path(__file__).parent


-def get_validated_version() -> str:
+def read_project() -> str:
+    """Read the project name from toml file.
+
+    ``tomllib`` was introduced with Python 3.11. To support earlier versions
+    ``configparser`` is used. Therefore the tomlfile must be readable as
+    config file until the first comment.
+
+    .. versionadded:: 9.0
+    """
+    toml = []
+    with open(path / 'pyproject.toml') as f:
+        for line in f:
+            if line.startswith('#'):
+                break
+            toml.append(line)
+
+    config = configparser.ConfigParser()
+    config.read_string(''.join(toml))
+    return config['project']['name'].strip('"')
+
+
+def get_validated_version(name: str) -> str:
     """Get a validated pywikibot module version string.

     The version number from pywikibot.__metadata__.__version__ is used.
@@ -133,7 +150,14 @@

     :return: pywikibot module version string
     """
-    version = metadata.__version__
+    # import metadata
+    metadata = _DottedDict()
+    with open(path / name / '__metadata__.py') as f:
+        exec(f.read(), None, metadata)
+    assert metadata.__url__.endswith(
+        name.title())  # type: ignore[attr-defined]
+
+    version = metadata.__version__  # type: ignore[attr-defined]
     if 'sdist' not in sys.argv:
         return version

@@ -217,139 +241,17 @@
     """Setup entry point."""
     from setuptools import setup

-    version = get_validated_version()
+    name = read_project()
     setup(
-        name=metadata.__name__,
-        version=version,
-        description=metadata.__description__,
+        version=get_validated_version(name),
         long_description=read_desc('README.rst'),
         long_description_content_type='text/x-rst',
-        # author
-        # author_email
-        maintainer=metadata.__maintainer__,
-        maintainer_email=metadata.__maintainer_email__,
-        url=metadata.__url__,
-        download_url=metadata.__download_url__,
         packages=get_packages(name),
-        # py_modules
-        # scripts
-        # ext_package
-        # ext_modules
-        # distclass
-        # script_name
-        # script_args
-        # options
-        license=metadata.__license__,
-        # license_files
-        keywords=metadata.__keywords__.split(),
-        # platforms
-        # cmdclass
-        # package_dir
         include_package_data=True,
-        # exclude_package_data
-        # package_data
-        # zip_safe
         install_requires=dependencies,
         extras_require=extra_deps,
-        python_requires='>=3.7.0',
-        # namespace_packages
         test_suite='tests.collector',
         tests_require=test_deps,
-        # test_loader
-        # eager_resources
-        project_urls={
-            'Documentation': 'https://doc.wikimedia.org/pywikibot/stable/',
-            'Source':
-                
'https://gerrit.wikimedia.org/r/plugins/gitiles/pywikibot/core/',  # noqa: E501
-            'GitHub Mirror': 'https://github.com/wikimedia/pywikibot',
-            'Tracker': 'https://phabricator.wikimedia.org/tag/pywikibot/',
-        },
-        entry_points={
-            'console_scripts': [
-                'pwb = pywikibot.scripts.wrapper:run',
-            ],
-        },
-        classifiers=[
-            'Development Status :: 5 - Production/Stable',
-            'Environment :: Console',
-            'Intended Audience :: Developers',
-            'License :: OSI Approved :: MIT License',
-            'Natural Language :: Afrikaans',
-            'Natural Language :: Arabic',
-            'Natural Language :: Basque',
-            'Natural Language :: Bengali',
-            'Natural Language :: Bosnian',
-            'Natural Language :: Bulgarian',
-            'Natural Language :: Cantonese',
-            'Natural Language :: Catalan',
-            'Natural Language :: Chinese (Simplified)',
-            'Natural Language :: Chinese (Traditional)',
-            'Natural Language :: Croatian',
-            'Natural Language :: Czech',
-            'Natural Language :: Danish',
-            'Natural Language :: Dutch',
-            'Natural Language :: English',
-            'Natural Language :: Esperanto',
-            'Natural Language :: Finnish',
-            'Natural Language :: French',
-            'Natural Language :: Galician',
-            'Natural Language :: German',
-            'Natural Language :: Greek',
-            'Natural Language :: Hebrew',
-            'Natural Language :: Hindi',
-            'Natural Language :: Hungarian',
-            'Natural Language :: Icelandic',
-            'Natural Language :: Indonesian',
-            'Natural Language :: Irish',
-            'Natural Language :: Italian',
-            'Natural Language :: Japanese',
-            'Natural Language :: Javanese',
-            'Natural Language :: Korean',
-            'Natural Language :: Latin',
-            'Natural Language :: Latvian',
-            'Natural Language :: Lithuanian',
-            'Natural Language :: Macedonian',
-            'Natural Language :: Malay',
-            'Natural Language :: Marathi',
-            'Natural Language :: Nepali',
-            'Natural Language :: Norwegian',
-            'Natural Language :: Panjabi',
-            'Natural Language :: Persian',
-            'Natural Language :: Polish',
-            'Natural Language :: Portuguese',
-            'Natural Language :: Portuguese (Brazilian)',
-            'Natural Language :: Romanian',
-            'Natural Language :: Russian',
-            'Natural Language :: Serbian',
-            'Natural Language :: Slovak',
-            'Natural Language :: Slovenian',
-            'Natural Language :: Spanish',
-            'Natural Language :: Swedish',
-            'Natural Language :: Tamil',
-            'Natural Language :: Telugu',
-            'Natural Language :: Thai',
-            'Natural Language :: Tibetan',
-            'Natural Language :: Turkish',
-            'Natural Language :: Ukrainian',
-            'Natural Language :: Urdu',
-            'Natural Language :: Vietnamese',
-            'Operating System :: OS Independent',
-            'Programming Language :: Python',
-            'Programming Language :: Python :: 3',
-            'Programming Language :: Python :: 3 :: Only',
-            '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 :: 3.13',
-            'Programming Language :: Python :: Implementation :: CPython',
-            'Programming Language :: Python :: Implementation :: PyPy',
-            'Topic :: Internet :: WWW/HTTP :: Dynamic Content :: Wiki',
-            'Topic :: Software Development :: Libraries :: Python Modules',
-            'Topic :: Utilities',
-        ],
     )


diff --git a/tests/setup_tests.py b/tests/setup_tests.py
index d03ede0..ddc9040 100644
--- a/tests/setup_tests.py
+++ b/tests/setup_tests.py
@@ -25,9 +25,14 @@
     site = False
     net = False

+    def test_read_project(self):
+        """Test :func:`setup.read_project` function."""
+        self.assertEqual(setup.read_project(), 'pywikibot')
+
     def test_get_validated_version(self):
         """Test :func:`setup.get_validated_version` function."""
-        self.assertEqual(setup.get_validated_version(), pywikibot.__version__)
+        self.assertEqual(setup.get_validated_version('pywikibot'),
+                         pywikibot.__version__)

     def test_read_desc(self):
         """Test :func:`setup.read_desc` function."""

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/995443?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Iae9643f3fe49a41e1997790b8c4bec5ef1616b36
Gerrit-Change-Number: 995443
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to