├── caniusepython3 ├── test │ ├── __init__.py │ ├── test_command.py │ ├── test_check.py │ ├── test_dependencies.py │ ├── test_pypi.py │ └── test_cli.py ├── command.py ├── overrides.json ├── __init__.py ├── dependencies.py ├── pypi.py └── __main__.py ├── setup.cfg ├── MANIFEST.in ├── .travis.yml ├── .gitignore ├── setup.py ├── README_PyPI.rst ├── README.md └── LICENSE /caniusepython3/test/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [wheel] 2 | universal = 1 3 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README_PyPI.rst 2 | include caniusepython3/overrides.json 3 | include LICENSE 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | python: 4 | - "2.6" 5 | - "2.7" 6 | - "3.2" 7 | - "3.3" 8 | 9 | install: pip install -e . 10 | script: nosetests 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *venv 2 | 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Packages 9 | MANIFEST 10 | *.egg 11 | *.egg-info 12 | dist 13 | build 14 | eggs 15 | parts 16 | bin 17 | var 18 | sdist 19 | develop-eggs 20 | .installed.cfg 21 | lib 22 | lib64 23 | __pycache__ 24 | 25 | # Installer logs 26 | pip-log.txt 27 | 28 | # Unit test / coverage reports 29 | .coverage 30 | htmlcov 31 | .tox 32 | nosetests.xml 33 | -------------------------------------------------------------------------------- /caniusepython3/command.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Google Inc. All rights reserved. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from __future__ import unicode_literals 16 | 17 | import setuptools 18 | 19 | import caniusepython3 as ciu 20 | import caniusepython3.__main__ as ciu_main 21 | from caniusepython3 import pypi 22 | 23 | 24 | class Command(setuptools.Command): 25 | 26 | description = """Run caniusepython3 over a setup.py file.""" 27 | 28 | user_options = [] 29 | 30 | def _dependencies(self): 31 | projects = [] 32 | for attr in ('install_requires', 'tests_require'): 33 | requirements = getattr(self.distribution, attr, None) or [] 34 | for project in requirements: 35 | if not project: 36 | continue 37 | projects.append(pypi.just_name(project)) 38 | extras = getattr(self.distribution, 'extras_require', None) or {} 39 | for value in extras.values(): 40 | projects.extend(map(pypi.just_name, value)) 41 | return projects 42 | 43 | def initialize_options(self): 44 | pass 45 | 46 | def run(self): 47 | ciu_main.check(self._dependencies()) 48 | 49 | def finalize_options(self): 50 | pass 51 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | import os 4 | 5 | 6 | # Installed name used for various commands (both script and setuptools). 7 | command_name = os.environ.get('CIU_ALT_NAME') or 'caniusepython3' 8 | 9 | with open('README_PyPI.rst') as file: 10 | long_description = file.read() 11 | 12 | setup(name='caniusepython3', 13 | version='2.1.0', 14 | description='Determine what projects are blocking you from porting to Python 3', 15 | long_description=long_description, 16 | author='Brett Cannon', 17 | author_email='brett@python.org', 18 | url='https://github.com/brettcannon/caniusepython3', 19 | packages=['caniusepython3', 'caniusepython3.test'], 20 | include_package_data=True, 21 | install_requires=['distlib', 'setuptools', 'pip', # Input flexibility 22 | 'argparse', 'futures', # Functionality 23 | 'mock'], # Testing 24 | test_suite='caniusepython3.test', 25 | classifiers=[ 26 | 'Development Status :: 5 - Production/Stable', 27 | 'Environment :: Console', 28 | 'Intended Audience :: Developers', 29 | 'License :: OSI Approved :: Apache Software License', 30 | 'Programming Language :: Python', 31 | 'Programming Language :: Python :: 2.6', 32 | 'Programming Language :: Python :: 2.7', 33 | 'Programming Language :: Python :: 3', 34 | 'Programming Language :: Python :: 3.2', 35 | 'Programming Language :: Python :: 3.3', 36 | 'Programming Language :: Python :: 3.4', 37 | ], 38 | entry_points={ 39 | 'console_scripts': [ 40 | '{0} = caniusepython3.__main__:main'.format(command_name), 41 | ], 42 | 'distutils.commands': [ 43 | '{0} = caniusepython3.command:Command'.format(command_name), 44 | ], 45 | }, 46 | zip_safe=True, 47 | ) 48 | -------------------------------------------------------------------------------- /caniusepython3/test/test_command.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Google Inc. All rights reserved. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from __future__ import unicode_literals 16 | 17 | from caniusepython3 import command 18 | 19 | from distutils import dist 20 | import unittest 21 | 22 | def make_command(requires): 23 | return command.Command(dist.Distribution(requires)) 24 | 25 | class RequiresTests(unittest.TestCase): 26 | 27 | def verify_cmd(self, requirements): 28 | requires = {requirements: ['pip']} 29 | cmd = make_command(requires) 30 | got = cmd._dependencies() 31 | self.assertEqual(frozenset(got), frozenset(['pip'])) 32 | return cmd 33 | 34 | def test_install_requires(self): 35 | self.verify_cmd('install_requires') 36 | 37 | def test_tests_require(self): 38 | self.verify_cmd('tests_require') 39 | 40 | def test_extras_require(self): 41 | cmd = make_command({'extras_require': {'testing': ['pip']}}) 42 | got = frozenset(cmd._dependencies()) 43 | self.assertEqual(got, frozenset(['pip'])) 44 | 45 | 46 | class OptionsTests(unittest.TestCase): 47 | 48 | def test_finalize_options(self): 49 | # Don't expect anything to happen. 50 | make_command({}).finalize_options() 51 | 52 | 53 | class NetworkTests(unittest.TestCase): 54 | 55 | def test_run(self): 56 | make_command({'install_requires': ['pip']}).run() 57 | -------------------------------------------------------------------------------- /caniusepython3/overrides.json: -------------------------------------------------------------------------------- 1 | { 2 | "awscli":"https://pypi.python.org/pypi/awscli", 3 | "beautifulsoup": "https://pypi.python.org/pypi/beautifulsoup4", 4 | "bcdoc":"https://github.com/boto/bcdoc/blob/master/tox.ini", 5 | "botocore":"https://github.com/boto/botocore/blob/master/tox.ini", 6 | "django-social-auth": "https://pypi.python.org/pypi/python-social-auth", 7 | "extras": "https://pypi.python.org/pypi/extras", 8 | "httpretty": "https://twitter.com/CyrilRoelandt/status/437995014321238016", 9 | "ipaddress": "http://docs.python.org/3/library/ipaddress.html", 10 | "jmespath": "https://github.com/boto/jmespath/blob/master/tox.ini", 11 | "logbook": "https://pythonhosted.org/Logbook/features.html", 12 | "mox": "https://pypi.python.org/pypi/mox3", 13 | "mox3": "https://pypi.python.org/pypi/mox3", 14 | "multiprocessing": "http://docs.python.org/3/library/multiprocessing.html", 15 | "ordereddict": "http://docs.python.org/3/library/collections.html#collections.OrderedDict", 16 | "pil": "https://pypi.python.org/pypi/Pillow", 17 | "pylint": "https://bitbucket.org/logilab/pylint/src/default/setup.py", 18 | "pyrss2gen": "https://pypi.python.org/pypi/PyRSS2Gen", 19 | "pysqlite": "http://docs.python.org/3/library/sqlite3.html", 20 | "python-memcached": "https://pypi.python.org/pypi/python3-memcached", 21 | "pyvirtualdisplay": "https://pypi.python.org/pypi/PyVirtualDisplay", 22 | "rsa": "https://pypi.python.org/pypi/rsa", 23 | "ssh": "https://github.com/bitprophet/ssh/", 24 | "ssl": "http://docs.python.org/3/library/ssl.html", 25 | "unittest2": "http://docs.python.org/3/library/unittest.html", 26 | "uuid": "http://docs.python.org/3/library/uuid.html", 27 | "uwsgi": "https://pypi.python.org/pypi/uWSGI", 28 | "warlock": "https://github.com/bcwaldon/warlock/blob/master/tox.ini", 29 | "wsgiref": "http://docs.python.org/3/library/wsgiref.html", 30 | "xlwt": "https://pypi.python.org/pypi/xlwt-future", 31 | "zc.recipe.egg": "https://pypi.python.org/pypi/zc.recipe.egg/" 32 | } 33 | -------------------------------------------------------------------------------- /caniusepython3/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Google Inc. All rights reserved. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Calculate whether the specified package(s) and their dependencies support Python 3.""" 16 | 17 | from __future__ import unicode_literals 18 | 19 | from caniusepython3 import __main__ as main 20 | from caniusepython3 import pypi 21 | 22 | import multiprocessing 23 | 24 | 25 | try: 26 | CPU_COUNT = max(2, multiprocessing.cpu_count()) 27 | except NotImplementedError: #pragma: no cover 28 | CPU_COUNT = 2 29 | 30 | 31 | def check(requirements_paths=[], metadata=[], projects=[]): 32 | """Return True if all of the specified dependencies have been ported to Python 3. 33 | 34 | The requirements_paths argument takes a sequence of file paths to 35 | requirements files. The 'metadata' argument takes a sequence of strings 36 | representing metadata. The 'projects' argument takes a sequence of project 37 | names. 38 | 39 | Any project that is not listed on PyPI will be considered ported. 40 | """ 41 | dependencies = main.projects_from_requirements(requirements_paths) 42 | dependencies.extend(main.projects_from_metadata(metadata)) 43 | dependencies.extend(projects) 44 | dependencies = set(name.lower() for name in dependencies) 45 | 46 | py3_projects = pypi.all_py3_projects() 47 | all_projects = pypi.all_projects() 48 | 49 | for dependency in dependencies: 50 | if dependency in all_projects and dependency not in py3_projects: 51 | return False 52 | return True 53 | -------------------------------------------------------------------------------- /caniusepython3/test/test_check.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Google Inc. All rights reserved. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from __future__ import unicode_literals 16 | 17 | import caniusepython3 as ciu 18 | 19 | import tempfile 20 | import unittest 21 | 22 | EXAMPLE_METADATA = """Metadata-Version: 1.2 23 | Name: TestingMetadata 24 | Version: 0.5 25 | Summary: testing 26 | Home-page: http://github.com/brettcannon/caniusepython3 27 | Author: Brett Cannon 28 | Author-email: brett@python.org 29 | License: Apache 30 | Requires-Dist: paste 31 | """ 32 | 33 | 34 | class CheckTest(unittest.TestCase): 35 | 36 | # When testing input, make sure to use project names that **will** lead to 37 | # a False answer since unknown projects are skipped. 38 | 39 | def test_success(self): 40 | self.assertTrue(ciu.check(projects=['scipy', 'numpy', 'ipython'])) 41 | 42 | def test_failure(self): 43 | self.assertFalse(ciu.check(projects=['paste'])) 44 | 45 | def test_requirements(self): 46 | with tempfile.NamedTemporaryFile('w') as file: 47 | file.write('paste\n') 48 | file.flush() 49 | self.assertFalse(ciu.check(requirements_paths=[file.name])) 50 | 51 | def test_metadata(self): 52 | self.assertFalse(ciu.check(metadata=[EXAMPLE_METADATA])) 53 | 54 | def test_projects(self): 55 | # Implicitly done by test_success and test_failure. 56 | pass 57 | 58 | def test_case_insensitivity(self): 59 | self.assertFalse(ciu.check(projects=['PaStE'])) 60 | 61 | def test_ignore_missing_projects(self): 62 | self.assertTrue(ciu.check(projects=['sdfsjdfsdlfk;jasdflkjasdfdsfsdf'])) 63 | -------------------------------------------------------------------------------- /caniusepython3/test/test_dependencies.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Google Inc. All rights reserved. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from __future__ import unicode_literals 16 | 17 | from caniusepython3 import dependencies 18 | 19 | import io 20 | import unittest 21 | 22 | 23 | class GraphResolutionTests(unittest.TestCase): 24 | 25 | def test_all_projects_okay(self): 26 | # A, B, and C are fine on their own. 27 | self.assertEqual(set(), dependencies.reasons_to_paths({})) 28 | 29 | def test_leaf_okay(self): 30 | # A -> B where B is okay. 31 | reasons = {'A': None} 32 | self.assertEqual(frozenset([('A',)]), 33 | dependencies.reasons_to_paths(reasons)) 34 | 35 | def test_leaf_bad(self): 36 | # A -> B -> C where all projects are bad. 37 | reasons = {'A': None, 'B': 'A', 'C': 'B'} 38 | self.assertEqual(frozenset([('C', 'B', 'A')]), 39 | dependencies.reasons_to_paths(reasons)) 40 | 41 | 42 | class NetworkTests(unittest.TestCase): 43 | 44 | def test_blocking_dependencies(self): 45 | got = dependencies.blocking_dependencies(['pastescript'], {'paste': ''}) 46 | want = frozenset([('pastedeploy', 'pastescript')]) 47 | self.assertEqual(frozenset(got), want) 48 | 49 | def test_dependencies(self): 50 | got = dependencies.dependencies('pastescript') 51 | self.assertEqual(set(got), frozenset(['pastedeploy', 'paste'])) 52 | 53 | def test_dependencies_no_project(self): 54 | got = dependencies.dependencies('sdflksjdfsadfsadfad') 55 | if hasattr(self, 'assertIsNone'): 56 | self.assertIsNone(got) 57 | else: 58 | self.assertTrue(got is None) 59 | 60 | def test_blocking_dependencies_no_project(self): 61 | got = dependencies.blocking_dependencies(['asdfsadfdsfsdffdfadf'], {}) 62 | self.assertEqual(got, frozenset()) 63 | 64 | if __name__ == '__main__': 65 | unittest.main() 66 | -------------------------------------------------------------------------------- /README_PyPI.rst: -------------------------------------------------------------------------------- 1 | Can I Use Python 3? 2 | =================== 3 | 4 | This script takes in a set of dependencies and then figures out which 5 | of them are holding you up from porting to Python 3. 6 | 7 | Command-line/Web Usage 8 | ---------------------- 9 | 10 | You can specify your dependencies in multiple ways:: 11 | 12 | caniusepython3 -r requirements.txt test-requirement.txt 13 | caniusepython3 -m PKG-INFO 14 | caniusepython3 -p numpy scipy ipython 15 | # If your project's setup.py uses setuptools 16 | # (note that setup_requires can't be checked) ... 17 | python setup.py caniusepython3 18 | 19 | The output of the script will tell you how many (implicit) dependencies you need 20 | to transition to Python 3 in order to allow you to make the same transition. It 21 | will also list what projects have no dependencies blocking their 22 | transition so you can ask them to start a port to Python 3. 23 | 24 | If you prefer a web interface you can use https://caniusepython3.com by 25 | Jannis Leidel. 26 | 27 | 28 | Integrating With Your Tests 29 | --------------------------- 30 | 31 | If you want to check for Python 3 availability as part of your tests, you can 32 | use ``icanusepython3.check()``:: 33 | 34 | def check(requirements_paths=[], metadata=[], projects=[]): 35 | """Return True if all of the specified dependencies have been ported to Python 3. 36 | 37 | The requirements_paths argument takes a sequence of file paths to 38 | requirements files. The 'metadata' argument takes a sequence of strings 39 | representing metadata. The 'projects' argument takes a sequence of project 40 | names. 41 | 42 | Any project that is not listed on PyPI will be considered ported. 43 | """ 44 | 45 | You can then integrate it into your tests like so:: 46 | 47 | import unittest 48 | import caniusepython3 49 | 50 | class DependenciesOnPython3(unittest.TestCase): 51 | def test_dependencies(self): 52 | # Will begin to fail when dependencies are no longer blocking you 53 | # from using Python 3. 54 | self.assertFalse(caniusepython3.check(projects=['ipython'])) 55 | 56 | For the change log, how to tell if a project has been ported, as well as help on 57 | how to port a project, please see the 58 | `project website `__. 59 | 60 | Secret, bonus feature 61 | --------------------- 62 | If you would like to use a different name for the script and 63 | setuptools command then set the environment variable ``CIU_ALT_NAME`` to what 64 | you would like the alternative name to be. Reddit suggests ``icanhazpython3``. 65 | -------------------------------------------------------------------------------- /caniusepython3/test/test_pypi.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Google Inc. All rights reserved. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from __future__ import unicode_literals 16 | 17 | from caniusepython3 import pypi 18 | 19 | import unittest 20 | 21 | 22 | class NameTests(unittest.TestCase): 23 | 24 | def test_simple(self): 25 | want = 'simple-name_with.everything-separator_known' 26 | got = pypi.just_name(want) 27 | self.assertEqual(got, want) 28 | 29 | def test_requirements(self): 30 | want = 'project.name' 31 | got = pypi.just_name(want + '>=2.0.1') 32 | self.assertEqual(got, want) 33 | 34 | def test_bad_requirements(self): 35 | # From the OpenStack requirements file: 36 | # https://raw2.github.com/openstack/requirements/master/global-requirements.txt 37 | want = 'warlock' 38 | got = pypi.just_name(want + '>1.01<2') 39 | self.assertEqual(got, want) 40 | 41 | def test_metadata(self): 42 | want = 'foo' 43 | got = pypi.just_name("foo; sys.platform == 'okook'") 44 | self.assertEqual(got, want) 45 | 46 | 47 | class OverridesTests(unittest.TestCase): 48 | 49 | def test_all_lowercase(self): 50 | for name in pypi.overrides(): 51 | self.assertEqual(name, name.lower()) 52 | 53 | 54 | class NetworkTests(unittest.TestCase): 55 | 56 | def py3_classifiers(self): 57 | key_classifier = 'Programming Language :: Python :: 3' 58 | classifiers = frozenset(pypi.py3_classifiers()) 59 | if hasattr(self, 'assertIn'): 60 | self.asssertIn(key_classifier, classifiers) 61 | else: 62 | self.assertTrue(key_classifier in classifiers) 63 | if hasattr(self, 'assertGreaterEqual'): 64 | self.assertGreaterEqual(len(classifiers), 5) 65 | else: 66 | self.assertTrue(len(classifiers) >= 5) 67 | for classifier in classifiers: 68 | self.assertTrue(classifier.startswith(key_classifier)) 69 | 70 | 71 | def test_all_py3_projects(self): 72 | projects = pypi.all_py3_projects() 73 | if hasattr(self, 'assertGreater'): 74 | self.assertGreater(len(projects), 3000) 75 | else: 76 | self.assertTrue(len(projects) > 3000) 77 | self.assertTrue(all(project == project.lower() for project in projects)) 78 | self.assertTrue(frozenset(pypi.overrides().keys()).issubset(projects)) 79 | 80 | def test_all_py3_projects_explicit_overrides(self): 81 | added_port = 'asdfasdfasdfadsffffdasfdfdfdf' 82 | projects = pypi.all_py3_projects(set([added_port])) 83 | if hasattr(self, 'assertIn'): 84 | self.assertIn(added_port, projects) 85 | else: 86 | self.assertTrue(added_port in projects) 87 | 88 | def test_all_projects(self): 89 | projects = pypi.all_projects() 90 | self.assertTrue(all(project == project.lower() for project in projects)) 91 | if hasattr(self, 'assertGreaterEqual'): 92 | self.assertGreaterEqual(len(projects), 40000) 93 | else: 94 | self.assertTrue(len(projects) >= 40000) 95 | -------------------------------------------------------------------------------- /caniusepython3/dependencies.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Google Inc. All rights reserved. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from __future__ import unicode_literals 16 | 17 | import distlib.locators 18 | 19 | import caniusepython3 as ciu 20 | from caniusepython3 import pypi 21 | 22 | import concurrent.futures 23 | import logging 24 | 25 | 26 | class LowerDict(dict): 27 | 28 | def __getitem__(self, key): 29 | return super(LowerDict, self).__getitem__(key.lower()) 30 | 31 | 32 | def reasons_to_paths(reasons): 33 | """Calculate the dependency paths to the reasons of the blockers. 34 | 35 | Paths will be in reverse-dependency order (i.e. parent projects are in 36 | ascending order). 37 | 38 | """ 39 | blockers = set(reasons.keys()) - set(reasons.values()) 40 | paths = set() 41 | for blocker in blockers: 42 | path = [blocker] 43 | parent = reasons[blocker] 44 | while parent: 45 | path.append(parent) 46 | parent = reasons.get(parent) 47 | paths.add(tuple(path)) 48 | return paths 49 | 50 | 51 | def dependencies(project_name): 52 | """Get the dependencies for a project.""" 53 | log = logging.getLogger('ciu') 54 | deps = [] 55 | log.info('Locating {0}'.format(project_name)) 56 | located = distlib.locators.locate(project_name, prereleases=True) 57 | if located is None: 58 | log.warning('{0} not found'.format(project_name)) 59 | return None 60 | for dep in located.run_requires: 61 | # Drop any version details from the dependency name. 62 | deps.append(pypi.just_name(dep)) 63 | return deps 64 | 65 | 66 | def blocking_dependencies(projects, py3_projects): 67 | """Starting from 'projects', find all projects which are blocking Python 3 usage. 68 | 69 | Any project in 'py3_projects' is considered ported and thus will not have 70 | its dependencies searched. Version requirements are also ignored as it is 71 | assumed that if a project is updating to support Python 3 then they will be 72 | willing to update to the latest version of their dependencies. The only 73 | dependencies checked are those required to run the project. 74 | 75 | """ 76 | check = [project.lower() 77 | for project in projects if project.lower() not in py3_projects] 78 | reasons = LowerDict((project, None) for project in check) 79 | thread_pool_executor = concurrent.futures.ThreadPoolExecutor( 80 | max_workers=ciu.CPU_COUNT) 81 | with thread_pool_executor as executor: 82 | while len(check) > 0: 83 | new_check = [] 84 | for parent, deps in zip(check, executor.map(dependencies, check)): 85 | if deps is None: 86 | # Can't find any results for a project, so ignore it so as 87 | # to not accidentally consider indefinitely that a project 88 | # can't port. 89 | del reasons[parent] 90 | continue 91 | for dep in deps: 92 | if dep in py3_projects: 93 | continue 94 | reasons[dep] = parent 95 | new_check.append(dep) 96 | check = new_check 97 | return reasons_to_paths(reasons) 98 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Can I Use Python 3? 2 | 3 | [![Build Status](https://travis-ci.org/brettcannon/caniusepython3.png?branch=master)](http://img.shields.io/travis/brettcannon/caniusepython3.svg) 4 | 5 | You can read the documentation on how to use caniusepython3 from its 6 | [PyPI page](https://pypi.python.org/pypi/caniusepython3). A [web interface](https://github.com/jezdez/caniusepython3.com) 7 | is also available. 8 | 9 | 10 | # How do you tell if a project has been ported to Python 3? 11 | 12 | On [PyPI](https://pypi.python.org/) each project can specify various 13 | [trove classifiers](https://pypi.python.org/pypi?%3Aaction=list_classifiers) 14 | (typically in a project's `setup.py` through a [`classifier`](https://docs.python.org/3/distutils/setupscript.html#additional-meta-data) 15 | argument to `setup()`). 16 | There are various classifiers related to what version of Python a project can 17 | run on. E.g.: 18 | 19 | Programming Language :: Python :: 3 20 | Programming Language :: Python :: 3.0 21 | Programming Language :: Python :: 3.1 22 | Programming Language :: Python :: 3.2 23 | Programming Language :: Python :: 3.3 24 | Programming Language :: Python :: 3.4 25 | 26 | As long as a trove classifier for some version of Python 3 is specified then the 27 | project is considered to support Python 3 (project owners: it is preferred you 28 | **at least** specify `Programming Language :: Python :: 3` as that is how you 29 | end up listed on the [Python 3 Packages list on PyPI](https://pypi.python.org/pypi?%3Aaction=packages_rss); 30 | you can represent Python 2 support with `Programming Language :: Python`). 31 | 32 | The other way is through a [manual override](https://github.com/brettcannon/caniusepython3/blob/master/caniusepython3/overrides.json) in 33 | `caniusepython3` itself. This list of projects exists because: 34 | 35 | * They are now part of [Python's standard library](http://docs.python.org/3/py-modindex.html) in some release of Python 3 36 | * Their Python 3 port is under a different name 37 | * They are missing a Python 3 trove classifier but have actually been ported 38 | 39 | If any of these various requirements are met, then a project is considered to 40 | support Python 3 and thus will be added to the manual overrides list. You can 41 | see the list of overrides when you run the script with verbose output turned on. 42 | 43 | 44 | # How can I get a project ported to Python 3? 45 | 46 | Typically projects which have not switched to Python 3 yet are waiting for: 47 | 48 | * A dependency to be ported to Python 3 49 | * Someone to volunteer to put in the time and effort to do the port 50 | 51 | Since `caniusepython3` will tell you what dependencies are blocking a project 52 | that you depend on from being ported, you can try to port a project farther 53 | down your dependency graph to help a more direct dependency make the transition. 54 | 55 | Which brings up the second point: volunteering to do a port. Most projects 56 | happily accept help, they just have not done the port yet because they have 57 | not had the time. Some projects are simply waiting for people to ask for it, so 58 | even speaking up politely and requesting a port can get the process started. 59 | 60 | If you are looking for help to port a project, you can always search online for 61 | various sources of help. If you want a specific starting point there are 62 | [HOWTOs](http://docs.python.org/3/howto/index.html) in the Python documentation 63 | on [porting pure Python modules](http://docs.python.org/3/howto/pyporting.html) 64 | and [extension modules](http://docs.python.org/3/howto/cporting.html). 65 | 66 | # Change Log 67 | 68 | ## 2.1.0 69 | * Verbose output will print what manual overrides are used and why 70 | (when available) 71 | * Fix logging to only be configured when running as a script as well as fix a 72 | format bug 73 | * Usual override updates 74 | 75 | ## 2.0.3 76 | * Fixed `setup.py caniusepython3` to work with `extras_require` properly 77 | * Fix various errors triggered from the moving of the `just_name()` function to 78 | a new module in 2.0.0 (patch by Vaibhav Sagar w/ input from Jannis Leidel) 79 | * Usual overrides tweaks (thanks to CyrilRoelandteNovance for contributing) 80 | 81 | ## 2.0.2 82 | * Fix lack of unicode usage in a test 83 | * Make Python 2.6 happy again due to its distate of empty XML-RPC results 84 | 85 | ## 2.0.1 86 | * Fix syntax error 87 | 88 | ## 2.0.0 89 | * Tweak overrides 90 | * `-r`, `-m`, and `-p` now take 1+ arguments instead of a single comma-separated 91 | list 92 | * Unrecognized projects are considered ported to prevent the lack of info on 93 | the unrecognized project perpetually suggesting that it's never been ported 94 | * Introduced `icanusepython3.check()` 95 | 96 | ## 1.2.1 97 | * Fix `-v` to actually do something again 98 | * Tweaked overrides 99 | 100 | ## 1.2.0 101 | * `-r` accepts a comma-separated list of file paths 102 | 103 | ## 1.1.0 104 | * Setuptools command support 105 | * Various fixes 106 | 107 | ## 1.0 108 | Initial release. 109 | -------------------------------------------------------------------------------- /caniusepython3/pypi.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Google Inc. All rights reserved. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from __future__ import unicode_literals 16 | 17 | import concurrent.futures 18 | import contextlib 19 | import json 20 | import logging 21 | import multiprocessing 22 | import pkgutil 23 | import re 24 | try: 25 | import urllib.request as urllib_request 26 | except ImportError: #pragma: no cover 27 | import urllib2 as urllib_request 28 | import xml.parsers.expat 29 | try: 30 | import xmlrpc.client as xmlrpc_client 31 | except ImportError: #pragma: no cover 32 | import xmlrpclib as xmlrpc_client 33 | 34 | 35 | try: 36 | CPU_COUNT = max(2, multiprocessing.cpu_count()) 37 | except NotImplementedError: #pragma: no cover 38 | CPU_COUNT = 2 39 | 40 | PROJECT_NAME = re.compile(r'[\w.-]+') 41 | 42 | 43 | def just_name(supposed_name): 44 | """Strip off any versioning or restrictions metadata from a project name.""" 45 | return PROJECT_NAME.match(supposed_name).group(0).lower() 46 | 47 | @contextlib.contextmanager 48 | def pypi_client(): 49 | client = xmlrpc_client.ServerProxy('http://pypi.python.org/pypi') 50 | try: 51 | yield client 52 | finally: 53 | try: 54 | client('close')() 55 | except xml.parsers.expat.ExpatError: #pragma: no cover 56 | # The close hack is not in Python 2.6. 57 | pass 58 | 59 | 60 | def overrides(): 61 | """Load a set containing projects who are missing the proper Python 3 classifier. 62 | 63 | Project names are always lowercased. 64 | 65 | """ 66 | raw_bytes = pkgutil.get_data(__name__, 'overrides.json') 67 | return json.loads(raw_bytes.decode('utf-8')) 68 | 69 | 70 | def py3_classifiers(): 71 | """Fetch the Python 3-related trove classifiers.""" 72 | url = 'https://pypi.python.org/pypi?%3Aaction=list_classifiers' 73 | response = urllib_request.urlopen(url) 74 | try: 75 | try: 76 | status = response.status 77 | except AttributeError: #pragma: no cover 78 | status = response.code 79 | if status != 200: #pragma: no cover 80 | msg = 'PyPI responded with status {0} for {1}'.format(status, url) 81 | raise ValueError(msg) 82 | data = response.read() 83 | finally: 84 | response.close() 85 | classifiers = data.decode('utf-8').splitlines() 86 | base_classifier = 'Programming Language :: Python :: 3' 87 | return (classifier for classifier in classifiers 88 | if classifier.startswith(base_classifier)) 89 | 90 | 91 | def projects_matching_classifier(classifier): 92 | """Find all projects matching the specified trove classifier.""" 93 | log = logging.getLogger('ciu') 94 | with pypi_client() as client: 95 | log.info('Fetching project list for {0!r}'.format(classifier)) 96 | try: 97 | return frozenset(result[0].lower() 98 | for result in client.browse([classifier])) 99 | except xml.parsers.expat.ExpatError: #pragma: no cover 100 | # Python 2.6 doesn't like empty results. 101 | logging.getLogger('ciu').info("PyPI didn't return any results") 102 | return [] 103 | 104 | 105 | def all_py3_projects(manual_overrides=None): 106 | """Return the set of names of all projects ported to Python 3, lowercased.""" 107 | log = logging.getLogger('ciu') 108 | projects = set() 109 | thread_pool_executor = concurrent.futures.ThreadPoolExecutor( 110 | max_workers=CPU_COUNT) 111 | with thread_pool_executor as executor: 112 | for result in map(projects_matching_classifier, py3_classifiers()): 113 | projects.update(result) 114 | if manual_overrides is None: 115 | manual_overrides = overrides() 116 | stale_overrides = projects.intersection(manual_overrides) 117 | log.info('Adding {0} overrides:'.format(len(manual_overrides))) 118 | for override in sorted(manual_overrides): 119 | msg = override 120 | try: 121 | msg += ' ({0})'.format(manual_overrides[override]) 122 | except TypeError: 123 | # No reason a set can't be used. 124 | pass 125 | log.info(' ' + msg) 126 | if stale_overrides: #pragma: no cover 127 | log.warning('Stale overrides: {0}'.format(stale_overrides)) 128 | projects.update(manual_overrides) 129 | return projects 130 | 131 | 132 | def all_projects(): 133 | """Get the set of all projects on PyPI.""" 134 | log = logging.getLogger('ciu') 135 | with pypi_client() as client: 136 | log.info('Fetching all project names from PyPI') 137 | return frozenset(name.lower() for name in client.list_packages()) 138 | -------------------------------------------------------------------------------- /caniusepython3/__main__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Google Inc. All rights reserved. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from __future__ import print_function 16 | from __future__ import unicode_literals 17 | 18 | import caniusepython3 as ciu 19 | from caniusepython3 import pypi 20 | from caniusepython3 import dependencies 21 | 22 | import distlib.metadata 23 | import pip.req 24 | 25 | import argparse 26 | import io 27 | import logging 28 | import sys 29 | 30 | 31 | def projects_from_requirements(requirements): 32 | """Extract the project dependencies from a Requirements specification.""" 33 | log = logging.getLogger('ciu') 34 | valid_reqs = [] 35 | for requirements_path in requirements: 36 | reqs = pip.req.parse_requirements(requirements_path) 37 | for req in reqs: 38 | if not req.name: 39 | log.warning('A requirement lacks a name ' 40 | '(e.g. no `#egg` on a `file:` path)') 41 | elif req.editable: 42 | log.warning( 43 | 'Skipping {0}: editable projects unsupported'.format(req.name)) 44 | elif req.url and req.url.startswith('file:'): 45 | log.warning( 46 | 'Skipping {0}: file-specified projects unsupported'.format(req.name)) 47 | else: 48 | valid_reqs.append(req.name) 49 | return valid_reqs 50 | 51 | 52 | def projects_from_metadata(metadata): 53 | """Extract the project dependencies from a metadata spec.""" 54 | projects = [] 55 | for data in metadata: 56 | meta = distlib.metadata.Metadata(fileobj=io.StringIO(data)) 57 | projects.extend(pypi.just_name(project) for project in meta.run_requires) 58 | return projects 59 | 60 | 61 | def projects_from_cli(args): 62 | """Take arguments through the CLI can create a list of specified projects.""" 63 | description = ('Determine if a set of project dependencies will work with ' 64 | 'Python 3') 65 | parser = argparse.ArgumentParser(description=description) 66 | req_help = 'path(s) to a pip requirements file (e.g. requirements.txt)' 67 | parser.add_argument('--requirements', '-r', nargs='+', default=(), 68 | help=req_help) 69 | meta_help = 'path(s) to a PEP 426 metadata file (e.g. PKG-INFO, pydist.json)' 70 | parser.add_argument('--metadata', '-m', nargs='+', default=(), 71 | help=meta_help) 72 | parser.add_argument('--projects', '-p', nargs='+', default=(), 73 | help='name(s) of projects to test for Python 3 support') 74 | parser.add_argument('--verbose', '-v', action='store_true', 75 | help='verbose output (e.g. list compatibility overrides)') 76 | parsed = parser.parse_args(args) 77 | 78 | if not (parsed.requirements or parsed.metadata or parsed.projects): 79 | parser.error("Missing 'requirements', 'metadata', or 'projects'") 80 | 81 | projects = [] 82 | if parsed.verbose: 83 | logging.getLogger('ciu').setLevel(logging.INFO) 84 | projects.extend(projects_from_requirements(parsed.requirements)) 85 | metadata = [] 86 | for metadata_path in parsed.metadata: 87 | with io.open(metadata_path) as file: 88 | metadata.append(file.read()) 89 | projects.extend(projects_from_metadata(metadata)) 90 | projects.extend(parsed.projects) 91 | 92 | return projects 93 | 94 | 95 | def message(blockers): 96 | """Create a sequence of key messages based on what is blocking.""" 97 | if not blockers: 98 | return ['You have 0 projects blocking you from using Python 3!'] 99 | flattened_blockers = set() 100 | for blocker_reasons in blockers: 101 | for blocker in blocker_reasons: 102 | flattened_blockers.add(blocker) 103 | need = 'You need {0} project{1} to transition to Python 3.' 104 | formatted_need = need.format(len(flattened_blockers), 105 | 's' if len(flattened_blockers) != 1 else '') 106 | can_port = ('Of {0} {1} project{2}, {3} {4} no direct dependencies ' 107 | 'blocking {5} transition:') 108 | formatted_can_port = can_port.format( 109 | 'those' if len(flattened_blockers) != 1 else 'that', 110 | len(flattened_blockers), 111 | 's' if len(flattened_blockers) != 1 else '', 112 | len(blockers), 113 | 'have' if len(blockers) != 1 else 'has', 114 | 'their' if len(blockers) != 1 else 'its') 115 | return formatted_need, formatted_can_port 116 | 117 | 118 | def pprint_blockers(blockers): 119 | """Pretty print blockers into a sequence of strings. 120 | 121 | Results will be sorted by top-level project name. This means that if a 122 | project is blocking another project then the dependent project will be 123 | what is used in the sorting, not the project at the bottom of the 124 | dependency graph. 125 | 126 | """ 127 | pprinted = [] 128 | for blocker in sorted(blockers, key=lambda x: tuple(reversed(x))): 129 | buf = [blocker[0]] 130 | if len(blocker) > 1: 131 | buf.append(' (which is blocking ') 132 | buf.append(', which is blocking '.join(blocker[1:])) 133 | buf.append(')') 134 | pprinted.append(''.join(buf)) 135 | return pprinted 136 | 137 | 138 | def check(projects): 139 | """Check the specified projects for Python 3 compatibility.""" 140 | log = logging.getLogger('ciu') 141 | log.info('{0} top-level projects to check'.format(len(projects))) 142 | print('Finding and checking dependencies ...') 143 | blockers = dependencies.blocking_dependencies(projects, pypi.all_py3_projects()) 144 | 145 | print('') 146 | for line in message(blockers): 147 | print(line) 148 | 149 | print('') 150 | for line in pprint_blockers(blockers): 151 | print(' ', line) 152 | 153 | 154 | def main(args=sys.argv[1:]): 155 | check(projects_from_cli(args)) 156 | 157 | 158 | if __name__ == '__main__': #pragma: no cover 159 | # Without this, the 'ciu' logger will emit nothing. 160 | logging.basicConfig(format='[%(levelname)s] %(message)s') 161 | main() 162 | -------------------------------------------------------------------------------- /caniusepython3/test/test_cli.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Google Inc. All rights reserved. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from __future__ import unicode_literals 16 | 17 | import caniusepython3.__main__ as ciu_main 18 | 19 | import io 20 | import logging 21 | import tempfile 22 | import unittest 23 | try: 24 | from unittest import mock 25 | except ImportError: 26 | import mock 27 | 28 | 29 | EXAMPLE_REQUIREMENTS = """ 30 | # From 31 | # http://www.pip-installer.org/en/latest/reference/pip_install.html#requirement-specifiers 32 | # but without the quotes for shell protection. 33 | FooProject >= 1.2 34 | Fizzy [foo, bar] 35 | PickyThing<1.6,>1.9,!=1.9.6,<2.0a0,==2.4c1 36 | Hello 37 | -e git+https://github.com/brettcannon/caniusepython3#egg=caniusepython3 38 | file:../caniusepython3#egg=caniusepython3 39 | # Docs say to specify an #egg argument, but apparently it's optional. 40 | file:../../lib/project 41 | """ 42 | 43 | EXAMPLE_EXTRA_REQUIREMENTS = """ 44 | testingstuff 45 | """ 46 | 47 | EXAMPLE_METADATA = """Metadata-Version: 1.2 48 | Name: CLVault 49 | Version: 0.5 50 | Summary: Command-Line utility to store and retrieve passwords 51 | Home-page: http://bitbucket.org/tarek/clvault 52 | Author: Tarek Ziade 53 | Author-email: tarek@ziade.org 54 | License: PSF 55 | Keywords: keyring,password,crypt 56 | Requires-Dist: foo; sys.platform == 'okook' 57 | Requires-Dist: bar 58 | Platform: UNKNOWN 59 | """ 60 | 61 | EXAMPLE_EXTRA_METADATA = """Metadata-Version: 1.2 62 | Name: ExtraTest 63 | Version: 0.5 64 | Summary: Just for testing 65 | Home-page: nowhere 66 | Author: nobody 67 | License: Apache 68 | Requires-Dist: baz 69 | """ 70 | 71 | class CLITests(unittest.TestCase): 72 | 73 | expected_requirements = frozenset(['FooProject', 'Fizzy', 'PickyThing', 74 | 'Hello']) 75 | expected_extra_requirements = frozenset(['testingstuff']) 76 | expected_metadata = frozenset(['foo', 'bar']) 77 | expected_extra_metadata = frozenset(['baz']) 78 | 79 | def setUp(self): 80 | log = logging.getLogger('ciu') 81 | self._prev_log_level = log.getEffectiveLevel() 82 | logging.getLogger('ciu').setLevel(1000) 83 | 84 | def tearDown(self): 85 | logging.getLogger('ciu').setLevel(self._prev_log_level) 86 | 87 | def test_requirements(self): 88 | with tempfile.NamedTemporaryFile('w') as file: 89 | file.write(EXAMPLE_REQUIREMENTS) 90 | file.flush() 91 | got = ciu_main.projects_from_requirements([file.name]) 92 | self.assertEqual(set(got), self.expected_requirements) 93 | 94 | def test_multiple_requirements_files(self): 95 | with tempfile.NamedTemporaryFile('w') as f1: 96 | f1.write(EXAMPLE_REQUIREMENTS) 97 | f1.flush() 98 | with tempfile.NamedTemporaryFile('w') as f2: 99 | f2.write(EXAMPLE_EXTRA_REQUIREMENTS) 100 | f2.flush() 101 | got = ciu_main.projects_from_requirements([f1.name, f2.name]) 102 | want = self.expected_requirements.union(self.expected_extra_requirements) 103 | self.assertEqual(set(got), want) 104 | 105 | def test_metadata(self): 106 | got = ciu_main.projects_from_metadata([EXAMPLE_METADATA]) 107 | self.assertEqual(set(got), self.expected_metadata) 108 | 109 | def test_multiple_metadata(self): 110 | got = ciu_main.projects_from_metadata([EXAMPLE_METADATA, 111 | EXAMPLE_EXTRA_METADATA]) 112 | want = self.expected_metadata.union(self.expected_extra_metadata) 113 | self.assertEqual(set(got), want) 114 | 115 | def test_cli_for_requirements(self): 116 | with tempfile.NamedTemporaryFile('w') as file: 117 | file.write(EXAMPLE_REQUIREMENTS) 118 | file.flush() 119 | args = ['--requirements', file.name] 120 | got = ciu_main.projects_from_cli(args) 121 | self.assertEqual(set(got), self.expected_requirements) 122 | 123 | def test_cli_for_metadata(self): 124 | with tempfile.NamedTemporaryFile('w') as file: 125 | file.write(EXAMPLE_METADATA) 126 | file.flush() 127 | args = ['--metadata', file.name] 128 | got = ciu_main.projects_from_cli(args) 129 | self.assertEqual(set(got), self.expected_metadata) 130 | 131 | def test_cli_for_projects(self): 132 | args = ['--projects', 'foo', 'bar'] 133 | got = ciu_main.projects_from_cli(args) 134 | self.assertEqual(set(got), frozenset(['foo', 'bar'])) 135 | 136 | def test_message_plural(self): 137 | blockers = [['A'], ['B']] 138 | messages = ciu_main.message(blockers) 139 | self.assertEqual(2, len(messages)) 140 | want = 'You need 2 projects to transition to Python 3.' 141 | self.assertEqual(messages[0], want) 142 | want = ('Of those 2 projects, 2 have no direct dependencies blocking ' 143 | 'their transition:') 144 | self.assertEqual(messages[1], want) 145 | 146 | def test_message_singular(self): 147 | blockers = [['A']] 148 | messages = ciu_main.message(blockers) 149 | self.assertEqual(2, len(messages)) 150 | want = 'You need 1 project to transition to Python 3.' 151 | self.assertEqual(messages[0], want) 152 | want = ('Of that 1 project, 1 has no direct dependencies blocking ' 153 | 'its transition:') 154 | self.assertEqual(messages[1], want) 155 | 156 | def test_message_no_blockers(self): 157 | messages = ciu_main.message([]) 158 | self.assertEqual( 159 | ['You have 0 projects blocking you from using Python 3!'], 160 | messages) 161 | 162 | def test_pprint_blockers(self): 163 | simple = [['A']] 164 | fancy = [['A', 'B']] 165 | nutty = [['A', 'B', 'C']] 166 | repeated = [['A', 'C'], ['B']] # Also tests sorting. 167 | got = ciu_main.pprint_blockers(simple) 168 | self.assertEqual(list(got), ['A']) 169 | got = ciu_main.pprint_blockers(fancy) 170 | self.assertEqual(list(got), ['A (which is blocking B)']) 171 | got = ciu_main.pprint_blockers(nutty) 172 | self.assertEqual(list(got), 173 | ['A (which is blocking B, which is blocking C)']) 174 | got = ciu_main.pprint_blockers(repeated) 175 | self.assertEqual(list(got), ['B', 'A (which is blocking C)']) 176 | 177 | @mock.patch('argparse.ArgumentParser.error') 178 | def test_projects_must_be_specified(self, parser_error): 179 | ciu_main.projects_from_cli([]) 180 | self.assertEqual( 181 | mock.call("Missing 'requirements', 'metadata', or 'projects'"), 182 | parser_error.call_args) 183 | 184 | def test_verbose_output(self): 185 | ciu_main.projects_from_cli(['-v', '-p', 'ipython']) 186 | self.assertTrue(logging.getLogger('ciu').isEnabledFor(logging.INFO)) 187 | 188 | 189 | #@unittest.skip('faster testing') 190 | class NetworkTests(unittest.TestCase): 191 | 192 | @mock.patch('sys.stdout', io.StringIO()) 193 | def test_e2e(self): 194 | # Make sure at least one project that will never be in Python 3 is 195 | # included. 196 | args = '--projects', 'numpy', 'scipy', 'matplotlib', 'ipython', 'paste' 197 | ciu_main.main(args) 198 | 199 | 200 | if __name__ == '__main__': 201 | unittest.main() 202 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------