]> granicus.if.org Git - esp-idf/blob - tools/check_python_dependencies.py
Merge branch 'bugfix/btdm_fix_connect_interval_error_in_slave_adv_params' into 'master'
[esp-idf] / tools / check_python_dependencies.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2018 Espressif Systems (Shanghai) PTE LTD
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 import os
18 import sys
19 import argparse
20 try:
21     import pkg_resources
22 except:
23     print('pkg_resources cannot be imported probably because the pip package is not installed and/or using a '
24           'legacy Python interpreter. Please refer to the Get Started section of the ESP-IDF Programming Guide for '
25            'setting up the required packages.')
26     sys.exit(1)
27
28 if __name__ == "__main__":
29     idf_path = os.getenv("IDF_PATH")
30
31     parser = argparse.ArgumentParser(description='ESP32 Python package dependency checker')
32     parser.add_argument('--requirements', '-r',
33             help='Path to the requrements file',
34             default=idf_path + '/requirements.txt')
35     args = parser.parse_args()
36
37     # Special case for MINGW32 Python, needs some packages
38     # via MSYS2 not via pip or system breaks...
39     if sys.platform == "win32" and \
40        os.environ.get("MSYSTEM", None) == "MINGW32" and \
41        "/mingw32/bin/python" in sys.executable:
42         failed = False
43         try:
44             import cryptography
45         except ImportError:
46             print("Please run the following command to install MSYS2's MINGW Python cryptography package:")
47             print("pacman -S mingw-w64-i686-python%d-cryptography" % (sys.version_info[0],))
48             failed = True
49         try:
50             import setuptools
51         except ImportError:
52             print("Please run the following command to install MSYS2's MINGW Python setuptools package:")
53             print("pacman -S mingw-w64-i686-python%d-setuptools" % (sys.version_info[0],))
54             failed = True
55         if failed:
56             sys.exit(1)
57
58     not_satisfied = []
59     with open(args.requirements) as f:
60         for line in f:
61             line = line.strip()
62             try:
63                 pkg_resources.require(line)
64             except:
65                 not_satisfied.append(line)
66
67     if len(not_satisfied) > 0:
68         print('The following Python requirements are not satisfied:')
69         for requirement in not_satisfied:
70             print(requirement)
71         print('Please run "{} -m pip install --user -r {}" for resolving the issue.'.format(sys.executable, args.requirements))
72         sys.exit(1)
73
74     print('Python requirements from {} are satisfied.'.format(args.requirements))