PYTHON 13
Setup.py Guest on 13th October 2020 11:35:50 PM
  1. # -*- coding: utf-8 -*-
  2. """Installer script for Pywikibot 3.0 framework."""
  3. #
  4. # (C) Pywikibot team, 2009-2020
  5. #
  6. # Distributed under the terms of the MIT license.
  7. #
  8. from __future__ import (absolute_import, division,
  9.                         print_function, unicode_literals)
  10.  
  11. import os
  12. import sys
  13.  
  14. from setuptools import find_packages, setup
  15.  
  16. PYTHON_VERSION = sys.version_info[:3]
  17. PY2 = (PYTHON_VERSION[0] == 2)
  18.  
  19. versions_required_message = """
  20. Pywikibot is not available on:
  21. {version}
  22.  
  23. This version of Pywikibot only supports Python 2.7.4+ or 3.4+.
  24. """
  25.  
  26.  
  27. def python_is_supported():
  28.     """Check that Python is supported."""
  29.     # Any change to this must be copied to pwb.py
  30.     return PYTHON_VERSION >= (3, 4, 0) or PY2 and PYTHON_VERSION >= (2, 7, 4)
  31.  
  32.  
  33. if not python_is_supported():
  34.     raise RuntimeError(versions_required_message.format(version=sys.version))
  35.  
  36. # ------- setup extra_requires ------- #
  37. extra_deps = {
  38.     # Core library dependencies
  39.     'eventstreams': ['sseclient!=0.0.23,!=0.0.24,>=0.0.18'],
  40.     'isbn': ['python-stdnum'],
  41.     'Graphviz': ['pydot>=1.2'],
  42.     'Google': ['google>=1.7'],
  43.     'mwparserfromhell': ['mwparserfromhell>=0.3.3'],
  44.     'Tkinter': [
  45.         'Pillow<7.0.0;python_version<"3"',
  46.         'Pillow<6.0.0;python_version=="3.4"',
  47.         'Pillow;python_version>="3.5"',
  48.     ],
  49.     'security': [
  50.         'requests[security]'
  51.         ';python_full_version=="2.7.7" or python_full_version=="2.7.8"',
  52.         'pycparser!=2.14',
  53.     ],
  54.     'mwoauth': ['mwoauth!=0.3.1,>=0.2.4'],
  55.     'html': ['BeautifulSoup4'],
  56.     'http': ['fake_useragent'],
  57.     'flake8': [  # Due to incompatibilities between packages the order matters.
  58.         'flake8>=3.7.5',
  59.         'pydocstyle<=3.0.0;python_version<"3"',
  60.         'pydocstyle>=4.0.0;python_version>="3.4"',
  61.         'hacking',
  62.         'flake8-coding',
  63.         'flake8-comprehensions',
  64.         'flake8-docstrings>=1.3.1',
  65.         'flake8-future-import',
  66.         'flake8-mock>=0.3',
  67.         'flake8-print>=2.0.1',
  68.         'flake8-quotes>=2.0.1',
  69.         'flake8-string-format',
  70.         'flake8-tuple>=0.2.8',
  71.         'flake8-no-u-prefixed-strings>=0.2',
  72.         'pep8-naming>=0.7',
  73.         'pyflakes>=2.1.0',
  74.     ],
  75.     # Additional core library dependencies which are only available on Python 2
  76.     'csv': ['unicodecsv;python_version<"3"'],
  77. }
  78.  
  79.  
  80. # ------- setup extra_requires for scripts ------- #
  81. script_deps = {
  82.     'flickrripper.py': [
  83.         'flickrapi',
  84.         'Pillow<7.0.0;python_version<"3"',
  85.         'Pillow<6.0.0;python_version=="3.4"',
  86.         'Pillow;python_version>="3.5"',
  87.     ],
  88.     'states_redirect.py': ['pycountry'],
  89.     'weblinkchecker.py': ['memento_client!=0.6.0,>=0.5.1'],
  90.     'patrol.py': ['mwparserfromhell>=0.3.3'],
  91. }
  92. script_deps['data_ingestion.py'] = extra_deps['csv']
  93.  
  94. extra_deps.update(script_deps)
  95.  
  96. # ------- setup install_requires ------- #
  97. dependencies = ['requests>=2.20.1,<2.22.0; python_version == "3.4"',
  98.                 'requests>=2.20.1; python_version != "3.4"',
  99.                 'enum34>=1.1.6; python_version < "3"']
  100. # tools.ip does not have a hard dependency on an IP address module,
  101. # as it falls back to using regexes if one is not available.
  102. # The functional backport of py3 ipaddress is acceptable:
  103. # https://pypi.org/project/ipaddress
  104. # However the Debian package python-ipaddr is also supported:
  105. # https://pypi.org/project/ipaddr
  106. # Other backports are likely broken.
  107. # ipaddr 2.1.10+ is distributed with Debian and Fedora. See T105443.
  108. dependencies.append('ipaddr>=2.1.10;python_version<"3"')
  109.  
  110. # version.package_version() uses pathlib which is a python 3 library.
  111. # pathlib2 is required for python 2.7
  112. dependencies.append('pathlib2;python_version<"3"')
  113.  
  114. # Python versions before 2.7.9 will cause urllib3 to trigger
  115. # InsecurePlatformWarning warnings for all HTTPS requests. By
  116. # installing with security extras, requests will automatically set
  117. # them up and the warnings will stop. See
  118. # <https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning>
  119. # for more details.
  120. # There is no secure version of cryptography for Python 2.7.6 or older.
  121. dependencies += extra_deps['security']
  122.  
  123.  
  124. try:
  125.     import bz2
  126. except ImportError:
  127.     # Use bz2file if the python is not compiled with bz2 support.
  128.     dependencies.append('bz2file')
  129. else:
  130.     assert bz2
  131.  
  132.  
  133. # ------- setup tests_require ------- #
  134. test_deps = ['bz2file', 'mock']
  135. # Some of the ui_tests depend on accessing the console window's menu
  136. # to set the console font and copy and paste, achieved using pywinauto
  137. # which depends on pywin32.
  138. # These tests may be disabled because pywin32 depends on VC++, is time
  139. # consuming to build, and the console window can't be accessed during appveyor
  140. # builds.
  141. # Microsoft makes available a compiler for Python 2.7
  142. # http://www.microsoft.com/en-au/download/details.aspx?id=44266
  143. if os.name == 'nt' and os.environ.get('PYSETUP_TEST_NO_UI', '0') != '1':
  144.     test_deps += [
  145.         'pywinauto>0.6.4;python_version>="3.5" or python_version<"3"',
  146.         'pywinauto<=0.6.4;python_version=="3.4"',
  147.         'pywin32>220;python_version>="3.5" or python_version<"3"',
  148.         'pywin32<=220;python_version=="3.4"',
  149.     ]
  150.  
  151. # Add all dependencies as test dependencies,
  152. # so all scripts can be compiled for script_tests, etc.
  153. if 'PYSETUP_TEST_EXTRAS' in os.environ:
  154.     test_deps += [i for k, v in extra_deps.items() if k != 'flake8' for i in v]
  155.  
  156.     if 'requests[security]' in test_deps:
  157.         # Bug T105767 on Python 2.7 release 9+
  158.         if PY2 and PYTHON_VERSION[2] >= 9:
  159.             test_deps.remove('requests[security]')
  160.  
  161. # These extra dependencies are needed other unittest fails to load tests.
  162. test_deps += extra_deps['csv']
  163. test_deps += extra_deps['eventstreams']
  164. test_deps += ['six;python_version>="3"']
  165.  
  166.  
  167. def get_version(name):
  168.     """Get a valid pywikibot module version string."""
  169.     version = '3.0'
  170.     try:
  171.         import subprocess
  172.         date = subprocess.check_output(
  173.             ['git', 'log', '-1', '--format=%ci']).strip()
  174.         date = date.decode().split(' ')[0].replace('-', '')
  175.         version += '.' + date
  176.         if 'sdist' not in sys.argv:
  177.             version += '.dev0'
  178.     except Exception as e:
  179.         print(e)
  180.         from pkg_resources import get_distribution, DistributionNotFound
  181.         try:
  182.             version = get_distribution(name).version
  183.         except DistributionNotFound as e:
  184.             print(e)
  185.             version += '.dev0'
  186.     return version
  187.  
  188.  
  189. def read_desc(filename):
  190.     """Read long description.
  191.  
  192.    Combine included restructured text files which must be done before
  193.    uploading because the source isn't available after creating the package.
  194.    """
  195.     desc = []
  196.     with open(filename) as f:
  197.         for line in f:
  198.             if line.strip().startswith('.. include::'):
  199.                 include = os.path.relpath(line.rsplit('::')[1].strip())
  200.                 if os.path.exists(include):
  201.                     with open(include) as g:
  202.                         desc.append(g.read())
  203.                 else:
  204.                     print('Cannot include {0}; file not found'.format(include))
  205.             else:
  206.                 desc.append(line)
  207.     return ''.join(desc)
  208.  
  209.  
  210. name = 'pywikibot'
  211. setup(
  212.     name=name,
  213.     version=get_version(name),
  214.     description='Python MediaWiki Bot Framework',
  215.     long_description=read_desc('README.rst'),
  216.     keywords=['API', 'bot', 'framework', 'mediawiki', 'pwb', 'python',
  217.               'pywikibot', 'pywikipedia', 'pywikipediabot', 'wiki',
  218.               'wikimedia', 'wikipedia'],
  219.     maintainer='The Pywikibot team',
  220.     maintainer_email='[email protected]',
  221.     license='MIT License',
  222.     packages=[str(name)] + [package
  223.                             for package in find_packages()
  224.                             if package.startswith('pywikibot.')],
  225.     python_requires='>=2.7.4, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
  226.     install_requires=dependencies,
  227.     extras_require=extra_deps,
  228.     url='https://www.mediawiki.org/wiki/Manual:Pywikibot',
  229.     download_url='https://tools.wmflabs.org/pywikibot/',
  230.     test_suite='tests.collector',
  231.     tests_require=test_deps,
  232.     classifiers=[
  233.         'Development Status :: 5 - Production/Stable',
  234.         'Environment :: Console',
  235.         'Intended Audience :: Developers',
  236.         'License :: OSI Approved :: MIT License',
  237.         'Natural Language :: English',
  238.         'Operating System :: OS Independent',
  239.         'Programming Language :: Python',
  240.         'Programming Language :: Python :: 2',
  241.         'Programming Language :: Python :: 2.7',
  242.         'Programming Language :: Python :: 3',
  243.         'Programming Language :: Python :: 3.4',
  244.         'Programming Language :: Python :: 3.5',
  245.         'Programming Language :: Python :: 3.6',
  246.         'Programming Language :: Python :: 3.7',
  247.         'Programming Language :: Python :: 3.8',
  248.         'Programming Language :: Python :: Implementation :: CPython',
  249.         'Topic :: Internet :: WWW/HTTP :: Dynamic Content :: Wiki',
  250.         'Topic :: Software Development :: Libraries :: Python Modules',
  251.         'Topic :: Utilities',
  252.     ],
  253.     use_2to3=False
  254. )

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.