Skip to content

Commit

Permalink
better handling of plugin version
Browse files Browse the repository at this point in the history
  • Loading branch information
seb5g committed Oct 28, 2023
1 parent 2414a50 commit 19a1e0b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
23 changes: 17 additions & 6 deletions src/pymodaq_plugin_manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from readme_renderer.rst import render

from pymodaq_plugin_manager.validate import get_plugins
from pymodaq_plugin_manager.validate import get_pypi_pymodaq
from pymodaq_plugin_manager.validate import get_pypi_pymodaq, get_package_metadata
from pymodaq_plugin_manager import __version__ as version
from pymodaq_plugin_manager.utils import QVariant, TableModel, TableView, SpinBoxDelegate, get_pymodaq_version

Expand Down Expand Up @@ -122,19 +122,21 @@ def __init__(self, parent, standalone=False):
def check_version(self, show=True):
try:
current_version = version_mod.parse(version)
available_version = [version_mod.parse(ver) for ver in
get_pypi_pymodaq('pymodaq-plugin-manager')['versions']]

latest = get_package_metadata('pymodaq_plugin_manager')
available_versions = list(latest['releases'].keys())[::-1]

msgBox = QtWidgets.QMessageBox()
if max(available_version) > current_version:
msgBox.setText(f"A new version of PyMoDAQ Plugin Manager is available, {str(max(available_version))}!")
if max(available_versions) > current_version:
msgBox.setText(f"A new version of PyMoDAQ Plugin Manager is available, {str(max(available_versions))}!")
msgBox.setInformativeText("Do you want to install it?")
msgBox.setStandardButtons(msgBox.Ok | msgBox.Cancel)
msgBox.setDefaultButton(msgBox.Ok)

ret = msgBox.exec()

if ret == msgBox.Ok:
command = [sys.executable, '-m', 'pip', 'install', f'pymodaq-plugin-manager=={str(max(available_version))}']
command = [sys.executable, '-m', 'pip', 'install', f'pymodaq-plugin-manager=={str(max(available_versions))}']
subprocess.Popen(command)

self.restart()
Expand Down Expand Up @@ -371,6 +373,15 @@ def display_info(self, index):
self.info_widget.insertHtml(render(plugin['description']))


def main_without_qt():
win = QtWidgets.QMainWindow()
win.setWindowTitle('PyMoDAQ Plugin Manager')
widget = QtWidgets.QWidget()
win.setCentralWidget(widget)
prog = PluginManager(widget, standalone=True)
win.show()


def main():
app = QtWidgets.QApplication(sys.argv)
win = QtWidgets.QMainWindow()
Expand Down
15 changes: 11 additions & 4 deletions src/pymodaq_plugin_manager/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def get_metadata_from_json(json_as_dict: dict) -> dict:
pass


def get_pypi_pymodaq(package_name='pymodaq-plugins', pymodaq_version: Version = None):
def get_pypi_pymodaq(package_name='pymodaq-plugins', pymodaq_version: Version = None, pymodaq_latest: Version = None):
""" Get the latest plugin info compatible with a given version of pymodaq
Parameters
Expand All @@ -143,6 +143,8 @@ def get_pypi_pymodaq(package_name='pymodaq-plugins', pymodaq_version: Version =
return
if isinstance(pymodaq_version, str):
pymodaq_version = Version(pymodaq_version)
if pymodaq_latest is None:
pymodaq_latest = Version(list(get_package_metadata('pymodaq')['releases'].keys())[-1])
latest = get_package_metadata(package_name)
if latest is not None:
if pymodaq_version is not None:
Expand All @@ -155,6 +157,9 @@ def get_pypi_pymodaq(package_name='pymodaq-plugins', pymodaq_version: Version =
return
if pymodaq_version in specifier:
return get_metadata_from_json(versioned)
elif pymodaq_latest == pymodaq_version: # if not in specifier and requested pymodaq version is
# latest, not need to loop into older package versions, they won't be compatible either
return
else:
return get_metadata_from_json(latest)

Expand All @@ -175,9 +180,10 @@ def get_pypi_plugins(browse_pypi=True, pymodaq_version: Union[Version, str] = No
"""
plugins = []
packages = get_pypi_package_list('pymodaq-plugins')
pymodaq_latest = Version(get_pypi_pymodaq('pymodaq')['version'])
for package in packages:
logger.info(f'Fetching metadata for package {package}')
metadata = get_pypi_pymodaq(package, pymodaq_version)
metadata = get_pypi_pymodaq(package, pymodaq_version, pymodaq_latest)
if metadata is not None:
title = metadata['description'].split('\n')[0]
if '(' in title and ')' in title:
Expand Down Expand Up @@ -372,8 +378,9 @@ def write_plugin_doc():


if __name__ == '__main__':
write_plugin_doc()
#write_plugin_doc()
# versions = get_pypi_pymodaq()
# from pymodaq_plugin_manager import __version__ as version
# print(version)
#print(get_pypi_package_list('pymodaq-plugins'))
#print(get_pypi_package_list('pymodaq-plugins'))
plugins = get_pypi_plugins(pymodaq_version='4.0.8')

0 comments on commit 19a1e0b

Please sign in to comment.