├── test ├── __init__.py ├── arch │ ├── __init__.py │ └── test_imports.py ├── unit │ ├── __init__.py │ ├── model │ │ ├── __init__.py │ │ ├── test_dotpath.py │ │ └── test_node.py │ ├── conftest.py │ ├── test_plugin.py │ └── test_query.py ├── integration │ ├── __init__.py │ ├── plugin │ │ ├── __init__.py │ │ ├── test_arch.py │ │ ├── test_explain.py │ │ └── test_projectpath.py │ └── test_parser.py └── conftest.py ├── src └── pyarch │ ├── __init__.py │ ├── parser.py │ ├── query.py │ ├── plugin.py │ └── model.py ├── .flake8 ├── .gitignore ├── pyproject.toml ├── noxfile.py ├── README.md ├── LICENSE.md └── poetry.lock /test/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/pyarch/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/arch/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/unit/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/integration/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/unit/model/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/integration/plugin/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/conftest.py: -------------------------------------------------------------------------------- 1 | pytest_plugins = ['pytester'] 2 | -------------------------------------------------------------------------------- /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 79 3 | per-file-ignores = __init__.py:F401 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ 2 | /dist/ 3 | .pytest_cache/ 4 | .nox/ 5 | .coverage 6 | /htmlcov 7 | .venv/ 8 | venv/ 9 | .mypy_cache/ 10 | .idea/ 11 | -------------------------------------------------------------------------------- /test/integration/plugin/test_arch.py: -------------------------------------------------------------------------------- 1 | def test_simple_project(pytester): 2 | pytester.makepyfile(foobar='from foo import bar') 3 | pytester.makepyfile( 4 | """ 5 | def test_arch(arch): 6 | assert arch.import_of('foo.bar') in arch.modules_at('foobar') 7 | assert arch.import_of('fiz') not in arch.modules_at('foobar') 8 | """ 9 | ) 10 | result = pytester.runpytest() 11 | result.assert_outcomes(passed=1) 12 | print(result.stdout) 13 | -------------------------------------------------------------------------------- /test/unit/conftest.py: -------------------------------------------------------------------------------- 1 | from inspect import cleandoc 2 | from pathlib import Path 3 | 4 | import pytest 5 | 6 | from pyarch.parser import build_import_model 7 | 8 | 9 | def _yield_project_modules(struct: dict[str, str | dict], current_path: Path): 10 | for key, value in struct.items(): 11 | path = current_path / key 12 | match value: 13 | case dict(): 14 | yield from _yield_project_modules(value, path) 15 | case str(): 16 | yield path, cleandoc(value) 17 | 18 | 19 | @pytest.fixture 20 | def arch_root_node(project_structure, mocker): 21 | """Overrides the fixture from the plugin with an in-memory version.""" 22 | 23 | def mock_walk_modules(_): 24 | return _yield_project_modules(project_structure, Path()) 25 | 26 | mocker.patch('pyarch.parser._walk_modules', mock_walk_modules) 27 | return build_import_model(Path()) 28 | -------------------------------------------------------------------------------- /test/arch/test_imports.py: -------------------------------------------------------------------------------- 1 | def test_internal_dependencies(arch): 2 | assert arch.import_of('pyarch.parser') not in arch.modules_at( 3 | 'pyarch', exclude=['plugin'] 4 | ) 5 | assert arch.import_of('pyarch.query') not in arch.modules_at( 6 | 'pyarch', exclude=['plugin'] 7 | ) 8 | assert arch.import_of('pyarch.plugin') not in arch.modules_at( 9 | 'pyarch', exclude=['plugin'] 10 | ) 11 | assert arch.import_of('pyarch.model') in arch.modules_at('pyarch.plugin') 12 | assert arch.import_of('pyarch.model') in arch.modules_at('pyarch.query') 13 | assert arch.import_of('pyarch.model') in arch.modules_at('pyarch.parser') 14 | 15 | 16 | def test_all_internal_imports_must_be_relative(arch): 17 | assert arch.import_of('pyarch', absolute=True) not in arch.modules_at( 18 | 'pyarch' 19 | ) 20 | 21 | 22 | def test_external_dependencies(arch): 23 | assert arch.import_of('ast') not in arch.modules_at( 24 | 'pyarch', exclude=['parser'] 25 | ) 26 | assert arch.import_of('pytest') not in arch.modules_at( 27 | 'pyarch', exclude=['plugin'] 28 | ) 29 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "pytest-arch" 3 | version = "0.1.4" 4 | description = "A pythonic derivative of ArchUnit, in the form of a pytest plugin." 5 | license = "Apache-2.0" 6 | authors = ["Niko Wilbert "] 7 | classifiers = ["Framework :: Pytest"] 8 | packages = [ 9 | { include = "pyarch", from = "src" }, 10 | ] 11 | 12 | [tool.poetry.plugins."pytest11"] 13 | arch = "pyarch.plugin" 14 | 15 | [tool.poetry.dependencies] 16 | python = "^3.10" 17 | pytest = "^7.2.2" 18 | 19 | [tool.poetry.group.dev.dependencies] 20 | nox = "^2022.11.21" 21 | nox-poetry = "^1.0.2" 22 | flake8 = "~4.0.1" # 5.0.4 is incompatible with blue 23 | mypy = "^1.1.1" 24 | blue = "^0.9.1" 25 | pytest-mock = "^3.10.0" 26 | coverage = "^7.2.1" 27 | 28 | [build-system] 29 | requires = ["poetry-core>=1.0.0"] 30 | build-backend = "poetry.core.masonry.api" 31 | 32 | [tool.isort] 33 | profile = "black" 34 | line_length = 79 35 | 36 | [tool.mypy] 37 | python_version = "3.10" 38 | ignore_missing_imports = true 39 | no_implicit_optional = true 40 | warn_return_any = true 41 | show_error_codes = true 42 | warn_unused_ignores = true 43 | disallow_untyped_defs = true 44 | 45 | -------------------------------------------------------------------------------- /noxfile.py: -------------------------------------------------------------------------------- 1 | import webbrowser 2 | from pathlib import Path 3 | 4 | import nox 5 | from nox_poetry import session 6 | 7 | src_path = 'src' 8 | code_paths = [src_path, 'test', 'noxfile.py'] 9 | 10 | nox.options.sessions = [ 11 | 'blue', 12 | 'isort', 13 | 'flake8', 14 | 'mypy', 15 | 'pytest', 16 | 'coverage', 17 | ] 18 | 19 | 20 | @session 21 | def blue(session): 22 | session.install('blue') 23 | session.run('blue', *code_paths) 24 | 25 | 26 | @session 27 | def isort(session): 28 | session.install('isort') 29 | session.run('isort', *code_paths) 30 | 31 | 32 | @session 33 | def flake8(session): 34 | session.install('flake8') 35 | session.run('flake8', *code_paths) 36 | 37 | 38 | @session 39 | def mypy(session): 40 | session.install('mypy', '.') 41 | session.run('mypy', src_path) 42 | 43 | 44 | @session(python=['3.10', '3.11']) 45 | def pytest(session): 46 | session.install('pytest', 'pytest-mock', '.') 47 | session.run('pytest') 48 | 49 | 50 | @session 51 | def coverage(session): 52 | session.install('pytest', 'pytest-mock', 'coverage', '.') 53 | session.run( 54 | 'coverage', 55 | 'run', 56 | '--source', 57 | 'pyarch', 58 | '-m', 59 | 'pytest', 60 | 'test/integration', 61 | 'test/unit', 62 | ) 63 | try: 64 | session.run( 65 | 'coverage', 'report', '--fail-under', '100', '--show-missing' 66 | ) 67 | finally: 68 | if 'html' in session.posargs: 69 | session.run('coverage', 'html', '--skip-covered') 70 | webbrowser.open((Path.cwd() / 'htmlcov' / 'index.html').as_uri()) 71 | -------------------------------------------------------------------------------- /test/integration/plugin/test_explain.py: -------------------------------------------------------------------------------- 1 | def test_explain_contains_fail(pytester): 2 | pytester.makepyfile(foo='import fizz') 3 | pytester.makepyfile( 4 | """ 5 | def test_arch(arch): 6 | assert arch.import_of('bar') in arch.modules_at('foo') 7 | """ 8 | ) 9 | result = pytester.runpytest() 10 | result.assert_outcomes(failed=1) 11 | explanation_lines = [ 12 | line for line in result.outlines if 'no matching import' in line 13 | ] 14 | assert len(explanation_lines) == 1 15 | assert 'foo.py' in explanation_lines[0] 16 | 17 | 18 | def test_explain_not_contains_fail(pytester): 19 | pytester.makepyfile( 20 | foobar=""" 21 | from foo import bar 22 | import foo.bar 23 | """ 24 | ) 25 | pytester.makepyfile( 26 | """ 27 | def test_arch(arch): 28 | assert arch.import_of('foo.bar') not in arch.modules_at('foobar') 29 | """ 30 | ) 31 | result = pytester.runpytest() 32 | result.assert_outcomes(failed=1) 33 | explanation_lines = [ 34 | line for line in result.outlines if 'found import' in line 35 | ] 36 | assert len(explanation_lines) == 2 37 | assert 'foobar.py:1' in explanation_lines[0] 38 | assert 'foobar.py:2' in explanation_lines[1] 39 | 40 | 41 | def test_assertrepr_compare_does_not_apply(pytester): 42 | """Check that we don't break explanations for other types.""" 43 | pytester.makepyfile(foobar='') 44 | pytester.makepyfile( 45 | """ 46 | def test_other(arch): 47 | assert [1, 2] == [1, 2, 3] 48 | """ 49 | ) 50 | result = pytester.runpytest() 51 | result.assert_outcomes(failed=1) 52 | explanation_lines = [ 53 | line for line in result.outlines if 'contains one more item' in line 54 | ] 55 | assert len(explanation_lines) == 1 56 | -------------------------------------------------------------------------------- /src/pyarch/parser.py: -------------------------------------------------------------------------------- 1 | import ast 2 | import logging 3 | from pathlib import Path 4 | from typing import Generator, Sequence, Tuple 5 | 6 | from .model import DotPath, ImportInModule, RootNode 7 | 8 | log = logging.getLogger(__name__) 9 | 10 | 11 | def build_import_model(base_path: Path) -> RootNode: 12 | root_node = RootNode() 13 | for module_path, module_content in _walk_modules(base_path): 14 | module_ast = ast.parse(module_content, str(module_path)) 15 | dot_path = DotPath.from_path(module_path.relative_to(base_path)) 16 | node = root_node.get_or_add(dot_path, module_path) 17 | imports = _collect_imports(module_ast, dot_path) 18 | if module_path.name == '__init__.py': 19 | node.add_data_for_init_file(imports) 20 | else: 21 | node.add_imports(imports) 22 | return root_node 23 | 24 | 25 | def _collect_imports( 26 | module_ast: ast.Module, node_path: DotPath 27 | ) -> Sequence[ImportInModule]: 28 | imports: list[ImportInModule] = [] 29 | for ast_node in ast.walk(module_ast): 30 | match ast_node: 31 | case ast.Import() as ast_import: 32 | for alias in ast_import.names: 33 | imports.append( 34 | ImportInModule( 35 | import_path=DotPath(alias.name), 36 | line_no=alias.lineno, 37 | ) 38 | ) 39 | case ast.ImportFrom() as ast_import_from: 40 | for alias in ast_import_from.names: 41 | if ast_import_from.module: 42 | from_path = DotPath(ast_import_from.module) 43 | else: 44 | from_path = DotPath() 45 | if (level := ast_import_from.level) > 0: 46 | if level > len(node_path.parts): 47 | log.warning( 48 | f'Skipping import from {node_path} because ' 49 | f'relative import level goes beyond project.' 50 | ) 51 | continue 52 | else: 53 | from_path = ( 54 | DotPath(node_path.parts[:-level]) / from_path 55 | ) 56 | from_path /= alias.name 57 | imports.append( 58 | ImportInModule( 59 | import_path=from_path, 60 | line_no=alias.lineno, 61 | level=ast_import_from.level, 62 | ) 63 | ) 64 | return imports 65 | 66 | 67 | def _walk_modules(base_path: Path) -> Generator[Tuple[Path, str], None, None]: 68 | for path in base_path.glob('**/*.py'): 69 | if not any(part.startswith('.') for part in path.parts): 70 | yield path, path.read_text() 71 | -------------------------------------------------------------------------------- /src/pyarch/query.py: -------------------------------------------------------------------------------- 1 | from typing import Iterable, Iterator, Optional, Tuple 2 | 3 | from .model import DotPath, ImportInModule, ModuleNode 4 | 5 | 6 | class ImportOf: 7 | """Represents a single import of something from a module.""" 8 | 9 | def __init__(self, path: DotPath, *, absolute: bool | None = None): 10 | self._import_path = path 11 | self._absolute = absolute 12 | 13 | def __str__(self) -> str: 14 | return f'import of {self._import_path}' 15 | 16 | def __repr__(self) -> str: 17 | # pytest uses repr for the explanation of failed assertions 18 | return str(self) 19 | 20 | @property 21 | def import_path(self) -> DotPath: 22 | return self._import_path 23 | 24 | @property 25 | def absolute(self) -> bool | None: 26 | return self._absolute 27 | 28 | 29 | class ModulesAt: 30 | """Represents a module tree with its imports.""" 31 | 32 | def __init__( 33 | self, 34 | base_node: ModuleNode, 35 | exclude: Optional[Iterable[DotPath]] = None, 36 | ): 37 | self._base_node = base_node 38 | self._exclude = exclude or [] 39 | 40 | def __contains__(self, import_of: ImportOf) -> bool: 41 | """ 42 | Checks if the given import path or any sub-path is imported anywhere 43 | in this package. 44 | 45 | Example: If the given import path is 'a.b' then an import 46 | of 'a.b.c' would be reported as well, but not an import of 'a'. 47 | """ 48 | if isinstance(import_of, ImportOf): 49 | return next(self._matching_imports(import_of), None) is not None 50 | raise NotImplementedError() 51 | 52 | def __str__(self) -> str: 53 | return f'modules at {self._base_node.file_path}' 54 | 55 | def __repr__(self) -> str: 56 | # pytest uses repr for the explanation of failed assertions 57 | return str(self) 58 | 59 | def explain_why_contains_is_false(self, import_of: ImportOf) -> list[str]: 60 | return [ 61 | f'no matching import in module {module_node.file_path}' 62 | for module_node in self._base_node.walk(exclude=self._exclude) 63 | if module_node.file_path.suffix == '.py' 64 | ] 65 | 66 | def explain_why_contains_is_true(self, import_of: ImportOf) -> list[str]: 67 | return [ 68 | f'found import of {import_of.import_path} in module ' 69 | f'{module_node.file_path}:{import_by.line_no}' 70 | for module_node, import_by in self._matching_imports(import_of) 71 | ] 72 | 73 | def _matching_imports( 74 | self, import_of: ImportOf 75 | ) -> Iterator[Tuple[ModuleNode, ImportInModule]]: 76 | import_of_path = import_of.import_path 77 | for module_node in self._base_node.walk(exclude=self._exclude): 78 | for import_by in module_node.imports: 79 | if import_by.import_path.is_relative_to(import_of_path): 80 | if ( 81 | import_of.absolute is None 82 | or import_of.absolute != bool(import_by.level) 83 | ): 84 | yield module_node, import_by 85 | -------------------------------------------------------------------------------- /test/unit/model/test_dotpath.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import pytest 4 | 5 | from pyarch.model import DotPath 6 | 7 | 8 | @pytest.mark.parametrize( 9 | 'path, parts', 10 | [ 11 | (None, tuple()), 12 | ('', tuple()), 13 | ('aa', ('aa',)), 14 | ('a.b', ('a', 'b')), 15 | ('ab.cd.e', ('ab', 'cd', 'e')), 16 | ('ab..cd', ('ab', '', 'cd')), 17 | ([], tuple()), 18 | (['a', 'b'], ('a', 'b')), 19 | (DotPath('a.b'), ('a', 'b')), 20 | (DotPath(''), tuple()), 21 | ], 22 | ) 23 | def test_dotpath_init(path: str, parts: tuple[str, ...]): 24 | assert DotPath(path).parts == parts 25 | 26 | 27 | @pytest.mark.parametrize( 28 | 'path, dotpath', 29 | [ 30 | (Path(), DotPath()), 31 | (Path('aa') / 'bb', DotPath('aa.bb')), 32 | (Path('a.py'), DotPath('a')), 33 | (Path('a') / 'b.py', DotPath('a.b')), 34 | (Path('a') / '__init__.py', DotPath('a')), 35 | (Path('a.b') / 'c', DotPath(('a.b', 'c'))), 36 | ], 37 | ) 38 | def test_dotpath_from_path(path: Path, dotpath: DotPath): 39 | assert DotPath.from_path(path) == dotpath 40 | 41 | 42 | @pytest.mark.parametrize( 43 | 'path, other, result', 44 | [ 45 | ('', '', True), 46 | ('a', 'a', True), 47 | ('a.b', 'a', True), 48 | ('aa.b', 'aa.b', True), 49 | ('b.b', 'a.b', False), 50 | ('a.b', 'b', False), 51 | ('ab.cd.e', 'ab.cd', True), 52 | ('e.ab.cd', 'ab.cd', False), 53 | ], 54 | ) 55 | def test_dotpath_is_relative_to(path: str, other: str, result: bool): 56 | assert DotPath(path).is_relative_to(DotPath(other)) == result 57 | 58 | 59 | def test_dotpath_name(): 60 | assert DotPath('a.bb').name == 'bb' 61 | 62 | 63 | def test_dotpath_name_index_error(): 64 | with pytest.raises(IndexError): 65 | _ = DotPath().name 66 | 67 | 68 | @pytest.mark.parametrize( 69 | 'dotpath, parent', 70 | [ 71 | (DotPath('aa'), DotPath()), 72 | (DotPath('aa.bb.cc'), DotPath('aa.bb')), 73 | (DotPath(), DotPath()), 74 | ], 75 | ) 76 | def test_dotpath_parent(dotpath: DotPath, parent: DotPath): 77 | assert dotpath.parent == parent 78 | 79 | 80 | def test_dotpath_str(): 81 | assert str(DotPath('ab.cd.e')) == 'ab.cd.e' 82 | 83 | 84 | def test_dotpath_repr(): 85 | assert repr(DotPath('ab.cd.e')) == "DotPath(('ab', 'cd', 'e'))" 86 | 87 | 88 | def test_dotpath_equal(): 89 | assert DotPath('ab.cd.e') == DotPath('ab.cd.e') 90 | assert DotPath('ab.cd.e') != DotPath('ab.d.e') 91 | 92 | 93 | def test_dotpath_equal_other_type(): 94 | assert DotPath('ab.cd.e') != 42 95 | 96 | 97 | def test_dotpath_truediv(): 98 | assert DotPath('a.b') / DotPath('c') == DotPath('a.b.c') 99 | assert DotPath('a') / 'b' == DotPath('a.b') 100 | assert 'a' / DotPath('b') == DotPath('a.b') 101 | 102 | 103 | def test_dotpath_hash(): 104 | assert hash(DotPath('a')) != hash(DotPath('b')) 105 | assert hash(DotPath('a.b')) == hash(DotPath('a.b')) 106 | assert hash(DotPath('a.b')) != hash(DotPath('a.c')) 107 | 108 | 109 | def test_dotpath_hash_stable(): 110 | dp = DotPath('a.b') 111 | assert hash(dp) == hash(dp) 112 | -------------------------------------------------------------------------------- /test/unit/test_plugin.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | 4 | @pytest.mark.parametrize( 5 | 'project_structure', 6 | [{'a.py': 'from b import x'}], 7 | ) 8 | def test_arch_fixture(arch): 9 | assert arch.import_of('b.x') in arch.modules_at('a') 10 | assert arch.import_of('b.y') not in arch.modules_at('a') 11 | 12 | 13 | @pytest.mark.parametrize( 14 | 'project_structure', 15 | [ 16 | { 17 | 'a': { 18 | 'b': { 19 | 'c.py': """ 20 | from .. import x 21 | from ..x.y import z as xyz 22 | """, 23 | } 24 | }, 25 | } 26 | ], 27 | ) 28 | def test_relative_import(arch): 29 | assert arch.import_of('x') not in arch.modules_at('a') 30 | assert arch.import_of('x') not in arch.modules_at('a.b') 31 | assert arch.import_of('a.x') in arch.modules_at('a') 32 | assert arch.import_of('a.x') in arch.modules_at('a.b') 33 | assert arch.import_of('x.y.z') not in arch.modules_at('a') 34 | assert arch.import_of('x.y.z') not in arch.modules_at('a.b.c') 35 | assert arch.import_of('a.x.y.z') in arch.modules_at('a') 36 | assert arch.import_of('a.x.y.z') in arch.modules_at('a.b.c') 37 | assert arch.import_of('x.y.m') not in arch.modules_at('a.b') 38 | 39 | 40 | @pytest.mark.parametrize( 41 | 'project_structure', 42 | [ 43 | { 44 | 'a': { 45 | 'b.py': 'from .x import y', 46 | 'c.py': 'from ..x import y', 47 | 'd.py': 'from x import y', 48 | }, 49 | } 50 | ], 51 | ) 52 | def test_import_absolute_argument(arch): 53 | assert arch.import_of('a') in arch.modules_at('a.b') 54 | assert arch.import_of('a.x') in arch.modules_at('a.b') 55 | assert arch.import_of('a.x.y') in arch.modules_at('a.b') 56 | assert arch.import_of('a', absolute=True) not in arch.modules_at('a.b') 57 | assert arch.import_of('a.x', absolute=True) not in arch.modules_at('a.b') 58 | assert arch.import_of('a.x.y', absolute=True) not in arch.modules_at('a.b') 59 | assert arch.import_of('a', absolute=False) in arch.modules_at('a.b') 60 | assert arch.import_of('a.x', absolute=False) in arch.modules_at('a.b') 61 | assert arch.import_of('a.x.y', absolute=False) in arch.modules_at('a.b') 62 | 63 | assert arch.import_of('x.y') in arch.modules_at('a.c') 64 | assert arch.import_of('x.y', absolute=False) in arch.modules_at('a.c') 65 | assert arch.import_of('x', absolute=False) in arch.modules_at('a.c') 66 | 67 | assert arch.import_of('x.y') in arch.modules_at('a.d') 68 | assert arch.import_of('x.y', absolute=True) in arch.modules_at('a.d') 69 | assert arch.import_of('x.y', absolute=False) not in arch.modules_at('a.d') 70 | 71 | 72 | @pytest.mark.parametrize( 73 | 'project_structure', 74 | [ 75 | { 76 | 'r': { 77 | 'a.py': 'import x', 78 | 'b.py': """ 79 | import x 80 | import y 81 | """, 82 | }, 83 | } 84 | ], 85 | ) 86 | def test_modules_exclude_argument(arch): 87 | assert arch.import_of('y') in arch.modules_at('r') 88 | assert arch.import_of('y') not in arch.modules_at('r', exclude=['b']) 89 | assert arch.import_of('x') in arch.modules_at('r', exclude=['b']) 90 | assert arch.import_of('x') not in arch.modules_at('r', exclude=['a', 'b']) 91 | assert arch.import_of('y') not in arch.modules_at('r', exclude=['a', 'b']) 92 | 93 | 94 | @pytest.mark.parametrize( 95 | 'project_structure', 96 | [{'r': {'a.py': 'import x'}}], 97 | ) 98 | def test_module_exclude_argument_wrong_type(arch): 99 | with pytest.raises(TypeError): 100 | arch.modules_at('r', exclude='a') 101 | 102 | 103 | @pytest.mark.parametrize( 104 | 'project_structure', 105 | [{'a.py': ''}], 106 | ) 107 | def test_module_not_found(arch): 108 | with pytest.raises(KeyError): 109 | arch.modules_at('foobar') 110 | -------------------------------------------------------------------------------- /test/unit/model/test_node.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import pytest 4 | 5 | from pyarch.model import DotPath, ImportInModule, ModuleNode, RootNode 6 | 7 | 8 | @pytest.fixture 9 | def tree_base_node(): 10 | base_node = RootNode() 11 | base_node.get_or_add(DotPath('1'), Path('1')) 12 | base_node.get_or_add(DotPath('2'), Path('2')) 13 | base_node.get_or_add(DotPath('2.1'), Path('1', '2')) 14 | return base_node 15 | 16 | 17 | @pytest.mark.parametrize( 18 | 'path_str, result_name', 19 | [ 20 | ('1', '1'), 21 | ('2', '2'), 22 | ('2.1', '1'), 23 | ], 24 | ) 25 | def test_node_get(tree_base_node, path_str, result_name): 26 | assert tree_base_node.get(DotPath(path_str)).name == result_name 27 | 28 | 29 | def test_node_get_nested(tree_base_node): 30 | assert tree_base_node.get(DotPath('2')).get(DotPath('1')).name == '1' 31 | 32 | 33 | def test_node_get_non_existend(tree_base_node): 34 | assert tree_base_node.get(DotPath('1.1')) is None 35 | 36 | 37 | def test_node_get_root(tree_base_node): 38 | with pytest.raises(KeyError): 39 | assert tree_base_node.get(DotPath()) 40 | 41 | 42 | def test_node_get_or_add(): 43 | root_node = RootNode() 44 | new_node = root_node.get_or_add(DotPath('a'), Path('a')) 45 | assert new_node.name == 'a' 46 | assert new_node.file_path == Path('a') 47 | assert root_node.get(DotPath('a')).name == 'a' 48 | 49 | 50 | def test_node_get_or_add_new_parent(tree_base_node): 51 | new_node = tree_base_node.get_or_add(DotPath('1.a.b'), Path('1', 'a', 'b')) 52 | assert new_node.name == 'b' 53 | assert new_node.file_path == Path('1', 'a', 'b') 54 | new_parent_node = tree_base_node.get(DotPath('1.a')) 55 | assert new_parent_node.name == 'a' 56 | assert new_parent_node.file_path == Path('1', 'a') 57 | assert new_parent_node.get(DotPath('b')).name == 'b' 58 | 59 | 60 | def test_node_get_or_add_root(tree_base_node): 61 | with pytest.raises(KeyError): 62 | assert tree_base_node.get_or_add(DotPath(), Path()) 63 | 64 | 65 | def test_node_add_imports(): 66 | imports = [ 67 | ImportInModule(DotPath('a'), line_no=1), 68 | ImportInModule(DotPath('b'), line_no=2), 69 | ] 70 | node = ModuleNode('x', Path('foobar')) 71 | assert len(node.imports) == 0 72 | node.add_imports(imports) 73 | assert len(node.imports) == 2 74 | assert {str(import_of.import_path) for import_of in node.imports} == { 75 | 'a', 76 | 'b', 77 | } 78 | 79 | 80 | def test_node_for_init_file(): 81 | imports = [ 82 | ImportInModule(DotPath('a'), line_no=1), 83 | ImportInModule(DotPath('b'), line_no=2), 84 | ] 85 | node = ModuleNode('x', Path('foobar')) 86 | assert node.file_path.name == 'foobar' 87 | assert len(node.imports) == 0 88 | node.add_data_for_init_file(imports) 89 | assert len(node.imports) == 2 90 | assert node.file_path == Path('foobar') / '__init__.py' 91 | 92 | 93 | def test_node_walk(): 94 | base_node = ModuleNode('base', Path()) 95 | base_node.get_or_add(DotPath('a.c'), Path()) 96 | base_node.get_or_add(DotPath('a.b.x'), Path()) 97 | visited = [node.name for node in base_node.walk()] 98 | assert len(visited) == 5 99 | assert set(visited) == {'base', 'a', 'c', 'b', 'x'} 100 | 101 | 102 | @pytest.mark.parametrize( 103 | 'exclude, visited', 104 | [ 105 | ([], {'r', 'a', 'b', 'c', 'd'}), 106 | ([''], {'r', 'a', 'b', 'c', 'd'}), 107 | (['r'], {'r', 'a', 'b', 'c', 'd'}), 108 | (['b'], {'r', 'a', 'b', 'c', 'd'}), 109 | (['d'], {'r', 'a', 'b', 'c', 'd'}), 110 | (['x'], {'r', 'a', 'b', 'c', 'd'}), 111 | (['a'], {'r'}), 112 | (['a', 'a'], {'r'}), 113 | (['a.b'], {'r', 'a', 'd'}), 114 | (['a.b', 'a'], {'r'}), 115 | (['a.b', 'a.d'], {'r', 'a'}), 116 | (['a.b', 'a.d', 'x.y'], {'r', 'a'}), 117 | ], 118 | ) 119 | def test_node_walk_exclude(exclude, visited): 120 | base_node = ModuleNode('r', Path()) 121 | base_node.get_or_add(DotPath('a.b.c'), Path()) 122 | base_node.get_or_add(DotPath('a.d'), Path()) 123 | assert { 124 | node.name 125 | for node in base_node.walk(exclude=[DotPath(p) for p in exclude]) 126 | } == visited 127 | -------------------------------------------------------------------------------- /test/unit/test_query.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from pyarch.model import DotPath 4 | from pyarch.query import ImportOf, ModulesAt 5 | 6 | 7 | @pytest.mark.parametrize( 8 | 'project_structure', 9 | [ 10 | { 11 | 'a.py': 'from b import x', 12 | } 13 | ], 14 | ) 15 | def test_contains_flat(arch_root_node): 16 | a = arch_root_node.get(DotPath('a')) 17 | assert ImportOf(DotPath('b')) in ModulesAt(a) 18 | assert ImportOf(DotPath('b.x')) in ModulesAt(a) 19 | assert ImportOf(DotPath('c')) not in ModulesAt(a) 20 | assert ImportOf(DotPath('b.y')) not in ModulesAt(a) 21 | 22 | 23 | @pytest.mark.parametrize( 24 | 'project_structure', 25 | [{'d': {'e.py': 'import x'}}], 26 | ) 27 | def test_contains_nested(arch_root_node): 28 | d = arch_root_node.get(DotPath('d')) 29 | assert ImportOf(DotPath('x')) in ModulesAt(d) 30 | assert ImportOf(DotPath('y')) not in ModulesAt(d) 31 | 32 | 33 | @pytest.mark.parametrize( 34 | 'project_structure', 35 | [{'a.py': ''}], 36 | ) 37 | def test_contains_with_wrong_type(arch): 38 | with pytest.raises(NotImplementedError): 39 | assert 42 in arch.modules_at('a') 40 | 41 | 42 | @pytest.mark.parametrize( 43 | 'project_structure', 44 | [{'d': {'a.py': 'import x', 'b.py': 'import y'}}], 45 | ) 46 | def test_explain_contains_false(arch_root_node): 47 | d = arch_root_node.get(DotPath('d')) 48 | lines = ModulesAt(d).explain_why_contains_is_false(ImportOf(DotPath('z'))) 49 | assert len(lines) == 2 50 | assert 'no matching' in lines[0] 51 | assert 'no matching' in lines[1] 52 | assert 'a.py' in lines[0] 53 | assert 'b.py' in lines[1] 54 | 55 | 56 | @pytest.mark.parametrize( 57 | 'project_structure', 58 | [ 59 | {'r': {'a.py': 'import x', '__init__.py': 'import x'}}, 60 | ], 61 | ) 62 | def test_explain_contains_false_with_init(arch_root_node): 63 | r = arch_root_node.get(DotPath('r')) 64 | lines = ModulesAt(r).explain_why_contains_is_false(ImportOf(DotPath('y'))) 65 | assert len(lines) == 2 66 | assert '__init__.py' in lines[0] 67 | 68 | 69 | @pytest.mark.parametrize( 70 | 'project_structure', 71 | [ 72 | { 73 | 'a.py': """ 74 | import x.y 75 | import x.z 76 | """ 77 | } 78 | ], 79 | ) 80 | def test_explain_contains_true(arch_root_node): 81 | a = arch_root_node.get(DotPath('a')) 82 | lines = ModulesAt(a).explain_why_contains_is_true(ImportOf(DotPath('x'))) 83 | assert len(lines) == 2 84 | assert 'found import of x' in lines[0] 85 | assert 'a.py:1' in lines[0] 86 | assert 'found import of x' in lines[1] 87 | assert 'a.py:2' in lines[1] 88 | 89 | 90 | @pytest.mark.parametrize( 91 | 'project_structure, absolute, n_lines', 92 | [ 93 | ({'a.py': 'import x'}, True, 1), 94 | ({'a.py': 'from . import x'}, True, 0), 95 | ({'a.py': 'import x'}, False, 0), 96 | ({'a.py': 'from . import x'}, False, 1), 97 | ({'a.py': 'import x'}, None, 1), 98 | ({'a.py': 'from . import x'}, None, 1), 99 | ], 100 | ) 101 | def test_explain_contains_true_with_absolute( 102 | arch_root_node, absolute, n_lines 103 | ): 104 | a = arch_root_node.get(DotPath('a')) 105 | lines = ModulesAt(a).explain_why_contains_is_true( 106 | ImportOf(DotPath('x'), absolute=absolute) 107 | ) 108 | assert len(lines) == n_lines 109 | 110 | 111 | @pytest.mark.parametrize( 112 | 'project_structure', 113 | [ 114 | {'r': {'a.py': 'import x', 'b.py': 'import x'}}, 115 | ], 116 | ) 117 | def test_explain_contains_true_with_exclude(arch_root_node): 118 | r = arch_root_node.get(DotPath('r')) 119 | lines = ModulesAt(r, exclude=[DotPath('b')]).explain_why_contains_is_true( 120 | ImportOf(DotPath('x')) 121 | ) 122 | assert len(lines) == 1 123 | assert 'a.py' in lines[0] 124 | 125 | 126 | @pytest.mark.parametrize( 127 | 'project_structure', 128 | [ 129 | {'r': {'a.py': 'import x', 'b.py': 'import x'}}, 130 | ], 131 | ) 132 | def test_explain_contains_false_with_exclude(arch_root_node): 133 | r = arch_root_node.get(DotPath('r')) 134 | lines = ModulesAt(r, exclude=[DotPath('b')]).explain_why_contains_is_false( 135 | ImportOf(DotPath('y')) 136 | ) 137 | assert len(lines) == 1 138 | assert 'a.py' in lines[0] 139 | -------------------------------------------------------------------------------- /test/integration/plugin/test_projectpath.py: -------------------------------------------------------------------------------- 1 | from inspect import cleandoc 2 | 3 | 4 | def test_project_path_from_toml_config(pytester): 5 | """Test that config values are read from pyproject.toml""" 6 | pytester.makepyprojecttoml( 7 | """ 8 | [tool.pytest.ini_options] 9 | arch_project_paths = [ 10 | "foobar", 11 | "/foo/bar" 12 | ] 13 | """ 14 | ) 15 | pytester.makepyfile( 16 | """ 17 | from pathlib import Path 18 | 19 | def test_arch(arch_project_paths, pytestconfig): 20 | assert len(arch_project_paths) == 2 21 | assert arch_project_paths[0] == pytestconfig.rootpath / 'foobar' 22 | assert arch_project_paths[1] == Path('/foo/bar') 23 | """ 24 | ) 25 | result = pytester.runpytest() 26 | result.assert_outcomes(passed=1) 27 | 28 | 29 | def test_project_path_from_ini_config(pytester): 30 | """Test that config values are read from tox.ini""" 31 | pytester.makeini( 32 | """ 33 | [pytest] 34 | arch_project_paths = 35 | foobar 36 | /foo/bar 37 | """ 38 | ) 39 | pytester.makepyfile( 40 | """ 41 | from pathlib import Path 42 | 43 | def test_arch(arch_project_paths, pytestconfig): 44 | assert len(arch_project_paths) == 2 45 | assert arch_project_paths[0] == pytestconfig.rootpath / 'foobar' 46 | assert arch_project_paths[1] == Path('/foo/bar') 47 | 48 | """ 49 | ) 50 | result = pytester.runpytest() 51 | result.assert_outcomes(passed=1) 52 | 53 | 54 | def test_project_path_from_heuristic_with_src_dir(pytester): 55 | """Test that config values are read from tox.ini""" 56 | (pytester.path / 'root' / 'src' / 'foobar').mkdir(parents=True) 57 | (pytester.path / 'root' / 'test').mkdir(parents=True) 58 | (pytester.path / 'root' / 'pyproject.toml').write_text('#') 59 | (pytester.path / 'root' / 'test' / 'test_path.py').write_text( 60 | cleandoc( 61 | f""" 62 | def test_path(arch_project_paths): 63 | assert len(arch_project_paths) == 1 64 | assert (str(arch_project_paths[0]) == 65 | '{pytester.path / 'root' / 'src'}') 66 | """ 67 | ) 68 | ) 69 | result = pytester.runpytest('--rootdir', pytester.path / 'root' / 'test') 70 | result.assert_outcomes(passed=1) 71 | 72 | 73 | def test_project_path_from_heuristic_with_nested_dirs(pytester): 74 | """Test that config values are read from tox.ini""" 75 | (pytester.path / 'root' / 'foobar').mkdir(parents=True) 76 | (pytester.path / 'root' / 'test1' / 'test2').mkdir(parents=True) 77 | (pytester.path / 'root' / 'pyproject.toml').write_text('#') 78 | (pytester.path / 'root' / 'test1' / 'test2' / 'test_path.py').write_text( 79 | cleandoc( 80 | f""" 81 | def test_path(arch_project_paths): 82 | assert len(arch_project_paths) == 1 83 | assert str(arch_project_paths[0]) == '{pytester.path / 'root'}' 84 | """ 85 | ) 86 | ) 87 | result = pytester.runpytest( 88 | '--rootdir', pytester.path / 'root' / 'test1' / 'test2' 89 | ) 90 | result.assert_outcomes(passed=1) 91 | 92 | 93 | def test_project_path_from_heuristic_with_setup_py(pytester): 94 | """Test that config values are read from tox.ini""" 95 | (pytester.path / 'root' / 'foobar').mkdir(parents=True) 96 | (pytester.path / 'root' / 'test').mkdir(parents=True) 97 | (pytester.path / 'root' / 'setup.py').write_text('#') 98 | (pytester.path / 'root' / 'test' / 'test_path.py').write_text( 99 | cleandoc( 100 | f""" 101 | def test_path(arch_project_paths): 102 | assert len(arch_project_paths) == 1 103 | assert str(arch_project_paths[0]) == '{pytester.path / 'root'}' 104 | """ 105 | ) 106 | ) 107 | result = pytester.runpytest('--rootdir', pytester.path / 'root' / 'test') 108 | result.assert_outcomes(passed=1) 109 | 110 | 111 | def test_project_path_multiple_not_implemented(pytester): 112 | pytester.makepyprojecttoml( 113 | """ 114 | [tool.pytest.ini_options] 115 | arch_project_paths = [ 116 | "foobar", 117 | "/foo/bar" 118 | ] 119 | """ 120 | ) 121 | pytester.makepyfile('def test_arch(arch): pass') 122 | result = pytester.runpytest() 123 | result.assert_outcomes(errors=1) 124 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # pytest-arch 3 | 4 | *A pythonic derivative of [ArchUnit](https://www.archunit.org), in the form of a [pytest](https://www.pytest.org) plugin.* 5 | 6 | The idea is to write automated tests for the architecture aspects of your Python project. 7 | 8 | For now, this plugin covers import statements in your Python code. This enables you to write automated tests for the dependencies in your project. 9 | 10 | ### Simple example 11 | ```python 12 | def test_import(arch): 13 | assert arch.import_of('foo') in arch.modules_at('bar') 14 | ``` 15 | This will check that module `foo` is imported in module `bar`. 16 | 17 | Both `import_of` and `modules_at` are inclusive with regards to substructures 18 | (i.e., if there is an import of `foo.foo2` in a subpackage `bar.bar2` then the assertion is true). 19 | 20 | ### Installation & use 21 | 22 | Install `pytest-arch` via the Python package manager of your choice (e.g., pip or poetry). 23 | 24 | If your project structure is "normal" then you can simply start using the `arch` fixture in your tests right away, as seen above. 25 | 26 | ### Complex examples 27 | Imports in tests are always specified like absolute imports (i.e., fully qualified). 28 | 29 | ```python 30 | def test_import_subpackage(arch): 31 | assert arch.import_of('fizz.buzz') not in arch.modules_at('foo.bar') 32 | ``` 33 | Checks that module `buzz` in package `fizz` is not imported in module `bar` of package `foo`. Note that the dot `.` is used as path separator (other path separators like `/` are not supported). 34 | 35 | 36 | ```python 37 | def test_import_complex(arch): 38 | assert arch.import_of('foo', absolute=True) in arch.modules_at( 39 | 'bar', exclude=['lorem', 'ipsum'] 40 | ) 41 | ``` 42 | Via the boolean argument `absolute` you can specify that only absolute or relative imports of `foo` should be considered. 43 | Via the argument `exclude` you can exclude subpackages from the check (in this case `bar.lorem` and `bar.ipsum`). 44 | 45 | ## Details 46 | 47 | ### How it works 48 | 49 | In principle this plugin uses the `ast` module from the standard libray to analyze at the abstract syntax tree of your project. Import statement are collected and normalized. This is triggered by using the `arch` fixture in a test. Note that this can take a while. Behind the scenes this data is then used by `arch.modules_at` factory method in your tests. 50 | 51 | The analysis of the abstact syntax tree is superficial, so there are limitations. Due to the dynamic nature of Python it is easy to circumvent tests if you want to. So we assume that this plugin is used in a "friendly" context. 52 | 53 | Note that we don't track how the imported symbols are used. For example, in the case of 54 | ```python 55 | import a 56 | ... 57 | a.b() 58 | ``` 59 | you will *not* be able to check that `a.b` is used (e.g., via `arch.import_of('a.b')`). 60 | 61 | ### Absolute vs. relative imports 62 | 63 | Imports in tests are always specified like absolute imports (i.e., fully qualified), regardless if relative imports are used in the source. You can optionally use the `absolute` argument for `arch.import_of` to distinguish between absolute and relative imports. 64 | 65 | Note that relative imports from outside the configured project source directory are not supported (because we can't normalize those). 66 | 67 | ### Internal vs. external imports 68 | 69 | Both imports from inside your project and from external packages (standard library or installed packages) are supported. 70 | 71 | ### Configuration 72 | 73 | This plugin uses a simple heuristic to determine the source root of your project. You can check the source root via the `arch_project_paths` fixture in a test. 74 | 75 | Alternatively you can specify the source root in the pytest configuration. If you use a `pyproject.toml` then this looks like: 76 | ``` 77 | [tool.pytest.ini_options] 78 | arch_project_paths = [ 79 | "foo/bar", 80 | ] 81 | ``` 82 | Other config formats are supported as well, as long as they are supported by pytest. 83 | 84 | ### Future plans 85 | 86 | - Possibly add more architecture aspects, beyond imports. 87 | - Optimize the implementation with regards to speed. 88 | 89 | ## License 90 | Licensed under the Apache License, Version 2.0 - see LICENSE.md in project root directory. 91 | 92 | ## Related Python libraries 93 | - https://pypi.org/project/import-linter 94 | - https://pypi.org/project/pytestarch 95 | - https://github.com/jwbargsten/pytest-archon 96 | - https://pypi.org/project/findimports 97 | - https://pypi.org/project/pydeps (based on bytecode, not AST) 98 | - https://docs.python.org/3/library/modulefinder.html (part of standard library, looks at runtime) 99 | -------------------------------------------------------------------------------- /src/pyarch/plugin.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from pathlib import Path 3 | from typing import Any, Iterable, Optional, Sequence 4 | 5 | import pytest 6 | 7 | from .model import DotPath, RootNode 8 | from .parser import build_import_model 9 | from .query import ImportOf, ModulesAt 10 | 11 | log = logging.getLogger(__name__) 12 | 13 | INI_NAME = 'arch_project_paths' 14 | PROJECT_CONFIG_FILES = ['pyproject.toml', 'setup.cfg', 'setup.py'] 15 | 16 | 17 | def pytest_addoption(parser: pytest.Parser) -> None: 18 | parser.addini( 19 | INI_NAME, 20 | type='paths', 21 | help='Paths for pytest-arch source code analysis ' 22 | '(relative to rootpath or absolute).', 23 | ) 24 | 25 | 26 | def pytest_assertrepr_compare( 27 | op: str, left: Any, right: Any 28 | ) -> Sequence[str] | None: 29 | match op, left, right: 30 | case 'not in', ImportOf() as import_of, ModulesAt() as package: 31 | first_line = f'{left} {op} {right}' 32 | return [first_line] + package.explain_why_contains_is_true( 33 | import_of 34 | ) 35 | case 'in', ImportOf() as import_of, ModulesAt() as package: 36 | first_line = f'{left} {op} {right}' 37 | return [first_line] + package.explain_why_contains_is_false( 38 | import_of 39 | ) 40 | return None 41 | 42 | 43 | @pytest.fixture(scope='session') 44 | def arch_project_paths(pytestconfig: pytest.Config) -> Sequence[Path]: 45 | """ 46 | Provides the project source code paths that are analyzed. 47 | 48 | This fixture normally isn't used explicitly in tests, unless you want 49 | to check that the project paths are set correctly. 50 | 51 | Logic for finding the project path: 52 | 1. If there is an `arch_project_paths` config entry in the pytest config 53 | then use that and be done. 54 | 2. If there is no config then start with the pytest root path. 55 | 3. Go up until a `pyproject.toml`, `setup.cfg`, or `setup.py` is found. 56 | 4. If there is a `src` directory directly below then use that, 57 | otherwise use the path from step 3. 58 | """ 59 | # Note: pytest already converts relative to absolute paths. 60 | if project_paths := pytestconfig.getini(INI_NAME): 61 | return project_paths # type: ignore[no-any-return] 62 | # Note: pytest considers config files in its rootpath heuristic 63 | # only if those files actually contain pytest config. 64 | for path in (pytestconfig.rootpath, *pytestconfig.rootpath.parents): 65 | for config_file in PROJECT_CONFIG_FILES: 66 | if (path / config_file).exists(): 67 | if (src_path := path / 'src').exists(): 68 | return [src_path] 69 | return [path] 70 | return [pytestconfig.rootpath] 71 | 72 | 73 | @pytest.fixture(scope='session') 74 | def arch_root_node(arch_project_paths: Sequence[Path]) -> RootNode: 75 | """ 76 | Provides the root node of the tree of analyzed Python modules. 77 | 78 | Normally this isn't used explicitly in tests. 79 | """ 80 | if len(arch_project_paths) != 1: 81 | raise NotImplementedError() 82 | log.info(f'creating architecture model for {arch_project_paths[0]}') 83 | return build_import_model(arch_project_paths[0]) 84 | 85 | 86 | class ArchFixture: 87 | """Factory for architecture objects to be used in test assertions.""" 88 | 89 | def __init__(self, arch_root_node: RootNode): 90 | self._root_node = arch_root_node 91 | 92 | def modules_at( 93 | self, path: str, *, exclude: Optional[Iterable[str]] = None 94 | ) -> ModulesAt: 95 | """ 96 | Return object representing the module tree for the given path. 97 | 98 | It supports the operators `in` and `not in` to check if it does 99 | or does not contain certain imports. 100 | """ 101 | 102 | node = self._root_node.get(DotPath(path)) 103 | if not node: 104 | raise KeyError(f'Found no node for path {path} in project.') 105 | if isinstance(exclude, str): 106 | raise TypeError( 107 | f'Value "{exclude}" for exclude argument is of type str, ' 108 | f'but should be an iterable (like ["{exclude}"]).' 109 | ) 110 | return ModulesAt(node, exclude=[DotPath(e) for e in exclude or []]) 111 | 112 | @staticmethod 113 | def import_of(dot_path: str, *, absolute: bool | None = None) -> ImportOf: 114 | """ 115 | Returns object representing an import of something from a module. 116 | 117 | This includes imports of child elements. So 'a.b' would also match 118 | imports of 'a.b.c'. 119 | 120 | On the other hand, it does not cover imports of parent. So 'a.b' would 121 | not match imports of 'a'. 122 | 123 | Note that the use of 'a.b' in the following example can't be expressed: 124 | import a 125 | ... 126 | a.b() 127 | """ 128 | return ImportOf(DotPath(dot_path), absolute=absolute) 129 | 130 | 131 | @pytest.fixture 132 | def arch(arch_root_node: RootNode) -> ArchFixture: 133 | """ 134 | Provides a factory that is used to create the architecture representation 135 | objects for test assertions. 136 | """ 137 | return ArchFixture(arch_root_node) 138 | -------------------------------------------------------------------------------- /test/integration/test_parser.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from inspect import cleandoc 3 | from pathlib import Path 4 | 5 | import pytest 6 | 7 | from pyarch.model import DotPath, ImportInModule 8 | from pyarch.parser import build_import_model 9 | 10 | 11 | def _create_project_on_disk(struct: dict[str, str | dict], current_path: Path): 12 | for key, value in struct.items(): 13 | path = current_path / key 14 | match value: 15 | case dict(): 16 | path.mkdir() 17 | _create_project_on_disk(value, path) 18 | case str(): 19 | path.write_text(cleandoc(value)) 20 | 21 | 22 | @pytest.fixture 23 | def project_path( 24 | project_structure: dict[str, str | dict], tmp_path: Path 25 | ) -> Path: 26 | _create_project_on_disk(project_structure, tmp_path) 27 | return tmp_path 28 | 29 | 30 | @pytest.mark.parametrize( 31 | 'project_structure, path, import_obj', 32 | [ 33 | ( 34 | { 35 | 'a': {'b.py': 'from .. import y'}, 36 | }, 37 | 'a.b', 38 | ImportInModule(import_path=DotPath('y'), line_no=1, level=2), 39 | ), 40 | ( 41 | {'a': {'b': {'c.py': '...\nfrom .. import y'}}}, 42 | 'a.b.c', 43 | ImportInModule(import_path=DotPath('a.y'), line_no=2, level=2), 44 | ), 45 | ( 46 | {'a': {'b.py': '...\n\nfrom .x import y'}}, 47 | 'a.b', 48 | ImportInModule(import_path=DotPath('a.x.y'), line_no=3, level=1), 49 | ), 50 | ], 51 | ) 52 | def test_relative_import(project_path: Path, path: DotPath, import_obj): 53 | base_node = build_import_model(project_path) 54 | assert base_node.get(DotPath(path)).imports == [import_obj] 55 | 56 | 57 | @pytest.mark.parametrize( 58 | 'project_structure', 59 | [ 60 | { 61 | 'a': {'b.py': 'from ... import y'}, 62 | } 63 | ], 64 | ) 65 | def test_relative_import_beyond_base(project_path, caplog): 66 | base_node = build_import_model(project_path) 67 | warnings = [ 68 | record 69 | for record in caplog.records 70 | if record.levelno == logging.WARNING 71 | ] 72 | assert len(warnings) == 1 73 | assert 'relative import' in warnings[0].msg 74 | assert base_node.get(DotPath('a.b')).imports == [] 75 | 76 | 77 | @pytest.mark.parametrize( 78 | 'project_structure', 79 | [ 80 | { 81 | 'a': {'__init__.py': 'import x'}, 82 | } 83 | ], 84 | ) 85 | def test_import_from_init(project_path): 86 | base_node = build_import_model(project_path) 87 | assert base_node.get(DotPath('a')).imports == [ 88 | ImportInModule(DotPath(('x')), 1) 89 | ] 90 | 91 | 92 | @pytest.mark.parametrize( 93 | 'project_structure, path, import_obj', 94 | [ 95 | ( 96 | { 97 | 'a': {'b.py': 'import x'}, 98 | }, 99 | 'a.b', 100 | ImportInModule(import_path=DotPath('x'), line_no=1), 101 | ), 102 | ( 103 | {'a': {'b': {'c.py': '...\nimport x as y'}}}, 104 | 'a.b.c', 105 | ImportInModule(import_path=DotPath('x'), line_no=2), 106 | ), 107 | ], 108 | ) 109 | def test_absolute_import(project_path: Path, path: DotPath, import_obj): 110 | base_node = build_import_model(project_path) 111 | assert base_node.get(DotPath(path)).imports == [import_obj] 112 | 113 | 114 | @pytest.mark.parametrize( 115 | 'project_structure', 116 | [ 117 | { 118 | 'a.py': """ 119 | try: 120 | import foo 121 | except: 122 | import bar 123 | """, 124 | } 125 | ], 126 | ) 127 | def test_import_in_nested_block(project_path): 128 | base_node = build_import_model(project_path) 129 | assert base_node.get(DotPath('a')).imports == [ 130 | ImportInModule(import_path=DotPath('foo'), line_no=2), 131 | ImportInModule(import_path=DotPath('bar'), line_no=4), 132 | ] 133 | 134 | 135 | @pytest.mark.parametrize( 136 | 'project_structure', 137 | [ 138 | { 139 | 'a': { 140 | 'b.py': """ 141 | from .x import y 142 | from .x.y import z as xyz 143 | """, 144 | }, 145 | 'x': { 146 | '__init__.py': """ 147 | import a 148 | """, 149 | 'y.py': """ 150 | import a 151 | import a.b as ab 152 | from a.b import c 153 | """, 154 | }, 155 | } 156 | ], 157 | ) 158 | def test_project_structure_nodes(project_path: Path): 159 | node = build_import_model(project_path) 160 | assert len(node.get(DotPath('a')).imports) == 0 161 | assert node.get(DotPath('a'))._file_path == project_path / 'a' 162 | assert len(node.get(DotPath('a.b')).imports) == 2 163 | assert node.get(DotPath('a.b'))._file_path == project_path / 'a' / 'b.py' 164 | assert len(node.get(DotPath('x')).imports) == 1 165 | assert ( 166 | node.get(DotPath('x'))._file_path == project_path / 'x' / '__init__.py' 167 | ) 168 | assert len(node.get(DotPath('x.y')).imports) == 3 169 | assert node.get(DotPath('x.y'))._file_path == project_path / 'x' / 'y.py' 170 | 171 | 172 | @pytest.mark.parametrize( 173 | 'project_structure', 174 | [ 175 | { 176 | 'a': {'b.py': 'import x', '.d': {'c.py': 'import x'}}, 177 | '.m.py': 'import y', 178 | } 179 | ], 180 | ) 181 | def test_hidden_dirs_and_files_are_excluded(project_path: Path): 182 | node = build_import_model(project_path) 183 | assert node.get(DotPath('a.b')) 184 | assert len(node.get(DotPath('a'))._children) == 1 185 | assert len(node._children) == 1 186 | 187 | 188 | @pytest.mark.parametrize( 189 | 'project_structure', 190 | [ 191 | { 192 | 'a.py': '', 193 | } 194 | ], 195 | ) 196 | def test_empty_file(project_path): 197 | base_node = build_import_model(project_path) 198 | assert base_node.get(DotPath('a')).imports == [] 199 | -------------------------------------------------------------------------------- /src/pyarch/model.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | from pathlib import Path, PurePath 3 | from typing import Any, Iterable, Iterator, Optional, Sequence, Union 4 | 5 | 6 | class DotPath: 7 | """ 8 | Represent a 'path' with dot as the separator, 9 | as it is used for imports in Python. 10 | 11 | Largely follows the Path interface from pathlib. 12 | """ 13 | 14 | def __init__(self, path: str | Iterable[str] | 'DotPath' | None = None): 15 | self._parts: tuple[str, ...] 16 | self._hash: Optional[int] = None 17 | if not path: 18 | self._parts = tuple() 19 | elif isinstance(path, str): 20 | self._parts = tuple(path.split('.')) 21 | elif isinstance(path, DotPath): 22 | self._parts = path.parts 23 | else: 24 | self._parts = tuple(path) 25 | 26 | @classmethod 27 | def from_path(cls, path: PurePath) -> 'DotPath': 28 | parts = list(path.parts) 29 | if len(parts) == 0: 30 | return DotPath() 31 | if parts[-1] == '__init__.py': 32 | parts.pop() 33 | else: 34 | parts[-1] = parts[-1].removesuffix('.py') 35 | return cls(parts) 36 | 37 | def is_relative_to(self, other: 'DotPath') -> bool: 38 | if len(other.parts) > len(self.parts): 39 | return False 40 | if other.parts == self.parts[: len(other.parts)]: 41 | return True 42 | return False 43 | 44 | @property 45 | def parts(self) -> tuple[str, ...]: 46 | return self._parts 47 | 48 | @property 49 | def name(self) -> str: 50 | return self._parts[-1] 51 | 52 | @property 53 | def parent(self) -> 'DotPath': 54 | return DotPath(self._parts[:-1]) 55 | 56 | def __str__(self) -> str: 57 | return '.'.join(self._parts) 58 | 59 | def __repr__(self) -> str: 60 | return f'{type(self).__name__}({self.parts})' 61 | 62 | def __hash__(self) -> int: 63 | if self._hash is None: 64 | self._hash = hash(tuple(self._parts)) 65 | return self._hash 66 | 67 | def __eq__(self, other: Any) -> bool: 68 | if not isinstance(other, DotPath): 69 | return NotImplemented 70 | return self._parts == other._parts 71 | 72 | def __truediv__(self, other: Union['DotPath', str]) -> 'DotPath': 73 | return DotPath(self.parts + DotPath(other).parts) 74 | 75 | def __rtruediv__(self, other: Union['DotPath', str]) -> 'DotPath': 76 | return DotPath(DotPath(other).parts + self.parts) 77 | 78 | 79 | @dataclass 80 | class ImportInModule: 81 | """Represents a single import in a module.""" 82 | 83 | import_path: DotPath 84 | line_no: int 85 | level: int = 0 86 | 87 | 88 | class RootNode: 89 | """Represents the root of a tree of module nodes.""" 90 | 91 | def __init__(self) -> None: 92 | self._children: dict[str, 'ModuleNode'] = {} 93 | 94 | def get(self, dot_path: DotPath) -> Optional['ModuleNode']: 95 | if not dot_path.parts: 96 | raise KeyError('Empty path is not supported on root node.') 97 | if child := self._children.get(dot_path.parts[0]): 98 | remaining_path = ( 99 | DotPath(dot_path.parts[1:]) 100 | if len(dot_path.parts) > 1 101 | else DotPath() 102 | ) 103 | return child.get(remaining_path) 104 | return None 105 | 106 | def get_or_add(self, dot_path: DotPath, file_path: Path) -> 'ModuleNode': 107 | if not dot_path.parts: 108 | raise KeyError('Empty path is not supported on root node.') 109 | name = dot_path.parts[0] 110 | remaining_path = ( 111 | DotPath(dot_path.parts[1:]) 112 | if len(dot_path.parts) > 1 113 | else DotPath() 114 | ) 115 | if not (child := self._children.get(name)): 116 | if remaining_path.parts: 117 | child_file_path = Path( 118 | *file_path.parts[: -len(remaining_path.parts)] 119 | ) 120 | else: 121 | child_file_path = file_path 122 | child = ModuleNode(name=name, file_path=child_file_path) 123 | self._children[name] = child 124 | return child.get_or_add(remaining_path, file_path) 125 | 126 | 127 | class ModuleNode(RootNode): 128 | """Represents a node in a Python module tree. 129 | 130 | Its main use is representing a Python module, but it can also 131 | represent a simple directory. 132 | 133 | If the module is a package then the content of this node actually 134 | represents the __init__.py file (in this case there is no separate 135 | node for the __init__.py file). 136 | """ 137 | 138 | def __init__(self, name: str, file_path: Path): 139 | super().__init__() 140 | self._name: str = name 141 | self._file_path: Path = file_path 142 | self._imports: list[ImportInModule] = [] 143 | 144 | @property 145 | def name(self) -> str: 146 | """The name of the module or directory. 147 | 148 | The `.py` file extension is not included in the name. 149 | """ 150 | return self._name 151 | 152 | @property 153 | def imports(self) -> Sequence[ImportInModule]: 154 | return self._imports 155 | 156 | @property 157 | def file_path(self) -> Path: 158 | """Absolute path of the module or directory. 159 | 160 | If this node represents a package with an `__init__.py` file, 161 | then the `file_path` points to that file. 162 | """ 163 | return self._file_path 164 | 165 | def add_imports(self, imports: Iterable[ImportInModule]) -> None: 166 | self._imports += imports 167 | 168 | def add_data_for_init_file( 169 | self, imports: Iterable[ImportInModule] 170 | ) -> None: 171 | """Turn a directory node into a package node, 172 | with data from the `__init__.py` file. 173 | 174 | There is no separate node for the `__init__.py` file. 175 | """ 176 | if self._file_path.name != '__init__.py': 177 | assert not self._file_path.suffix 178 | self._file_path /= '__init__.py' 179 | self.add_imports(imports) 180 | 181 | def get(self, dot_path: DotPath) -> Optional['ModuleNode']: 182 | """Return the node from this tree corresponding to the dot path.""" 183 | if not dot_path.parts: 184 | return self 185 | return super().get(dot_path) 186 | 187 | def get_or_add(self, dot_path: DotPath, file_path: Path) -> 'ModuleNode': 188 | """Return the node for this dot_path. 189 | 190 | If this node and any of its parents are missing then they are 191 | first added to the tree. 192 | """ 193 | if not dot_path.parts: 194 | return self 195 | return super().get_or_add(dot_path, file_path) 196 | 197 | def walk( 198 | self, exclude: Optional[Iterable[DotPath]] = None 199 | ) -> Iterator['ModuleNode']: 200 | """Return all nodes including and below this node. 201 | 202 | If the exclude argument is used then the given paths are 203 | expected to be relative to this node. 204 | """ 205 | yield self 206 | for child in self._children.values(): 207 | relative_exclude = None 208 | if exclude: 209 | relative_exclude = { 210 | DotPath(p.parts[1:]) 211 | for p in exclude 212 | if p.parts and p.parts[0] == child.name 213 | } 214 | if DotPath() in relative_exclude: 215 | continue 216 | yield from child.walk(exclude=relative_exclude) 217 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /poetry.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Poetry 1.4.0 and should not be changed by hand. 2 | 3 | [[package]] 4 | name = "argcomplete" 5 | version = "2.1.1" 6 | description = "Bash tab completion for argparse" 7 | category = "dev" 8 | optional = false 9 | python-versions = ">=3.6" 10 | files = [ 11 | {file = "argcomplete-2.1.1-py3-none-any.whl", hash = "sha256:17041f55b8c45099428df6ce6d0d282b892471a78c71375d24f227e21c13f8c5"}, 12 | {file = "argcomplete-2.1.1.tar.gz", hash = "sha256:72e08340852d32544459c0c19aad1b48aa2c3a96de8c6e5742456b4f538ca52f"}, 13 | ] 14 | 15 | [package.extras] 16 | lint = ["flake8", "mypy"] 17 | test = ["coverage", "flake8", "mypy", "pexpect", "wheel"] 18 | 19 | [[package]] 20 | name = "attrs" 21 | version = "22.2.0" 22 | description = "Classes Without Boilerplate" 23 | category = "main" 24 | optional = false 25 | python-versions = ">=3.6" 26 | files = [ 27 | {file = "attrs-22.2.0-py3-none-any.whl", hash = "sha256:29e95c7f6778868dbd49170f98f8818f78f3dc5e0e37c0b1f474e3561b240836"}, 28 | {file = "attrs-22.2.0.tar.gz", hash = "sha256:c9227bfc2f01993c03f68db37d1d15c9690188323c067c641f1a35ca58185f99"}, 29 | ] 30 | 31 | [package.extras] 32 | cov = ["attrs[tests]", "coverage-enable-subprocess", "coverage[toml] (>=5.3)"] 33 | dev = ["attrs[docs,tests]"] 34 | docs = ["furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib-towncrier", "towncrier", "zope.interface"] 35 | tests = ["attrs[tests-no-zope]", "zope.interface"] 36 | tests-no-zope = ["cloudpickle", "cloudpickle", "hypothesis", "hypothesis", "mypy (>=0.971,<0.990)", "mypy (>=0.971,<0.990)", "pympler", "pympler", "pytest (>=4.3.0)", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-mypy-plugins", "pytest-xdist[psutil]", "pytest-xdist[psutil]"] 37 | 38 | [[package]] 39 | name = "black" 40 | version = "22.1.0" 41 | description = "The uncompromising code formatter." 42 | category = "dev" 43 | optional = false 44 | python-versions = ">=3.6.2" 45 | files = [ 46 | {file = "black-22.1.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:1297c63b9e1b96a3d0da2d85d11cd9bf8664251fd69ddac068b98dc4f34f73b6"}, 47 | {file = "black-22.1.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:2ff96450d3ad9ea499fc4c60e425a1439c2120cbbc1ab959ff20f7c76ec7e866"}, 48 | {file = "black-22.1.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:0e21e1f1efa65a50e3960edd068b6ae6d64ad6235bd8bfea116a03b21836af71"}, 49 | {file = "black-22.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e2f69158a7d120fd641d1fa9a921d898e20d52e44a74a6fbbcc570a62a6bc8ab"}, 50 | {file = "black-22.1.0-cp310-cp310-win_amd64.whl", hash = "sha256:228b5ae2c8e3d6227e4bde5920d2fc66cc3400fde7bcc74f480cb07ef0b570d5"}, 51 | {file = "black-22.1.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:b1a5ed73ab4c482208d20434f700d514f66ffe2840f63a6252ecc43a9bc77e8a"}, 52 | {file = "black-22.1.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:35944b7100af4a985abfcaa860b06af15590deb1f392f06c8683b4381e8eeaf0"}, 53 | {file = "black-22.1.0-cp36-cp36m-win_amd64.whl", hash = "sha256:7835fee5238fc0a0baf6c9268fb816b5f5cd9b8793423a75e8cd663c48d073ba"}, 54 | {file = "black-22.1.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:dae63f2dbf82882fa3b2a3c49c32bffe144970a573cd68d247af6560fc493ae1"}, 55 | {file = "black-22.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5fa1db02410b1924b6749c245ab38d30621564e658297484952f3d8a39fce7e8"}, 56 | {file = "black-22.1.0-cp37-cp37m-win_amd64.whl", hash = "sha256:c8226f50b8c34a14608b848dc23a46e5d08397d009446353dad45e04af0c8e28"}, 57 | {file = "black-22.1.0-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:2d6f331c02f0f40aa51a22e479c8209d37fcd520c77721c034517d44eecf5912"}, 58 | {file = "black-22.1.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:742ce9af3086e5bd07e58c8feb09dbb2b047b7f566eb5f5bc63fd455814979f3"}, 59 | {file = "black-22.1.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:fdb8754b453fb15fad3f72cd9cad3e16776f0964d67cf30ebcbf10327a3777a3"}, 60 | {file = "black-22.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f5660feab44c2e3cb24b2419b998846cbb01c23c7fe645fee45087efa3da2d61"}, 61 | {file = "black-22.1.0-cp38-cp38-win_amd64.whl", hash = "sha256:6f2f01381f91c1efb1451998bd65a129b3ed6f64f79663a55fe0e9b74a5f81fd"}, 62 | {file = "black-22.1.0-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:efbadd9b52c060a8fc3b9658744091cb33c31f830b3f074422ed27bad2b18e8f"}, 63 | {file = "black-22.1.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:8871fcb4b447206904932b54b567923e5be802b9b19b744fdff092bd2f3118d0"}, 64 | {file = "black-22.1.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:ccad888050f5393f0d6029deea2a33e5ae371fd182a697313bdbd835d3edaf9c"}, 65 | {file = "black-22.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:07e5c049442d7ca1a2fc273c79d1aecbbf1bc858f62e8184abe1ad175c4f7cc2"}, 66 | {file = "black-22.1.0-cp39-cp39-win_amd64.whl", hash = "sha256:373922fc66676133ddc3e754e4509196a8c392fec3f5ca4486673e685a421321"}, 67 | {file = "black-22.1.0-py3-none-any.whl", hash = "sha256:3524739d76b6b3ed1132422bf9d82123cd1705086723bc3e235ca39fd21c667d"}, 68 | {file = "black-22.1.0.tar.gz", hash = "sha256:a7c0192d35635f6fc1174be575cb7915e92e5dd629ee79fdaf0dcfa41a80afb5"}, 69 | ] 70 | 71 | [package.dependencies] 72 | click = ">=8.0.0" 73 | mypy-extensions = ">=0.4.3" 74 | pathspec = ">=0.9.0" 75 | platformdirs = ">=2" 76 | tomli = ">=1.1.0" 77 | 78 | [package.extras] 79 | colorama = ["colorama (>=0.4.3)"] 80 | d = ["aiohttp (>=3.7.4)"] 81 | jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] 82 | uvloop = ["uvloop (>=0.15.2)"] 83 | 84 | [[package]] 85 | name = "blue" 86 | version = "0.9.1" 87 | description = "Blue -- Some folks like black but I prefer blue." 88 | category = "dev" 89 | optional = false 90 | python-versions = "*" 91 | files = [ 92 | {file = "blue-0.9.1-py3-none-any.whl", hash = "sha256:037742c072c58a2ff024f59fb9164257b907f97f8f862008db3b013d1f27cc22"}, 93 | {file = "blue-0.9.1.tar.gz", hash = "sha256:76b4f26884a8425042356601d80773db6e0e14bebaa7a59d7c54bf8cef2e2af5"}, 94 | ] 95 | 96 | [package.dependencies] 97 | black = "22.1.0" 98 | flake8 = ">=3.8,<5.0.0" 99 | 100 | [[package]] 101 | name = "click" 102 | version = "8.1.3" 103 | description = "Composable command line interface toolkit" 104 | category = "dev" 105 | optional = false 106 | python-versions = ">=3.7" 107 | files = [ 108 | {file = "click-8.1.3-py3-none-any.whl", hash = "sha256:bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48"}, 109 | {file = "click-8.1.3.tar.gz", hash = "sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e"}, 110 | ] 111 | 112 | [package.dependencies] 113 | colorama = {version = "*", markers = "platform_system == \"Windows\""} 114 | 115 | [[package]] 116 | name = "colorama" 117 | version = "0.4.6" 118 | description = "Cross-platform colored terminal text." 119 | category = "main" 120 | optional = false 121 | python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" 122 | files = [ 123 | {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, 124 | {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, 125 | ] 126 | 127 | [[package]] 128 | name = "colorlog" 129 | version = "6.7.0" 130 | description = "Add colours to the output of Python's logging module." 131 | category = "dev" 132 | optional = false 133 | python-versions = ">=3.6" 134 | files = [ 135 | {file = "colorlog-6.7.0-py2.py3-none-any.whl", hash = "sha256:0d33ca236784a1ba3ff9c532d4964126d8a2c44f1f0cb1d2b0728196f512f662"}, 136 | {file = "colorlog-6.7.0.tar.gz", hash = "sha256:bd94bd21c1e13fac7bd3153f4bc3a7dc0eb0974b8bc2fdf1a989e474f6e582e5"}, 137 | ] 138 | 139 | [package.dependencies] 140 | colorama = {version = "*", markers = "sys_platform == \"win32\""} 141 | 142 | [package.extras] 143 | development = ["black", "flake8", "mypy", "pytest", "types-colorama"] 144 | 145 | [[package]] 146 | name = "coverage" 147 | version = "7.2.1" 148 | description = "Code coverage measurement for Python" 149 | category = "dev" 150 | optional = false 151 | python-versions = ">=3.7" 152 | files = [ 153 | {file = "coverage-7.2.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:49567ec91fc5e0b15356da07a2feabb421d62f52a9fff4b1ec40e9e19772f5f8"}, 154 | {file = "coverage-7.2.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d2ef6cae70168815ed91388948b5f4fcc69681480a0061114db737f957719f03"}, 155 | {file = "coverage-7.2.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3004765bca3acd9e015794e5c2f0c9a05587f5e698127ff95e9cfba0d3f29339"}, 156 | {file = "coverage-7.2.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:cca7c0b7f5881dfe0291ef09ba7bb1582cb92ab0aeffd8afb00c700bf692415a"}, 157 | {file = "coverage-7.2.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b2167d116309f564af56f9aa5e75ef710ef871c5f9b313a83050035097b56820"}, 158 | {file = "coverage-7.2.1-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:cb5f152fb14857cbe7f3e8c9a5d98979c4c66319a33cad6e617f0067c9accdc4"}, 159 | {file = "coverage-7.2.1-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:87dc37f16fb5e3a28429e094145bf7c1753e32bb50f662722e378c5851f7fdc6"}, 160 | {file = "coverage-7.2.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:e191a63a05851f8bce77bc875e75457f9b01d42843f8bd7feed2fc26bbe60833"}, 161 | {file = "coverage-7.2.1-cp310-cp310-win32.whl", hash = "sha256:e3ea04b23b114572b98a88c85379e9e9ae031272ba1fb9b532aa934c621626d4"}, 162 | {file = "coverage-7.2.1-cp310-cp310-win_amd64.whl", hash = "sha256:0cf557827be7eca1c38a2480484d706693e7bb1929e129785fe59ec155a59de6"}, 163 | {file = "coverage-7.2.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:570c21a29493b350f591a4b04c158ce1601e8d18bdcd21db136fbb135d75efa6"}, 164 | {file = "coverage-7.2.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:9e872b082b32065ac2834149dc0adc2a2e6d8203080501e1e3c3c77851b466f9"}, 165 | {file = "coverage-7.2.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fac6343bae03b176e9b58104a9810df3cdccd5cfed19f99adfa807ffbf43cf9b"}, 166 | {file = "coverage-7.2.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:abacd0a738e71b20e224861bc87e819ef46fedba2fb01bc1af83dfd122e9c319"}, 167 | {file = "coverage-7.2.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d9256d4c60c4bbfec92721b51579c50f9e5062c21c12bec56b55292464873508"}, 168 | {file = "coverage-7.2.1-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:80559eaf6c15ce3da10edb7977a1548b393db36cbc6cf417633eca05d84dd1ed"}, 169 | {file = "coverage-7.2.1-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:0bd7e628f6c3ec4e7d2d24ec0e50aae4e5ae95ea644e849d92ae4805650b4c4e"}, 170 | {file = "coverage-7.2.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:09643fb0df8e29f7417adc3f40aaf379d071ee8f0350ab290517c7004f05360b"}, 171 | {file = "coverage-7.2.1-cp311-cp311-win32.whl", hash = "sha256:1b7fb13850ecb29b62a447ac3516c777b0e7a09ecb0f4bb6718a8654c87dfc80"}, 172 | {file = "coverage-7.2.1-cp311-cp311-win_amd64.whl", hash = "sha256:617a94ada56bbfe547aa8d1b1a2b8299e2ec1ba14aac1d4b26a9f7d6158e1273"}, 173 | {file = "coverage-7.2.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8649371570551d2fd7dee22cfbf0b61f1747cdfb2b7587bb551e4beaaa44cb97"}, 174 | {file = "coverage-7.2.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5d2b9b5e70a21474c105a133ba227c61bc95f2ac3b66861143ce39a5ea4b3f84"}, 175 | {file = "coverage-7.2.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ae82c988954722fa07ec5045c57b6d55bc1a0890defb57cf4a712ced65b26ddd"}, 176 | {file = "coverage-7.2.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:861cc85dfbf55a7a768443d90a07e0ac5207704a9f97a8eb753292a7fcbdfcfc"}, 177 | {file = "coverage-7.2.1-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:0339dc3237c0d31c3b574f19c57985fcbe494280153bbcad33f2cdf469f4ac3e"}, 178 | {file = "coverage-7.2.1-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:5928b85416a388dd557ddc006425b0c37e8468bd1c3dc118c1a3de42f59e2a54"}, 179 | {file = "coverage-7.2.1-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:8d3843ca645f62c426c3d272902b9de90558e9886f15ddf5efe757b12dd376f5"}, 180 | {file = "coverage-7.2.1-cp37-cp37m-win32.whl", hash = "sha256:6a034480e9ebd4e83d1aa0453fd78986414b5d237aea89a8fdc35d330aa13bae"}, 181 | {file = "coverage-7.2.1-cp37-cp37m-win_amd64.whl", hash = "sha256:6fce673f79a0e017a4dc35e18dc7bb90bf6d307c67a11ad5e61ca8d42b87cbff"}, 182 | {file = "coverage-7.2.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:7f099da6958ddfa2ed84bddea7515cb248583292e16bb9231d151cd528eab657"}, 183 | {file = "coverage-7.2.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:97a3189e019d27e914ecf5c5247ea9f13261d22c3bb0cfcfd2a9b179bb36f8b1"}, 184 | {file = "coverage-7.2.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a81dbcf6c6c877986083d00b834ac1e84b375220207a059ad45d12f6e518a4e3"}, 185 | {file = "coverage-7.2.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:78d2c3dde4c0b9be4b02067185136b7ee4681978228ad5ec1278fa74f5ca3e99"}, 186 | {file = "coverage-7.2.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3a209d512d157379cc9ab697cbdbb4cfd18daa3e7eebaa84c3d20b6af0037384"}, 187 | {file = "coverage-7.2.1-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:f3d07edb912a978915576a776756069dede66d012baa503022d3a0adba1b6afa"}, 188 | {file = "coverage-7.2.1-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:8dca3c1706670297851bca1acff9618455122246bdae623be31eca744ade05ec"}, 189 | {file = "coverage-7.2.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:b1991a6d64231a3e5bbe3099fb0dd7c9aeaa4275ad0e0aeff4cb9ef885c62ba2"}, 190 | {file = "coverage-7.2.1-cp38-cp38-win32.whl", hash = "sha256:22c308bc508372576ffa3d2dbc4824bb70d28eeb4fcd79d4d1aed663a06630d0"}, 191 | {file = "coverage-7.2.1-cp38-cp38-win_amd64.whl", hash = "sha256:b0c0d46de5dd97f6c2d1b560bf0fcf0215658097b604f1840365296302a9d1fb"}, 192 | {file = "coverage-7.2.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:4dd34a935de268a133e4741827ae951283a28c0125ddcdbcbba41c4b98f2dfef"}, 193 | {file = "coverage-7.2.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:0f8318ed0f3c376cfad8d3520f496946977abde080439d6689d7799791457454"}, 194 | {file = "coverage-7.2.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:834c2172edff5a08d78e2f53cf5e7164aacabeb66b369f76e7bb367ca4e2d993"}, 195 | {file = "coverage-7.2.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e4d70c853f0546855f027890b77854508bdb4d6a81242a9d804482e667fff6e6"}, 196 | {file = "coverage-7.2.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8a6450da4c7afc4534305b2b7d8650131e130610cea448ff240b6ab73d7eab63"}, 197 | {file = "coverage-7.2.1-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:99f4dd81b2bb8fc67c3da68b1f5ee1650aca06faa585cbc6818dbf67893c6d58"}, 198 | {file = "coverage-7.2.1-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:bdd3f2f285ddcf2e75174248b2406189261a79e7fedee2ceeadc76219b6faa0e"}, 199 | {file = "coverage-7.2.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:f29351393eb05e6326f044a7b45ed8e38cb4dcc38570d12791f271399dc41431"}, 200 | {file = "coverage-7.2.1-cp39-cp39-win32.whl", hash = "sha256:e2b50ebc2b6121edf352336d503357321b9d8738bb7a72d06fc56153fd3f4cd8"}, 201 | {file = "coverage-7.2.1-cp39-cp39-win_amd64.whl", hash = "sha256:bd5a12239c0006252244f94863f1c518ac256160cd316ea5c47fb1a11b25889a"}, 202 | {file = "coverage-7.2.1-pp37.pp38.pp39-none-any.whl", hash = "sha256:436313d129db7cf5b4ac355dd2bd3f7c7e5294af077b090b85de75f8458b8616"}, 203 | {file = "coverage-7.2.1.tar.gz", hash = "sha256:c77f2a9093ccf329dd523a9b2b3c854c20d2a3d968b6def3b820272ca6732242"}, 204 | ] 205 | 206 | [package.extras] 207 | toml = ["tomli"] 208 | 209 | [[package]] 210 | name = "distlib" 211 | version = "0.3.6" 212 | description = "Distribution utilities" 213 | category = "dev" 214 | optional = false 215 | python-versions = "*" 216 | files = [ 217 | {file = "distlib-0.3.6-py2.py3-none-any.whl", hash = "sha256:f35c4b692542ca110de7ef0bea44d73981caeb34ca0b9b6b2e6d7790dda8f80e"}, 218 | {file = "distlib-0.3.6.tar.gz", hash = "sha256:14bad2d9b04d3a36127ac97f30b12a19268f211063d8f8ee4f47108896e11b46"}, 219 | ] 220 | 221 | [[package]] 222 | name = "exceptiongroup" 223 | version = "1.1.0" 224 | description = "Backport of PEP 654 (exception groups)" 225 | category = "main" 226 | optional = false 227 | python-versions = ">=3.7" 228 | files = [ 229 | {file = "exceptiongroup-1.1.0-py3-none-any.whl", hash = "sha256:327cbda3da756e2de031a3107b81ab7b3770a602c4d16ca618298c526f4bec1e"}, 230 | {file = "exceptiongroup-1.1.0.tar.gz", hash = "sha256:bcb67d800a4497e1b404c2dd44fca47d3b7a5e5433dbab67f96c1a685cdfdf23"}, 231 | ] 232 | 233 | [package.extras] 234 | test = ["pytest (>=6)"] 235 | 236 | [[package]] 237 | name = "filelock" 238 | version = "3.9.0" 239 | description = "A platform independent file lock." 240 | category = "dev" 241 | optional = false 242 | python-versions = ">=3.7" 243 | files = [ 244 | {file = "filelock-3.9.0-py3-none-any.whl", hash = "sha256:f58d535af89bb9ad5cd4df046f741f8553a418c01a7856bf0d173bbc9f6bd16d"}, 245 | {file = "filelock-3.9.0.tar.gz", hash = "sha256:7b319f24340b51f55a2bf7a12ac0755a9b03e718311dac567a0f4f7fabd2f5de"}, 246 | ] 247 | 248 | [package.extras] 249 | docs = ["furo (>=2022.12.7)", "sphinx (>=5.3)", "sphinx-autodoc-typehints (>=1.19.5)"] 250 | testing = ["covdefaults (>=2.2.2)", "coverage (>=7.0.1)", "pytest (>=7.2)", "pytest-cov (>=4)", "pytest-timeout (>=2.1)"] 251 | 252 | [[package]] 253 | name = "flake8" 254 | version = "4.0.1" 255 | description = "the modular source code checker: pep8 pyflakes and co" 256 | category = "dev" 257 | optional = false 258 | python-versions = ">=3.6" 259 | files = [ 260 | {file = "flake8-4.0.1-py2.py3-none-any.whl", hash = "sha256:479b1304f72536a55948cb40a32dce8bb0ffe3501e26eaf292c7e60eb5e0428d"}, 261 | {file = "flake8-4.0.1.tar.gz", hash = "sha256:806e034dda44114815e23c16ef92f95c91e4c71100ff52813adf7132a6ad870d"}, 262 | ] 263 | 264 | [package.dependencies] 265 | mccabe = ">=0.6.0,<0.7.0" 266 | pycodestyle = ">=2.8.0,<2.9.0" 267 | pyflakes = ">=2.4.0,<2.5.0" 268 | 269 | [[package]] 270 | name = "iniconfig" 271 | version = "2.0.0" 272 | description = "brain-dead simple config-ini parsing" 273 | category = "main" 274 | optional = false 275 | python-versions = ">=3.7" 276 | files = [ 277 | {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, 278 | {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, 279 | ] 280 | 281 | [[package]] 282 | name = "mccabe" 283 | version = "0.6.1" 284 | description = "McCabe checker, plugin for flake8" 285 | category = "dev" 286 | optional = false 287 | python-versions = "*" 288 | files = [ 289 | {file = "mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"}, 290 | {file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"}, 291 | ] 292 | 293 | [[package]] 294 | name = "mypy" 295 | version = "1.1.1" 296 | description = "Optional static typing for Python" 297 | category = "dev" 298 | optional = false 299 | python-versions = ">=3.7" 300 | files = [ 301 | {file = "mypy-1.1.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:39c7119335be05630611ee798cc982623b9e8f0cff04a0b48dfc26100e0b97af"}, 302 | {file = "mypy-1.1.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:61bf08362e93b6b12fad3eab68c4ea903a077b87c90ac06c11e3d7a09b56b9c1"}, 303 | {file = "mypy-1.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:dbb19c9f662e41e474e0cff502b7064a7edc6764f5262b6cd91d698163196799"}, 304 | {file = "mypy-1.1.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:315ac73cc1cce4771c27d426b7ea558fb4e2836f89cb0296cbe056894e3a1f78"}, 305 | {file = "mypy-1.1.1-cp310-cp310-win_amd64.whl", hash = "sha256:5cb14ff9919b7df3538590fc4d4c49a0f84392237cbf5f7a816b4161c061829e"}, 306 | {file = "mypy-1.1.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:26cdd6a22b9b40b2fd71881a8a4f34b4d7914c679f154f43385ca878a8297389"}, 307 | {file = "mypy-1.1.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:5b5f81b40d94c785f288948c16e1f2da37203c6006546c5d947aab6f90aefef2"}, 308 | {file = "mypy-1.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:21b437be1c02712a605591e1ed1d858aba681757a1e55fe678a15c2244cd68a5"}, 309 | {file = "mypy-1.1.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:d809f88734f44a0d44959d795b1e6f64b2bbe0ea4d9cc4776aa588bb4229fc1c"}, 310 | {file = "mypy-1.1.1-cp311-cp311-win_amd64.whl", hash = "sha256:a380c041db500e1410bb5b16b3c1c35e61e773a5c3517926b81dfdab7582be54"}, 311 | {file = "mypy-1.1.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:b7c7b708fe9a871a96626d61912e3f4ddd365bf7f39128362bc50cbd74a634d5"}, 312 | {file = "mypy-1.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c1c10fa12df1232c936830839e2e935d090fc9ee315744ac33b8a32216b93707"}, 313 | {file = "mypy-1.1.1-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:0a28a76785bf57655a8ea5eb0540a15b0e781c807b5aa798bd463779988fa1d5"}, 314 | {file = "mypy-1.1.1-cp37-cp37m-win_amd64.whl", hash = "sha256:ef6a01e563ec6a4940784c574d33f6ac1943864634517984471642908b30b6f7"}, 315 | {file = "mypy-1.1.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d64c28e03ce40d5303450f547e07418c64c241669ab20610f273c9e6290b4b0b"}, 316 | {file = "mypy-1.1.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:64cc3afb3e9e71a79d06e3ed24bb508a6d66f782aff7e56f628bf35ba2e0ba51"}, 317 | {file = "mypy-1.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ce61663faf7a8e5ec6f456857bfbcec2901fbdb3ad958b778403f63b9e606a1b"}, 318 | {file = "mypy-1.1.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:2b0c373d071593deefbcdd87ec8db91ea13bd8f1328d44947e88beae21e8d5e9"}, 319 | {file = "mypy-1.1.1-cp38-cp38-win_amd64.whl", hash = "sha256:2888ce4fe5aae5a673386fa232473014056967f3904f5abfcf6367b5af1f612a"}, 320 | {file = "mypy-1.1.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:19ba15f9627a5723e522d007fe708007bae52b93faab00f95d72f03e1afa9598"}, 321 | {file = "mypy-1.1.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:59bbd71e5c58eed2e992ce6523180e03c221dcd92b52f0e792f291d67b15a71c"}, 322 | {file = "mypy-1.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9401e33814cec6aec8c03a9548e9385e0e228fc1b8b0a37b9ea21038e64cdd8a"}, 323 | {file = "mypy-1.1.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:4b398d8b1f4fba0e3c6463e02f8ad3346f71956b92287af22c9b12c3ec965a9f"}, 324 | {file = "mypy-1.1.1-cp39-cp39-win_amd64.whl", hash = "sha256:69b35d1dcb5707382810765ed34da9db47e7f95b3528334a3c999b0c90fe523f"}, 325 | {file = "mypy-1.1.1-py3-none-any.whl", hash = "sha256:4e4e8b362cdf99ba00c2b218036002bdcdf1e0de085cdb296a49df03fb31dfc4"}, 326 | {file = "mypy-1.1.1.tar.gz", hash = "sha256:ae9ceae0f5b9059f33dbc62dea087e942c0ccab4b7a003719cb70f9b8abfa32f"}, 327 | ] 328 | 329 | [package.dependencies] 330 | mypy-extensions = ">=1.0.0" 331 | tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} 332 | typing-extensions = ">=3.10" 333 | 334 | [package.extras] 335 | dmypy = ["psutil (>=4.0)"] 336 | install-types = ["pip"] 337 | python2 = ["typed-ast (>=1.4.0,<2)"] 338 | reports = ["lxml"] 339 | 340 | [[package]] 341 | name = "mypy-extensions" 342 | version = "1.0.0" 343 | description = "Type system extensions for programs checked with the mypy type checker." 344 | category = "dev" 345 | optional = false 346 | python-versions = ">=3.5" 347 | files = [ 348 | {file = "mypy_extensions-1.0.0-py3-none-any.whl", hash = "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d"}, 349 | {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"}, 350 | ] 351 | 352 | [[package]] 353 | name = "nox" 354 | version = "2022.11.21" 355 | description = "Flexible test automation." 356 | category = "dev" 357 | optional = false 358 | python-versions = ">=3.7" 359 | files = [ 360 | {file = "nox-2022.11.21-py3-none-any.whl", hash = "sha256:0e41a990e290e274cb205a976c4c97ee3c5234441a8132c8c3fd9ea3c22149eb"}, 361 | {file = "nox-2022.11.21.tar.gz", hash = "sha256:e21c31de0711d1274ca585a2c5fde36b1aa962005ba8e9322bf5eeed16dcd684"}, 362 | ] 363 | 364 | [package.dependencies] 365 | argcomplete = ">=1.9.4,<3.0" 366 | colorlog = ">=2.6.1,<7.0.0" 367 | packaging = ">=20.9" 368 | virtualenv = ">=14" 369 | 370 | [package.extras] 371 | tox-to-nox = ["jinja2", "tox"] 372 | 373 | [[package]] 374 | name = "nox-poetry" 375 | version = "1.0.2" 376 | description = "nox-poetry" 377 | category = "dev" 378 | optional = false 379 | python-versions = ">=3.7,<4.0" 380 | files = [ 381 | {file = "nox-poetry-1.0.2.tar.gz", hash = "sha256:22bc397979393a0283f5161af708a3a430e1c7e0cc2be274c7b27e9e46de0412"}, 382 | {file = "nox_poetry-1.0.2-py3-none-any.whl", hash = "sha256:a53c36eccbd67f15b5b83dd6562d077dd326c71fd4a942528d8b2299c417dbbe"}, 383 | ] 384 | 385 | [package.dependencies] 386 | nox = ">=2020.8.22" 387 | packaging = ">=20.9" 388 | tomlkit = ">=0.7" 389 | 390 | [[package]] 391 | name = "packaging" 392 | version = "23.0" 393 | description = "Core utilities for Python packages" 394 | category = "main" 395 | optional = false 396 | python-versions = ">=3.7" 397 | files = [ 398 | {file = "packaging-23.0-py3-none-any.whl", hash = "sha256:714ac14496c3e68c99c29b00845f7a2b85f3bb6f1078fd9f72fd20f0570002b2"}, 399 | {file = "packaging-23.0.tar.gz", hash = "sha256:b6ad297f8907de0fa2fe1ccbd26fdaf387f5f47c7275fedf8cce89f99446cf97"}, 400 | ] 401 | 402 | [[package]] 403 | name = "pathspec" 404 | version = "0.11.0" 405 | description = "Utility library for gitignore style pattern matching of file paths." 406 | category = "dev" 407 | optional = false 408 | python-versions = ">=3.7" 409 | files = [ 410 | {file = "pathspec-0.11.0-py3-none-any.whl", hash = "sha256:3a66eb970cbac598f9e5ccb5b2cf58930cd8e3ed86d393d541eaf2d8b1705229"}, 411 | {file = "pathspec-0.11.0.tar.gz", hash = "sha256:64d338d4e0914e91c1792321e6907b5a593f1ab1851de7fc269557a21b30ebbc"}, 412 | ] 413 | 414 | [[package]] 415 | name = "platformdirs" 416 | version = "3.1.0" 417 | description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." 418 | category = "dev" 419 | optional = false 420 | python-versions = ">=3.7" 421 | files = [ 422 | {file = "platformdirs-3.1.0-py3-none-any.whl", hash = "sha256:13b08a53ed71021350c9e300d4ea8668438fb0046ab3937ac9a29913a1a1350a"}, 423 | {file = "platformdirs-3.1.0.tar.gz", hash = "sha256:accc3665857288317f32c7bebb5a8e482ba717b474f3fc1d18ca7f9214be0cef"}, 424 | ] 425 | 426 | [package.extras] 427 | docs = ["furo (>=2022.12.7)", "proselint (>=0.13)", "sphinx (>=6.1.3)", "sphinx-autodoc-typehints (>=1.22,!=1.23.4)"] 428 | test = ["appdirs (==1.4.4)", "covdefaults (>=2.2.2)", "pytest (>=7.2.1)", "pytest-cov (>=4)", "pytest-mock (>=3.10)"] 429 | 430 | [[package]] 431 | name = "pluggy" 432 | version = "1.0.0" 433 | description = "plugin and hook calling mechanisms for python" 434 | category = "main" 435 | optional = false 436 | python-versions = ">=3.6" 437 | files = [ 438 | {file = "pluggy-1.0.0-py2.py3-none-any.whl", hash = "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"}, 439 | {file = "pluggy-1.0.0.tar.gz", hash = "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"}, 440 | ] 441 | 442 | [package.extras] 443 | dev = ["pre-commit", "tox"] 444 | testing = ["pytest", "pytest-benchmark"] 445 | 446 | [[package]] 447 | name = "pycodestyle" 448 | version = "2.8.0" 449 | description = "Python style guide checker" 450 | category = "dev" 451 | optional = false 452 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" 453 | files = [ 454 | {file = "pycodestyle-2.8.0-py2.py3-none-any.whl", hash = "sha256:720f8b39dde8b293825e7ff02c475f3077124006db4f440dcbc9a20b76548a20"}, 455 | {file = "pycodestyle-2.8.0.tar.gz", hash = "sha256:eddd5847ef438ea1c7870ca7eb78a9d47ce0cdb4851a5523949f2601d0cbbe7f"}, 456 | ] 457 | 458 | [[package]] 459 | name = "pyflakes" 460 | version = "2.4.0" 461 | description = "passive checker of Python programs" 462 | category = "dev" 463 | optional = false 464 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" 465 | files = [ 466 | {file = "pyflakes-2.4.0-py2.py3-none-any.whl", hash = "sha256:3bb3a3f256f4b7968c9c788781e4ff07dce46bdf12339dcda61053375426ee2e"}, 467 | {file = "pyflakes-2.4.0.tar.gz", hash = "sha256:05a85c2872edf37a4ed30b0cce2f6093e1d0581f8c19d7393122da7e25b2b24c"}, 468 | ] 469 | 470 | [[package]] 471 | name = "pytest" 472 | version = "7.2.2" 473 | description = "pytest: simple powerful testing with Python" 474 | category = "main" 475 | optional = false 476 | python-versions = ">=3.7" 477 | files = [ 478 | {file = "pytest-7.2.2-py3-none-any.whl", hash = "sha256:130328f552dcfac0b1cec75c12e3f005619dc5f874f0a06e8ff7263f0ee6225e"}, 479 | {file = "pytest-7.2.2.tar.gz", hash = "sha256:c99ab0c73aceb050f68929bc93af19ab6db0558791c6a0715723abe9d0ade9d4"}, 480 | ] 481 | 482 | [package.dependencies] 483 | attrs = ">=19.2.0" 484 | colorama = {version = "*", markers = "sys_platform == \"win32\""} 485 | exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} 486 | iniconfig = "*" 487 | packaging = "*" 488 | pluggy = ">=0.12,<2.0" 489 | tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} 490 | 491 | [package.extras] 492 | testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "xmlschema"] 493 | 494 | [[package]] 495 | name = "pytest-mock" 496 | version = "3.10.0" 497 | description = "Thin-wrapper around the mock package for easier use with pytest" 498 | category = "dev" 499 | optional = false 500 | python-versions = ">=3.7" 501 | files = [ 502 | {file = "pytest-mock-3.10.0.tar.gz", hash = "sha256:fbbdb085ef7c252a326fd8cdcac0aa3b1333d8811f131bdcc701002e1be7ed4f"}, 503 | {file = "pytest_mock-3.10.0-py3-none-any.whl", hash = "sha256:f4c973eeae0282963eb293eb173ce91b091a79c1334455acfac9ddee8a1c784b"}, 504 | ] 505 | 506 | [package.dependencies] 507 | pytest = ">=5.0" 508 | 509 | [package.extras] 510 | dev = ["pre-commit", "pytest-asyncio", "tox"] 511 | 512 | [[package]] 513 | name = "tomli" 514 | version = "2.0.1" 515 | description = "A lil' TOML parser" 516 | category = "main" 517 | optional = false 518 | python-versions = ">=3.7" 519 | files = [ 520 | {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, 521 | {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, 522 | ] 523 | 524 | [[package]] 525 | name = "tomlkit" 526 | version = "0.11.6" 527 | description = "Style preserving TOML library" 528 | category = "dev" 529 | optional = false 530 | python-versions = ">=3.6" 531 | files = [ 532 | {file = "tomlkit-0.11.6-py3-none-any.whl", hash = "sha256:07de26b0d8cfc18f871aec595fda24d95b08fef89d147caa861939f37230bf4b"}, 533 | {file = "tomlkit-0.11.6.tar.gz", hash = "sha256:71b952e5721688937fb02cf9d354dbcf0785066149d2855e44531ebdd2b65d73"}, 534 | ] 535 | 536 | [[package]] 537 | name = "typing-extensions" 538 | version = "4.5.0" 539 | description = "Backported and Experimental Type Hints for Python 3.7+" 540 | category = "dev" 541 | optional = false 542 | python-versions = ">=3.7" 543 | files = [ 544 | {file = "typing_extensions-4.5.0-py3-none-any.whl", hash = "sha256:fb33085c39dd998ac16d1431ebc293a8b3eedd00fd4a32de0ff79002c19511b4"}, 545 | {file = "typing_extensions-4.5.0.tar.gz", hash = "sha256:5cb5f4a79139d699607b3ef622a1dedafa84e115ab0024e0d9c044a9479ca7cb"}, 546 | ] 547 | 548 | [[package]] 549 | name = "virtualenv" 550 | version = "20.20.0" 551 | description = "Virtual Python Environment builder" 552 | category = "dev" 553 | optional = false 554 | python-versions = ">=3.7" 555 | files = [ 556 | {file = "virtualenv-20.20.0-py3-none-any.whl", hash = "sha256:3c22fa5a7c7aa106ced59934d2c20a2ecb7f49b4130b8bf444178a16b880fa45"}, 557 | {file = "virtualenv-20.20.0.tar.gz", hash = "sha256:a8a4b8ca1e28f864b7514a253f98c1d62b64e31e77325ba279248c65fb4fcef4"}, 558 | ] 559 | 560 | [package.dependencies] 561 | distlib = ">=0.3.6,<1" 562 | filelock = ">=3.4.1,<4" 563 | platformdirs = ">=2.4,<4" 564 | 565 | [package.extras] 566 | docs = ["furo (>=2022.12.7)", "proselint (>=0.13)", "sphinx (>=6.1.3)", "sphinx-argparse (>=0.4)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=22.12)"] 567 | test = ["covdefaults (>=2.2.2)", "coverage (>=7.1)", "coverage-enable-subprocess (>=1)", "flaky (>=3.7)", "packaging (>=23)", "pytest (>=7.2.1)", "pytest-env (>=0.8.1)", "pytest-freezegun (>=0.4.2)", "pytest-mock (>=3.10)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)"] 568 | 569 | [metadata] 570 | lock-version = "2.0" 571 | python-versions = "^3.10" 572 | content-hash = "047641493f5e58b29655fe45fc64a2a4f90556269e011edd376a96d3a81f19ef" 573 | --------------------------------------------------------------------------------