Skip to content

Commit d6af3c4

Browse files
committed
Rewrite unsupported plugins logic and hard-code plover version for now
1 parent 7eca10b commit d6af3c4

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

plover/plugins_manager/package_index.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,16 @@
77

88
PYPI_URL = 'https://pypi.org/pypi'
99
REGISTRY_URL = 'https://github.com/openstenoproject/plover_plugins_registry/raw/master/registry.json'
10-
#TODO update with proper URL
11-
UNSUPPORTED_PLUGINS_URL = 'https://raw.githubusercontent.com/mkrnr/plover_plugins_registry/registry_plover_v5/unsupported.json'
1210

1311

14-
def find_plover_plugins_releases(pypi_url=None, registry_url=None, unsupported_plugins_url=None, capture=None):
12+
def find_plover_plugins_releases(pypi_url=None, registry_url=None, capture=None):
1513

1614
if pypi_url is None:
1715
pypi_url = os.environ.get('PYPI_URL', PYPI_URL)
1816

1917
if registry_url is None:
2018
registry_url = os.environ.get('REGISTRY_URL', REGISTRY_URL)
2119

22-
if unsupported_plugins_url is None:
23-
unsupported_plugins_url = os.environ.get('UNSUPPORTED_PLUGINS_URL', UNSUPPORTED_PLUGINS_URL)
24-
2520
session = CachedFuturesSession()
2621

2722
in_progress = set()
@@ -42,8 +37,6 @@ def fetch_release(name, version=None):
4237
for name in session.get(registry_url).result().json():
4338
fetch_release(name)
4439

45-
unsupported_plugins_dict=session.get(unsupported_plugins_url).result().json()
46-
4740
while in_progress:
4841
for future in as_completed(list(in_progress)):
4942
in_progress.remove(future)
@@ -60,8 +53,6 @@ def fetch_release(name, version=None):
6053
continue
6154
name, version = info['name'], info['version']
6255
all_releases[(name, version)] = release
63-
if name in unsupported_plugins_dict:
64-
info['unsupported_plover_version'] = unsupported_plugins_dict[name]
6556

6657
all_releases = [
6758
release

plover/plugins_manager/plugin_metadata.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class PluginMetadata(namedtuple('PluginMetadata', '''
1717
name
1818
summary
1919
version
20-
unsupported_plover_version
2120
''')):
2221

2322
@property

plover/plugins_manager/registry.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
from plover.plugins_manager import global_registry, local_registry
55

6+
from plover.plugins_manager.requests import CachedFuturesSession
7+
68

79
class PackageState:
810

@@ -46,6 +48,9 @@ def __lt__(self, other):
4648
def __repr__(self):
4749
return str(self)
4850

51+
#TODO update with proper URL
52+
UNSUPPORTED_PLUGINS_URL = 'https://raw.githubusercontent.com/mkrnr/plover_plugins_registry/registry_plover_v5/unsupported.json'
53+
4954

5055
class Registry:
5156

@@ -90,14 +95,23 @@ def parse_unsupported_plover_version(self, unsupported_plover_version)->int:
9095
) from e
9196
else:
9297
raise ValueError(
93-
f'Unknown format for unsupported_plover_version "{unsupported_plover_version}" from plugin metadata'
98+
f'Unknown format for unsupported plover version "{unsupported_plover_version}" from plugin metadata'
9499
)
95100

96101

97-
def is_plugin_supported(self, unsupported_plover_version):
98-
if unsupported_plover_version:
99-
parsed_unsupported_plover_version = self.parse_unsupported_plover_version(unsupported_plover_version)
102+
def is_plugin_supported(self,pkg, unsupported_plugins_dict):
103+
if not unsupported_plugins_dict:
104+
return True
105+
if pkg.name in unsupported_plugins_dict:
106+
unsupported_plover_version= unsupported_plugins_dict[pkg.name]
107+
try:
108+
parsed_unsupported_plover_version = self.parse_unsupported_plover_version(unsupported_plover_version)
109+
except:
110+
log.warning(f'Failed to parse unsupported plover version "{pkg.unsupported_plover_version}" for plugin {pkg.name}, assuming plugin is supported',exc_info=True)
111+
return True
100112
current_major_plover_version = int(__version__.split('.')[0])
113+
#TODO remove this overwrite after PR-1601 is merged and 5.0.0-alpha.1 released
114+
current_major_plover_version = 5
101115
return current_major_plover_version < parsed_unsupported_plover_version
102116
else:
103117
return True
@@ -106,9 +120,17 @@ def update(self):
106120
try:
107121
available_plugins = global_registry.list_plugins()
108122
except:
109-
log.error("failed to fetch list of available plugins from PyPI",
123+
log.error("Failed to fetch list of available plugins from PyPI",
110124
exc_info=True)
111125
return
126+
127+
session = CachedFuturesSession()
128+
try:
129+
unsupported_plugins_dict=session.get(UNSUPPORTED_PLUGINS_URL).result().json()
130+
except:
131+
log.warning("Failed to fetch list of unsupported plugins, assuming all plugins are supported",
132+
exc_info=True)
133+
112134
for name, metadata in available_plugins.items():
113135
pkg = self._packages.get(name)
114136
if pkg is None:
@@ -118,10 +140,5 @@ def update(self):
118140
pkg.available = metadata
119141
if pkg.current and pkg.current.parsed_version < pkg.latest.parsed_version:
120142
pkg.status = 'outdated'
121-
try:
122-
is_plugin_supported = self.is_plugin_supported(pkg.unsupported_plover_version)
123-
except:
124-
log.warning(f'Failed to parse unsupported plover version "{pkg.unsupported_plover_version}" for plugin {pkg.name}, assuming plugin is supported',exc_info=True)
125-
is_plugin_supported = True
126-
if not is_plugin_supported:
143+
if not self.is_plugin_supported(pkg, unsupported_plugins_dict):
127144
pkg.status = 'unsupported'

0 commit comments

Comments
 (0)