2023-02-05 19:45:31 +00:00
|
|
|
import requests
|
2023-02-04 21:58:21 +00:00
|
|
|
|
2023-02-05 20:15:39 +00:00
|
|
|
from ldm.invoke import __app_name__, __version__
|
2023-02-04 21:58:21 +00:00
|
|
|
|
2023-02-05 19:45:31 +00:00
|
|
|
local_version = str(__version__).replace("-", "")
|
|
|
|
package_name = str(__app_name__)
|
2023-02-04 21:58:21 +00:00
|
|
|
|
|
|
|
|
2023-02-05 19:45:31 +00:00
|
|
|
def get_pypi_versions(package_name=package_name) -> list[str]:
|
2023-02-04 21:58:21 +00:00
|
|
|
"""Get the versions of the package from PyPI"""
|
|
|
|
url = f"https://pypi.org/pypi/{package_name}/json"
|
2023-02-05 19:45:31 +00:00
|
|
|
response = requests.get(url).json()
|
2023-02-04 21:58:21 +00:00
|
|
|
versions: list[str] = list(response["releases"].keys())
|
|
|
|
return versions
|
|
|
|
|
|
|
|
|
2023-02-05 19:45:31 +00:00
|
|
|
def local_on_pypi(package_name=package_name, local_version=local_version) -> bool:
|
2023-02-04 21:58:21 +00:00
|
|
|
"""Compare the versions of the package from PyPI and the local package"""
|
|
|
|
pypi_versions = get_pypi_versions(package_name)
|
|
|
|
return local_version in pypi_versions
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if local_on_pypi():
|
|
|
|
print(f"Package {package_name} is up to date")
|
|
|
|
else:
|
|
|
|
print(f"Package {package_name} is not up to date")
|