Xqt merged this change.

View Change

Approvals: jenkins-bot: Verified D3r1ck01: Looks good to me, approved
[IMPR] Check for all modules which are mandatory

Currently pwb checks for unspecified requests requirement.
This patch enables checking for all required modules which
are mandatory for a given Python release including the
version number of the package. This ensures that the
package has to be updated if necessary.

Change-Id: I345a752a3a808fbae4e7909a860b4b304fb1ad28
---
M pwb.py
M setup.py
2 files changed, 85 insertions(+), 53 deletions(-)

diff --git a/pwb.py b/pwb.py
index 28eb5b9..6622ba5 100755
--- a/pwb.py
+++ b/pwb.py
@@ -33,7 +33,7 @@
PYTHON_VERSION = sys.version_info[:3]
PY2 = (PYTHON_VERSION[0] == 2)

-versions_required_message = """
+VERSIONS_REQUIRED_MESSAGE = """
Pywikibot is not available on:
{version}

@@ -48,7 +48,7 @@


if not python_is_supported():
- print(versions_required_message.format(version=sys.version))
+ print(VERSIONS_REQUIRED_MESSAGE.format(version=sys.version))
sys.exit(1)

pwb = None
@@ -139,6 +139,36 @@
return fname, list(args[index + int(bool(fname)):]), args[:index]


+def check_modules():
+ """Check whether mandatory modules are present."""
+ import pkg_resources
+ from setup import dependencies
+ missing_requirements = []
+
+ for requirement in pkg_resources.parse_requirements(dependencies):
+ if requirement.marker is None \
+ or pkg_resources.evaluate_marker(str(requirement.marker)):
+ try:
+ pkg_resources.resource_exists(requirement, requirement.name)
+ except (pkg_resources.DistributionNotFound,
+ pkg_resources.VersionConflict) as e:
+ print(e)
+ missing_requirements.append(requirement)
+
+ del pkg_resources
+ del dependencies
+
+ if not missing_requirements:
+ return True
+
+ print('\nPlease install/update required module{} with:\n\n'
+ .format('s' if len(missing_requirements) > 1 else ''))
+ for requirement in missing_requirements:
+ print(' pip install "{}"\n'
+ .format(str(requirement).partition(';')[0]))
+ return False
+
+
# Establish a normalised path for the directory containing pwb.py.
# Either it is '.' if the user's current working directory is the same,
# or it is the absolute path for the directory of pwb.py
@@ -148,12 +178,8 @@
if rewrite_path not in sys.path[:2]:
sys.path.insert(1, rewrite_path)

-try:
- import requests
-except ImportError as e:
- raise ImportError("{0}\nPython module 'requests' is required.\n"
- "Try running 'pip install requests'.".format(e))
-del requests
+if not check_modules():
+ sys.exit()

filename, args, local_args = handle_args(*sys.argv)

diff --git a/setup.py b/setup.py
index 3c8a684..dd4c784 100644
--- a/setup.py
+++ b/setup.py
@@ -214,48 +214,54 @@
return ''.join(desc)


-name = 'pywikibot'
-setup(
- name=name,
- version=get_version(name),
- description='Python MediaWiki Bot Framework',
- long_description=read_desc('README.rst'),
- keywords=['API', 'bot', 'framework', 'mediawiki', 'pwb', 'python',
- 'pywikibot', 'pywikipedia', 'pywikipediabot', 'wiki',
- 'wikimedia', 'wikipedia'],
- maintainer='The Pywikibot team',
- maintainer_email='pywikibot@lists.wikimedia.org',
- license='MIT License',
- packages=[str(name)] + [package
- for package in find_packages()
- if package.startswith('pywikibot.')],
- python_requires='>=2.7.4, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
- install_requires=dependencies,
- extras_require=extra_deps,
- url='https://www.mediawiki.org/wiki/Manual:Pywikibot',
- download_url='https://tools.wmflabs.org/pywikibot/',
- test_suite='tests.collector',
- tests_require=test_deps,
- classifiers=[
- 'Development Status :: 5 - Production/Stable',
- 'Environment :: Console',
- 'Intended Audience :: Developers',
- 'License :: OSI Approved :: MIT License',
- 'Natural Language :: English',
- 'Operating System :: OS Independent',
- 'Programming Language :: Python',
- 'Programming Language :: Python :: 2',
- 'Programming Language :: Python :: 2.7',
- 'Programming Language :: Python :: 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 :: Implementation :: CPython',
- 'Topic :: Internet :: WWW/HTTP :: Dynamic Content :: Wiki',
- 'Topic :: Software Development :: Libraries :: Python Modules',
- 'Topic :: Utilities',
- ],
- use_2to3=False
-)
+def main():
+ """Setup entry point."""
+ name = 'pywikibot'
+ setup(
+ name=name,
+ version=get_version(name),
+ description='Python MediaWiki Bot Framework',
+ long_description=read_desc('README.rst'),
+ keywords=['API', 'bot', 'framework', 'mediawiki', 'pwb', 'python',
+ 'pywikibot', 'pywikipedia', 'pywikipediabot', 'wiki',
+ 'wikimedia', 'wikipedia'],
+ maintainer='The Pywikibot team',
+ maintainer_email='pywikibot@lists.wikimedia.org',
+ license='MIT License',
+ packages=[str(name)] + [package
+ for package in find_packages()
+ if package.startswith('pywikibot.')],
+ python_requires='>=2.7.4, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
+ install_requires=dependencies,
+ extras_require=extra_deps,
+ url='https://www.mediawiki.org/wiki/Manual:Pywikibot',
+ download_url='https://tools.wmflabs.org/pywikibot/',
+ test_suite='tests.collector',
+ tests_require=test_deps,
+ classifiers=[
+ 'Development Status :: 5 - Production/Stable',
+ 'Environment :: Console',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: MIT License',
+ 'Natural Language :: English',
+ 'Operating System :: OS Independent',
+ 'Programming Language :: Python',
+ 'Programming Language :: Python :: 2',
+ 'Programming Language :: Python :: 2.7',
+ 'Programming Language :: Python :: 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 :: Implementation :: CPython',
+ 'Topic :: Internet :: WWW/HTTP :: Dynamic Content :: Wiki',
+ 'Topic :: Software Development :: Libraries :: Python Modules',
+ 'Topic :: Utilities',
+ ],
+ use_2to3=False
+ )
+
+
+if __name__ == '__main__':
+ main()

To view, visit change 577966. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I345a752a3a808fbae4e7909a860b4b304fb1ad28
Gerrit-Change-Number: 577966
Gerrit-PatchSet: 10
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot (75)