Skip to content

Commit

Permalink
Merge pull request #109 from ESSS/fb-ASIM-5082-sdk-version-on-plugin-…
Browse files Browse the repository at this point in the history
…file

Allow to add some extra text to created hmplugin file
  • Loading branch information
prusse-martin authored Feb 10, 2023
2 parents 67e7136 + 67533c9 commit a5aeb3e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
8 changes: 7 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
History
=======

0.5.0 (UNRELEASED)
==================

- Allow to add some extra text to created hmplugin file.


0.4.0 (2020-10-23)
==================

- When removing plugins they are first moved to a ``.trash`` dir and not directly deleted.
- Allow HookManager to call hooks of a specific plugin
- Allow HookManager to call hooks of a specific plugin.


0.3.0 (2019-12-16)
Expand Down
23 changes: 16 additions & 7 deletions hookman/hookman_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def generate_plugin_package(
plugin_dir: Union[Path, str],
dst_path: Path = None,
extras_defaults: Optional[Dict[str, str]] = None,
package_name_suffix: Optional[str] = None,
):
"""
Creates a .hmplugin file using the name provided on package_name argument.
Expand All @@ -284,6 +285,9 @@ def generate_plugin_package(
:param Dict[str,str] extras_defaults:
(key, value) entries to be added to "extras" if not defined by the original input yaml.
:param Optional[str] package_name_suffix:
If not `None` this string is inserted after the plugin version in the filename.
"""
plugin_dir = Path(plugin_dir)
if dst_path is None:
Expand All @@ -297,13 +301,6 @@ def generate_plugin_package(
self._validate_plugin_config_file(assets_dir / "plugin.yaml")
plugin_info = PluginInfo(assets_dir / "plugin.yaml", hooks_available=None)

if sys.platform == "win32":
shared_lib_extension = "*.dll"
hmplugin_path = dst_path / f"{package_name}-{plugin_info.version}-win64.hmplugin"
else:
shared_lib_extension = "*.so"
hmplugin_path = dst_path / f"{package_name}-{plugin_info.version}-linux64.hmplugin"

contents = (assets_dir / "plugin.yaml").read_text()
if extras_defaults is not None:
import strictyaml
Expand All @@ -314,6 +311,18 @@ def generate_plugin_package(
contents_dict["extras"] = dict(sorted(extras.items()))
contents = contents_dict.as_yaml()

hmplugin_base_name_components = [package_name, plugin_info.version]
if package_name_suffix is not None:
hmplugin_base_name_components.append(package_name_suffix)

if sys.platform == "win32": # pragma: no cover (apparently merge reports of the same files)
shared_lib_extension = "*.dll"
hmplugin_base_name_components.append("win64")
else:
shared_lib_extension = "*.so"
hmplugin_base_name_components.append("linux64")

hmplugin_path = dst_path / ("-".join(hmplugin_base_name_components) + ".hmplugin")
with ZipFile(hmplugin_path, "w") as zip_file:
for file in assets_dir.rglob("*"):
if file.name == "plugin.yaml":
Expand Down
15 changes: 11 additions & 4 deletions tests/test_hookman_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ def test_generate_plugin_package_invalid_shared_lib_name(acme_hook_specs_file, t
)


def test_generate_plugin_package(acme_hook_specs_file, tmpdir, mock_plugin_id_from_dll):
@pytest.mark.parametrize('package_name_extra', [None, 'foo'])
def test_generate_plugin_package(acme_hook_specs_file, tmpdir, mock_plugin_id_from_dll, package_name_extra):
hg = HookManGenerator(hook_spec_file_path=acme_hook_specs_file)
plugin_id = "acme"
hg.generate_plugin_template(
Expand All @@ -219,15 +220,21 @@ def test_generate_plugin_package(acme_hook_specs_file, tmpdir, mock_plugin_id_fr
package_name="acme",
plugin_dir=plugin_dir,
extras_defaults={"key": "default", "key3": "default"},
package_name_suffix=package_name_extra,
)

from hookman.plugin_config import PluginInfo

version = PluginInfo(Path(tmpdir / "acme/assets/plugin.yaml"), None).version

win_plugin_name = f"{plugin_id}-{version}-win64.hmplugin"
linux_plugin_name = f"{plugin_id}-{version}-linux64.hmplugin"
hm_plugin_name = win_plugin_name if sys.platform == "win32" else linux_plugin_name
base_plugin_name_components = [plugin_id, version]
if package_name_extra is not None:
base_plugin_name_components.append(package_name_extra)
if sys.platform == "win32":
base_plugin_name_components.append("win64")
else:
base_plugin_name_components.append("linux64")
hm_plugin_name = "-".join(base_plugin_name_components) + ".hmplugin"

compressed_plugin = plugin_dir / hm_plugin_name
assert compressed_plugin.exists()
Expand Down

0 comments on commit a5aeb3e

Please sign in to comment.