|
23 | 23 | import urllib
|
24 | 24 | import zipfile
|
25 | 25 | from concurrent.futures import ThreadPoolExecutor
|
| 26 | +from importlib.metadata import version |
| 27 | +from importlib.resources import files # nosemgrep: python.lang.compatibility.python37.python37-compatibility-importlib2 |
26 | 28 | from io import BytesIO
|
27 | 29 | from shlex import quote
|
28 | 30 | from typing import Callable, NoReturn
|
|
31 | 33 |
|
32 | 34 | import boto3
|
33 | 35 | import dateutil.parser
|
34 |
| -import pkg_resources |
35 | 36 | import yaml
|
| 37 | +from packaging.version import parse |
36 | 38 | from yaml import SafeLoader
|
37 | 39 | from yaml.constructor import ConstructorError
|
38 | 40 | from yaml.resolver import BaseResolver
|
@@ -149,8 +151,8 @@ def zip_dir(path):
|
149 | 151 | """
|
150 | 152 | file_out = BytesIO()
|
151 | 153 | with zipfile.ZipFile(file_out, "w", zipfile.ZIP_DEFLATED) as ziph:
|
152 |
| - for root, _, files in os.walk(path): |
153 |
| - for file in files: |
| 154 | + for root, _, files_list in os.walk(path): |
| 155 | + for file in files_list: |
154 | 156 | _add_file_to_zip(
|
155 | 157 | ziph,
|
156 | 158 | os.path.join(root, file),
|
@@ -305,8 +307,8 @@ def get_templates_bucket_path():
|
305 | 307 |
|
306 | 308 | def get_installed_version(base_version_only: bool = False):
|
307 | 309 | """Get the version of the installed aws-parallelcluster package."""
|
308 |
| - pkg_distribution = pkg_resources.get_distribution("aws-parallelcluster") |
309 |
| - return pkg_distribution.version if not base_version_only else pkg_distribution.parsed_version.base_version |
| 310 | + pkg_version = version("aws-parallelcluster") |
| 311 | + return pkg_version if not base_version_only else parse(pkg_version).base_version |
310 | 312 |
|
311 | 313 |
|
312 | 314 | def warn(message):
|
@@ -576,7 +578,7 @@ def retrieve_supported_regions():
|
576 | 578 | retrieve_supported_regions.cache = f.read().decode("utf-8").split("\n")
|
577 | 579 | except URLError:
|
578 | 580 | # When the file is not found on the URL, use local file. This is useful when developing new versions.
|
579 |
| - with open(pkg_resources.resource_filename(__name__, "/resources/supported-regions"), encoding="utf-8") as f: |
| 581 | + with open(str(files(__package__) / "resources" / "supported-regions"), encoding="utf-8") as f: |
580 | 582 | retrieve_supported_regions.cache = f.read().split("\n")
|
581 | 583 | return retrieve_supported_regions.cache
|
582 | 584 |
|
|
0 commit comments