check_python_dependencies.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. not_satisfied = []
  34. with open(args.requirements) as f:
  35. for line in f:
  36. line = line.strip()
  37. try:
  38. pkg_resources.require(line)
  39. except:
  40. not_satisfied.append(line)
  41. if len(not_satisfied) > 0:
  42. print('The following Python requirements are not satisfied:')
  43. for requirement in not_satisfied:
  44. print(requirement)
  45. print('Please run "{} -m pip install -r {}" for resolving the issue.'.format(sys.executable, args.requirements))
  46. sys.exit(1)
  47. print('Python requirements from {} are satisfied.'.format(args.requirements))