Skip to content

Commit

Permalink
fix: adapt to interface changes; add more metadata to templates (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneskoester authored Dec 12, 2023
1 parent 8cb86f3 commit d3efe48
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 30 deletions.
28 changes: 18 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ jobs:
- name: Check out the code
uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install poetry
run: pipx install poetry
run: pip install poetry

- name: Determine dependencies
run: poetry lock

- uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "3.11"
cache: poetry

- name: Install Dependencies using Poetry
Expand All @@ -36,15 +40,19 @@ jobs:
- name: Check out the code
uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install poetry
run: pipx install poetry
run: pip install poetry

- name: Determine dependencies
run: poetry lock

- uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "3.11"
cache: poetry

- name: Install Dependencies using Poetry
Expand All @@ -58,25 +66,25 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install poetry
run: pipx install poetry
run: pip install poetry

- name: Determine dependencies
run: poetry lock

- uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "3.11"
cache: poetry

- name: Install dependencies
run: |
poetry install
- name: Install example plugin
run: |
pip install --no-dependencies git+https://github.com/snakemake/snakemake-executor-flux.git
- name: Run pytest
run: poetry run coverage run -m pytest tests/tests.py

Expand Down
27 changes: 19 additions & 8 deletions poetry_snakemake_plugin/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@
from cleo.commands.command import Command
import subprocess as sp
from jinja2 import Environment, PackageLoader, select_autoescape
import tomli
import toml


class ScaffoldSnakemakePluginCommandBase(Command, ABC):
@abstractmethod
def get_dependencies(self) -> List[str]:
def get_templates(self) -> List[str]:
...

@abstractmethod
def get_package_name_prefix(self) -> str:
def get_plugin_type(self) -> str:
...

@abstractmethod
def get_templates(self) -> List[str]:
...
def get_dependencies(self) -> List[str]:
return [f"snakemake-interface-{self.get_plugin_type()}-plugins"]

def get_package_name_prefix(self) -> str:
return f"snakemake-{self.get_plugin_type()}-plugin-"

def handle(self) -> int:
# add dependencies
Expand Down Expand Up @@ -46,8 +48,8 @@ def handle(self) -> int:
keep_trailing_newline=True,
)

with open("pyproject.toml", "rb") as f:
pyproject = tomli.load(f)
with open("pyproject.toml", "r") as f:
pyproject = toml.load(f)

package_name = pyproject["tool"]["poetry"]["name"]
if not package_name.startswith(self.get_package_name_prefix()):
Expand All @@ -58,6 +60,15 @@ def handle(self) -> int:

plugin_name = package_name.replace(self.get_package_name_prefix(), "")

pyproject["tool"]["poetry"]["repository"] = "https://github.com/your/plugin"
pyproject["tool"]["poetry"]["documentation"] = (
"https://snakemake.github.io/snakemake-plugin-catalog/plugins/"
f"{self.get_plugin_type()}/{plugin_name}.html"
)

with open("pyproject.toml", "w") as f:
toml.dump(pyproject, f)

def render_template(name, dest: Path):
dest.parent.mkdir(exist_ok=True, parents=True)
with open(dest, "w") as f:
Expand Down
9 changes: 3 additions & 6 deletions poetry_snakemake_plugin/executor_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ class ScaffoldSnakemakeExecutorPluginCommand(ScaffoldSnakemakePluginCommandBase)
"dependencies and code snippets."
)

def get_dependencies(self) -> List[str]:
return ["snakemake-interface-executor-plugins"]

def get_package_name_prefix(self) -> str:
return "snakemake-executor-plugin-"

def get_templates(self, module_path: Path, tests_path: Path) -> List[str]:
return [
("executor-plugins/init.py", module_path / "__init__.py"),
("executor-plugins/tests.py.j2", tests_path / "tests.py"),
]

def get_plugin_type(self) -> str:
return "executor"
9 changes: 3 additions & 6 deletions poetry_snakemake_plugin/storage_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ class ScaffoldSnakemakeStoragePluginCommand(ScaffoldSnakemakePluginCommandBase):
"dependencies and code snippets."
)

def get_dependencies(self) -> List[str]:
return ["snakemake-interface-storage-plugins"]

def get_package_name_prefix(self) -> str:
return "snakemake-storage-plugin-"

def get_templates(self, module_path: Path, tests_path: Path) -> List[str]:
return [
("storage-plugins/init.py", module_path / "__init__.py"),
("storage-plugins/tests.py", tests_path / "tests.py"),
]

def get_plugin_type(self) -> str:
return "storage"
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ python = "^3.8.1"
poetry = "^1.2"
cleo = "^2.0.1"
jinja2 = "^3.1.2"
toml = "^0.10.2"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.1"
Expand Down

0 comments on commit d3efe48

Please sign in to comment.