diff --git a/news/7664.feature.rst b/news/7664.feature.rst new file mode 100644 index 00000000000..7ad13f3d720 --- /dev/null +++ b/news/7664.feature.rst @@ -0,0 +1,3 @@ +Include ``location`` field for editable distribution entries in +``pip list --json``, so the fields outputted match the default "columns" +format. diff --git a/src/pip/_internal/commands/list.py b/src/pip/_internal/commands/list.py index dcf9432638a..381a2fbbe8a 100644 --- a/src/pip/_internal/commands/list.py +++ b/src/pip/_internal/commands/list.py @@ -309,8 +309,9 @@ def format_for_json(packages, options): 'name': dist.project_name, 'version': str(dist.version), } - if options.verbose >= 1: + if options.verbose >= 1 or dist_is_editable(dist): info['location'] = dist.location + if options.verbose >= 1: info['installer'] = get_installer(dist) if options.outdated: info['latest_version'] = str(dist.latest_version) diff --git a/tests/functional/test_list.py b/tests/functional/test_list.py index 40dfbdea30d..08beb6cad59 100644 --- a/tests/functional/test_list.py +++ b/tests/functional/test_list.py @@ -160,11 +160,19 @@ def test_uptodate_flag(script, data): 'list', '-f', data.find_links, '--no-index', '--uptodate', '--format=json', ) - assert {"name": "simple", "version": "1.0"} \ - not in json.loads(result.stdout) # 3.0 is latest - assert {"name": "pip-test-package", "version": "0.1.1"} \ - in json.loads(result.stdout) # editables included - assert {"name": "simple2", "version": "3.0"} in json.loads(result.stdout) + json_result = json.loads(result.stdout) + + # 3.0 is latest + assert "simple" not in {d["name"] for d in json_result} + # editables included + assert { + "name": "pip-test-package", + "version": "0.1.1", + "location": os.path.normcase( + str(script.venv_path / "src" / "pip-test-package") + ), + } in json_result + assert {"name": "simple2", "version": "3.0"} in json_result @pytest.mark.network @@ -212,15 +220,27 @@ def test_outdated_flag(script, data): 'list', '-f', data.find_links, '--no-index', '--outdated', '--format=json', ) - assert {"name": "simple", "version": "1.0", - "latest_version": "3.0", "latest_filetype": "sdist"} \ - in json.loads(result.stdout) - assert dict(name="simplewheel", version="1.0", - latest_version="2.0", latest_filetype="wheel") \ - in json.loads(result.stdout) - assert dict(name="pip-test-package", version="0.1", - latest_version="0.1.1", latest_filetype="sdist") \ - in json.loads(result.stdout) + assert { + "name": "simple", + "version": "1.0", + "latest_version": "3.0", + "latest_filetype": "sdist", + } in json.loads(result.stdout) + assert { + "name": "simplewheel", + "version": "1.0", + "latest_version": "2.0", + "latest_filetype": "wheel", + } in json.loads(result.stdout) + assert { + "name": "pip-test-package", + "version": "0.1", + "location": os.path.normcase( + str(script.venv_path / "src" / "pip-test-package") + ), + "latest_version": "0.1.1", + "latest_filetype": "sdist", + } in json.loads(result.stdout) assert "simple2" not in {p["name"] for p in json.loads(result.stdout)} diff --git a/tests/functional/test_uninstall.py b/tests/functional/test_uninstall.py index 878e713ed9e..34f92c0e726 100644 --- a/tests/functional/test_uninstall.py +++ b/tests/functional/test_uninstall.py @@ -506,8 +506,14 @@ def test_uninstall_setuptools_develop_install(script, data): script.run('python', 'setup.py', 'install', expect_stderr=True, cwd=pkg_path) list_result = script.pip('list', '--format=json') - assert {"name": os.path.normcase("FSPkg"), "version": "0.1.dev0"} \ - in json.loads(list_result.stdout), str(list_result) + egg_name = "FSPkg-0.1.dev0-py{0}.{1}.egg".format(*sys.version_info) + assert { + "name": os.path.normcase("FSPkg"), + "version": "0.1.dev0", + "location": os.path.normcase( + str(script.site_packages_path / egg_name) + ), + } in json.loads(list_result.stdout), str(list_result) # Uninstall both develop and install uninstall = script.pip('uninstall', 'FSPkg', '-y') assert any(filename.endswith('.egg') @@ -534,8 +540,11 @@ def test_uninstall_editable_and_pip_install(script, data): script.pip('install', '--ignore-installed', '.', expect_stderr=True, cwd=pkg_path) list_result = script.pip('list', '--format=json') - assert {"name": "FSPkg", "version": "0.1.dev0"} \ - in json.loads(list_result.stdout) + assert { + "name": "FSPkg", + "version": "0.1.dev0", + "location": os.path.normcase(str(script.site_packages_path)), + } in json.loads(list_result.stdout) # Uninstall both develop and install uninstall = script.pip('uninstall', 'FSPkg', '-y') assert not any(filename.endswith('.egg-link')