check_python_dependencies.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. import os
  17. import sys
  18. import argparse
  19. try:
  20. import pkg_resources
  21. except:
  22. print('pkg_resources cannot be imported probably because the pip package is not installed and/or using a '
  23. 'legacy Python interpreter. Please refer to the Get Started section of the ESP-IDF Programming Guide for '
  24. 'setting up the required packages.')
  25. sys.exit(1)
  26. if __name__ == "__main__":
  27. idf_path = os.getenv("IDF_PATH")
  28. parser = argparse.ArgumentParser(description='ESP32 Python package dependency checker')
  29. parser.add_argument('--requirements', '-r',
  30. help='Path to the requrements file',
  31. default=idf_path + '/requirements.txt')
  32. args = parser.parse_args()
  33. # Special case for MINGW32 Python, needs some packages
  34. # via MSYS2 not via pip or system breaks...
  35. if sys.platform == "win32" and \
  36. os.environ.get("MSYSTEM", None) == "MINGW32" and \
  37. "/mingw32/bin/python" in sys.executable:
  38. failed = False
  39. try:
  40. import cryptography
  41. except ImportError:
  42. print("Please run the following command to install MSYS2's MINGW Python cryptography package:")
  43. print("pacman -S mingw-w64-i686-python%d-cryptography" % (sys.version_info[0],))
  44. failed = True
  45. try:
  46. import setuptools
  47. except ImportError:
  48. print("Please run the following command to install MSYS2's MINGW Python setuptools package:")
  49. print("pacman -S mingw-w64-i686-python%d-setuptools" % (sys.version_info[0],))
  50. failed = True
  51. if failed:
  52. sys.exit(1)
  53. not_satisfied = []
  54. with open(args.requirements) as f:
  55. for line in f:
  56. line = line.strip()
  57. try:
  58. pkg_resources.require(line)
  59. except:
  60. not_satisfied.append(line)
  61. if len(not_satisfied) > 0:
  62. print('The following Python requirements are not satisfied:')
  63. for requirement in not_satisfied:
  64. print(requirement)
  65. print('Please refer to the Get Started section of the ESP-IDF Programming Guide for setting up the required '
  66. 'packages. Alternatively, you can run "{} -m pip install --user -r {}" for resolving the issue.'
  67. ''.format(sys.executable, args.requirements))
  68. sys.exit(1)
  69. print('Python requirements from {} are satisfied.'.format(args.requirements))