2018-08-15 03:52:07 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2019-01-08 05:40:49 -05:00
|
|
|
import argparse
|
2018-08-15 03:52:07 -04:00
|
|
|
import os
|
|
|
|
import sys
|
2019-01-08 05:40:49 -05:00
|
|
|
|
2018-08-15 03:52:07 -04:00
|
|
|
try:
|
|
|
|
import pkg_resources
|
2018-11-30 07:31:44 -05:00
|
|
|
except Exception:
|
2018-08-15 03:52:07 -04: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 07:31:44 -05:00
|
|
|
'setting up the required packages.')
|
2018-08-15 03:52:07 -04:00
|
|
|
sys.exit(1)
|
|
|
|
|
2018-11-30 07:31:44 -05:00
|
|
|
|
2018-11-30 07:22:31 -05:00
|
|
|
def escape_backslash(path):
|
|
|
|
if sys.platform == "win32":
|
|
|
|
# escaped backslashes are necessary in order to be able to copy-paste the printed path
|
|
|
|
return path.replace("\\", "\\\\")
|
|
|
|
else:
|
|
|
|
return path
|
|
|
|
|
2018-11-30 07:31:44 -05:00
|
|
|
|
2019-01-08 05:40:49 -05:00
|
|
|
def is_virtualenv():
|
|
|
|
"""Detects if current python is inside virtualenv, pyvenv (python 3.4-3.5) or venv"""
|
|
|
|
|
|
|
|
return (hasattr(sys, 'real_prefix') or
|
|
|
|
(hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix))
|
|
|
|
|
|
|
|
|
2018-08-15 03:52:07 -04:00
|
|
|
if __name__ == "__main__":
|
2018-08-28 14:01:25 -04:00
|
|
|
idf_path = os.getenv("IDF_PATH")
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='ESP32 Python package dependency checker')
|
|
|
|
parser.add_argument('--requirements', '-r',
|
2018-11-30 07:31:44 -05:00
|
|
|
help='Path to the requrements file',
|
|
|
|
default=os.path.join(idf_path, 'requirements.txt'))
|
2018-08-28 14:01:25 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2018-08-15 03:52:07 -04:00
|
|
|
not_satisfied = []
|
2018-08-28 14:01:25 -04:00
|
|
|
with open(args.requirements) as f:
|
2018-08-15 03:52:07 -04:00
|
|
|
for line in f:
|
|
|
|
line = line.strip()
|
|
|
|
try:
|
|
|
|
pkg_resources.require(line)
|
2018-11-30 07:31:44 -05:00
|
|
|
except Exception:
|
2018-08-15 03:52:07 -04:00
|
|
|
not_satisfied.append(line)
|
|
|
|
|
|
|
|
if len(not_satisfied) > 0:
|
|
|
|
print('The following Python requirements are not satisfied:')
|
|
|
|
for requirement in not_satisfied:
|
|
|
|
print(requirement)
|
2019-04-17 03:32:03 -04:00
|
|
|
if os.environ.get('IDF_PYTHON_ENV_PATH'):
|
|
|
|
# We are running inside a private virtual environment under IDF_TOOLS_PATH,
|
|
|
|
# ask the user to run install.bat again.
|
|
|
|
if sys.platform == "win32" and not os.environ.get("MSYSTEM"):
|
|
|
|
install_script = 'install.bat'
|
|
|
|
else:
|
|
|
|
install_script = 'install.sh'
|
|
|
|
print('To install the missing packages, please run "%s"' % os.path.join(idf_path, install_script))
|
|
|
|
elif sys.platform == "win32" and os.environ.get("MSYSTEM", None) == "MINGW32" and "/mingw32/bin/python" in sys.executable:
|
2018-12-19 08:04:57 -05:00
|
|
|
print("The recommended way to install a packages is via \"pacman\". Please run \"pacman -Ss <package_name>\" for"
|
|
|
|
" searching the package database and if found then "
|
2020-06-04 04:39:20 -04:00
|
|
|
"\"pacman -S mingw-w64-i686-python-<package_name>\" for installing it.")
|
2018-12-19 08:04:57 -05:00
|
|
|
print("NOTE: You may need to run \"pacman -Syu\" if your package database is older and run twice if the "
|
|
|
|
"previous run updated \"pacman\" itself.")
|
|
|
|
print("Please read https://github.com/msys2/msys2/wiki/Using-packages for further information about using "
|
|
|
|
"\"pacman\"")
|
|
|
|
# Special case for MINGW32 Python, needs some packages
|
|
|
|
# via MSYS2 not via pip or system breaks...
|
|
|
|
for requirement in not_satisfied:
|
|
|
|
if requirement.startswith('cryptography'):
|
|
|
|
print("WARNING: The cryptography package have dependencies on system packages so please make sure "
|
|
|
|
"you run \"pacman -Syu\" followed by \"pacman -S mingw-w64-i686-python{}-cryptography\"."
|
|
|
|
"".format(sys.version_info[0],))
|
|
|
|
continue
|
|
|
|
elif requirement.startswith('setuptools'):
|
|
|
|
print("Please run the following command to install MSYS2's MINGW Python setuptools package:")
|
2020-06-04 04:39:20 -04:00
|
|
|
print("pacman -S mingw-w64-i686-python-setuptools")
|
2018-12-19 08:04:57 -05:00
|
|
|
continue
|
|
|
|
else:
|
|
|
|
print('Please refer to the Get Started section of the ESP-IDF Programming Guide for setting up the required'
|
|
|
|
' packages.')
|
2019-01-08 05:40:49 -05:00
|
|
|
print('Alternatively, you can run "{} -m pip install {}-r {}" for resolving the issue.'
|
|
|
|
''.format(escape_backslash(sys.executable),
|
|
|
|
'' if is_virtualenv() else '--user ',
|
|
|
|
escape_backslash(args.requirements)))
|
2018-08-15 03:52:07 -04:00
|
|
|
sys.exit(1)
|
|
|
|
|
2018-08-28 14:01:25 -04:00
|
|
|
print('Python requirements from {} are satisfied.'.format(args.requirements))
|