Skip to content

Commit

Permalink
Revert "remove lots"
Browse files Browse the repository at this point in the history
This reverts commit 97ee984.
  • Loading branch information
Christian-B committed Dec 6, 2024
1 parent 97ee984 commit 20c3388
Show file tree
Hide file tree
Showing 168 changed files with 17,371 additions and 0 deletions.
5 changes: 5 additions & 0 deletions spinn_utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from spinn_utilities._version import __version__ # NOQA
from spinn_utilities._version import __version_name__ # NOQA
from spinn_utilities._version import __version_month__ # NOQA
from spinn_utilities._version import __version_year__ # NOQA
19 changes: 19 additions & 0 deletions spinn_utilities/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) 2017 The University of Manchester
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "1!7.3.1"
__version_month__ = "TBD"
__version_year__ = "TBD"
__version_day__ = "TBD"
__version_name__ = "To Do"
80 changes: 80 additions & 0 deletions spinn_utilities/abstract_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright (c) 2017 The University of Manchester
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
A trimmed down version of standard Python Abstract Base classes.
"""
from typing import Any, Dict, Type, TypeVar, Tuple
#: :meta private:
T = TypeVar("T")


def abstractmethod(funcobj: T) -> T:
"""
A decorator indicating abstract methods.
Requires that the metaclass is :py:class:`AbstractBase` or derived from
it. A class that has a metaclass derived from :py:class:`AbstractBase`
cannot be instantiated unless all of its abstract methods are overridden.
The abstract methods can be called using any of the normal
'super' call mechanisms.
Usage::
class C(object, metaclass=AbstractBase):
@abstractmethod
def my_abstract_method(self, ...):
...
"""
funcobj.__isabstractmethod__ = True # type: ignore[attr-defined]
return funcobj


class AbstractBase(type):
"""
Metaclass for defining Abstract Base Classes (AbstractBases).
Use this metaclass to create an AbstractBase. An AbstractBase can be
subclassed directly, and then acts as a mix-in class.
This is a trimmed down version of ABC.
Unlike ABC you can not register unrelated concrete classes.
Usage::
class C(object, metaclass=AbstractBase):
@abstractmethod
def my_abstract_method(self, ...):
...
"""

def __new__(mcs, name: str, bases: Tuple[Type, ...],
namespace: Dict[str, Any], **kwargs: Any) -> "AbstractBase":
# Actually make the class
abs_cls = super().__new__(mcs, name, bases, namespace, **kwargs)

# Get set of abstract methods from namespace
abstracts = set(nm for nm, val in namespace.items()
if getattr(val, "__isabstractmethod__", False))

# Augment with abstract methods from superclasses
for base in bases:
for nm in getattr(base, "__abstractmethods__", set()):
val = getattr(abs_cls, nm, None)
if getattr(val, "__isabstractmethod__", False):
abstracts.add(nm)

# Lock down the set
abs_cls.__abstractmethods__ = frozenset( # type: ignore[attr-defined]
abstracts)
return abs_cls
40 changes: 40 additions & 0 deletions spinn_utilities/abstract_context_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2017 The University of Manchester
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from types import TracebackType
from typing import Optional, Type
from typing_extensions import Literal, Self
from .abstract_base import AbstractBase, abstractmethod


class AbstractContextManager(object, metaclass=AbstractBase):
"""
Closeable class that supports being used as a simple context manager.
"""

__slots__ = ()

@abstractmethod
def close(self) -> None:
"""
How to actually close the underlying resources.
"""

def __enter__(self) -> Self:
return self

def __exit__(self, exc_type: Optional[Type], exc_val: Exception,
exc_tb: TracebackType) -> Literal[False]:
self.close()
return False
50 changes: 50 additions & 0 deletions spinn_utilities/bytestring_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright (c) 2018 The University of Manchester
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Optional


def as_string(byte_string: bytes, start: Optional[int] = None,
end: Optional[int] = None) -> str:
"""
Returns the length and the hex values.
The length is always the full length irrespective of the start and end.
:param bytes byte_string: data as a byte string
:param int start:
The inclusive start of the slice to convert to hexadecimal.
May be `None`
:param int end:
The exclusive end of the slice to convert to hexadecimal. May be `None`
:return:
The length of the byte string and the comma separated hex values, as a
descriptive string
:rtype: str
"""
return "(" + str(len(byte_string)) + ")" + as_hex(byte_string, start, end)


def as_hex(byte_string: bytes, start: Optional[int] = None,
end: Optional[int] = None) -> str:
"""
Returns the byte string as string showing the hex values
:param bytes byte_string: data as a byte string
:param int start: the inclusive start of the slice to return. May be `None`
:param int end: the exclusive end of the slice to return. May be `None`
:return: Comma-separated hex values
:rtype: str
"""
# pylint: disable=consider-using-f-string
return ','.join('%02x' % i for i in iter(byte_string[start:end]))
21 changes: 21 additions & 0 deletions spinn_utilities/citation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2018 The University of Manchester
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from .citation_updater_and_doi_generator import CitationUpdaterAndDoiGenerator
from .citation_aggregator import (
CitationAggregator, generate_aggregate)

__all__ = [
"CitationAggregator", "CitationUpdaterAndDoiGenerator",
"generate_aggregate"]
Loading

0 comments on commit 20c3388

Please sign in to comment.