Skip to content

Commit

Permalink
Support chris_plugin>=0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Oct 12, 2023
1 parent 7cd003e commit c2651d0
Show file tree
Hide file tree
Showing 4 changed files with 490 additions and 468 deletions.
7 changes: 6 additions & 1 deletion chrisomatic/core/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,17 @@ def from_given(cls, p: GivenCubePlugin) -> Self:

def fill(self, json_representation: str) -> str:
"""
Adds inferred values for `name`, `dock_image`, and `public_repo` to the given plugin JSON representation.
If necessary, adds inferred values for `name`, `dock_image`, and `public_repo` to the given plugin JSON representation.
These fields are typically missing from automatically self-generated plugin JSON representations due to
historical reasons and technical debt.
https://github.com/FNNDSC/CHRIS_docs/commit/5078aaf934bdbe313e85367f88aff7c14730a1d4
This is necessary for Python-based _ChRIS_ plugins built on top of:
- [`chris_plugin`](https://pypi.org/project/chris_plugin/) prior to [version 0.3.0](https://github.com/FNNDSC/chris_plugin/releases/tag/v0.3.0)
- [`chrisapp`](https://github.com/FNNDSC/chrisapp)
"""
obj = json.loads(json_representation)
self.__set_if_missing(obj, "name", self.name)
Expand Down
27 changes: 24 additions & 3 deletions chrisomatic/helpers/pldesc.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,41 @@ async def try_obtain_json_description(
status.keep_current()
guessing_methods: list[
Callable[
[aiodocker.Docker, GivenCubePlugin, DeprecatedState],
[aiodocker.Docker, GivenCubePlugin, Channel],
Awaitable[Optional[str]],
]
] = [_json_from_chris_plugin_info, _json_from_old_chrisapp]
] = [
_json_from_chris_plugin_info_post030,
_json_from_chris_plugin_info_pre030,
_json_from_old_chrisapp,
]
for guess_method in guessing_methods:
json_representation = await guess_method(docker, plugin, status)
if json_representation is not None:
return json_representation
return None


async def _json_from_chris_plugin_info(
async def _json_from_chris_plugin_info_post030(
docker: aiodocker.Docker, plugin: GivenCubePlugin, status: Channel
) -> Optional[str]:
"""
Run `chris_plugin_info` with its usage since version 0.3.0
"""
command = ["chris_plugin_info", "--dock-image", plugin.dock_image]
if plugin.public_repo:
command.extend(["--public-repo", plugin.public_repo])
if plugin.name:
command.extend(["--name", plugin.name])
return await _try_run(docker, plugin, status, command)


async def _json_from_chris_plugin_info_pre030(
docker: aiodocker.Docker, plugin: GivenCubePlugin, status: Channel
) -> Optional[str]:
"""
Run `chris_plugin_info` with its usage from before version 0.3.0
"""
return await _try_run(docker, plugin, status, ("chris_plugin_info",))


Expand Down
Loading

0 comments on commit c2651d0

Please sign in to comment.