Skip to content

Conversation

screamerbg
Copy link
Contributor

pip.get_installed_distributions() is no longer available in pip 10. This PR fixes this by using the user-facing commands of pip and ensure future and backwards compatibility.

Also bumps Mbed CLI version to 1.5.1

@screamerbg screamerbg changed the title Fixed pip support, especially pip10 (#657) Fix: pip support, especially pip10 (#657) Apr 25, 2018
@@ -1448,8 +1448,8 @@ def check_requirements(self, show_warning=False):
missing = []
try:
with open(os.path.join(req_path, req_file), 'r') as f:
import pip
installed_packages = [re.sub(r'-', '_', package.project_name.lower()) for package in pip.get_installed_distributions(local_only=True)]
pkg_list = pquery([python_cmd, '-m', 'pip', 'list', '-l']) or ""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please note that -l is a deprecated option
it produces following warning:

DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.

consider using --format=legacy or --format=column instead

Copy link
Contributor Author

@screamerbg screamerbg Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alzix pip list -l is for listing the locally installed python modules. -l, --local If in a virtualenv that has global access, do not list globally-installed packages.

(pressed Ctrl+Enter by accident)

The problem with using --format=legacy is that it's not backwards compatible with pip < 10, so we can't use it either 😃

$ pip --version
pip 8.1.2 from /Library/Python/2.7/site-packages (python 2.7)

$ pip list -l --format=legacy

Usage:   
  pip list [options]

no such option: --format

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're going to either have to live with the deprecation warning, or add pip 10 as a dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also tried forcing the columns format using the --format=columns option and the code above is handling it just fine:

[snip]
                pkg_list = pquery([python_cmd, '-m', 'pip', 'list', '-l', '--format=columns']) or ""
[snip]
$ pip uninstall pyyaml
Uninstalling PyYAML-3.12:
  Would remove:
    c:\progra~1\python\lib\site-packages\pyyaml-3.12-py2.7.egg-info
    c:\progra~1\python\lib\site-packages\yaml\*
Proceed (y/n)?
Your response ('') was not one of the expected responses: y, n
Proceed (y/n)? y
  Successfully uninstalled PyYAML-3.12

$ mbed update --clean
[mbed] Synchronizing dependency references...
[mbed] Updating program "mbed-os-example-wifi" to latest revision in the current branch
[mbed] Updating library "esp8266-driver" to rev #264468722a97
[mbed] Updating library "mbed-os" to rev #c05d72c3c005 (tag: mbed-os-5.8.3)
[mbed] Updating library "wifi-x-nucleo-idw01m1" to rev #5871f7011d7f
[mbed] Auto-installing missing Python modules...

$ pip list | grep -i pyyaml
PyYAML                        3.12

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're suggesting that we don't need to worry about the deprecation warning. That's how I took it at least.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly. Sorry that I didn't explicitly said it. Was writing this in between meetings 😀

@alzix
Copy link

alzix commented Apr 25, 2018

i'm sorry for the confusion about the '-l/--local' but i vote for adding --format=columns to get rid of the deprecation warning

@screamerbg
Copy link
Contributor Author

@alzix That would break the backwards compatibility with pip < 10. Where do you see the warning? When using mbed CLI or when using pip? I'm not seeing any warnings on Windows with pip 10.0.1

@screamerbg
Copy link
Contributor Author

@alzix @theotherjimmy Note that this is now breaking the CI.

@alzix
Copy link

alzix commented Apr 25, 2018

@screamerbg I see the deprecation warning on pip 9.0.3 Linux

@screamerbg screamerbg requested a review from sg- April 25, 2018 17:03
@screamerbg
Copy link
Contributor Author

@alzix I don't get any warnings from pip 9.0.3 on Mac when using mbed CLI.

$ sudo pip uninstall mbed-greentea
The directory '/Users/mihsto01/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Uninstalling mbed-greentea-1.3.3:
  /Library/Python/2.7/site-packages/mbed_greentea-1.3.3-py2.7.egg-info
  /Library/Python/2.7/site-packages/mbed_greentea/__init__.py
  /Library/Python/2.7/site-packages/mbed_greentea/__init__.pyc
[SNIP]
  /Library/Python/2.7/site-packages/test/report_api.py
  /Library/Python/2.7/site-packages/test/report_api.pyc
  /usr/local/bin/mbedgt
Proceed (y/n)? y
  Successfully uninstalled mbed-greentea-1.3.3
The directory '/Users/mihsto01/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
You are using pip version 9.0.3, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

$ sudo mbed update --clean
[mbed] Synchronizing dependency references...
[mbed] Updating program "mbed-os-example-wifi" to latest revision in the current branch
[mbed] Updating library "esp8266-driver" to rev #264468722a97
[mbed] Updating library "mbed-os" to rev #c05d72c3c005 (tags: latest, mbed-os-5.8.3)
[mbed] Updating library "wifi-x-nucleo-idw01m1" to rev #5871f7011d7f
[mbed] Auto-installing missing Python modules...

$ python --version
Python 2.7.10

$ pip --version
pip 9.0.3 from /Library/Python/2.7/site-packages (python 2.7)

I only get a warning when directly calling pip

$ pip list -l | grep -i greentea
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
mbed-greentea (1.3.3)
You are using pip version 9.0.3, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

@theotherjimmy
Copy link
Contributor

@alzix I think @screamerbg is asking if you see the warning when using Mbed CLI from this branch. I don't see the warning on Linux with this branch and any version of Pip (I tried 9.0.3 and 10.0.1).

Copy link
Contributor

@cmonr cmonr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@screamerbg
Copy link
Contributor Author

Thanks. Just fixed the CI issue caused by faulty pip module;

@screamerbg screamerbg merged commit b97a944 into ARMmbed:master Apr 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants