| 1 | Patch-Source: https://github.com/ansible-community/ansible-bender/commit/7b9a61a0015f08702bba0e9c66411f074986c52f
|
| 2 | ---
|
| 3 | From 7b9a61a0015f08702bba0e9c66411f074986c52f Mon Sep 17 00:00:00 2001
|
| 4 | From: Maxwell G <[email protected]>
|
| 5 | Date: Mon, 6 Mar 2023 07:24:19 -0600
|
| 6 | Subject: [PATCH] Remove pkg_resources usage
|
| 7 |
|
| 8 | pkg_resources is deprecated [1] and expensive to import. Use the newer,
|
| 9 | leaner importlib.metadata package instead.
|
| 10 |
|
| 11 | [1] https://github.com/pypa/setuptools/commit/a1aeda391a0c462ea53627bcdf50dd4c0daadaed
|
| 12 | ---
|
| 13 | ansible_bender/__init__.py | 12 ++++++++----
|
| 14 | ansible_bender/cli.py | 8 ++++----
|
| 15 | 2 files changed, 12 insertions(+), 8 deletions(-)
|
| 16 |
|
| 17 | diff --git a/ansible_bender/__init__.py b/ansible_bender/__init__.py
|
| 18 | index 5602d79..df367ca 100644
|
| 19 | |
| 20 | |
| 21 | @@ -6,9 +6,13 @@
|
| 22 | $ ab build ./playbook.yaml fedora:28 my-custom-image
|
| 23 |
|
| 24 | """
|
| 25 | -from pkg_resources import get_distribution, DistributionNotFound
|
| 26 | try:
|
| 27 | - __version__ = get_distribution(__name__).version
|
| 28 | -except DistributionNotFound:
|
| 29 | + from importlib.metadata import version, PackageNotFoundError
|
| 30 | +except ImportError:
|
| 31 | + from importlib_metadata import version, PackageNotFoundError
|
| 32 | +
|
| 33 | +try:
|
| 34 | + __version__ = version(__name__)
|
| 35 | +except PackageNotFoundError:
|
| 36 | # package is not installed
|
| 37 | - pass
|
| 38 | + __version__ = None
|
| 39 | diff --git a/ansible_bender/cli.py b/ansible_bender/cli.py
|
| 40 | index 744f753..9490f3a 100644
|
| 41 | |
| 42 | |
| 43 | @@ -6,10 +6,10 @@
|
| 44 | import json
|
| 45 | import sys
|
| 46 | import subprocess
|
| 47 | -import pkg_resources
|
| 48 | import yaml
|
| 49 | from tabulate import tabulate
|
| 50 |
|
| 51 | +from ansible_bender import __version__
|
| 52 | from ansible_bender.api import Application
|
| 53 | from ansible_bender.constants import ANNOTATIONS_KEY, PLAYBOOK_TEMPLATE
|
| 54 | from ansible_bender.core import AnsibleVarsParser
|
| 55 | @@ -421,9 +421,9 @@ def run(self):
|
| 56 | subcommand = getattr(self.args, "subcommand", "nope")
|
| 57 | try:
|
| 58 | if self.args.version:
|
| 59 | - try:
|
| 60 | - print(pkg_resources.get_distribution("ansible-bender").version)
|
| 61 | - except pkg_resources.DistributionNotFound:
|
| 62 | + if __version__ is not None:
|
| 63 | + print(__version__)
|
| 64 | + else:
|
| 65 | print("Ansible-bender is not installed, therefore we can't print the version.")
|
| 66 | print("Please run `python3 setup.py --version` instead.")
|
| 67 | return 18
|