├── manifest.in ├── pytrait ├── __init__.py ├── errors.py ├── trait.py ├── struct.py └── impl.py ├── setup.cfg ├── examples ├── supertraits.py ├── blanket_impl.py └── basics.py ├── setup.py ├── README.md └── LICENSE.txt /manifest.in: -------------------------------------------------------------------------------- 1 | include pyproject.toml 2 | include *.md 3 | include LICENSE.txt 4 | include setup.py 5 | -------------------------------------------------------------------------------- /pytrait/__init__.py: -------------------------------------------------------------------------------- 1 | from abc import abstractmethod 2 | 3 | from pytrait.errors import * 4 | from pytrait.trait import Trait 5 | from pytrait.impl import Impl 6 | from pytrait.struct import Struct 7 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | name = pytrait 3 | version = 0.0.3 4 | author = Xander Rudelis 5 | license_files = LICENSE.txt 6 | description = Rust-like traits for Python3 7 | long_description = file: README.md 8 | long_description_content_type = text/markdown 9 | -------------------------------------------------------------------------------- /pytrait/errors.py: -------------------------------------------------------------------------------- 1 | class PytraitError(RuntimeError): 2 | pass 3 | 4 | 5 | class DisallowedInitError(PytraitError): 6 | pass 7 | 8 | 9 | class NonMethodAttrError(PytraitError): 10 | pass 11 | 12 | 13 | class MultipleImplementationError(PytraitError): 14 | pass 15 | 16 | 17 | class InheritanceError(PytraitError): 18 | pass 19 | 20 | 21 | class NamingConventionError(PytraitError): 22 | pass 23 | -------------------------------------------------------------------------------- /examples/supertraits.py: -------------------------------------------------------------------------------- 1 | from pytrait import Trait, Impl, Struct, abstractmethod 2 | 3 | 4 | class Building(metaclass=Trait): 5 | @abstractmethod 6 | def floor_area(self) -> float: 7 | pass 8 | 9 | 10 | class Residence(Building, metaclass=Trait): 11 | """ 12 | Residence has Building as a supertrait, so it is a superset of Building. 13 | 14 | All types implementing Residence must also implement Building's interface. 15 | 16 | Among Traits, multiple inheritance is allowed. 17 | """ 18 | 19 | @abstractmethod 20 | def number_of_residents(self) -> int: 21 | pass 22 | 23 | 24 | class ImplResidenceForApartmentBuilding(Residence, metaclass=Impl): 25 | def floor_area(self) -> float: 26 | return self._floor_area 27 | 28 | def number_of_residents(self) -> int: 29 | # One resident per 60 square meters 30 | return int(self._floor_area // 60) 31 | 32 | 33 | class ApartmentBuilding(metaclass=Struct): 34 | _floor_area: float 35 | 36 | 37 | if __name__ == "__main__": 38 | apartment_building = ApartmentBuilding(150.0) 39 | print(apartment_building.number_of_residents()) 40 | print(apartment_building.traits) 41 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | with open("README.md", "r", encoding="utf-8") as fh: 4 | long_description = fh.read() 5 | 6 | setup( 7 | name="pytrait", 8 | version="0.0.3", 9 | description="Rust-like traits for Python3", 10 | long_description=long_description, 11 | long_description_content_type="text/markdown", 12 | author="Xander Rudelis", 13 | url="https://github.com/xrudelis/pytrait", 14 | classifiers=[ 15 | "Development Status :: 3 - Alpha", 16 | "Intended Audience :: Developers", 17 | "Topic :: Software Development", 18 | "License :: OSI Approved :: Apache Software License", 19 | "Programming Language :: Python :: 3", 20 | "Programming Language :: Python :: 3.6", 21 | "Programming Language :: Python :: 3.7", 22 | "Programming Language :: Python :: 3.8", 23 | "Programming Language :: Python :: 3.9", 24 | "Programming Language :: Python :: 3.10", 25 | "Programming Language :: Python :: 3 :: Only", 26 | ], 27 | keywords="trait, traits", 28 | package_dir={"": "./"}, 29 | packages=find_packages(where="./"), 30 | python_requires=">=3.6, <4", 31 | ) 32 | -------------------------------------------------------------------------------- /examples/blanket_impl.py: -------------------------------------------------------------------------------- 1 | from pytrait import Trait, Impl, Struct, abstractmethod 2 | 3 | 4 | class Animal(metaclass=Trait): 5 | @abstractmethod 6 | def name(self) -> str: 7 | pass 8 | 9 | @abstractmethod 10 | def noise(self) -> str: 11 | pass 12 | 13 | def talk(self): 14 | print(f"{self.name()} says {self.noise()}") 15 | 16 | 17 | class Person(metaclass=Trait): 18 | @abstractmethod 19 | def first_name(self) -> str: 20 | pass 21 | 22 | @abstractmethod 23 | def last_name(self) -> str: 24 | pass 25 | 26 | 27 | class ImplAnimal(Animal, metaclass=Impl, target="Person"): 28 | """All people are also animals""" 29 | 30 | def name(self) -> str: 31 | return f"{self.first_name()} {self.last_name()}" 32 | 33 | def noise(self) -> str: 34 | return "Hello" 35 | 36 | 37 | class ImplPerson(Person, metaclass=Impl, target="Englishman"): 38 | def first_name(self) -> str: 39 | return self._first_name 40 | 41 | def last_name(self) -> str: 42 | return "Smith" 43 | 44 | 45 | class Englishman(metaclass=Struct): 46 | _first_name: str 47 | 48 | def noise(self) -> str: 49 | return "Good day to you, sir!" 50 | 51 | 52 | if __name__ == "__main__": 53 | johnny = Englishman("John") 54 | johnny.talk() 55 | -------------------------------------------------------------------------------- /examples/basics.py: -------------------------------------------------------------------------------- 1 | # Re-implementation of https://doc.rust-lang.org/rust-by-example/trait.html 2 | from pytrait import Trait, Impl, Struct, abstractmethod 3 | 4 | 5 | class Animal(metaclass=Trait): 6 | @abstractmethod 7 | def name(self) -> str: 8 | pass 9 | 10 | @abstractmethod 11 | def noise(self) -> str: 12 | pass 13 | 14 | def talk(self): 15 | print(f"{self.name()} says {self.noise()}") 16 | 17 | 18 | class ImplAnimalForSheep(Animal, metaclass=Impl): 19 | def name(self) -> str: 20 | return self._name 21 | 22 | def noise(self) -> str: 23 | if self.is_naked(): 24 | return "baaaaah?" 25 | else: 26 | return "baaaaah!" 27 | 28 | # Default trait methods can be overridden. 29 | def talk(self): 30 | print(f"{self.name()} pauses briefly... {self.noise()}") 31 | 32 | 33 | class Sheep(metaclass=Struct): 34 | _name: str 35 | naked: bool = False 36 | 37 | def is_naked(self) -> bool: 38 | return self.naked 39 | 40 | def shear(self): 41 | if self.is_naked(): 42 | print(f"{self._name} is already naked...") 43 | else: 44 | print(f"{self._name} gets a haircut!") 45 | self.naked = True 46 | 47 | 48 | if __name__ == "__main__": 49 | dolly = Sheep(_name="Dolly") 50 | dolly.talk() 51 | dolly.shear() 52 | dolly.talk() 53 | -------------------------------------------------------------------------------- /pytrait/trait.py: -------------------------------------------------------------------------------- 1 | from abc import ABCMeta 2 | from typing import Any, Dict, Generator, Tuple 3 | 4 | import pytrait 5 | 6 | 7 | def _disallowed_init(self, *args, **kwargs): 8 | # Raises an error like "Trait MyTrait cannot be instantiated" or 9 | # "Impl ImplMyTraitForMyStruct cannot be instantiated" 10 | raise pytrait.DisallowedInitError( 11 | f"{self.__class__.__class__.__name__} {self.__class__.__name__} cannot " 12 | f"be instantiated." 13 | ) 14 | 15 | 16 | class Trait(ABCMeta): 17 | """ 18 | Use metaclass=Trait when declaring a class, in order for the class to define a 19 | Trait. Traits should have no explicit base class. 20 | 21 | Traits are very similar to abstract classes and interfaces. Like interfaces, the 22 | main goal is to define the available behavior for other types. Like abstract 23 | classes, traits can have some implementation defined for methods. But unlike 24 | abstract classes, Traits never inherit, and methods are either strictly abstract 25 | without implementation, or are concrete methods that cannot be overridden. 26 | """ 27 | 28 | allowed_attrs = ( 29 | "__doc__", 30 | "__module__", 31 | "__qualname__", 32 | ) 33 | 34 | # Keep track of all available traits by name 35 | trait_registry: Dict[str, "Trait"] = dict() 36 | 37 | def __new__(meta, name: str, bases: Tuple[type], attrs: Dict[str, Any], **kwargs): 38 | cls = super().__new__(meta, name, bases, attrs) 39 | # Disallow instantiation by defining __init__() 40 | setattr(cls, "__init__", _disallowed_init) 41 | return cls 42 | 43 | def __init__(cls, name: str, bases: Tuple[type], attrs: Dict[str, Any]): 44 | if __debug__: 45 | cls.require_inherit_traits(name, bases) 46 | cls.require_method_attrs(name, attrs) 47 | Trait.trait_registry[name] = cls 48 | super(ABCMeta, cls).__init__(name, bases, attrs) 49 | 50 | def __repr__(cls): 51 | return f"{cls.__class__.__name__} {cls.__module__}.{cls.__qualname__}" 52 | 53 | def require_inherit_traits(cls, name: str, bases: Tuple[type]): 54 | """Require that we only inhert from Trait classes.""" 55 | for base in bases: 56 | if base.__class__ is not Trait: 57 | raise pytrait.InheritanceError( 58 | f"{name} must inherit from Traits only, " 59 | f"got: {base.__name__} of type {base.__class__.__name__}" 60 | ) 61 | 62 | def require_method_attrs(cls, name: str, attrs: Dict[str, Any]): 63 | """ 64 | Require that the class has no non-method attributes. 65 | 66 | State should be defined in Structs only. 67 | """ 68 | non_method_attrs = list() 69 | for attr, value in attrs.items(): 70 | if attr not in cls.allowed_attrs and not callable(value): 71 | non_method_attrs.append(attr) 72 | if non_method_attrs: 73 | non_method_attrs = ", ".join(non_method_attrs) 74 | raise pytrait.NonMethodAttrError( 75 | f"{cls.__class__.__name__} {name} must not have non-method " 76 | f"attributes, got: {non_method_attrs}" 77 | ) 78 | 79 | def supertraits(cls) -> Generator["Trait", None, None]: 80 | """Yields this class and any supertraits recursively.""" 81 | yield cls 82 | for base in cls.__bases__: 83 | if base is object: 84 | return 85 | yield from base.supertraits() 86 | -------------------------------------------------------------------------------- /pytrait/struct.py: -------------------------------------------------------------------------------- 1 | from abc import ABCMeta 2 | from dataclasses import dataclass 3 | import itertools as it 4 | import sys 5 | from typing import Any, Dict, Tuple 6 | 7 | import pytrait 8 | from pytrait import Impl 9 | 10 | 11 | class Struct(Impl): 12 | """ 13 | Use metaclass=Struct when declaring a class, in order for the class to be a Struct 14 | in the trait system. The class will automatically find Impl blocks to inherit from. 15 | 16 | Struct is a metaclass, and must subclass the metaclass Impl because classes of type 17 | Struct subclass classes of type Impl. 18 | """ 19 | 20 | def __new__(meta, name: str, bases: Tuple[Any], attrs: Dict[str, Any], **kwargs): 21 | """ 22 | Passing keyword args after metaclass=Struct will provide options to dataclass. 23 | """ 24 | if __debug__ and len(bases) > 0: 25 | raise pytrait.InheritanceError( 26 | f"Struct {name} must have no explicit superclasses." 27 | ) 28 | # Automatically add Impls for this Struct to bases 29 | impl_bases = Impl.registry[name] 30 | traits_implemented = set( 31 | it.chain.from_iterable(impl.traits() for impl in impl_bases) 32 | ) 33 | traits_to_check_for_blanket_impls = traits_implemented.copy() 34 | # Automatically add blanket Impls for this struct to bases. 35 | # This is "recursive", so if we get a trait satisfied from a blanket 36 | # implementation, that may afford even more blanket implementations. 37 | # We also find any supertrait of implemented traits, since these are also 38 | # implemented traits. 39 | while traits_to_check_for_blanket_impls: 40 | trait = traits_to_check_for_blanket_impls.pop() 41 | additional_impls = Impl.blanket_registry.get(trait.__name__) 42 | if additional_impls is None: 43 | # If trait is not a blanket trait, we don't get more Impls from it. 44 | continue 45 | impl_bases.extend(additional_impls) 46 | traits = set( 47 | it.chain.from_iterable(impl.traits() for impl in additional_impls) 48 | ) 49 | traits_implemented.update(traits) 50 | traits_to_check_for_blanket_impls.update(traits) 51 | bases = bases + tuple(impl_bases) 52 | cls = super(ABCMeta, meta).__new__(meta, name, bases, attrs) 53 | cls.traits = frozenset(traits_implemented) 54 | # If we're using Python 3.10 or newer, use the slots feature of dataclasses 55 | # by default to prevent the programmer from adding new attrs to a non-frozen 56 | # dataclass. 57 | if sys.version_info >= (3, 10, 0): 58 | if "slots" not in kwargs: 59 | kwargs["slots"] = True 60 | # Make the cls be a dataclass. 61 | return dataclass(cls, **kwargs) 62 | 63 | def __init__(cls, name: str, bases: Tuple[Impl], attrs: Dict[str, Any], **kwargs): 64 | if __debug__: 65 | # Check that we only inherit directly from Impls, and that no two Impls 66 | # share a method of the same name. 67 | 68 | # Mapping from methodname to the name of the trait that we got the 69 | # method from 70 | methodnames_seen: Dict[str, str] = dict() 71 | for base in bases: 72 | trait_name = base.__bases__[0].__name__ 73 | if base.__class__ is not Impl: 74 | raise pytrait.InheritanceError( 75 | f"Struct {name} must only inherit from classes of type " 76 | f"Impl, got class {base}" 77 | ) 78 | for attr, value in attrs.items(): 79 | if callable(value): 80 | # Make sure no two traits clash with the same methods 81 | if attr in methodnames_seen: 82 | raise pytrait.MultipleImplementationError( 83 | f"Method {attr}() defined twice, due to Traits " 84 | f"{methodnames_seen[attr]} and " 85 | f"{trait_name}" 86 | ) 87 | methodnames_seen[attr] = trait_name 88 | 89 | super(ABCMeta, cls).__init__(name, bases, attrs) 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Find the package here: https://pypi.org/project/pytrait/ 2 | 3 | PyTrait 4 | ======= 5 | 6 | Do you like Python, but think that multiple inheritance is a bit too flexible? Are you 7 | looking for a more constrained way to define interfaces and re-use code? 8 | 9 | Try using PyTraits! 10 | 11 | We provide three metaclasses that aid writing code for shared behavior separately from 12 | concrete types. For the most part, `Trait`s define interfaces, `Struct`s define state, 13 | and `Impl`s define implementation. `Trait`s must be defined before any `Impl`s which 14 | implement them, and `Impl`s must be defined before the `Struct`s that use them. 15 | 16 | See examples under `examples/`. 17 | 18 | 19 | Traits 20 | ------ 21 | 22 | Traits are abstract base classes (ABCs). There's really not much else to say, except 23 | that these ABCs are always implemented in `Impl` classes, which themselves have no 24 | abstract methods, but are not concrete classes; instead an `Impl` is associated with 25 | another type that it bestows implementation upon. This would be either a concrete class 26 | (always a `Struct`) or all such concrete classes implementing a given `Trait`. 27 | 28 | 29 | ```python 30 | from pytrait import Trait, abstractmethod 31 | 32 | class MyTrait(metaclass=Trait): 33 | @abstractmethod 34 | def my_method(self) -> str: 35 | pass 36 | ``` 37 | 38 | 39 | Structs 40 | ------- 41 | 42 | Python has _dataclasses_, and they're great. We're using them internally for our 43 | Structs, so whenever you see `metaclass=Struct`, the class is also a dataclass. 44 | Don't get confused with the existing Python module `struct` -- that one is lower-case. 45 | 46 | ```python 47 | from pytrait import Struct 48 | 49 | class MyStruct(metaclass=Struct): 50 | my_message: str = "this is a dataclass" 51 | 52 | def __post_init__(self): 53 | assert my_message == "this is a dataclass" 54 | ``` 55 | 56 | Impls 57 | ----- 58 | 59 | `Impl`s bring together `Trait`s and `Struct`s. They represent the implementation details 60 | that satisfy one particular interface. 61 | 62 | Why isn't the implementation just all together under the `Struct`? Organization, 63 | mostly. Also, "blanket" `Impl`s can provide implementation for any `Struct` implementing 64 | a given `Trait`, so `Impl`s allow for greater code re-use. 65 | 66 | `Impl`s have to indicate which `Struct`s they bestow implementation upon. You can 67 | follow a strict naming convention, like `ImplMyTraitForMyStruct`. This is sufficient. 68 | Or, you can use any name you want so long as you also provide a keyword argument 69 | `target="StructName"` alongside the `metaclass` argument. 70 | 71 | ```python 72 | from pytrait import Impl 73 | 74 | class MyImpl(MyTrait, metaclass=Impl, target="MyStruct"): 75 | ... 76 | ``` 77 | 78 | or equivalently, 79 | 80 | ```python 81 | from pytrait import Impl 82 | 83 | class ImplMyTraitForMyStruct(MyTrait, metaclass=Impl): 84 | ... 85 | ``` 86 | 87 | This is used to automate the list of implementations for `MyStruct`; you don't need to 88 | explicitly list any superclasses of `MyStruct`, just based on the `Impl` name it will 89 | inherit from all relevant `Impl`s. 90 | 91 | 92 | FAQ 93 | === 94 | 95 | 96 | This reminds me of another programming language 97 | ----------------------------------------------- 98 | 99 | That is not a question, but you have indeed figured me out. This way of organizing 100 | Python code was heavily inspired by the Rust programming language. But beyond being an 101 | imitation, it's a testament to how powerful Python is. My philosophy is that if 102 | you're not using the flexibility of Python to limit yourself, you're not making use of 103 | the full flexibility of Python. 104 | 105 | 106 | What doesn't work? 107 | ------------------ 108 | 109 | A Struct can't have traits with overlapping method names. Rust can solve this 110 | with its "fully qualified syntax", or by type constraints, but Python will 111 | by default only resolve to the method from the first listed superclass (see 112 | Python's "Method Resolution Order"). 113 | 114 | I don't think there's any easy way around this, because in Python there's no clear way 115 | to choose which implementation to use based on type annotation. If you _really_ want to 116 | let a `Struct` implement two traits that have the same method name, you can always wrap 117 | your class definition in a try block and catch the `MultipleImplementationError`. Maybe 118 | you can find a way to make it work. 119 | -------------------------------------------------------------------------------- /pytrait/impl.py: -------------------------------------------------------------------------------- 1 | from abc import ABCMeta 2 | from typing import Any, Dict, Generator, List, Optional, Tuple 3 | 4 | import pytrait 5 | from pytrait import Trait 6 | 7 | 8 | class Impl(Trait): 9 | """ 10 | Use metaclass=Impl when declaring a class, in order for the class to be an Impl 11 | in the trait system. Each Impl has one base class, which must be a Trait. Impls 12 | implement that Trait for either a specific Struct, or for all structs implementing 13 | a Trait. 14 | 15 | Impl is a metaclass, and must subclass the metaclass Trait because classes of type 16 | Impl subclass classes of type Trait. 17 | 18 | If `target` is provided (the name of the Struct or Trait this Impl provides 19 | implementation for), then we relax the requirement for the Impl class to be 20 | named ImplMyTraitForTarget. 21 | """ 22 | 23 | registry: Dict[str, List["Impl"]] = dict() 24 | blanket_registry: Dict[str, List["Impl"]] = dict() 25 | 26 | def __init__( 27 | cls, 28 | name: str, 29 | bases: Tuple[type], 30 | attrs: Dict[str, Any], 31 | target: Optional[str] = None, 32 | ): 33 | # We require an explicit base class here, unlike with Struct, because if the 34 | # substring "For" is in either a trait or target name, then our naming 35 | # convention would be ambiguous. Alternatively, the argument "target" can be 36 | # provided, with the name of the target Struct or Trait. 37 | if len(bases) != 1: 38 | basenames = tuple(base.__name__ for base in bases) 39 | raise pytrait.InheritanceError( 40 | f"Impl {name} must list exactly 1 Trait as a base class, got: " 41 | f"{basenames}" 42 | ) 43 | 44 | base = bases[0] 45 | cls.trait_name = base.__name__ 46 | if target is None: 47 | prefix_len = len(f"Impl{cls.trait_name}For") 48 | cls.target_name = name[prefix_len:] 49 | else: 50 | cls.target_name = target 51 | 52 | if __debug__: 53 | cls.require_inherit_traits(name, bases) 54 | cls.require_method_attrs(name, attrs) 55 | cls.require_no_abstract_methods(name, base, attrs) 56 | if target is None: 57 | cls.require_naming_convention(name, cls.trait_name, cls.target_name) 58 | 59 | # Add this class to the registry, so that it is automatically chosen as a 60 | # superclass for the relevant struct(s) 61 | 62 | # Look for target in Trait registry so that we know if this is a blanket 63 | # impl or not 64 | blanket_impl = cls.target_name in Trait.trait_registry 65 | if blanket_impl: 66 | if cls.target_name in Impl.blanket_registry: 67 | Impl.blanket_registry[cls.target_name].append(cls) 68 | else: 69 | Impl.blanket_registry[cls.target_name] = [cls] 70 | else: 71 | if cls.target_name in Impl.registry: 72 | Impl.registry[cls.target_name].append(cls) 73 | else: 74 | Impl.registry[cls.target_name] = [cls] 75 | 76 | super(ABCMeta, cls).__init__(name, bases, attrs) 77 | 78 | def require_naming_convention(cls, name: str, trait_name: str, target_name: str): 79 | if name != f"Impl{trait_name}For{target_name}": 80 | raise pytrait.NamingConventionError( 81 | "We require either naming all Impl classes like " 82 | "ImplTraitForStruct, or providing the target argument." 83 | ) 84 | 85 | def require_no_abstract_methods(cls, name: str, base: Trait, attrs: Dict[str, Any]): 86 | # Check that we implement all Trait abstract methods 87 | base_abstractmethods = set(base.__abstractmethods__) 88 | for attr, value in attrs.items(): 89 | if callable(value) and hasattr(base, attr): 90 | if attr in base_abstractmethods: 91 | base_abstractmethods.remove(attr) 92 | 93 | if base_abstractmethods: 94 | abstractmethods = ", ".join(f"{name}()" for name in base_abstractmethods) 95 | raise pytrait.PytraitError( 96 | f"Impl {name} must implement required methods: " f"{abstractmethods}" 97 | ) 98 | 99 | def traits(cls) -> Generator[Trait, None, None]: 100 | """ 101 | Yields traits that this Impl implements. 102 | 103 | This can be multiple because Traits are allowed to inherit from any number of 104 | other Traits. 105 | """ 106 | for base in cls.__bases__: 107 | yield from base.supertraits() 108 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | https://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | Copyright 2021 Xander Rudelis 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); 182 | you may not use this file except in compliance with the License. 183 | You may obtain a copy of the License at 184 | 185 | https://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 190 | See the License for the specific language governing permissions and 191 | limitations under the License. 192 | --------------------------------------------------------------------------------