From a071f1ef62301fc3b14008f75e6fb1d3d384caa1 Mon Sep 17 00:00:00 2001 From: Adam Li Date: Tue, 31 Oct 2023 10:37:03 -0400 Subject: [PATCH] Fix yaml and add linting Signed-off-by: Adam Li --- .circleci/config.yml | 4 +- .github/workflows/main.yml | 32 ++-- .pre-commit-config.yaml | 9 +- .yamllint.yaml | 6 + poetry.lock | 71 +++++++- pyproject.toml | 309 +++++++++++++++++---------------- pywhy_graphs/algorithms/pag.py | 12 +- 7 files changed, 267 insertions(+), 176 deletions(-) create mode 100644 .yamllint.yaml diff --git a/.circleci/config.yml b/.circleci/config.yml index 01d02c83b..80c5cc17c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -74,7 +74,7 @@ jobs: - python/install-packages: pkg-manager: poetry - cache-version: "v2" # change to clear cache + cache-version: "v2" # change to clear cache args: "--with docs --extras viz --extras sims" - run: name: Check poetry package versions @@ -162,7 +162,7 @@ jobs: cat $BASH_ENV - python/install-packages: pkg-manager: poetry - cache-version: "v1" # change to clear cache + cache-version: "v1" # change to clear cache args: "--with docs" - run: name: make linkcheck diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d0f533420..d29fbdb64 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,15 +5,15 @@ concurrency: on: pull_request: paths: - - '**.py' - - '**.yml' - - '**.toml' + - "**.py" + - "**.yml" + - "**.toml" push: branches: [main] paths: - - '**.py' + - "**.py" tags: - - 'v*.*.*' + - "v*.*.*" workflow_dispatch: jobs: @@ -22,25 +22,25 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - poetry-version: [1.6.1] + poetry-version: [1.6.1] steps: - name: Checkout repository uses: actions/checkout@v4 - name: Setup Python 3.9 uses: actions/setup-python@v4 with: - python-version: '3.9' - architecture: 'x64' + python-version: "3.9" + architecture: "x64" - name: Install Poetry ${{ matrix.poetry-version }} uses: abatilo/actions-poetry@v2.3.0 with: poetry-version: ${{ matrix.poetry-version }} - name: Install Poetry Dynamic Versioning Plugin run: pip install poetry-dynamic-versioning - + - name: Install dependencies run: poetry install --only style - + # check formatting of the code style - name: Check code formatting run: poetry run poe format_check @@ -72,7 +72,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - architecture: 'x64' + architecture: "x64" - name: Install Poetry ${{ matrix.poetry-version }} uses: abatilo/actions-poetry@v2.3.0 with: @@ -130,7 +130,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - architecture: 'x64' + architecture: "x64" - name: Install Poetry ${{ matrix.poetry-version }} uses: abatilo/actions-poetry@v2.3.0 with: @@ -143,19 +143,19 @@ jobs: run: | poetry install --with test - name: Install Networkx (main) - if: "matrix.networkx == 'main'" + if: "matrix.networkx == 'main'" run: | pip uninstall -yq networkx git clone https://github.com/networkx/networkx.git cd networkx pip install .[default] - + - name: Setup torch for pgmpy if: "matrix.os == 'ubuntu'" shell: bash run: | sudo apt-get install nvidia-cuda-toolkit nvidia-cuda-toolkit-gcc - + - name: Run pytest # headless via Xvfb on linux run: poetry run poe unit_test - name: Upload coverage stats to codecov @@ -179,7 +179,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.9 - architecture: 'x64' + architecture: "x64" - name: Install dependencies run: | python -m pip install --progress-bar off --upgrade pip setuptools wheel diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 58ae1c555..0daef6d00 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,10 +3,10 @@ repos: - repo: https://github.com/floatingpurr/sync_with_poetry - rev: "0.4.0" # the revision or tag to clone at + rev: "0.4.0" # the revision or tag to clone at hooks: - id: sync_with_poetry - args: ["--all"] # optional args + args: ["--all"] # optional args - repo: https://github.com/psf/black rev: 22.12.0 hooks: @@ -27,18 +27,17 @@ repos: rev: "6.0.0" hooks: - id: flake8 - - repo: https://github.com/pre-commit/mirrors-mypy + - repo: https://github.com/pre-commit/mirrors-mypy rev: "v0.971" hooks: - id: mypy name: mypy (dodiscover) args: ["--config-file", "pyproject.toml"] files: ^dodiscover/ - - repo: https://github.com/pre-commit/mirrors-mypy + - repo: https://github.com/pre-commit/mirrors-mypy rev: "v0.971" hooks: - id: mypy name: mypy (tests) args: ["--config-file", "pyproject.toml"] files: ^tests/ - diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 000000000..33b82f99a --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,6 @@ +extends: default + +rules: + line-length: disable + document-start: disable + truthy: disable diff --git a/poetry.lock b/poetry.lock index 46a44e72d..368056f59 100644 --- a/poetry.lock +++ b/poetry.lock @@ -3097,6 +3097,32 @@ files = [ {file = "rpds_py-0.10.6.tar.gz", hash = "sha256:4ce5a708d65a8dbf3748d2474b580d606b1b9f91b5c6ab2a316e0b0cf7a4ba50"}, ] +[[package]] +name = "ruff" +version = "0.1.3" +description = "An extremely fast Python linter, written in Rust." +optional = false +python-versions = ">=3.7" +files = [ + {file = "ruff-0.1.3-py3-none-macosx_10_7_x86_64.whl", hash = "sha256:b46d43d51f7061652eeadb426a9e3caa1e0002470229ab2fc19de8a7b0766901"}, + {file = "ruff-0.1.3-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:b8afeb9abd26b4029c72adc9921b8363374f4e7edb78385ffaa80278313a15f9"}, + {file = "ruff-0.1.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ca3cf365bf32e9ba7e6db3f48a4d3e2c446cd19ebee04f05338bc3910114528b"}, + {file = "ruff-0.1.3-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:4874c165f96c14a00590dcc727a04dca0cfd110334c24b039458c06cf78a672e"}, + {file = "ruff-0.1.3-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:eec2dd31eed114e48ea42dbffc443e9b7221976554a504767ceaee3dd38edeb8"}, + {file = "ruff-0.1.3-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:dc3ec4edb3b73f21b4aa51337e16674c752f1d76a4a543af56d7d04e97769613"}, + {file = "ruff-0.1.3-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:2e3de9ed2e39160800281848ff4670e1698037ca039bda7b9274f849258d26ce"}, + {file = "ruff-0.1.3-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:1c595193881922cc0556a90f3af99b1c5681f0c552e7a2a189956141d8666fe8"}, + {file = "ruff-0.1.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0f75e670d529aa2288cd00fc0e9b9287603d95e1536d7a7e0cafe00f75e0dd9d"}, + {file = "ruff-0.1.3-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:76dd49f6cd945d82d9d4a9a6622c54a994689d8d7b22fa1322983389b4892e20"}, + {file = "ruff-0.1.3-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:918b454bc4f8874a616f0d725590277c42949431ceb303950e87fef7a7d94cb3"}, + {file = "ruff-0.1.3-py3-none-musllinux_1_2_i686.whl", hash = "sha256:d8859605e729cd5e53aa38275568dbbdb4fe882d2ea2714c5453b678dca83784"}, + {file = "ruff-0.1.3-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:0b6c55f5ef8d9dd05b230bb6ab80bc4381ecb60ae56db0330f660ea240cb0d4a"}, + {file = "ruff-0.1.3-py3-none-win32.whl", hash = "sha256:3e7afcbdcfbe3399c34e0f6370c30f6e529193c731b885316c5a09c9e4317eef"}, + {file = "ruff-0.1.3-py3-none-win_amd64.whl", hash = "sha256:7a18df6638cec4a5bd75350639b2bb2a2366e01222825562c7346674bdceb7ea"}, + {file = "ruff-0.1.3-py3-none-win_arm64.whl", hash = "sha256:12fd53696c83a194a2db7f9a46337ce06445fb9aa7d25ea6f293cf75b21aca9f"}, + {file = "ruff-0.1.3.tar.gz", hash = "sha256:3ba6145369a151401d5db79f0a47d50e470384d0d89d0d6f7fab0b589ad07c34"}, +] + [[package]] name = "scikit-learn" version = "1.3.2" @@ -3662,6 +3688,20 @@ files = [ {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, ] +[[package]] +name = "toml-sort" +version = "0.23.1" +description = "Toml sorting library" +optional = false +python-versions = ">=3.7,<4.0" +files = [ + {file = "toml_sort-0.23.1-py3-none-any.whl", hash = "sha256:69ae60de9c4d67478533697eb4119092e2b30ddffe5ca09bbad3912905c935a0"}, + {file = "toml_sort-0.23.1.tar.gz", hash = "sha256:833728c48b0f8d509aecd9ae8347768ca3a9332977b32c9fd2002932f0eb9c90"}, +] + +[package.dependencies] +tomlkit = ">=0.11.2" + [[package]] name = "tomli" version = "2.0.1" @@ -3673,6 +3713,17 @@ files = [ {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, ] +[[package]] +name = "tomlkit" +version = "0.12.1" +description = "Style preserving TOML library" +optional = false +python-versions = ">=3.7" +files = [ + {file = "tomlkit-0.12.1-py3-none-any.whl", hash = "sha256:712cbd236609acc6a3e2e97253dfc52d4c2082982a88f61b640ecf0817eab899"}, + {file = "tomlkit-0.12.1.tar.gz", hash = "sha256:38e1ff8edb991273ec9f6181244a6a391ac30e9f5098e7535640ea6be97a7c86"}, +] + [[package]] name = "torch" version = "2.0.0" @@ -3943,6 +3994,24 @@ files = [ [package.extras] test = ["pytest (>=6.0.0)", "setuptools (>=65)"] +[[package]] +name = "yamllint" +version = "1.32.0" +description = "A linter for YAML files." +optional = false +python-versions = ">=3.7" +files = [ + {file = "yamllint-1.32.0-py3-none-any.whl", hash = "sha256:d97a66e48da820829d96077d76b8dfbe6c6140f106e558dae87e81ac4e6b30b7"}, + {file = "yamllint-1.32.0.tar.gz", hash = "sha256:d01dde008c65de5b235188ab3110bebc59d18e5c65fc8a58267cd211cd9df34a"}, +] + +[package.dependencies] +pathspec = ">=0.5.3" +pyyaml = "*" + +[package.extras] +dev = ["doc8", "flake8", "flake8-import-order", "rstcheck[sphinx]", "sphinx"] + [[package]] name = "yaspin" version = "2.5.0" @@ -3979,4 +4048,4 @@ viz = ["pygraphviz"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.12" -content-hash = "50669d55677e05133c5318eb997ad956ef3ecf1dabeab5175a2fbddfc20e844b" +content-hash = "81d64d70ee159e1b96e09fc646e2e9e37b81e803e85a27686e66f3694b4c8b05" diff --git a/pyproject.toml b/pyproject.toml index 6235ce590..5acf30e6d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,91 @@ +[build-system] +requires = ["poetry-core>=1.0.8"] +build-backend = "poetry.core.masonry.api" + +[tool.bandit] +exclude_dirs = ["tests"] + +[tool.black] +line-length = 100 +target-version = ['py38'] +include = '\.pyi?$' +extend-exclude = ''' +( + __pycache__ + | \.github + | setup.py + | doc/ +) +''' + +[tool.coverage.report] +exclude_lines = ['pragma: no cover', 'if __name__ == .__main__.:'] +precision = 2 + +[tool.coverage.run] +branch = true +cover_pylib = false +source = ['pywhy_graphs'] +omit = [ + '**/__init__.py', + 'pywhy_graphs/config.py', + '**/networkxprotocol.py', + '**/tests/**', + 'pywhy_graphs.export.py' +] + +[tool.isort] +profile = 'black' +multi_line_output = 3 +line_length = 100 +py_version = 38 +extend_skip_glob = ['setup.py', 'doc/*', 'pywhy_graphs/__init__.py'] + +[tool.mypy] +ignore_missing_imports = true +no_site_packages = true + +[tool.poe.tasks] +_flake8 = 'flake8' +_bandit = 'bandit -r pywhy_graphs -c pyproject.toml' +_black = 'black .' +_isort = 'isort .' +_black_check = 'black --check pywhy_graphs examples' +_isort_check = 'isort --check .' +_pydocstyle = 'pydocstyle .' +_codespell = 'codespell pywhy_graphs/ doc/ examples/ --ignore-words=.codespellignore --skip "**/_build/*,**/auto_examples/*,**/generated/*,references.bib"' +_ruff = 'ruff . --fix' +_ruff_check = 'ruff .' +_toml_sort = 'toml-sort pyproject.toml --check' +_yamllint = 'yamllint . -c .yamllint.yaml --strict' +type_check = 'mypy -p pywhy_graphs --config-file pyproject.toml' +unit_test = 'pytest ./pywhy_graphs --cov=pywhy_graphs --cov-report=xml --cov-config=pyproject.toml' +build_docs = 'make -C doc clean html' +build_docs_noplot = 'make -C doc clean html-noplot' + +[[tool.poe.tasks.check]] +sequence = ['format', 'lint', 'type_check'] +ignore_fail = 'return_non_zero' + +[[tool.poe.tasks.format]] +sequence = ['_black', '_isort', '_ruff'] +ignore_fail = 'return_non_zero' + +[[tool.poe.tasks.format_check]] +sequence = ['_black_check', '_isort_check', '_ruff_check'] +ignore_fail = 'return_non_zero' + +[[tool.poe.tasks.lint]] +sequence = ['_flake8', '_bandit', '_codespell', '_pydocstyle', '_toml_sort', '_yamllint'] +ignore_fail = 'return_non_zero' + +# +# a standard verification sequence for use in pull requests +# +[[tool.poe.tasks.verify]] +sequence = ['format', 'lint', 'type_check', 'unit_test'] +ignore_fail = "return_non_zero" + [tool.poetry] name = "pywhy-graphs" # @@ -12,54 +100,60 @@ documentation = "https://py-why.github.io/pywhy-graphs" repository = "https://github.com/py-why/pywhy-graphs" readme = "README.md" classifiers = [ - 'Development Status :: 4 - Beta', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', + 'Development Status :: 4 - Beta', + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11' ] keywords = ['causality', 'graphs', 'causal-inference', 'graphical-model'] -[tool.poetry-dynamic-versioning] -enable = true -vcs = "git" - -[tool.poetry-dynamic-versioning.substitution] -files = ["pywhy_graphs/__init__.py"] - -[tool.setuptools] -include-package-data = false - -[tool.setuptools.packages.find] -include = ['pywhy_graphs*'] -exclude = ['*tests'] - [tool.poetry.dependencies] python = ">=3.9,<3.12" numpy = ">=1.22.0" scipy = ">=1.9.0" networkx = "^3.1" -importlib-resources = { version = "*", python = "<3.10" } -pygraphviz = { version = "*", optional = true } -pgmpy = { version = "*", optional = true } +importlib-resources = {version = "*", python = "<3.10"} +pygraphviz = {version = "*", optional = true} +pgmpy = {version = "*", optional = true} -[tool.poetry.group.test] +[tool.poetry.extras] +viz = ['pygraphviz'] +sims = ['pgmpy'] + +[tool.poetry.group.docs] optional = true -[tool.poetry.group.test.dependencies] + +[tool.poetry.group.docs.dependencies] poethepoet = "^0.20.0" -pytest = "^7.1.2" -pytest-cov = "^3.0.0" -joblib = { version = "^1.1.0" } # needed in dowhy's package -memory_profiler = { version = "^0.60.0" } -causal-learn = { version = "^0.1.2.8" } -ananke-causal = { version = "^0.3.3" } -pre-commit = "^3.0.4" -pandas = { version = ">=1.4" } # needed for simulation -torch = { version = ">=2.0.0,!=2.0.1,!=2.1.0" } +portray = "^1.7.0" +matplotlib = {version = ">=3.5.0"} +numpydoc = {version = "1.4"} +pydata-sphinx-theme = {version = "^0.9.0"} +sphinx = {version = "^5.1.1"} +sphinxcontrib-bibtex = {version = "^2.4.2"} +sphinx-issues = {version = "^3.0.1"} +sphinx-copybutton = {version = "^0.5.0"} +sphinx-gallery = {version = "^0.11.0"} +graphviz = {version = "^0.20.1"} +ipython = {version = "^7.4.0"} +nbsphinx = {version = "^0.8"} +dowhy = {version = "^0.8"} +pygraphviz = {version = "^1.11"} +memory_profiler = {version = "*"} +scikit-learn = {version = "^1.1.0"} # needed in dowhy's package +pandas = {version = ">=1.4"} # needed in dowhy's package +joblib = {version = "^1.1.0"} # needed in dowhy's package +tqdm = {version = "^4.64.0"} # needed in dowhy's package +typing-extensions = {version = "*"} # needed in dowhy's package +pillow = "^9.5.0" +cycler = "^0.11.0" +kiwisolver = "^1.4.4" [tool.poetry.group.style] optional = true + [tool.poetry.group.style.dependencies] poethepoet = "^0.20.0" mypy = "^0.971" @@ -70,104 +164,31 @@ bandit = "^1.7.4" pydocstyle = "^6.1.1" codespell = "^2.1.0" toml = "^0.10.2" +ruff = {version = "*"} +toml-sort = {version = "*"} +yamllint = {version = "*"} -[tool.poetry.group.docs] +[tool.poetry.group.test] optional = true -[tool.poetry.group.docs.dependencies] -poethepoet = "^0.20.0" -portray = "^1.7.0" -matplotlib = { version = ">=3.5.0" } -numpydoc = { version = "1.4" } -pydata-sphinx-theme = { version = "^0.9.0" } -sphinx = { version = "^5.1.1" } -sphinxcontrib-bibtex = { version = "^2.4.2" } -sphinx-issues = { version = "^3.0.1" } -sphinx-copybutton = { version = "^0.5.0" } -sphinx-gallery = { version = "^0.11.0" } -graphviz = { version = "^0.20.1" } -ipython = { version = "^7.4.0" } -nbsphinx = { version = "^0.8" } -dowhy = { version = "^0.8" } -pygraphviz = { version = "^1.11" } -memory_profiler = { version = "*" } -scikit-learn = { version = "^1.1.0" } # needed in dowhy's package -pandas = { version = ">=1.4" } # needed in dowhy's package -joblib = { version = "^1.1.0" } # needed in dowhy's package -tqdm = { version = "^4.64.0" } # needed in dowhy's package -typing-extensions = { version = "*" } # needed in dowhy's package -pillow = "^9.5.0" -cycler = "^0.11.0" -kiwisolver = "^1.4.4" - -[tool.poetry.extras] -viz = ['pygraphviz'] -sims = ['pgmpy'] - -[build-system] -requires = ["poetry-core>=1.0.8"] -build-backend = "poetry.core.masonry.api" - -[tool.poe.tasks] -_flake8 = 'flake8' -_bandit = 'bandit -r pywhy_graphs -c pyproject.toml' -_black = 'black .' -_isort = 'isort .' -_black_check = 'black --check pywhy_graphs examples' -_isort_check = 'isort --check .' -_pydocstyle = 'pydocstyle .' -_codespell = 'codespell pywhy_graphs/ doc/ examples/ --ignore-words=.codespellignore --skip "**/_build/*,**/auto_examples/*,**/generated/*,references.bib"' -type_check = 'mypy -p pywhy_graphs --config-file pyproject.toml' -unit_test = 'pytest ./pywhy_graphs --cov=pywhy_graphs --cov-report=xml --cov-config=pyproject.toml' -build_docs = 'make -C doc clean html' -build_docs_noplot = 'make -C doc clean html-noplot' - -[[tool.poe.tasks.lint]] -sequence = ['_flake8', '_bandit', '_codespell', '_pydocstyle'] -ignore_fail = 'return_non_zero' - -[[tool.poe.tasks.format]] -sequence = ['_black', '_isort'] -ignore_fail = 'return_non_zero' - -[[tool.poe.tasks.format_check]] -sequence = ['_black_check', '_isort_check'] -ignore_fail = 'return_non_zero' - -[[tool.poe.tasks.check]] -sequence = ['format', 'lint', 'type_check'] -ignore_fail = 'return_non_zero' - -# -# a standard verification sequence for use in pull requests -# -[[tool.poe.tasks.verify]] -sequence = ['format', 'lint', 'type_check', 'unit_test'] -ignore_fail = "return_non_zero" - -[tool.black] -line-length = 100 -target-version = ['py38'] -include = '\.pyi?$' -extend-exclude = ''' -( - __pycache__ - | \.github - | setup.py - | doc/ -) -''' +[tool.poetry.group.test.dependencies] +poethepoet = "^0.20.0" +pytest = "^7.1.2" +pytest-cov = "^3.0.0" +joblib = {version = "^1.1.0"} # needed in dowhy's package +memory_profiler = {version = "^0.60.0"} +causal-learn = {version = "^0.1.2.8"} +ananke-causal = {version = "^0.3.3"} +pre-commit = "^3.0.4" +pandas = {version = ">=1.4"} # needed for simulation +torch = {version = ">=2.0.0,!=2.0.1,!=2.1.0"} -[tool.pylint] -max-line-length = 120 -disable = ["W0511"] +[tool.poetry-dynamic-versioning] +enable = true +vcs = "git" -[tool.isort] -profile = 'black' -multi_line_output = 3 -line_length = 100 -py_version = 38 -extend_skip_glob = ['setup.py', 'doc/*', 'pywhy_graphs/__init__.py'] +[tool.poetry-dynamic-versioning.substitution] +files = ["pywhy_graphs/__init__.py"] [tool.pydocstyle] convention = 'numpy' @@ -176,30 +197,26 @@ match = '^(?!setup|__init__|test_).*\.py' match-dir = '^pywhy_graphs.*' add_ignore = 'D100,D104,D105,D107' -[tool.mypy] -ignore_missing_imports = true -no_site_packages = true +[tool.pylint] +max-line-length = 120 +disable = ["W0511"] [tool.pytest.ini_options] minversion = '6.0' addopts = '--durations 20 --junit-xml=junit-results.xml --verbose' filterwarnings = ["ignore::DeprecationWarning"] -[tool.coverage.run] -branch = true -cover_pylib = false -source = ['pywhy_graphs'] -omit = [ - '**/__init__.py', - 'pywhy_graphs/config.py', - '**/networkxprotocol.py', - '**/tests/**', - 'pywhy_graphs.export.py', -] +[tool.ruff] +extend-exclude = ['doc', 'setup.py'] +line-length = 88 +ignore = ['E731'] -[tool.coverage.report] -exclude_lines = ['pragma: no cover', 'if __name__ == .__main__.:'] -precision = 2 +[tool.ruff.per-file-ignores] +'__init__.py' = ['F401'] -[tool.bandit] -exclude_dirs = ["tests"] +[tool.setuptools] +include-package-data = false + +[tool.setuptools.packages.find] +include = ['pywhy_graphs*'] +exclude = ['*tests'] diff --git a/pywhy_graphs/algorithms/pag.py b/pywhy_graphs/algorithms/pag.py index 6f9e4f284..84a43ea3e 100644 --- a/pywhy_graphs/algorithms/pag.py +++ b/pywhy_graphs/algorithms/pag.py @@ -1030,9 +1030,9 @@ def _meek_rule3(graph: CPDAG, i: str, j: str) -> bool: if graph.has_edge(i, j, graph.undirected_edge_name): # For all the pairs of nodes adjacent to i, # look for (k, l), such that j -> l and k -> l - for k, l in combinations(graph.neighbors(i), 2): + for k, l_node in combinations(graph.neighbors(i), 2): # Skip if k and l are adjacent. - if l in graph.neighbors(k): + if l_node in graph.neighbors(k): continue # Skip if not k->j. if graph.has_edge(j, k, graph.directed_edge_name) or ( @@ -1040,19 +1040,19 @@ def _meek_rule3(graph: CPDAG, i: str, j: str) -> bool: ): continue # Skip if not l->j. - if graph.has_edge(j, l, graph.directed_edge_name) or ( - not graph.has_edge(l, j, graph.directed_edge_name) + if graph.has_edge(j, l_node, graph.directed_edge_name) or ( + not graph.has_edge(l_node, j, graph.directed_edge_name) ): continue # check if the triple is inside graph's excluded triples - if frozenset((l, i, k)) in graph.excluded_triples: + if frozenset((l_node, i, k)) in graph.excluded_triples: continue # if i - k and i - l, then at this point, we have a valid path # to orient if graph.has_edge(k, i, graph.undirected_edge_name) and graph.has_edge( - l, i, graph.undirected_edge_name + l_node, i, graph.undirected_edge_name ): graph.orient_uncertain_edge(i, j) added_arrows = True