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
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
import logging
|
|
||||||
|
|
||||||
from pkg_resources import resource_string
|
import importlib.resources
|
||||||
|
import logging
|
||||||
|
|
||||||
from zuul.lib.logutil import get_annotated_logger
|
from zuul.lib.logutil import get_annotated_logger
|
||||||
|
|
||||||
|
@ -40,8 +40,9 @@ class GraphQLClient:
|
||||||
'canmerge-legacy',
|
'canmerge-legacy',
|
||||||
]
|
]
|
||||||
for query_name in query_names:
|
for query_name in query_names:
|
||||||
self.queries[query_name] = resource_string(
|
f = importlib.resources.files('zuul').joinpath(
|
||||||
__name__, '%s.graphql' % query_name).decode('utf-8')
|
'driver/github/graphql/%s.graphql' % query_name)
|
||||||
|
self.queries[query_name] = f.read_bytes().decode()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _prepare_query(query, variables):
|
def _prepare_query(query, variables):
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from importlib import metadata as importlib_metadata
|
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
|
is_release = None
|
||||||
git_version = None
|
git_version = None
|
||||||
try:
|
try:
|
||||||
_metadata = json.loads(
|
_metadata = json.loads(zuul_distribution.read_text('pbr.json'))
|
||||||
pkg_resources.get_distribution('zuul').get_metadata('pbr.json'))
|
|
||||||
if _metadata:
|
if _metadata:
|
||||||
is_release = _metadata['is_release']
|
is_release = _metadata['is_release']
|
||||||
git_version = _metadata['git_version']
|
git_version = _metadata['git_version']
|
||||||
|
|
Loading…
Reference in New Issue