Convert pkg_resources usage to importlib
Importlib is the modern replacement for pkg_resources and is bundled in python itself. Meanwhile pkg_resources is part of setuptools which is no longer included in python as of python3.12. Do this transition to be ready for python3.12 but also to modernize our package introspection. Change-Id: I9a404e34ae2a833a925dcc156073e0f3f0680a11
This commit is contained in:
parent
341e8d8ccd
commit
b52af834cc
@ -11,9 +11,9 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import logging
|
||||
|
||||
from pkg_resources import resource_string
|
||||
import importlib.resources
|
||||
import logging
|
||||
|
||||
from zuul.lib.logutil import get_annotated_logger
|
||||
|
||||
@ -40,8 +40,9 @@ class GraphQLClient:
|
||||
'canmerge-legacy',
|
||||
]
|
||||
for query_name in query_names:
|
||||
self.queries[query_name] = resource_string(
|
||||
__name__, '%s.graphql' % query_name).decode('utf-8')
|
||||
f = importlib.resources.files('zuul').joinpath(
|
||||
'driver/github/graphql/%s.graphql' % query_name)
|
||||
self.queries[query_name] = f.read_bytes().decode()
|
||||
|
||||
@staticmethod
|
||||
def _prepare_query(query, variables):
|
||||
|
@ -18,15 +18,14 @@
|
||||
import json
|
||||
|
||||
from importlib import metadata as importlib_metadata
|
||||
import pkg_resources
|
||||
|
||||
release_string = importlib_metadata.distribution('zuul').version
|
||||
zuul_distribution = importlib_metadata.distribution('zuul')
|
||||
release_string = zuul_distribution.version
|
||||
|
||||
is_release = None
|
||||
git_version = None
|
||||
try:
|
||||
_metadata = json.loads(
|
||||
pkg_resources.get_distribution('zuul').get_metadata('pbr.json'))
|
||||
_metadata = json.loads(zuul_distribution.read_text('pbr.json'))
|
||||
if _metadata:
|
||||
is_release = _metadata['is_release']
|
||||
git_version = _metadata['git_version']
|
||||
|
Loading…
x
Reference in New Issue
Block a user