Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: align with CI workflows of other interface packages #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/conventional-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: PR
on:
pull_request_target:
types:
- opened
- reopened
- edited
- synchronize

jobs:
title-format:
runs-on: ubuntu-latest
steps:
- uses: amannn/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62 changes: 62 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
on:
push:
branches:
- main

name: release-please

jobs:
release-please:
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
steps:
- uses: GoogleCloudPlatform/release-please-action@v3
id: release
with:
release-type: simple
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Update release-type for Python package.

The release-type should be set to "python" instead of "simple" for Python packages to ensure proper version management and changelog generation.

-          release-type: simple
+          release-type: python
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
release-type: simple
release-type: python


setup_and_build:
runs-on: ubuntu-latest
needs: release-please
if: ${{ needs.release-please.outputs.release_created }}
steps:
- uses: actions/checkout@v2

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version-file: "pyproject.toml"

- name: Install the project
run: uv sync --all-extras --dev

- name: Build source and wheel distribution
run: |
uv build

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: dist
path: dist/
pypi_publish:
name: Upload release to PyPI
needs: [release-please, setup_and_build]
runs-on: ubuntu-latest
environment:
name: release
permissions:
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: dist
path: dist/

- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
137 changes: 0 additions & 137 deletions .github/workflows/release.yml

This file was deleted.

54 changes: 54 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches-ignore: []
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove empty branches-ignore section.

The empty branches-ignore section is unnecessary and can be removed.

  pull_request:
-   branches-ignore: []
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
branches-ignore: []
pull_request:
🧰 Tools
🪛 actionlint (1.7.4)

8-8: "branches-ignore" section should not be empty

(syntax-check)


jobs:
formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove trailing spaces.

There are trailing spaces on lines 15, 29, and 43.

-      - uses: actions/checkout@v4
-      
+      - uses: actions/checkout@v4

Also applies to: 29-29, 43-43

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 15-15: trailing spaces

(trailing-spaces)

- name: Install uv and install project
uses: astral-sh/setup-uv@v5

- name: Install the project
run: uv sync --all-extras --dev

- name: Check formatting
run: uv run ruff format --check

linting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install uv and install project
uses: astral-sh/setup-uv@v5

- name: Install the project
run: uv sync --all-extras --dev

- name: Check code
run: uv run ruff check

testing:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install uv and install project
uses: astral-sh/setup-uv@v5

- name: Install the project
run: uv sync --all-extras --dev

- name: Run pytest
run: uv run coverage run -m pytest tests/tests.py

- name: Run Coverage
run: uv run coverage report -m
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ dependencies = [
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[dependency-groups]
dev = [
"coverage>=7.6.10",
"pytest>=8.3.4",
"ruff>=0.9.4",
]
4 changes: 2 additions & 2 deletions src/snakemake_interface_logger_plugins/registry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from snakemake_interface_common.plugin_registry import PluginRegistryBase
from snakemake_interface_logger_plugins import common
from snakemake_interface_logger_plugins.base import (
LoggerPluginBase,
LogHandlerBase,
)


Expand Down Expand Up @@ -48,7 +48,7 @@ def expected_attributes(self) -> Mapping[str, AttributeType]:
kind=AttributeKind.CLASS,
),
"LoggerPlugin": AttributeType(
cls=LoggerPluginBase,
cls=LogHandlerBase,
mode=AttributeMode.REQUIRED,
kind=AttributeKind.CLASS,
),
Expand Down
92 changes: 92 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import pytest
from unittest.mock import MagicMock
from logging import Handler
from typing import Optional
from dataclasses import dataclass, field
from snakemake_interface_logger_plugins.settings import LoggerPluginSettingsBase
from snakemake_interface_logger_plugins.registry import (
LoggerPluginRegistry,
LogHandlerBase,
)
from snakemake_interface_common.plugin_registry.tests import TestRegistryBase
from snakemake_interface_common.plugin_registry import PluginRegistryBase
from snakemake_interface_logger_plugins.registry.plugin import Plugin


@dataclass
class MockSettings(LoggerPluginSettingsBase):
"""Mock settings for the logger plugin."""

log_level: Optional[str] = field(
default=None,
metadata={
"help": "set the log level",
"env_var": False,
"required": False,
},
)


class MockPlugin(LogHandlerBase):
settings_cls = MockSettings # Use our mock settings class

def __init__(self, settings: Optional[LoggerPluginSettingsBase] = None):
if settings is None:
settings = MockSettings() # Provide default mock settings
super().__init__(settings)

def create_handler(
self,
quiet,
printshellcmds: bool,
printreason: bool,
debug_dag: bool,
nocolor: bool,
stdout: bool,
debug: bool,
mode,
show_failed_logs: bool,
dryrun: bool,
) -> Handler:
"""Mock logging handler."""
return MagicMock(spec=Handler)


class TestRegistry(TestRegistryBase):
__test__ = True

@pytest.fixture(autouse=True)
def reset_registry(self, monkeypatch):
"""Ensure the registry is completely reset for each test."""
if LoggerPluginRegistry._instance:
LoggerPluginRegistry._instance.plugins = {}
LoggerPluginRegistry._instance = None

registry = LoggerPluginRegistry()
registry.plugins = {
"rich": Plugin(
log_handler=MockPlugin,
_logger_settings_cls=MockSettings,
_name="rich",
)
} # Inject the mock plugin

monkeypatch.setattr(self, "get_registry", lambda: registry)

def get_registry(self) -> PluginRegistryBase:
return LoggerPluginRegistry()

def get_test_plugin_name(self) -> str:
return "rich"

def validate_plugin(self, plugin: LogHandlerBase):
assert plugin.settings_cls is MockSettings # Ensure settings class is correct

def validate_settings(
self, settings: LoggerPluginSettingsBase, plugin: LogHandlerBase
):
assert isinstance(settings, MockSettings)
assert settings.log_level == "info"

def get_example_args(self):
return ["--logger-rich-log-level", "info"]
Loading
Loading