use importlib.metadata to get package versions (#14753)

* use importlib_metadata to get package versions

* ignore untyped call

* stop ignoring the deprecation warning

* Revert "stop ignoring the deprecation warning"

This reverts commit 931fe8c794.

* include chiapos version data

* tweak
This commit is contained in:
Kyle Altendorf 2023-09-27 16:01:08 -04:00 committed by GitHub
parent 1dcade3996
commit 302e7e7f81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 8 deletions

View File

@ -49,7 +49,10 @@ keyring_imports = collect_submodules("keyring.backends")
# keyring uses entrypoints to read keyring.backends from metadata file entry_points.txt.
keyring_datas = copy_metadata("keyring")[0]
version_data = copy_metadata("chia-blockchain")[0]
version_data = [
copy_metadata(name)[0]
for name in ["chia-blockchain", "chiapos"]
]
block_cipher = None
@ -152,7 +155,7 @@ for path in sorted({path.parent for path in ROOT.joinpath("chia").rglob("*.hex")
datas.append((f"{path}/*.hex", path.relative_to(ROOT)))
datas.append((f"{ROOT}/chia/ssl/*", "chia/ssl"))
datas.append((f"{ROOT}/mozilla-ca/*", "mozilla-ca"))
datas.append(version_data)
datas.extend(version_data)
pathex = []

View File

@ -1,9 +1,10 @@
from __future__ import annotations
from pkg_resources import DistributionNotFound, get_distribution
import importlib.metadata
__version__: str
try:
__version__ = get_distribution("chia-blockchain").version
except DistributionNotFound:
__version__ = importlib.metadata.version("chia-blockchain")
except importlib.metadata.PackageNotFoundError:
# package is not installed
__version__ = "unknown"

View File

@ -5,13 +5,12 @@ After `chia plots create` becomes obsolete, consider removing it from there.
from __future__ import annotations
import asyncio
import importlib.metadata
import logging
from argparse import Namespace
from pathlib import Path
from typing import Any, Dict, Optional
import pkg_resources
from chia.plotting.create_plots import create_plots, resolve_plot_keys
from chia.plotting.util import Params, add_plot_directory, validate_plot_size
@ -19,7 +18,7 @@ log = logging.getLogger(__name__)
def get_chiapos_install_info() -> Optional[Dict[str, Any]]:
chiapos_version: str = pkg_resources.get_distribution("chiapos").version
chiapos_version: str = importlib.metadata.version("chiapos")
return {"display_name": "Chia Proof of Space", "version": chiapos_version, "installed": True}