2018-08-15 07:52:07 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
2021-09-16 14:48:03 +00:00
|
|
|
# SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
|
2021-08-13 07:11:42 +00:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2018-08-15 07:52:07 +00:00
|
|
|
|
2019-01-08 10:40:49 +00:00
|
|
|
import argparse
|
2018-08-15 07:52:07 +00:00
|
|
|
import os
|
2019-11-28 21:56:53 +00:00
|
|
|
import re
|
2018-08-15 07:52:07 +00:00
|
|
|
import sys
|
2019-01-08 10:40:49 +00:00
|
|
|
|
2021-09-16 14:48:03 +00:00
|
|
|
PYTHON_PACKAGE_RE = re.compile(r'[^<>=~]+')
|
|
|
|
|
2018-08-15 07:52:07 +00:00
|
|
|
try:
|
|
|
|
import pkg_resources
|
2021-09-16 14:48:03 +00:00
|
|
|
except ImportError:
|
2018-08-15 07:52:07 +00:00
|
|
|
print('pkg_resources cannot be imported probably because the pip package is not installed and/or using a '
|
|
|
|
'legacy Python interpreter. Please refer to the Get Started section of the ESP-IDF Programming Guide for '
|
2018-11-30 12:31:44 +00:00
|
|
|
'setting up the required packages.')
|
2018-08-15 07:52:07 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2018-11-30 12:31:44 +00:00
|
|
|
|
2021-01-26 02:49:01 +00:00
|
|
|
if __name__ == '__main__':
|
2020-04-16 09:52:19 +00:00
|
|
|
parser = argparse.ArgumentParser(description='ESP-IDF Python package dependency checker')
|
2018-08-28 18:01:25 +00:00
|
|
|
parser.add_argument('--requirements', '-r',
|
2021-09-16 14:48:03 +00:00
|
|
|
help='Path to a requirements file (can be used multiple times)',
|
|
|
|
action='append', default=[])
|
|
|
|
parser.add_argument('--constraints', '-c', default=[],
|
|
|
|
help='Path to a constraints file (can be used multiple times)',
|
|
|
|
action='append')
|
2018-08-28 18:01:25 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2021-09-16 14:48:03 +00:00
|
|
|
required_set = set()
|
|
|
|
for req_path in args.requirements:
|
|
|
|
with open(req_path) as f:
|
|
|
|
required_set |= set(i for i in map(str.strip, f.readlines()) if len(i) > 0 and not i.startswith('#'))
|
|
|
|
|
|
|
|
constr_dict = {} # for example package_name -> package_name==1.0
|
|
|
|
for const_path in args.constraints:
|
|
|
|
with open(const_path) as f:
|
|
|
|
for con in [i for i in map(str.strip, f.readlines()) if len(i) > 0 and not i.startswith('#')]:
|
|
|
|
if con.startswith('file://'):
|
|
|
|
con = os.path.basename(con)
|
|
|
|
elif con.startswith('--only-binary'):
|
|
|
|
continue
|
|
|
|
elif con.startswith('-e') and '#egg=' in con: # version control URLs, take the egg= part at the end only
|
|
|
|
con_m = re.search(r'#egg=([^\s]+)', con)
|
|
|
|
if not con_m:
|
|
|
|
print('Malformed input. Cannot find name in {}'.format(con))
|
|
|
|
sys.exit(1)
|
|
|
|
con = con_m[1]
|
|
|
|
|
|
|
|
name_m = PYTHON_PACKAGE_RE.search(con)
|
|
|
|
if not name_m:
|
|
|
|
print('Malformed input. Cannot find name in {}'.format(con))
|
|
|
|
sys.exit(1)
|
|
|
|
constr_dict[name_m[0]] = con
|
|
|
|
|
|
|
|
# We need to constrain package dependencies as well. So all installed packages need to be checked.
|
|
|
|
# For example package A requires package B. We have only A in our requirements. But the newest version of B could
|
|
|
|
# broke at some time and in that case we add a constraint for B (on the server) but don't have to update the
|
|
|
|
# requirement file (in the ESP-IDF repo).
|
|
|
|
required_set |= set(i.key for i in pkg_resources.working_set)
|
|
|
|
|
2018-08-15 07:52:07 +00:00
|
|
|
not_satisfied = []
|
2021-09-16 14:48:03 +00:00
|
|
|
for requirement in required_set:
|
|
|
|
# If there is a version-specific constraint for the requirement then use it. Otherwise, just use the
|
|
|
|
# requirement as is.
|
|
|
|
to_require = constr_dict.get(requirement, requirement)
|
|
|
|
try:
|
|
|
|
pkg_resources.require(to_require)
|
|
|
|
except pkg_resources.ResolutionError:
|
|
|
|
not_satisfied.append(to_require)
|
2018-08-15 07:52:07 +00:00
|
|
|
|
|
|
|
if len(not_satisfied) > 0:
|
|
|
|
print('The following Python requirements are not satisfied:')
|
2021-09-16 14:48:03 +00:00
|
|
|
print(os.linesep.join(not_satisfied))
|
|
|
|
if 'IDF_PYTHON_ENV_PATH' in os.environ:
|
2019-04-17 07:32:03 +00:00
|
|
|
# We are running inside a private virtual environment under IDF_TOOLS_PATH,
|
|
|
|
# ask the user to run install.bat again.
|
2021-09-16 14:48:03 +00:00
|
|
|
install_script = 'install.bat' if sys.platform == 'win32' else 'install.sh'
|
|
|
|
print('To install the missing packages, please run "{}"'.format(install_script))
|
2018-12-19 13:04:57 +00:00
|
|
|
else:
|
2019-11-04 14:43:13 +00:00
|
|
|
print('Please follow the instructions found in the "Set up the tools" section of '
|
2021-09-16 14:48:03 +00:00
|
|
|
'ESP-IDF Getting Started Guide.')
|
2020-04-16 09:52:19 +00:00
|
|
|
|
|
|
|
print('Diagnostic information:')
|
|
|
|
idf_python_env_path = os.environ.get('IDF_PYTHON_ENV_PATH')
|
|
|
|
print(' IDF_PYTHON_ENV_PATH: {}'.format(idf_python_env_path or '(not set)'))
|
|
|
|
print(' Python interpreter used: {}'.format(sys.executable))
|
2020-06-08 16:14:39 +00:00
|
|
|
if not idf_python_env_path or idf_python_env_path not in sys.executable:
|
2020-04-16 09:52:19 +00:00
|
|
|
print(' Warning: python interpreter not running from IDF_PYTHON_ENV_PATH')
|
|
|
|
print(' PATH: {}'.format(os.getenv('PATH')))
|
2018-08-15 07:52:07 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2021-09-16 14:48:03 +00:00
|
|
|
print('Python requirements are satisfied.')
|