diff --git a/.cspell.json b/.cspell.json index 8c38a961..9aa9ea83 100644 --- a/.cspell.json +++ b/.cspell.json @@ -26,8 +26,9 @@ "*particle*.*ml", ".constraints/*.txt", ".editorconfig", + ".envrc", + ".gitattributes", ".gitignore", - ".gitpod.*", ".pre-commit-config.yaml", ".prettierignore", ".readthedocs.yml", @@ -78,7 +79,6 @@ "gellmann", "genindex", "getsource", - "gitpod", "hankel", "heli", "heurisch", diff --git a/.envrc b/.envrc index cce3aa58..e1d415a5 100644 --- a/.envrc +++ b/.envrc @@ -1 +1,10 @@ -layout anaconda +if [ -e .venv ]; then + source .venv/bin/activate +elif [ -e venv ]; then + source venv/bin/activate +elif [ -e .pixi ]; then + watch_file pixi.lock + eval "$(pixi shell-hook)" +else + layout anaconda +fi diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..18f6c7e9 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +pixi.lock linguist-language=YAML linguist-generated=true diff --git a/.gitignore b/.gitignore index f7b7246a..d73bc42b 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,7 @@ TAGS # Virtual environments *venv/ +.pixi/ .tox/ pyvenv*/ @@ -51,7 +52,6 @@ pyvenv*/ !.cspell.json !.github/*.yml !.github/*/*.yml -!.gitpod.yml !.pre-commit-config.yaml !.readthedocs.yml !.vscode/*.json @@ -59,3 +59,4 @@ pyvenv*/ !codecov.yml !environment.yml !pyrightconfig.json +.pixi/ diff --git a/.gitpod.yml b/.gitpod.yml deleted file mode 100644 index abc3e5cc..00000000 --- a/.gitpod.yml +++ /dev/null @@ -1,37 +0,0 @@ -tasks: - - init: pyenv local 3.9 - - init: pip install -c .constraints/py3.9.txt -e .[dev] - -github: - prebuilds: - master: true - branches: false - pullRequests: true - pullRequestsFromForks: true - addComment: false - addBadge: false - addLabel: false - -vscode: - extensions: - - charliermarsh.ruff - - christian-kohler.path-intellisense - - eamodio.gitlens - - editorconfig.editorconfig - - esbenp.prettier-vscode - - executablebookproject.myst-highlight - - github.vscode-github-actions - - github.vscode-pull-request-github - - joaompinto.vscode-graphviz - - ms-python.mypy-type-checker - - ms-python.python - - ms-python.vscode-pylance - - ms-vscode.live-server - - ms-vsliveshare.vsliveshare - - redhat.vscode-yaml - - ryanluker.vscode-coverage-gutters - - soulcode.vscode-unwanted-extensions - - stkb.rewrap - - streetsidesoftware.code-spell-checker - - tamasfe.even-better-toml - - yzhang.markdown-all-in-one diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1a45fa78..84a3146c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,9 +4,7 @@ ci: skip: - check-jsonschema - mypy - - prettier - pyright - - taplo repos: - repo: meta @@ -14,11 +12,31 @@ repos: - id: check-hooks-apply - id: check-useless-excludes + - repo: https://github.com/ComPWA/policy + rev: 0.4.0 + hooks: + - id: check-dev-files + args: + - --doc-apt-packages=graphviz + - --no-prettierrc + - --pin-requirements=monthly + - --repo-name=qrules + - --repo-title=QRules + - id: colab-toc-visible + - id: fix-nbformat-version + - id: remove-empty-tags + - id: set-nb-cells + args: + - --add-install-cell + - --additional-packages=IPython + - --extras-require=doc,viz + - repo: https://github.com/kynan/nbstripout rev: 0.7.1 hooks: - id: nbstripout args: + - --drop-empty-cells - --extra-keys - | cell.attachments @@ -41,25 +59,6 @@ repos: metadata.varInspector metadata.vscode - - repo: https://github.com/ComPWA/policy - rev: 0.4.0 - hooks: - - id: check-dev-files - args: - - --doc-apt-packages=graphviz - - --no-prettierrc - - --pin-requirements=monthly - - --repo-name=qrules - - --repo-title=QRules - - id: colab-toc-visible - - id: fix-nbformat-version - - id: remove-empty-tags - - id: set-nb-cells - args: - - --add-install-cell - - --additional-packages=IPython - - --extras-require=doc,viz - - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.6.4 hooks: @@ -92,16 +91,15 @@ repos: args: ["--django"] - id: trailing-whitespace - - repo: https://github.com/pre-commit/mirrors-prettier - rev: v4.0.0-alpha.8 + - repo: https://github.com/ComPWA/prettier-pre-commit + rev: v3.3.3 hooks: - id: prettier - - repo: https://github.com/ComPWA/mirrors-taplo - rev: v0.8.1 + - repo: https://github.com/ComPWA/taplo-pre-commit + rev: v0.9.3 hooks: - - id: taplo - + - id: taplo-format - repo: https://github.com/pappasam/toml-sort rev: v0.23.1 hooks: diff --git a/.vscode/extensions.json b/.vscode/extensions.json index c48e310f..2b3cdd42 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -9,6 +9,7 @@ "github.vscode-github-actions", "github.vscode-pull-request-github", "joaompinto.vscode-graphviz", + "mhutchie.git-graph", "ms-python.mypy-type-checker", "ms-python.python", "ms-python.vscode-pylance", diff --git a/.vscode/settings.json b/.vscode/settings.json index a5b46e91..f63375fb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -34,7 +34,8 @@ "diffEditor.experimental.showMoves": true, "editor.formatOnSave": true, "files.associations": { - "**/.constraints/py*.txt": "pip-requirements" + "**/.constraints/py*.txt": "pip-requirements", + "**/pixi.lock": "yaml" }, "files.watcherExclude": { "**/*_cache/**": true, diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d514fb3e..4d2abc42 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,5 @@ # How to contribute? [![Open in Visual Studio Code](https://img.shields.io/badge/vscode-open-blue?logo=visualstudiocode)](https://open.vscode.dev/ComPWA/qrules) -[![GitPod](https://img.shields.io/badge/gitpod-open-blue?logo=gitpod)](https://gitpod.io/#https://github.com/ComPWA/qrules) This package is part of the [ComPWA Organization](https://github.com/ComPWA). For more information about how to contribute to the packages, go to [compwa.github.io/develop](https://compwa.github.io/develop)! diff --git a/README.md b/README.md index c8f8c30c..29bccede 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ [![Binder](https://static.mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/ComPWA/qrules/stable?filepath=docs/usage) [![Google Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ComPWA/qrules/blob/stable) [![Open in Visual Studio Code](https://img.shields.io/badge/vscode-open-blue?logo=visualstudiocode)](https://open.vscode.dev/ComPWA/qrules) -[![GitPod](https://img.shields.io/badge/gitpod-open-blue?logo=gitpod)](https://gitpod.io/#https://github.com/ComPWA/qrules) [![Documentation](https://readthedocs.org/projects/qrules/badge/?version=latest)](https://qrules.readthedocs.io) [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/ComPWA/qrules/main.svg)](https://results.pre-commit.ci/latest/github/ComPWA/qrules/main) diff --git a/environment.yml b/environment.yml index 866fc840..28571326 100644 --- a/environment.yml +++ b/environment.yml @@ -7,5 +7,3 @@ dependencies: - graphviz - pip: - -c .constraints/py3.9.txt -e .[dev] -variables: - PRETTIER_LEGACY_CLI: 1 diff --git a/pyproject.toml b/pyproject.toml index f836a7f9..ca0be06d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -146,6 +146,8 @@ namespaces = false where = ["src"] [tool.setuptools_scm] +local_scheme = "no-local-version" +version_scheme = "post-release" write_to = "src/qrules/version.py" [tool.coverage.run] @@ -201,6 +203,128 @@ module = ["sphinx.*"] ignore_missing_imports = true module = ["tqdm.*"] +[tool.pixi.project] +channels = ["conda-forge"] +platforms = ["linux-64"] + +[tool.pixi.activation.env] +PRETTIER_LEGACY_CLI = "1" + +[tool.pixi.dependencies] +graphviz = "*" +python = "3.9.*" + +[tool.pixi.environments] +default = {features = [ + "all", + "dev", + "doc", + "jupyter", + "sty", + "test", + "types", + "viz", +]} + +[tool.pixi.feature.dev.tasks.ci] +depends_on = ["cov", "docnb", "linkcheck", "sty"] + +[tool.pixi.feature.dev.tasks.cov] +cmd = """ +pytest tests/unit \ + --cov-fail-under=90 \ + --cov-report=html \ + --cov-report=xml \ + --cov=qrules +""" + +[tool.pixi.feature.dev.tasks.doc] +cmd = """ +sphinx-build \ + --keep-going \ + -TW \ + -b html \ + docs/ docs/_build/html +""" +env = {FORCE_COLOR = "yes"} + +[tool.pixi.feature.dev.tasks.doclive] +cmd = """ +sphinx-autobuild \ + --open-browser \ + --re-ignore .*/.ipynb_checkpoints/.* \ + --re-ignore .*/__pycache__/.* \ + --re-ignore .*\\.tmp \ + --re-ignore docs/.*\\.csv \ + --re-ignore docs/.*\\.gv \ + --re-ignore docs/.*\\.inv \ + --re-ignore docs/.*\\.json \ + --re-ignore docs/.*\\.pickle \ + --re-ignore docs/.*\\.yaml \ + --re-ignore docs/.*\\.yml \ + --re-ignore docs/_build/.* \ + --re-ignore docs/_images/.* \ + --re-ignore docs/_static/logo\\..* \ + --re-ignore docs/api/.* \ + --watch docs \ + --watch src \ + -b html \ + docs/ docs/_build/html +""" +env = {FORCE_COLOR = "yes"} + +[tool.pixi.feature.dev.tasks.docnb] +cmd = "pixi run doc" +env = {EXECUTE_NB = "yes", FORCE_COLOR = "yes"} + +[tool.pixi.feature.dev.tasks.docnb-force] +cmd = "pixi run doc" +env = {FORCE_COLOR = "yes", FORCE_EXECUTE_NB = "yes", PYTHONHASHSEED = "0"} + +[tool.pixi.feature.dev.tasks.docnblive] +cmd = "pixi run doclive" +env = {EXECUTE_NB = "yes", FORCE_COLOR = "yes", PYTHONHASHSEED = "0"} + +[tool.pixi.feature.dev.tasks.linkcheck] +cmd = """ +sphinx-build \ + -T \ + -b linkcheck \ + docs/ docs/_build/linkcheck +""" +env = {FORCE_COLOR = "yes"} + +[tool.pixi.feature.dev.tasks.nb] +cmd = "pytest --nbmake docs" + +[tool.pixi.feature.dev.tasks.pydeps] +cmd = """ +pydeps qrules \ + -o ../module_structure.svg \ + --exclude *._* \ + --max-bacon=1 \ + --noshow +""" + +[tool.pixi.feature.dev.tasks.sty] +cmd = "pre-commit run -a" +env = {SKIP = "pyright"} + +[tool.pixi.feature.dev.tasks.test] +cmd = """ +pytest \ + --cov-fail-under=90 \ + --cov-report=html \ + --cov-report=xml \ + --cov=qrules +""" + +[tool.pixi.feature.dev.tasks.tests] +cmd = "pytest src tests/unit" + +[tool.pixi.pypi-dependencies] +qrules = {path = ".", editable = true} + [tool.pyright] exclude = [ "**/.git", @@ -281,7 +405,6 @@ src = [ "src", "tests", ] -target-version = "py37" [tool.ruff.format] docstring-code-format = true @@ -398,6 +521,5 @@ sort_first = [ "tool.setuptools", "tool.setuptools_scm", ] -sort_table_keys = true spaces_indent_inline_array = 4 trailing_comma_inline_array = true diff --git a/src/qrules/solving.py b/src/qrules/solving.py index 73b22a50..8897ad06 100644 --- a/src/qrules/solving.py +++ b/src/qrules/solving.py @@ -440,16 +440,16 @@ def find_solutions(self, problem_set: QNProblemSet) -> QNResult: # noqa: C901 edge_not_satisfied_rules: dict[int, set[GraphElementRule]] = defaultdict(set) for node_id, rules in self.__node_rules.items(): for rule in rules: - if self.__scoresheet.rule_calls[(node_id, rule)] == 0: + if self.__scoresheet.rule_calls[node_id, rule] == 0: node_not_executed_rules[node_id].add(rule) - elif self.__scoresheet.rule_passes[(node_id, rule)] == 0: + elif self.__scoresheet.rule_passes[node_id, rule] == 0: node_not_satisfied_rules[node_id].add(rule) for edge_id, edge_rules in self.__edge_rules.items(): for rule in edge_rules: - if self.__scoresheet.rule_calls[(edge_id, rule)] == 0: + if self.__scoresheet.rule_calls[edge_id, rule] == 0: edge_not_executed_rules[edge_id].add(rule) - elif self.__scoresheet.rule_passes[(edge_id, rule)] == 0: + elif self.__scoresheet.rule_passes[edge_id, rule] == 0: edge_not_satisfied_rules[edge_id].add(rule) solutions = self.__convert_solution_keys(problem_set.topology, solutions) @@ -750,8 +750,8 @@ def __init__(self) -> None: def register_rule( self, graph_element_id: int, rule: Rule ) -> Callable[[bool], None]: - self.__rule_calls[(graph_element_id, rule)] = 0 - self.__rule_passes[(graph_element_id, rule)] = 0 + self.__rule_calls[graph_element_id, rule] = 0 + self.__rule_passes[graph_element_id, rule] = 0 return self.__create_callback(graph_element_id, rule) @@ -760,8 +760,8 @@ def __create_callback( ) -> Callable[[bool], None]: def passed_callback(passed: bool) -> None: if passed: - self.__rule_passes[(graph_element_id, rule)] += 1 - self.__rule_calls[(graph_element_id, rule)] += 1 + self.__rule_passes[graph_element_id, rule] += 1 + self.__rule_calls[graph_element_id, rule] += 1 return passed_callback