From 189967eb5d85c8866e425f805d0790cee232f09b Mon Sep 17 00:00:00 2001 From: Pierrick Rambaud Date: Mon, 13 Nov 2023 17:37:00 +0000 Subject: [PATCH] chore: wire the repository to the copier pypackage --- .copier-answers.yml | 12 ++ .devcontainer/devcontainer.json | 9 ++ .../PULL_REQUEST_TEMPLATE/pr_template.md | 9 +- .github/ISSUE_TEMPLATE/bug_report.md | 22 +--- .github/ISSUE_TEMPLATE/custom.md | 10 -- .github/ISSUE_TEMPLATE/feature_request.md | 7 +- .github/workflows/pypackage_check.yaml | 53 +++++++++ .../workflows/{release.yml => release.yaml} | 12 +- .github/workflows/unit.yaml | 86 ++++++++++++++ .github/workflows/unit.yml | 52 --------- .gitignore | 9 +- .pre-commit-config.yaml | 52 +++++++-- .readthedocs.yaml | 22 ++-- AUTHORS.rst | 24 ++-- CHANGELOG.md | 41 ------- CITATION.cff | 12 +- CODE_OF_CONDUCT.rst | 2 +- CONTRIBUTING.rst | 109 +++++++++++------- README.rst | 4 +- docs/{source => }/_static/.gitignore | 0 docs/{source => }/_static/custom.css | 0 docs/{source => }/_static/example.png | Bin docs/{source => }/_templates/.gitignore | 0 docs/authors.rst | 4 + docs/{source => }/conf.py | 2 +- docs/{source => }/contribute.rst | 0 .../examples/data/iris_quantum_kernel.npy | Bin docs/{source => }/examples/demo.ipynb | 0 docs/{source => }/index.rst | 5 +- docs/{source => }/install.rst | 0 docs/source/authors.rst | 4 - noxfile.py | 75 +++++++----- pyproject.toml | 107 +++++++++-------- qutree/__init__.py | 8 +- qutree/py.typed | 1 + setup.py | 5 - warnings.txt | 12 ++ 37 files changed, 458 insertions(+), 312 deletions(-) create mode 100644 .copier-answers.yml create mode 100644 .devcontainer/devcontainer.json rename .github/{ => ISSUE_TEMPLATE}/PULL_REQUEST_TEMPLATE/pr_template.md (81%) delete mode 100644 .github/ISSUE_TEMPLATE/custom.md create mode 100644 .github/workflows/pypackage_check.yaml rename .github/workflows/{release.yml => release.yaml} (61%) create mode 100644 .github/workflows/unit.yaml delete mode 100644 .github/workflows/unit.yml delete mode 100644 CHANGELOG.md rename docs/{source => }/_static/.gitignore (100%) rename docs/{source => }/_static/custom.css (100%) rename docs/{source => }/_static/example.png (100%) rename docs/{source => }/_templates/.gitignore (100%) create mode 100644 docs/authors.rst rename docs/{source => }/conf.py (99%) rename docs/{source => }/contribute.rst (100%) rename docs/{source => }/examples/data/iris_quantum_kernel.npy (100%) rename docs/{source => }/examples/demo.ipynb (100%) rename docs/{source => }/index.rst (80%) rename docs/{source => }/install.rst (100%) delete mode 100644 docs/source/authors.rst create mode 100644 qutree/py.typed delete mode 100644 setup.py create mode 100644 warnings.txt diff --git a/.copier-answers.yml b/.copier-answers.yml new file mode 100644 index 0000000..d1e7644 --- /dev/null +++ b/.copier-answers.yml @@ -0,0 +1,12 @@ +# Changes here will be overwritten by Copier +_commit: 0.1.5 +_src_path: gh:12rambau/pypackage +author_email: alice.barthe@cern.ch +author_first_name: Alice +author_last_name: Barthe +author_orcid: 0000-0002-1766-188X +github_repo_name: qutree +github_user: alice4space +project_name: qutree +project_slug: qutree +short_description: plot Bloch Sphere Binary Tree diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..8e7ad66 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,9 @@ +{ + "name": "Python 3", + "image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye", + "features": { + "ghcr.io/devcontainers-contrib/features/nox:2": {}, + "ghcr.io/devcontainers-contrib/features/pre-commit:2": {} + }, + "postCreateCommand": "pre-commit install" +} diff --git a/.github/PULL_REQUEST_TEMPLATE/pr_template.md b/.github/ISSUE_TEMPLATE/PULL_REQUEST_TEMPLATE/pr_template.md similarity index 81% rename from .github/PULL_REQUEST_TEMPLATE/pr_template.md rename to .github/ISSUE_TEMPLATE/PULL_REQUEST_TEMPLATE/pr_template.md index e625fb3..f9c309e 100644 --- a/.github/PULL_REQUEST_TEMPLATE/pr_template.md +++ b/.github/ISSUE_TEMPLATE/PULL_REQUEST_TEMPLATE/pr_template.md @@ -1,10 +1,9 @@ --- name: Pull request template about: Create a pull request -title: '' -labels: '' -assignees: '' - +title: "" +labels: "" +assignees: "" --- ## reference the related issue @@ -21,4 +20,4 @@ Describe the changes you propose ## comments -any other comments we should pay attention to \ No newline at end of file +any other comments we should pay attention to diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index dd84ea7..25ea003 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,10 +1,9 @@ --- name: Bug report about: Create a report to help us improve -title: '' -labels: '' -assignees: '' - +title: "" +labels: "" +assignees: "" --- **Describe the bug** @@ -12,27 +11,14 @@ A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: + 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' 4. See error -**Expected behavior** -A clear and concise description of what you expected to happen. - **Screenshots** If applicable, add screenshots to help explain your problem. -**Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] - -**Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] - **Additional context** Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/custom.md deleted file mode 100644 index 48d5f81..0000000 --- a/.github/ISSUE_TEMPLATE/custom.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -name: Custom issue template -about: Describe this issue template's purpose here. -title: '' -labels: '' -assignees: '' - ---- - - diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index bbcbbe7..2bc5d5f 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,10 +1,9 @@ --- name: Feature request about: Suggest an idea for this project -title: '' -labels: '' -assignees: '' - +title: "" +labels: "" +assignees: "" --- **Is your feature request related to a problem? Please describe.** diff --git a/.github/workflows/pypackage_check.yaml b/.github/workflows/pypackage_check.yaml new file mode 100644 index 0000000..69e6a47 --- /dev/null +++ b/.github/workflows/pypackage_check.yaml @@ -0,0 +1,53 @@ +name: template update check + +on: + workflow_dispatch: + schedule: + - cron: '0 0 1 * *' # Run at 00:00 on the first day of each month + +jobs: + check_version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.10" + - name: install dependencies + run: pip install requests + - name: get latest pypackage release + id: get_latest_release + run: | + RELEASE=$(curl -s https://api.github.com/repos/12rambau/pypackage/releases | jq -r '.[0].tag_name') + echo "latest=$RELEASE" >> $GITHUB_OUTPUT + echo "latest release: $RELEASE" + - name: get current pypackage version + id: get_current_version + run: | + RELEASE=$(yq -r "._commit" .copier-answers.yml) + echo "current=$RELEASE" >> $GITHUB_OUTPUT + echo "current release: $RELEASE" + - name: open issue + if: steps.get_current_version.outputs.current != steps.get_latest_release.outputs.latest + uses: rishabhgupta/git-action-issue@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + title: "Update template to ${{ steps.get_latest_release.outputs.latest }}" + body: | + The package is based on the ${{ steps.get_current_version.outputs.current }} version of [@12rambau/pypackage](https://github.com/12rambau/pypackage). + + The latest version of the template is ${{ steps.get_latest_release.outputs.latest }}. + + Please consider updating the template to the latest version to include all the latest developments. + + Run the following code in your project directory to update the template: + + ``` + copier update --trust --defaults --vcs-ref ${{ steps.get_latest_release.outputs.latest }} + ``` + + > **Note** + > You may need to reinstall ``copier`` and ``jinja2-time`` if they are not available in your environment. + + After solving the merging issues you can push back the changes to your main branch. + diff --git a/.github/workflows/release.yml b/.github/workflows/release.yaml similarity index 61% rename from .github/workflows/release.yml rename to .github/workflows/release.yaml index 7700ac6..af4ca67 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yaml @@ -9,12 +9,14 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.10" - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine build + run: pip install twine build nox + - name: update citation date + run: nox -s release-date - name: Build and publish env: TWINE_USERNAME: __token__ diff --git a/.github/workflows/unit.yaml b/.github/workflows/unit.yaml new file mode 100644 index 0000000..e70417b --- /dev/null +++ b/.github/workflows/unit.yaml @@ -0,0 +1,86 @@ +name: Unit tests + +on: + push: + branches: + - main + pull_request: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.10" + - uses: pre-commit/action@v3.0.0 + + mypy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.10" + - name: Install nox + run: pip install nox + - name: run mypy checks + run: nox -s mypy + + docs: + needs: [lint, mypy] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.10" + - name: Install nox + run: pip install nox + - name: build static docs + run: nox -s docs + + build: + needs: [lint, mypy] + strategy: + fail-fast: true + matrix: + os: [ubuntu-latest] + python-version: ["3.8", "3.9", "3.10", "3.11"] + include: + - os: macos-latest # macos test + python-version: "3.11" + - os: windows-latest # windows test + python-version: "3.11" + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install nox + run: pip install nox + - name: test with pytest + run: nox -s test + + coverage: + needs: [build] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.10" + - name: Install deps + run: pip install nox + - name: test with pytest + run: nox -s test + - name: assess dead fixtures + run: nox -s dead-fixtures + - name: codecov + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml deleted file mode 100644 index 03590ac..0000000 --- a/.github/workflows/unit.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Build - -on: - - push - - workflow_dispatch - -jobs: - - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: "3.8" - - uses: pre-commit/action@v3.0.0 - - name: mypy - uses: jpetrucciani/mypy-check@master - with: - path: './qutree' - requirements: "." - mypy_flags: | - --config-file ./pyproject.toml - --scripts-are-modules - --ignore-missing-imports - --install-types - --non-interactive - --disable-error-code func-returns-value - --warn-redundant-casts - - build: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - python-version: ["3.7", "3.8", "3.9", "3.10"] - - steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: pip install .[test] - - name: test with pytest - run: pytest --color=yes --cov --cov-report=xml tests - - name: codecov - uses: codecov/codecov-action@v3 - with: - token: ${{ secrets.CODECOV_TOKEN }} - verbose: true diff --git a/.gitignore b/.gitignore index d5bcfd0..857afd2 100644 --- a/.gitignore +++ b/.gitignore @@ -71,7 +71,7 @@ instance/ # Sphinx documentation docs/_build/ -docs/source/_api/ +docs/api/ # PyBuilder target/ @@ -130,5 +130,8 @@ dmypy.json # Pyre type checker .pyre/ -# system IDE -.vscode/ \ No newline at end of file +# system IDE +.vscode/ + +# image tmp file +*Zone.Identifier \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 35a2050..67a3941 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,23 +1,61 @@ default_install_hook_types: [pre-commit, commit-msg] repos: - - repo: 'https://github.com/psf/black' - rev: 22.3.0 + - repo: "https://github.com/psf/black" + rev: "22.3.0" hooks: - id: black stages: [commit] - - repo: 'https://github.com/commitizen-tools/commitizen' - rev: v2.18.0 + + - repo: "https://github.com/commitizen-tools/commitizen" + rev: "v2.18.0" hooks: - id: commitizen stages: [commit-msg] - - repo: 'https://github.com/kynan/nbstripout' - rev: 0.5.0 + + - repo: "https://github.com/kynan/nbstripout" + rev: "0.5.0" hooks: - id: nbstripout stages: [commit] + + - repo: "https://github.com/pre-commit/mirrors-prettier" + rev: "v2.7.1" + hooks: + - id: prettier + stages: [commit] + exclude: tests\/test_.+\. + - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: "v0.0.226" + rev: "v0.0.215" hooks: - id: ruff stages: [commit] + + - repo: https://github.com/PyCQA/doc8 + rev: "v1.1.1" + hooks: + - id: doc8 + stages: [commit] + + - repo: https://github.com/FHPythonUtils/LicenseCheck + rev: "2023.5.1" + hooks: + - id: licensecheck + stages: [commit] + + - repo: https://github.com/codespell-project/codespell + rev: v2.2.4 + hooks: + - id: codespell + stages: [commit] + additional_dependencies: + - tomli + + # Prevent committing inline conflict markers + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 + hooks: + - id: check-merge-conflict + stages: [commit] + args: [--assume-in-merge] diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 4cfb926..8237ac8 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -1,24 +1,18 @@ +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details -# -- Required ------------------------------------------------------------------ version: 2 -# -- build environment --------------------------------------------------------- build: - os: ubuntu-20.04 + os: ubuntu-22.04 tools: - python: "3.9" - jobs: - pre_build: - - sphinx-apidoc --force --module-first -o docs/source/_api ./qutree + python: "3.10" -# -- conf location ------------------------------------------------------------- sphinx: - configuration: docs/source/conf.py + configuration: docs/conf.py -# -- requirements -------------------------------------------------------------- python: install: - - method: pip - path: . - extra_requirements: - - doc + - method: pip + path: . + extra_requirements: + - doc diff --git a/AUTHORS.rst b/AUTHORS.rst index 82a8b0e..6dbb683 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -10,14 +10,14 @@ Thanks goes to these wonderful people (`emoji key Alice Barthe
- πŸ’» - πŸ€” - πŸ’¬ + πŸ’» + πŸ€” + πŸ’¬
- πŸ› - 🚧 + πŸ› + 🚧 πŸ‘€ -
+
πŸ’‘ @@ -28,12 +28,12 @@ Thanks goes to these wonderful people (`emoji key Pierrick Rambaud
- πŸ’» - πŸ› - πŸ“– + πŸ’» + πŸ› + πŸ“–
- 🚧 - πŸ‘€ + 🚧 + πŸ‘€ ⚠️
πŸš‡ @@ -43,4 +43,4 @@ Thanks goes to these wonderful people (`emoji key `_ specification. -Contributions of any kind are welcome! \ No newline at end of file +Contributions of any kind are welcome! diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index b43a834..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,41 +0,0 @@ -## v0.1.1 (2023-02-13) - -### Fix - -- refactor release env -- make bloch sphere background transparent - -### Refactor - -- replace link from 12rambau branch -- move the badges to the top of the file - -## v0.1.0 (2023-01-20) - -### Fix - -- use file from git repo - -### Refactor - -- typo in binder link -- typo in binder link - -## v0.0.0 (2023-01-20) - -### Feat - -- add dst file option (#6) -- add demo -- add BBT class - -### Fix - -- use any pathlike object -- access distant data in examples -- improve CD/CI - -### Refactor - -- solve mypy checks -- lint with ruff diff --git a/CITATION.cff b/CITATION.cff index 4cbde10..7c2ad93 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -11,24 +11,24 @@ authors: - given-names: Alice family-names: Barthe email: alice.barthe@cern.ch - affiliation: 'CERN, Leiden University' - orcid: 'https://orcid.org/0000-0002-1766-188X' + affiliation: "CERN, Leiden University" + orcid: "https://orcid.org/0000-0002-1766-188X" - given-names: Pierrick family-names: Rambaud email: pierrick.rambaud@fao.org affiliation: FAO - orcid: 'https://orcid.org/0000-0001-8764-5749' + orcid: "https://orcid.org/0000-0001-8764-5749" identifiers: - type: doi value: 10.5281/zenodo.7634517 -repository-code: 'https://github.com/alice4space/qutree' -url: 'https://pyqutree.readthedocs.io/en/stable/' +repository-code: "https://github.com/alice4space/qutree" +url: "https://pyqutree.readthedocs.io/en/stable/" abstract: >- This work presents an extension to the Bloch Sphere that allows to represent sets of multi-qubit pure states. The code includes the recursive algorithm to derive such representation from state vector coordinates, as well as - assciated plotting capacities. + associated plotting capacities. keywords: - quantum - qubit diff --git a/CODE_OF_CONDUCT.rst b/CODE_OF_CONDUCT.rst index b911cff..8d62350 100644 --- a/CODE_OF_CONDUCT.rst +++ b/CODE_OF_CONDUCT.rst @@ -137,4 +137,4 @@ enforcement ladder](https://github.com/mozilla/diversity). For answers to common questions about this code of conduct, see the FAQ at https://www.contributor-covenant.org/faq. Translations are available at -https://www.contributor-covenant.org/translations. \ No newline at end of file +https://www.contributor-covenant.org/translations. diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index d453610..89d3006 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -1,83 +1,108 @@ Contribute ========== -After forking the projet, run the following command to start developing: +Thank you for your help improving **qutree**! + +**qutree** uses `nox `__ to automate several development-related tasks. +Currently, the project uses four automation processes (called sessions) in ``noxfile.py``: + +- ``mypy``: to perform a mypy check on the lib; +- ``test``: to run the test with pytest; +- ``docs``: to build the documentation in the ``build`` folder; +- ``lint``: to run the pre-commits in an isolated environment + +Every nox session is run in its own virtual environment, and the dependencies are installed automatically. + +To run a specific nox automation process, use the following command: .. code-block:: console - git clone https://github.com/alice4space/qutree.git - cd qutree - pip install -e .[dev] + nox -s + +For example: ``nox -s test`` or ``nox -s docs``. + +Workflow for contributing changes +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +We follow a typical GitHub workflow of: + +- Create a personal fork of this repo +- Create a branch +- Open a pull request +- Fix findings of various linters and checks +- Work through code review -Nox ---- +See the following sections for more details. -:code:`nox` can be used to automatically create isolated local development environments with all of the correct packages installed to work on the lib. The rest of this guide focuses on using nox to start with a basic environment. +Clone the repository +^^^^^^^^^^^^^^^^^^^^ -You can call :code:`nox` from the command line in order to perform common actions that are needed in building the lib. :code:`nox` operates with isolated environments, so each action has its own packages installed in a local directory (:code:`.nox`). For common development actions, you’ll simply need to use :code:`nox` and won’t need to set up any other packages. - -Pre-commit hooks ----------------- +First off, you'll need your own copy of **qutree** codebase. You can clone it for local development like so: -:code:`pre-commit` allows us to run several checks on the codebase every time a new Git commit is made. This ensures standards and basic quality control for our code. +Fork the repository so you have your own copy on GitHub. See the `GitHub forking guide for more information `__. -Install the pre-commit in the repository: +Then, clone the repository locally so that you have a local copy to work on: .. code-block:: console - pre-commit install -t pre-commit -t commit-msg + git clone https://github.com//qutree + cd qutree -Linting operations will be run automatically for every downstream commit. +Then install the development version of the extension: -.. note:: +.. code-block:: console + + pip install -e .[dev] - to run liniting operation without commiting your change execute the following: +This will install the **qutree** library, together with two additional tools: +- `pre-commit `__ for automatically enforcing code standards and quality checks before commits. +- `nox `__, for automating common development tasks. - .. code-block:: console +Lastly, activate the pre-commit hooks by running: - nox -s lint +.. code-block:: console -Mypy ----- + pre-commit install -Mypy is a static type checker for Python. +This will install the necessary dependencies to run pre-commit every time you make a commit with Git. -Type checkers help ensure that you're using variables and functions in your code correctly. With mypy, add type hints (PEP 484) to your Python programs, and mypy will warn you when you use those types incorrectly. +Contribute to the codebase +^^^^^^^^^^^^^^^^^^^^^^^^^^ -Python is a dynamic language, so usually you'll only see errors in your code when you attempt to run it. Mypy is a static checker, so it finds bugs in your programs without even running them! +Any larger updates to the codebase should include tests and documentation. The tests are located in the ``tests`` folder, and the documentation is located in the ``docs`` folder. -to run the MyPy checks run: +To run the tests locally, use the following command: .. code-block:: console - nox -s mypy + nox -s test + +See :ref:`below ` for more information on how to update the documentation. -Documentation -------------- +.. _contributing-docs: -We build our documentation within the :code:`Sphinx` framework. execute the associated nox to build the file and produce the associated HTML: +Contribute to the docs +^^^^^^^^^^^^^^^^^^^^^^ + +The documentation is built using `Sphinx `__ and deployed to `Read the Docs `__. + +To build the documentation locally, use the following command: .. code-block:: console nox -s docs -The index file will be in :code:`./docs/build/html/index.html`. +For each pull request, the documentation is built and deployed to make it easier to review the changes in the PR. To access the docs build from a PR, click on the "Read the Docs" preview in the CI/CD jobs. -Release -------- +Release new version +^^^^^^^^^^^^^^^^^^^ -You need to use the :code:`commitizen` lib to create your release: ``__. - -In the files change the version number by runnning commitizen `bump`: +To release a new version, start by pushing a new bump from the local directory: -.. code-block:: console +.. code-block:: cz bump -It should modify for you the version number in :code:`qutree/__init__.py` and :code:`pyproject.toml` according to sementic versionning thanks to the conventional commit that we use in the lib. - -It will also update the :code:`CHANGELOG.md` file with the latest commits, sorted by categories. +The commitizen-tool will detect the semantic version name based on the existing commits messages. -You can now create a new tag with your new version number. use the same convention as the one found in :code:`pyproject.toml`: :code:`v$minor.$major.$patch$prerelease`. - -The CI should take everything in control from here and execute the :code:`Upload Python Package` GitHub Action that is publishing the new version on `PyPi `_. +Then push to Github. In Github design a new release using the same tag name nad the ``release.yaml`` job will send it to pipy. diff --git a/README.rst b/README.rst index 5927b18..cefcb38 100644 --- a/README.rst +++ b/README.rst @@ -20,7 +20,7 @@ qutree .. image:: https://img.shields.io/pypi/v/qutree?color=orange&logo=python&logoColor=white :target: https://pypi.org/project/qutree :alt: PyPI - + .. image:: https://img.shields.io/pypi/dm/qutree?logo=python&logoColor=white :target: https://pypi.org/project/qutree :alt: PyPI - Downloads @@ -89,7 +89,7 @@ If you find qutree useful in your research, please consider citing the following - Barthe, A., Grossi, M., Tura, J., and Dunjko, V.. (2023). Bloch Sphere Binary Trees: A method for the visualization of sets of multi-qubit systems pure states. https://doi.org/10.48550/arXiv.2302.02957 - + - Rambaud, P., Barthe, A.. (2023). qutree. Zenodo. https://doi.org/10.5281/zenodo.7634518 Contribute diff --git a/docs/source/_static/.gitignore b/docs/_static/.gitignore similarity index 100% rename from docs/source/_static/.gitignore rename to docs/_static/.gitignore diff --git a/docs/source/_static/custom.css b/docs/_static/custom.css similarity index 100% rename from docs/source/_static/custom.css rename to docs/_static/custom.css diff --git a/docs/source/_static/example.png b/docs/_static/example.png similarity index 100% rename from docs/source/_static/example.png rename to docs/_static/example.png diff --git a/docs/source/_templates/.gitignore b/docs/_templates/.gitignore similarity index 100% rename from docs/source/_templates/.gitignore rename to docs/_templates/.gitignore diff --git a/docs/authors.rst b/docs/authors.rst new file mode 100644 index 0000000..bcd0a5d --- /dev/null +++ b/docs/authors.rst @@ -0,0 +1,4 @@ +Authors +======= + +.. include :: ../../AUTHORS.rst diff --git a/docs/source/conf.py b/docs/conf.py similarity index 99% rename from docs/source/conf.py rename to docs/conf.py index 05494aa..b47c5da 100644 --- a/docs/source/conf.py +++ b/docs/conf.py @@ -28,7 +28,7 @@ "sphinx.ext.autosummary", "sphinx.ext.napoleon", "sphinx.ext.viewcode", - "nbsphinx", + "myst_nb", "sphinx_copybutton", # https://github.com/spatialaudio/nbsphinx/issues/687 "IPython.sphinxext.ipython_console_highlighting", diff --git a/docs/source/contribute.rst b/docs/contribute.rst similarity index 100% rename from docs/source/contribute.rst rename to docs/contribute.rst diff --git a/docs/source/examples/data/iris_quantum_kernel.npy b/docs/examples/data/iris_quantum_kernel.npy similarity index 100% rename from docs/source/examples/data/iris_quantum_kernel.npy rename to docs/examples/data/iris_quantum_kernel.npy diff --git a/docs/source/examples/demo.ipynb b/docs/examples/demo.ipynb similarity index 100% rename from docs/source/examples/demo.ipynb rename to docs/examples/demo.ipynb diff --git a/docs/source/index.rst b/docs/index.rst similarity index 80% rename from docs/source/index.rst rename to docs/index.rst index caed9c1..769397c 100644 --- a/docs/source/index.rst +++ b/docs/index.rst @@ -6,8 +6,7 @@ install Examples - API <_api/modules> contribute authors - - + + diff --git a/docs/source/install.rst b/docs/install.rst similarity index 100% rename from docs/source/install.rst rename to docs/install.rst diff --git a/docs/source/authors.rst b/docs/source/authors.rst deleted file mode 100644 index 3fa75ea..0000000 --- a/docs/source/authors.rst +++ /dev/null @@ -1,4 +0,0 @@ -Authors -======= - -.. include :: ../../AUTHORS.rst \ No newline at end of file diff --git a/noxfile.py b/noxfile.py index 0539ca9..94d0f24 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,50 +1,69 @@ -"""Define nox sessions for running tests and checks.""" +"""All the process that can be run using nox. + +The nox run are build in isolated environment that will be stored in .nox. to force the venv update, remove the .nox/xxx folder. +""" +import datetime +import fileinput import nox +nox.options.sessions = ["lint", "test", "docs", "mypy"] + @nox.session(reuse_venv=True) def lint(session): - """Lint everything possible using the pre-commit environment.""" + """Apply the pre-commits.""" session.install("pre-commit") - session.run("pre-commit", "run", "--a", *session.posargs) + session.run("pre-commit", "run", "--all-files", *session.posargs) -@nox.session(python=["3.7", "3.8", "3.9"]) +@nox.session(reuse_venv=True) def test(session): - """Run the lib test and export a coverage as html.""" + """Run all the test using the environment variable of the running machine.""" + session.install(".[test]") + test_files = session.posargs or ["tests"] + session.run("pytest", "--color=yes", "--cov", "--cov-report=xml", *test_files) + + +@nox.session(reuse_venv=True, name="dead-fixtures") +def dead_fixtures(session): + """Check for dead fixtures within the tests.""" session.install(".[test]") - session.run("pytest", "--color=yes", "--cov", "--cov-report=html", "tests") + session.run("pytest", "--dead-fixtures") @nox.session(reuse_venv=True) def docs(session): - """Build the html docs.""" + """Build the documentation.""" + build = session.posargs.pop() if session.posargs else "html" session.install(".[doc]") - session.run( - "sphinx-apidoc", - "--force", - "--module-first", - "-o", - "docs/source/_api", - "./qutree", - ) - session.run("sphinx-build", "-b", "html", "docs/source", "docs/build/html") + session.run("sphinx-build", "-v", "-b", build, "docs", f"docs/_build/{build}") @nox.session(name="mypy", reuse_venv=True) def mypy(session): """Run a mypy check of the lib.""" - session.install(".[dev]") + session.install("mypy") test_files = session.posargs or ["qutree"] - session.run( - "mypy", - "--scripts-are-modules", - "--ignore-missing-imports", - "--install-types", - "--non-interactive", - "--disable-error-code", - "func-returns-value", - "--warn-redundant-casts", - *test_files, - ) + session.run("mypy", *test_files) + + +@nox.session(reuse_venv=True) +def stubgen(session): + """Generate stub files for the lib but requires human attention before merge.""" + session.install("mypy") + package = session.posargs or ["qutree"] + session.run("stubgen", "-p", package[0], "-o", "stubs", "--include-private") + + +@nox.session(name="release-date", reuse_venv=True) +def release_date(session): + """Update the release date of the citation file.""" + current_date = datetime.datetime.now().strftime("%Y-%m-%d") + + with fileinput.FileInput("CITATION.cff", inplace=True) as file: + for line in file: + if line.startswith("date-released:"): + print(f'date-released: "{current_date}"') + else: + print(line, end="") diff --git a/pyproject.toml b/pyproject.toml index 79eb8e0..61b319a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,27 +1,30 @@ [build-system] -requires = ["setuptools>=61.2", "wheel"] -build-backend = "setuptools.build_meta" +requires = ["hatchling"] +build-backend = "hatchling.build" [project] name = "qutree" version = "0.1.1" description = "plot Bloch Sphere Binary Tree" -keywords = ["QTI", "Python"] +keywords = [ + "QTI", + "Python" +] classifiers = [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Topic :: Scientific/Engineering :: Physics", "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", ] -requires-python = ">=3.6.9" +requires-python = ">=3.8" dependencies = [ - "Deprecated", - "numpy", - "matplotlib", - "qutip" + "deprecated>=1.2.14", + "numpy", + "matplotlib", + "qutip", ] [[project.authors]] @@ -36,64 +39,62 @@ file = "README.rst" content-type = "text/x-rst" [project.urls] -Homepage = "https://github.com/alice4space/bbt" -Download = "https://github.com/alice4space/bbt/archive/${metadata:version}.tar.gz" +Homepage = "https://github.com/alice4space/qutree" [project.optional-dependencies] -dev = [ - "pre-commit", - "commitizen", - "nox", - "mypy", -] test = [ - "pytest", - "pytest-sugar", - "pytest-icdiff", - "pytest-cov", - "Flake8-pyproject", + "pytest", + "pytest-sugar", + "pytest-cov", + "pytest-deadfixtures" ] doc = [ - "Sphinx<6", - "pydata-sphinx-theme", - "nox", - "ipykernel", # for readthedocs - "nbsphinx", - "sphinx-copybutton", - # to run the examples - "ipython", - "pennylane", + "sphinx>=6.2.1", + "pydata-sphinx-theme", + "sphinx-copybutton", + "sphinx-design", + "ipykernel", + "ipython", + "myst-nb", + "pennylane", + ] demo = [ - "ipython", - "pennylane", + "ipython", + "pennylane", ] -[tool.setuptools] -include-package-data = true -packages = ["qutree"] -license-files = ["LICENSE"] +[tool.hatch.build.targets.wheel] +only-include = ["qutree"] + +[tool.hatch.envs.default] +dependencies = [ + "pre-commit", + "commitizen", + "nox" +] +post-install-commands = ["pre-commit install"] [tool.commitizen] -changelog_file = "CHANGELOG.md" tag_format = "v$major.$minor.$patch$prerelease" -update_changelog_on_bump = true +update_changelog_on_bump = false version = "0.1.1" -version_files = ["pyproject.toml:version", "qutree/__init__.py:__version__"] +version_files = [ + "pyproject.toml:version", + "qutree/__init__.py:__version__", +] [tool.pytest.ini_options] testpaths = "tests" -[tool.coverage.run] -source = ["qutree"] - [tool.ruff] ignore-init-module-imports = true fix = true select = ["E", "F", "W", "I", "D", "RUF"] ignore = [ - "E501", # line too long | Black take care of it - "D101", # Missing docstring in public class | set in the __init__ method only + "E501", # line too long | Black take care of it + "D101", # Missing docstring in public class | set in the __init__ method only + "D212", # Multi-line docstring | We use D213 ] [tool.ruff.flake8-quotes] @@ -104,3 +105,19 @@ convention = "google" [tool.ruff.per-file-ignores] "tests/*.py" = ["D"] # no docstring for the tests + +[tool.coverage.run] +source = ["qutree"] + +[tool.doc8] +ignore = ["D001"] # we follow a 1 line = 1 paragraph style + +[tool.mypy] +scripts_are_modules = true +ignore_missing_imports = true +install_types = true +non_interactive = true +warn_redundant_casts = true + +[tool.licensecheck] +using = "PEP631" diff --git a/qutree/__init__.py b/qutree/__init__.py index 58bc21d..345e405 100644 --- a/qutree/__init__.py +++ b/qutree/__init__.py @@ -31,7 +31,7 @@ def nphi_psi(psi: np.ndarray) -> Tuple[np.ndarray, np.ndarray]: def nthe_n0n1(n0: np.ndarray, n1: np.ndarray) -> Tuple[np.ndarray, np.ndarray]: - r"""Carthesian to Polar. + r"""Cartesian to Polar. Compute :math:`n` and :math:`\theta` such that :math:`[n0,n1] = n[cos(\theta),sin(\theta)]` @@ -68,7 +68,7 @@ def phimp_phi01(phi0, phi1): def thephi_to_xyz( the: np.ndarray, phi: np.ndarray ) -> Tuple[np.ndarray, np.ndarray, np.ndarray]: - r"""Spherical to carthesian. + r"""Spherical to cartesian. Args: the: array of the angles :math:`[0,\pi]` @@ -208,7 +208,7 @@ def add_data( """ assert ( states.shape[0] == 2**self.num_qubits - ), "The data doesnt fit the expected number of qubits" + ), "The data doesn't fit the expected number of qubits" assert len(states.shape) == 2, "the data must be a 2D tensor" self.num_samples = states.shape[1] @@ -240,7 +240,7 @@ def add_data( ): # case in which the color is a a 1D tensor, create colors matrix with cmap assert ( colors.shape[0] == self.num_samples - ), "the colors must have the same legth as the number of samples" + ), "the colors must have the same length as the number of samples" cm_custom = cm.get_cmap(cmap, 256) self.samples_colors = cm_custom(colors) else: diff --git a/qutree/py.typed b/qutree/py.typed new file mode 100644 index 0000000..2c85c45 --- /dev/null +++ b/qutree/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561. The mypy package uses inline types. \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index 52427c6..0000000 --- a/setup.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Minimal configuration for setuptools.""" - -import setuptools - -setuptools.setup() diff --git a/warnings.txt b/warnings.txt new file mode 100644 index 0000000..ee140f8 --- /dev/null +++ b/warnings.txt @@ -0,0 +1,12 @@ + +Traceback (most recent call last): + File "/mnt/e/WSL/Users/rambap/github/qutree/.nox/docs/lib/python3.9/site-packages/sphinx/cmd/build.py", line 293, in build_main + app = Sphinx(args.sourcedir, args.confdir, args.outputdir, + File "/mnt/e/WSL/Users/rambap/github/qutree/.nox/docs/lib/python3.9/site-packages/sphinx/application.py", line 211, in __init__ + self.config = Config.read(self.confdir, confoverrides or {}, self.tags) + File "/mnt/e/WSL/Users/rambap/github/qutree/.nox/docs/lib/python3.9/site-packages/sphinx/config.py", line 179, in read + raise ConfigError(__("config directory doesn't contain a conf.py file (%s)") % +sphinx.errors.ConfigError: config directory doesn't contain a conf.py file (/mnt/e/WSL/Users/rambap/github/qutree/docs) + +Configuration error: +config directory doesn't contain a conf.py file (/mnt/e/WSL/Users/rambap/github/qutree/docs)