This repository has been archived by the owner on Jan 2, 2021. It is now read-only.
/
__init__.py
69 lines (51 loc) · 2.5 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Copyright 2014 Google Inc. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Calculate whether the specified package(s) and their dependencies support Python 3."""
from __future__ import unicode_literals
from caniusepython3 import __main__ as main
from caniusepython3 import pypi
import multiprocessing
import distlib.util
# Use the Fastly CDN instead of red-dove.com for reliability.
_base_project_url = 'http://ciupy3-projects.global.ssl.fastly.net/pypi/projects/'
def get_project_data(name):
url = '%s%s/%s/project.json' % (_base_project_url, name[0].upper(), name)
return distlib.util._get_external_data(url)
distlib.util.get_project_data = get_project_data
del get_project_data
def get_package_data(name, version):
url = ('%s%s/%s/package-%s.json' % (_base_project_url, name[0].upper(),
name, version))
return distlib.util._get_external_data(url)
distlib.util.get_package_data = get_package_data
del get_package_data
try:
CPU_COUNT = max(2, multiprocessing.cpu_count())
except NotImplementedError: #pragma: no cover
CPU_COUNT = 2
def check(requirements_paths=[], metadata=[], projects=[]):
"""Return True if all of the specified dependencies have been ported to Python 3.
The requirements_paths argument takes a sequence of file paths to
requirements files. The 'metadata' argument takes a sequence of strings
representing metadata. The 'projects' argument takes a sequence of project
names.
Any project that is not listed on PyPI will be considered ported.
"""
dependencies = main.projects_from_requirements(requirements_paths)
dependencies.extend(main.projects_from_metadata(metadata))
dependencies.extend(projects)
dependencies = set(name.lower() for name in dependencies)
py3_projects = pypi.all_py3_projects()
all_projects = pypi.all_projects()
for dependency in dependencies:
if dependency in all_projects and dependency not in py3_projects:
return False
return True