♻️ Split the version and name retrieval functions to fine coarse functions.
This commit is contained in:
+51
-12
@@ -3,46 +3,85 @@ import importlib.metadata
|
|||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import requests
|
||||||
import toml
|
import toml
|
||||||
|
|
||||||
|
from tidal_dl_ng.constants import REQUESTS_TIMEOUT_SEC
|
||||||
|
|
||||||
def get_version_app() -> str:
|
|
||||||
|
def metadata_project() -> dict:
|
||||||
file_path: Path = Path(__file__)
|
file_path: Path = Path(__file__)
|
||||||
|
result: dict = {}
|
||||||
|
|
||||||
paths: [Path] = [
|
paths: [Path] = [
|
||||||
file_path.parent,
|
file_path.parent,
|
||||||
file_path.parent.parent,
|
file_path.parent.parent,
|
||||||
file_path.parent.parent.parent,
|
file_path.parent.parent.parent,
|
||||||
]
|
]
|
||||||
version: str = "0.0.0"
|
|
||||||
|
|
||||||
for pyproject_toml_dir in paths:
|
for pyproject_toml_dir in paths:
|
||||||
pyproject_toml_file: Path = pyproject_toml_dir / "pyproject.toml"
|
pyproject_toml_file: Path = pyproject_toml_dir / "pyproject.toml"
|
||||||
|
|
||||||
if pyproject_toml_file.exists() and pyproject_toml_file.is_file():
|
if pyproject_toml_file.exists() and pyproject_toml_file.is_file():
|
||||||
package_version: str = toml.load(pyproject_toml_file)["tool"]["poetry"]["version"]
|
result: str = toml.load(pyproject_toml_file)
|
||||||
|
|
||||||
version = package_version
|
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def version_app() -> str:
|
||||||
|
metadata: dict = metadata_project()
|
||||||
|
version: str = "0.0.0"
|
||||||
|
|
||||||
|
if metadata:
|
||||||
|
package_version: str = metadata["tool"]["poetry"]["version"]
|
||||||
|
|
||||||
|
version = package_version
|
||||||
|
|
||||||
return version
|
return version
|
||||||
|
|
||||||
|
|
||||||
def get_name_app() -> str:
|
def latest_version_available():
|
||||||
name_app: str = __package__ or __name__
|
response = requests.get(
|
||||||
|
"https://api.github.com/repos/v2ray/v2ray-core/releases/latest", timeout=REQUESTS_TIMEOUT_SEC
|
||||||
|
)
|
||||||
|
|
||||||
|
a = response.json()["name"]
|
||||||
|
print(a)
|
||||||
|
|
||||||
|
|
||||||
|
def name_package() -> str:
|
||||||
|
package_name: str = __package__ or __name__
|
||||||
|
|
||||||
|
return package_name
|
||||||
|
|
||||||
|
|
||||||
|
def is_dev_env() -> bool:
|
||||||
|
package_name: str = name_package()
|
||||||
|
result: bool = False
|
||||||
|
|
||||||
# Check if package is running from source code == dev mode
|
# Check if package is running from source code == dev mode
|
||||||
# If package is not running in PyInstaller environment.
|
# If package is not running in PyInstaller environment.
|
||||||
if getattr(sys, "frozen", True) and not hasattr(sys, "_MEIPASS"):
|
if getattr(sys, "frozen", True) and not hasattr(sys, "_MEIPASS"):
|
||||||
try:
|
try:
|
||||||
importlib.metadata.version(name_app)
|
importlib.metadata.version(package_name)
|
||||||
except:
|
except:
|
||||||
# If package is not installed
|
# If package is not installed
|
||||||
name_app = name_app + "-dev"
|
result = False
|
||||||
|
|
||||||
return name_app
|
return result
|
||||||
|
|
||||||
|
|
||||||
__name_display__ = get_name_app()
|
def name_app() -> str:
|
||||||
__version__ = get_version_app()
|
app_name: str = name_package()
|
||||||
|
is_dev: bool = is_dev_env()
|
||||||
|
|
||||||
|
if is_dev:
|
||||||
|
app_name = app_name + "-dev"
|
||||||
|
|
||||||
|
return app_name
|
||||||
|
|
||||||
|
|
||||||
|
__name_display__ = name_app()
|
||||||
|
__version__ = version_app()
|
||||||
|
|||||||
Reference in New Issue
Block a user