Skip to content

Commit 4b1ea19

Browse files
Find list of installed packages using pkg_resources (#12591)
* Find list of installed packages using pkg_resources
1 parent 117a6f5 commit 4b1ea19

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

eng/tox/install_dev_build_dependency.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313
from os import path
1414
from subprocess import check_call
1515

16-
from pip._internal.operations import freeze
17-
1816
# import common_task module
1917
root_dir = path.abspath(path.join(path.abspath(__file__), "..", "..", ".."))
2018
common_task_path = path.abspath(path.join(root_dir, "scripts", "devops_tasks"))
2119
sys.path.append(common_task_path)
22-
from common_tasks import process_glob_string
20+
from common_tasks import process_glob_string, get_installed_packages
2321
from tox_helper_tasks import get_package_details
2422

2523
EXCLUDED_PKGS = [
@@ -34,10 +32,10 @@
3432
# This script verifies installed package version and ensure all installed pacakges are dev build version
3533

3634

37-
def get_installed_packages(pkg_name_to_exclude):
35+
def get_installed_azure_packages(pkg_name_to_exclude):
3836
# This method returns a list of installed azure sdk packages
3937
installed_pkgs = [
40-
p.split("==")[0] for p in freeze.freeze() if p.startswith("azure-")
38+
p.split("==")[0] for p in get_installed_packages() if p.startswith("azure-")
4139
]
4240

4341
# Get valid list of Azure SDK packages in repo
@@ -100,7 +98,7 @@ def install_packages(packages):
10098

10199
def install_dev_build_packages(pkg_name_to_exclude):
102100
# Uninstall GA version and reinstall dev build version of dependent packages
103-
azure_pkgs = get_installed_packages(pkg_name_to_exclude)
101+
azure_pkgs = get_installed_azure_packages(pkg_name_to_exclude)
104102
uninstall_packages(azure_pkgs)
105103
install_packages(azure_pkgs)
106104

eng/tox/verify_installed_packages.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
import os
1010
import sys
1111
import logging
12-
from pip._internal.operations import freeze
12+
from os import path
1313

14+
# import common_task module
15+
root_dir = path.abspath(path.join(path.abspath(__file__), "..", "..", ".."))
16+
common_task_path = path.abspath(path.join(root_dir, "scripts", "devops_tasks"))
17+
sys.path.append(common_task_path)
18+
from common_tasks import get_installed_packages
1419

1520
def verify_packages(package_file_path):
1621
# this method verifies packages installed on machine is matching the expected package version
@@ -29,7 +34,7 @@ def verify_packages(package_file_path):
2934
sys.exit(1)
3035

3136
# find installed and expected packages
32-
installed = dict(p.split('==') for p in freeze.freeze() if p.startswith('azure') and "==" in p)
37+
installed = dict(p.split('==') for p in get_installed_packages() if p.startswith('azure') and "==" in p)
3338
expected = dict(p.split('==') for p in packages)
3439

3540
missing_packages = [pkg for pkg in expected.keys() if installed.get(pkg) != expected.get(pkg)]

scripts/devops_tasks/common_tasks.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import pdb
2323

2424
# Assumes the presence of setuptools
25-
from pkg_resources import parse_version, parse_requirements, Requirement
25+
from pkg_resources import parse_version, parse_requirements, Requirement, WorkingSet, working_set
2626

2727
# this assumes the presence of "packaging"
2828
from packaging.specifiers import SpecifierSet
@@ -420,4 +420,15 @@ def find_tools_packages(root_path):
420420
glob_string = os.path.join(root_path, "tools", "*", "setup.py")
421421
pkgs = [os.path.basename(os.path.dirname(p)) for p in glob.glob(glob_string)]
422422
logging.info("Packages in tools: {}".format(pkgs))
423-
return pkgs
423+
return pkgs
424+
425+
426+
def get_installed_packages(paths = None):
427+
"""Find packages in default or given lib paths
428+
"""
429+
# WorkingSet returns installed packages in given path
430+
# working_set returns installed packages in default path
431+
# if paths is set then find installed packages from given paths
432+
ws = WorkingSet(paths) if paths else working_set
433+
return ["{0}=={1}".format(p.project_name, p.version) for p in ws]
434+

scripts/devops_tasks/test_regression.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
filter_dev_requirements,
2323
find_packages_missing_on_pypi,
2424
find_whl,
25-
find_tools_packages
25+
find_tools_packages,
26+
get_installed_packages
2627
)
2728
from git_helper import get_release_tag, git_checkout_tag, git_checkout_branch, clone_repo
28-
from pip._internal.operations import freeze
2929

3030
AZURE_GLOB_STRING = "azure*"
3131

@@ -222,7 +222,7 @@ def _install_packages(self, dependent_pkg_path, pkg_to_exclude):
222222
temp_dir = self.context.temp_path
223223

224224
list_to_exclude = [pkg_to_exclude,]
225-
installed_pkgs = [p.split('==')[0] for p in list(freeze.freeze(paths=self.context.venv.lib_paths)) if p.startswith('azure-')]
225+
installed_pkgs = [p.split('==')[0] for p in get_installed_packages(self.context.venv.lib_paths) if p.startswith('azure-')]
226226
logging.info("Installed azure sdk packages:{}".format(installed_pkgs))
227227

228228
# Do not exclude list of packages in tools directory and so these tools packages will be reinstalled from repo branch we are testing
@@ -257,7 +257,7 @@ def _is_package_installed(self, package, version):
257257
venv_root = self.context.venv.path
258258
site_packages = self.context.venv.lib_paths
259259
logging.info("Searching for packages in :{}".format(site_packages))
260-
installed_pkgs = list(freeze.freeze(paths=site_packages))
260+
installed_pkgs = get_installed_packages(site_packages)
261261
logging.info("Installed packages: {}".format(installed_pkgs))
262262
# Verify installed package version
263263
# Search for exact version or dev build version of current version.

0 commit comments

Comments
 (0)