Skip to content

Commit

Permalink
Merge pull request #108 from seequent/LF-52351-adding-ci
Browse files Browse the repository at this point in the history
LF-52351 Adding ci
  • Loading branch information
XavierMilesSeequent authored Sep 6, 2024
2 parents 5360334 + 15ab5d9 commit 588ef6e
Show file tree
Hide file tree
Showing 32 changed files with 972 additions and 707 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: pre-commit

on:
push:
branches:
- master

pull_request:
branches:
- master

jobs:
pre-commit:
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Run pre-commit
uses: pre-commit/[email protected]
50 changes: 50 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Test

on:
push:
branches:
- master

pull_request:
branches:
- master

jobs:
test:
runs-on: "ubuntu-latest"

steps:
- name: Checkout repo
uses: actions/checkout@v4

# Install all supported Python versions as tox will handle them from the single command
- name: Setup Python 3.8
uses: actions/setup-python@v5
with:
python-version: "3.8"

- name: Setup Python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.9"

- name: Setup Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Setup Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Setup Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install dependencies
run: python -m pip install .[dev]

- name: Run tox targets
run: "python -m tox"
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-toml
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
language_version: python3.10

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
22 changes: 15 additions & 7 deletions pure_interface/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
from .errors import PureInterfaceError, InterfaceError, AdaptionError
from .interface import Interface, InterfaceType
from .interface import type_is_interface, get_type_interfaces
from .interface import get_interface_names, get_interface_method_names, get_interface_attribute_names
from .interface import get_is_development, set_is_development, get_missing_method_warnings
from ._sub_interface import sub_interface_of
from .adaption import adapts, register_adapter, AdapterTracker, adapt_args
from .adaption import AdapterTracker, adapt_args, adapts, register_adapter
from .delegation import Delegate
from .errors import AdaptionError, InterfaceError, PureInterfaceError
from .interface import (
Interface,
InterfaceType,
get_interface_attribute_names,
get_interface_method_names,
get_interface_names,
get_is_development,
get_missing_method_warnings,
get_type_interfaces,
set_is_development,
type_is_interface,
)

__version__ = '8.0.2'
__version__ = "8.0.2"
28 changes: 16 additions & 12 deletions pure_interface/_sub_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
The decorator checks that the sub-interface is infact a subset and
registers the larger interface as an implementation of the sub-interface.
"""

from inspect import signature
from typing import Callable, TypeVar, Type
from typing import Callable, Type, TypeVar

from . import errors, interface

AnotherInterfaceType = TypeVar('AnotherInterfaceType', bound=Type[interface.Interface])
AnotherInterfaceType = TypeVar("AnotherInterfaceType", bound=Type[interface.Interface])


def _check_interfaces_match(large_interface, small_interface):
Expand All @@ -18,38 +20,40 @@ def _check_interfaces_match(large_interface, small_interface):
small_methods = interface.get_interface_method_names(small_interface)

if len(small_attributes) + len(small_methods) == 0:
raise interface.InterfaceError(f'Sub-interface {small_interface.__name__} is empty')
raise interface.InterfaceError(f"Sub-interface {small_interface.__name__} is empty")

if not small_attributes.issubset(large_attributes):
new_attrs = sorted(small_attributes.difference(large_attributes))
attr_str = ', '.join(new_attrs)
msg = f'{small_interface.__name__} has attributes that are not on {large_interface.__name__}: {attr_str}'
attr_str = ", ".join(new_attrs)
msg = f"{small_interface.__name__} has attributes that are not on {large_interface.__name__}: {attr_str}"
raise interface.InterfaceError(msg)

if not small_methods.issubset(large_methods):
new_methods = sorted(small_methods.difference(large_methods))
method_str = ', '.join(new_methods)
msg = f'{small_interface.__name__} has methods that are not on {large_interface.__name__}: {method_str}'
method_str = ", ".join(new_methods)
msg = f"{small_interface.__name__} has methods that are not on {large_interface.__name__}: {method_str}"
raise interface.InterfaceError(msg)

for method_name in small_methods:
large_method = getattr(large_interface, method_name)
small_method = getattr(small_interface, method_name)
if signature(large_method) != signature(small_method):
msg = (f'Signature of method {method_name} on {large_interface.__name__} '
f'and {small_interface.__name__} must match exactly')
msg = (
f"Signature of method {method_name} on {large_interface.__name__} "
f"and {small_interface.__name__} must match exactly"
)
raise interface.InterfaceError(msg)


def sub_interface_of(
large_interface: interface.AnInterfaceType
large_interface: interface.AnInterfaceType,
) -> Callable[[AnotherInterfaceType], AnotherInterfaceType]:
if not interface.type_is_interface(large_interface):
raise errors.InterfaceError(f'sub_interface_of argument {large_interface} is not an interface type')
raise errors.InterfaceError(f"sub_interface_of argument {large_interface} is not an interface type")

def decorator(small_interface: AnotherInterfaceType) -> AnotherInterfaceType:
if not interface.type_is_interface(small_interface):
raise errors.InterfaceError('class decorated by sub_interface_of must be an interface type')
raise errors.InterfaceError("class decorated by sub_interface_of must be an interface type")
_check_interfaces_match(large_interface, small_interface)
small_interface.register(large_interface) # type: ignore[arg-type]

Expand Down
Loading

0 comments on commit 588ef6e

Please sign in to comment.