From 246dcb0ebe595a107d670769ff04fe463eec9bed Mon Sep 17 00:00:00 2001 From: Dominikus Hellgartner Date: Tue, 28 Jan 2025 12:19:36 +0100 Subject: [PATCH] feat: introduce import linter Goal: The different file formats should not depend on each other --- .github/workflows/lint_and_run_tests.yml | 3 ++ .importlinter | 14 +++++++ pyproject.toml | 4 +- uv.lock | 49 ++++++++++++++++++++++-- 4 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 .importlinter diff --git a/.github/workflows/lint_and_run_tests.yml b/.github/workflows/lint_and_run_tests.yml index dd91304..7c0b420 100644 --- a/.github/workflows/lint_and_run_tests.yml +++ b/.github/workflows/lint_and_run_tests.yml @@ -48,6 +48,9 @@ jobs: - name: Run mypy run: uv run python -m mypy src/ tests/ + - name: Run import linter + run: uv run lint-imports + test: runs-on: ${{ matrix.os }} if: | diff --git a/.importlinter b/.importlinter new file mode 100644 index 0000000..05dfdba --- /dev/null +++ b/.importlinter @@ -0,0 +1,14 @@ +[importlinter] +root_package = opossum_lib +# Optional: +include_external_packages = True +exclude_type_checking_imports = True + +[importlinter:contract:file-formats-independent] +name = The different file formats should be independent +type = independence +modules = + opossum_lib.opossum + opossum_lib.scancode +ignore_imports = + ** -> opossum_lib.core.opossum_model diff --git a/pyproject.toml b/pyproject.toml index 90ee51c..fdb6fb7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,6 @@ dependencies = [ "click>=8.1.8,<9", "pydantic>=2.10.6", "pyinstaller>=6.11.1", - "faker>=35.0.0", ] [project.urls] @@ -22,11 +21,12 @@ Repository = "https://github.com/opossum-tool/opossum-file" opossum-file = "opossum_lib.cli:opossum_file" [dependency-groups] -test = ["pytest>=8.3.4,<9"] +test = ["pytest>=8.3.4,<9", "faker>=35.0.0",] dev = [ "mypy>=1.14.1,<2", "pre-commit>=4.1.0,<5", "ruff>=0.9.3", + "import-linter>=2.1", ] [tool.uv] diff --git a/uv.lock b/uv.lock index 002d57a..975ca4b 100644 --- a/uv.lock +++ b/uv.lock @@ -80,6 +80,31 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/b9/f8/feced7779d755758a52d1f6635d990b8d98dc0a29fa568bbe0625f18fdf3/filelock-3.16.1-py3-none-any.whl", hash = "sha256:2082e5703d51fbf98ea75855d9d5527e33d8ff23099bec374a134febee6946b0", size = 16163 }, ] +[[package]] +name = "grimp" +version = "3.5" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/df/bd/4f919930f4b9c89a6d6905e4e8e4f11aa2489e385064501ff191c7b7d9cb/grimp-3.5.tar.gz", hash = "sha256:dc9560aed1d82222b361fe5f312a775b15a96b9237670f3a9fb20f44d30d5762", size = 833830 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/31/02/33f4b4bc6d22b5ff7672ce5c67464f4dcee6e86cf3a072cdc9b1d46e5178/grimp-3.5-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:448dba63f938d0e13e6121559749816e3b2644202c912cc308e7608c6034737a", size = 351545 }, + { url = "https://files.pythonhosted.org/packages/78/e0/44bd64767763160ea0862ad756b88dfd375060b5636aaeb79c10861f09ae/grimp-3.5-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:17113aba41269d0ee91512c96eeb850c7c668440c6a8e0bfc94d17762184b293", size = 342780 }, + { url = "https://files.pythonhosted.org/packages/55/e6/b0fc52ab1ee04c80f1709eaa2e99468a8981d0a23dcbc7c2c6e781da22cc/grimp-3.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e6a55614945c319d1dc692c3e43f3a02b80c116a1298e593f5f887b97e6c983a", size = 399300 }, + { url = "https://files.pythonhosted.org/packages/dc/b9/aa6365859c96881d02f6ad6ab8aa38eaced5887f3cc431165ed9ee7b35ea/grimp-3.5-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:aba7ce7839b72efb4c6d06404d2b2a3026e28dd89816f4e546b3cd6626cbeeb1", size = 405288 }, + { url = "https://files.pythonhosted.org/packages/7d/f8/32446714ed0f23a1b8067f9f627c55f7c186d3477baa5c6e6312c95060ab/grimp-3.5-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:eaedfba320a70d87b14acb25a685c8629586b943129c71ffd02b47d9531c11ce", size = 416565 }, + { url = "https://files.pythonhosted.org/packages/93/3c/185a0292111350823fdd7d61481157295d90260e248888ab274a00f84456/grimp-3.5-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:60a9afd3dd00ad1d301a07f97e26bc9ecdc3d2db39ab6ac46c315a7dea0a96cb", size = 437249 }, + { url = "https://files.pythonhosted.org/packages/1a/21/55ede2511dc111e9ca90d23e479e263e0845dc7e389515587f9575c5b139/grimp-3.5-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:11c66039c0475e5c9fc6a086264f11870181ae79f603caa5dffa1411ddad636b", size = 443560 }, + { url = "https://files.pythonhosted.org/packages/12/e1/79f6a4212d46ae6db6281c5b179990d2dd53c72eed7587592c0968f0d3f0/grimp-3.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bff39a0061790f074f86a7841cd8e6064aa7b2208cb1ee5c3f2e685dead2b66e", size = 393185 }, + { url = "https://files.pythonhosted.org/packages/46/62/1a7f8b54d73f3ef6595dd8bfa10686321c04b562fbb997e9d46f95fe7b96/grimp-3.5-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:cf7f5367c4a87b8e9f08c09e7401d2d73f21cb65d6142445819f9df0d6ab3f6b", size = 573292 }, + { url = "https://files.pythonhosted.org/packages/24/1d/b90853a0b7eb7aa08073dafd896551d26a416e922a68eb1cab35319593c7/grimp-3.5-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:edee4b087f007dab8b65461caf6a1b67b2f9480cceb5f6aceea87008d8f283c4", size = 664226 }, + { url = "https://files.pythonhosted.org/packages/6b/7b/ce6cf6ba2da6305725692ea2a7a4080da60ac075d23353fc07cae7adb5b7/grimp-3.5-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:6af125013ad2a56c18f2f53a3fcabbfbe96c70374abecd6f14b82dc444726ebe", size = 589077 }, + { url = "https://files.pythonhosted.org/packages/ad/29/03156310a1bf278e8dd46e2e02311bad1d1551b1555d245e28008c318086/grimp-3.5-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:24aabae0183ca5fd5a710257ff37120b55d8e6d6d4cbb2c08481552832e5c901", size = 560463 }, + { url = "https://files.pythonhosted.org/packages/1e/29/300daf9b6a7f3f979a379cda69e04374912031fd85f3b6f0e03d9b637263/grimp-3.5-cp313-none-win32.whl", hash = "sha256:506091bfd600dd7ad427586998ef5e54a2098485148a1499bd9af5943d2fb0b7", size = 222673 }, + { url = "https://files.pythonhosted.org/packages/e5/8c/15834d919407c1ab11590367e03ac9d1c162d518a0f54f2970e315e0d623/grimp-3.5-cp313-none-win_amd64.whl", hash = "sha256:099388df82d922ddc589f362f1a523ab053c8dee5d29a6b622b2cddf481c6a2f", size = 236037 }, +] + [[package]] name = "identify" version = "2.6.5" @@ -89,6 +114,20 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/ec/fa/dce098f4cdf7621aa8f7b4f919ce545891f489482f0bfa5102f3eca8608b/identify-2.6.5-py2.py3-none-any.whl", hash = "sha256:14181a47091eb75b337af4c23078c9d09225cd4c48929f521f3bf16b09d02566", size = 99078 }, ] +[[package]] +name = "import-linter" +version = "2.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "click" }, + { name = "grimp" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/5e/d3/546d27e9390061cbc692541612bbaa3f69a3ad23f592cfbfefe0517ff5b0/import_linter-2.1.tar.gz", hash = "sha256:393fadb2e91304c22c5ceab575213ed2b6a794abc7bd05ab345f2430930b2eae", size = 29160 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d8/38/137d5310c52c1b79d1588afa2ce5038cb3a10dbfd1a642962f3bc3ccbe61/import_linter-2.1-py3-none-any.whl", hash = "sha256:324d65035f0252a8e432f60256b0d0d32d8d5d6e4f8fd29716688b09d7a2217a", size = 41402 }, +] + [[package]] name = "iniconfig" version = "2.0.0" @@ -153,36 +192,40 @@ version = "0.1" source = { editable = "." } dependencies = [ { name = "click" }, - { name = "faker" }, { name = "pydantic" }, { name = "pyinstaller" }, ] [package.dev-dependencies] dev = [ + { name = "import-linter" }, { name = "mypy" }, { name = "pre-commit" }, { name = "ruff" }, ] test = [ + { name = "faker" }, { name = "pytest" }, ] [package.metadata] requires-dist = [ { name = "click", specifier = ">=8.1.8,<9" }, - { name = "faker", specifier = ">=35.0.0" }, { name = "pydantic", specifier = ">=2.10.6" }, { name = "pyinstaller", specifier = ">=6.11.1" }, ] [package.metadata.requires-dev] dev = [ + { name = "import-linter", specifier = ">=2.1" }, { name = "mypy", specifier = ">=1.14.1,<2" }, { name = "pre-commit", specifier = ">=4.1.0,<5" }, { name = "ruff", specifier = ">=0.9.3" }, ] -test = [{ name = "pytest", specifier = ">=8.3.4,<9" }] +test = [ + { name = "faker", specifier = ">=35.0.0" }, + { name = "pytest", specifier = ">=8.3.4,<9" }, +] [[package]] name = "packaging"