2018-08-15 07:52:07 +00: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.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2018-08-28 18:01:25 +00:00
|
|
|
import argparse
|
2018-08-15 07:52:07 +00:00
|
|
|
try:
|
|
|
|
import pkg_resources
|
2018-11-30 12:31:44 +00:00
|
|
|
except Exception:
|
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
|
|
|
|
2018-11-30 12:22:31 +00: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 12:31:44 +00:00
|
|
|
|
2018-08-15 07:52:07 +00:00
|
|
|
if __name__ == "__main__":
|
2018-08-28 18:01:25 +00:00
|
|
|
idf_path = os.getenv("IDF_PATH")
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='ESP32 Python package dependency checker')
|
|
|
|
parser.add_argument('--requirements', '-r',
|
2018-11-30 12:31:44 +00:00
|
|
|
help='Path to the requrements file',
|
|
|
|
default=os.path.join(idf_path, 'requirements.txt'))
|
2018-08-28 18:01:25 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2018-10-01 03:59:14 +00:00
|
|
|
# Special case for MINGW32 Python, needs some packages
|
|
|
|
# via MSYS2 not via pip or system breaks...
|
|
|
|
if sys.platform == "win32" and \
|
|
|
|
os.environ.get("MSYSTEM", None) == "MINGW32" and \
|
|
|
|
"/mingw32/bin/python" in sys.executable:
|
|
|
|
failed = False
|
|
|
|
try:
|
2018-11-30 12:31:44 +00:00
|
|
|
import cryptography # noqa: intentionally not used - imported for testing its availability
|
2018-10-01 03:59:14 +00:00
|
|
|
except ImportError:
|
|
|
|
print("Please run the following command to install MSYS2's MINGW Python cryptography package:")
|
2018-11-16 05:57:00 +00:00
|
|
|
print("pacman -Sy mingw-w64-i686-python%d-cryptography" % (sys.version_info[0],))
|
2018-10-01 03:59:14 +00:00
|
|
|
failed = True
|
|
|
|
try:
|
2018-11-30 12:31:44 +00:00
|
|
|
import setuptools # noqa: intentionally not used - imported for testing its availability
|
2018-10-01 03:59:14 +00:00
|
|
|
except ImportError:
|
|
|
|
print("Please run the following command to install MSYS2's MINGW Python setuptools package:")
|
2018-11-16 05:57:00 +00:00
|
|
|
print("pacman -Sy mingw-w64-i686-python%d-setuptools" % (sys.version_info[0],))
|
2018-10-01 03:59:14 +00:00
|
|
|
failed = True
|
|
|
|
if failed:
|
|
|
|
sys.exit(1)
|
|
|
|
|
2018-08-15 07:52:07 +00:00
|
|
|
not_satisfied = []
|
2018-08-28 18:01:25 +00:00
|
|
|
with open(args.requirements) as f:
|
2018-08-15 07:52:07 +00:00
|
|
|
for line in f:
|
|
|
|
line = line.strip()
|
|
|
|
try:
|
|
|
|
pkg_resources.require(line)
|
2018-11-30 12:31:44 +00:00
|
|
|
except Exception:
|
2018-08-15 07:52:07 +00: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)
|
2018-10-25 06:16:30 +00:00
|
|
|
print('Please refer to the Get Started section of the ESP-IDF Programming Guide for setting up the required '
|
|
|
|
'packages. Alternatively, you can run "{} -m pip install --user -r {}" for resolving the issue.'
|
2018-11-30 12:22:31 +00:00
|
|
|
''.format(escape_backslash(sys.executable), escape_backslash(args.requirements)))
|
2018-08-15 07:52:07 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2018-08-28 18:01:25 +00:00
|
|
|
print('Python requirements from {} are satisfied.'.format(args.requirements))
|