check_python_dependencies.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. try:
  19. import pkg_resources
  20. except:
  21. print('pkg_resources cannot be imported probably because the pip package is not installed and/or using a '
  22. 'legacy Python interpreter. Please refer to the Get Started section of the ESP-IDF Programming Guide for '
  23. 'setting up the required packages.')
  24. sys.exit(1)
  25. req_file = '{}/requirements.txt'.format(os.getenv("IDF_PATH"))
  26. if __name__ == "__main__":
  27. not_satisfied = []
  28. with open(req_file) as f:
  29. for line in f:
  30. line = line.strip()
  31. try:
  32. pkg_resources.require(line)
  33. except:
  34. not_satisfied.append(line)
  35. if len(not_satisfied) > 0:
  36. print('The following Python requirements are not satisfied:')
  37. for requirement in not_satisfied:
  38. print(requirement)
  39. print('Please run "{} -m pip install -r {}" for resolving the issue.'.format(sys.executable, req_file))
  40. sys.exit(1)
  41. print('Python requirements are satisfied.')