From 977af32d0fd8490f4a4d154b8d8c6da91d45b904 Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Wed, 19 Dec 2018 14:04:57 +0100 Subject: [PATCH 1/2] tools: Be more helpful to MSYS32 users with package installation --- tools/check_python_dependencies.py | 47 +++++++++++++++--------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/tools/check_python_dependencies.py b/tools/check_python_dependencies.py index d533746fed..501595ad2c 100755 --- a/tools/check_python_dependencies.py +++ b/tools/check_python_dependencies.py @@ -43,27 +43,6 @@ if __name__ == "__main__": default=os.path.join(idf_path, 'requirements.txt')) args = parser.parse_args() - # 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: - import cryptography # noqa: intentionally not used - imported for testing its availability - except ImportError: - print("Please run the following command to install MSYS2's MINGW Python cryptography package:") - print("pacman -S mingw-w64-i686-python%d-cryptography" % (sys.version_info[0],)) - failed = True - try: - import setuptools # noqa: intentionally not used - imported for testing its availability - except ImportError: - print("Please run the following command to install MSYS2's MINGW Python setuptools package:") - print("pacman -S mingw-w64-i686-python%d-setuptools" % (sys.version_info[0],)) - failed = True - if failed: - sys.exit(1) - not_satisfied = [] with open(args.requirements) as f: for line in f: @@ -77,8 +56,30 @@ if __name__ == "__main__": print('The following Python requirements are not satisfied:') for requirement in not_satisfied: print(requirement) - 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.' + if sys.platform == "win32" and os.environ.get("MSYSTEM", None) == "MINGW32" and "/mingw32/bin/python" in sys.executable: + print("The recommended way to install a packages is via \"pacman\". Please run \"pacman -Ss \" for" + " searching the package database and if found then " + "\"pacman -S mingw-w64-i686-python{}-\" for installing it.".format(sys.version_info[0],)) + print("NOTE: You may need to run \"pacman -Syu\" if your package database is older and run twice if the " + "previous run updated \"pacman\" itself.") + print("Please read https://github.com/msys2/msys2/wiki/Using-packages for further information about using " + "\"pacman\"") + # Special case for MINGW32 Python, needs some packages + # via MSYS2 not via pip or system breaks... + for requirement in not_satisfied: + if requirement.startswith('cryptography'): + print("WARNING: The cryptography package have dependencies on system packages so please make sure " + "you run \"pacman -Syu\" followed by \"pacman -S mingw-w64-i686-python{}-cryptography\"." + "".format(sys.version_info[0],)) + continue + elif requirement.startswith('setuptools'): + print("Please run the following command to install MSYS2's MINGW Python setuptools package:") + print("pacman -S mingw-w64-i686-python{}-setuptools".format(sys.version_info[0],)) + continue + else: + print('Please refer to the Get Started section of the ESP-IDF Programming Guide for setting up the required' + ' packages.') + print('Alternatively, you can run "{} -m pip install --user -r {}" for resolving the issue.' ''.format(escape_backslash(sys.executable), escape_backslash(args.requirements))) sys.exit(1) From c355d8a88ebdafcca8c9ec294e3d8abcb27a1b8f Mon Sep 17 00:00:00 2001 From: Sergei Silnov Date: Tue, 8 Jan 2019 11:40:49 +0100 Subject: [PATCH 2/2] python: Add check if current python is inside virtual environment --- tools/check_python_dependencies.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/check_python_dependencies.py b/tools/check_python_dependencies.py index 501595ad2c..c04c4dbd8c 100755 --- a/tools/check_python_dependencies.py +++ b/tools/check_python_dependencies.py @@ -14,9 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import argparse import os import sys -import argparse + try: import pkg_resources except Exception: @@ -34,6 +35,13 @@ def escape_backslash(path): return path +def is_virtualenv(): + """Detects if current python is inside virtualenv, pyvenv (python 3.4-3.5) or venv""" + + return (hasattr(sys, 'real_prefix') or + (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)) + + if __name__ == "__main__": idf_path = os.getenv("IDF_PATH") @@ -79,8 +87,10 @@ if __name__ == "__main__": else: print('Please refer to the Get Started section of the ESP-IDF Programming Guide for setting up the required' ' packages.') - print('Alternatively, you can run "{} -m pip install --user -r {}" for resolving the issue.' - ''.format(escape_backslash(sys.executable), escape_backslash(args.requirements))) + print('Alternatively, you can run "{} -m pip install {}-r {}" for resolving the issue.' + ''.format(escape_backslash(sys.executable), + '' if is_virtualenv() else '--user ', + escape_backslash(args.requirements))) sys.exit(1) print('Python requirements from {} are satisfied.'.format(args.requirements))