From c9cdc55d1a0fee7aeaf02951d58d5cf36806aa52 Mon Sep 17 00:00:00 2001 From: Roland-djee <9250798+Roland-djee@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:26:37 +0000 Subject: [PATCH] [Infra] Repo initialisation (#2) * Repo initialisation from template. * Adapt template to new package. * Fix import and add precommits file. * Trusted publishing and build docs workflow. * Correct README. * Correct import. --- .github/workflows/build_docs.yml | 48 +++++++++ .github/workflows/lint.yml | 31 ++++++ .github/workflows/test_fast.yml | 112 ++++++++++++++++++++ .gitignore | 169 ++++++------------------------- .pre-commit-config.yaml | 31 ++++++ README.md | 65 +++++++++++- docs/css/mkdocstrings.css | 11 ++ docs/index.md | 116 +++++++++++++++++++++ docs/javascripts/mathjax.js | 16 +++ docs/requirements.txt | 7 ++ docs/sample_page.md | 8 ++ mkdocs.yml | 79 +++++++++++++++ pyproject.toml | 164 ++++++++++++++++++++++++++++++ qadence_libs/__init__.py | 0 qadence_libs/main.py | 15 +++ setup.py | 5 + tests/conftest.py | 2 + tests/test_main.py | 16 +++ 18 files changed, 754 insertions(+), 141 deletions(-) create mode 100644 .github/workflows/build_docs.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/test_fast.yml create mode 100644 .pre-commit-config.yaml create mode 100644 docs/css/mkdocstrings.css create mode 100644 docs/index.md create mode 100644 docs/javascripts/mathjax.js create mode 100644 docs/requirements.txt create mode 100644 docs/sample_page.md create mode 100644 mkdocs.yml create mode 100644 pyproject.toml create mode 100644 qadence_libs/__init__.py create mode 100644 qadence_libs/main.py create mode 100644 setup.py create mode 100644 tests/conftest.py create mode 100644 tests/test_main.py diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml new file mode 100644 index 0000000..451f85d --- /dev/null +++ b/.github/workflows/build_docs.yml @@ -0,0 +1,48 @@ +name: Documentation + +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: {} + +concurrency: + group: docs-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + test_qadence_ubuntu: + name: docs (ubuntu) + runs-on: ubuntu-latest + steps: + + - name: Checkout Qadence + uses: actions/checkout@v4 + + - name: Install JetBrains Mono font + run: | + sudo apt install -y wget unzip fontconfig + wget https://download.jetbrains.com/fonts/JetBrainsMono-2.304.zip + unzip JetBrainsMono-2.304.zip -d JetBrainsMono + mkdir -p /usr/share/fonts/truetype/jetbrains + cp JetBrainsMono/fonts/ttf/*.ttf /usr/share/fonts/truetype/jetbrains/ + fc-cache -f -v + + - name: Install graphviz + run: sudo apt-get install -y graphviz + + - name: Set up Python 3.10 + uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: Install Hatch + run: | + pip install hatch + + - name: Build docs + run: | + hatch -v run docs:build diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..6d2ce72 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,31 @@ +name: Linting + +on: + push: + branches: + - main + pull_request: {} + workflow_dispatch: {} + +jobs: + lint: + + runs-on: ubuntu-latest + + steps: + - name: Checkout Qadence Libs + uses: actions/checkout@v4 + + - name: Set up Python 3.x + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Install pre-commit + run: | + pip install pre-commit + pre-commit install + + - name: Check files + run: | + pre-commit run --all-files diff --git a/.github/workflows/test_fast.yml b/.github/workflows/test_fast.yml new file mode 100644 index 0000000..24db091 --- /dev/null +++ b/.github/workflows/test_fast.yml @@ -0,0 +1,112 @@ +name: Tests + +on: + push: + branches: + - main + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + pull_request: + branches: + - main + workflow_dispatch: {} + +concurrency: + group: fast-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + + test_libs_ubuntu: + name: Qadence Libs (ubuntu) + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9", "3.10", "3.11"] + steps: + - name: Checkout Qadence Libs + uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install Hatch + run: | + pip install hatch + - name: Run fast tests + run: | + hatch -v run test + - name: Upload coverage data + uses: actions/upload-artifact@v4 + with: + name: "coverage-data" + path: .coverage.* + if-no-files-found: ignore + + publish: + name: Publish to PyPI + if: startsWith(github.ref, 'refs/tags/v') + needs: test_libs_ubuntu + runs-on: ubuntu-latest + permissions: + # IMPORTANT: this permission is mandatory for trusted publishing + id-token: write + steps: + - name: Check out Qadence Libs + uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + pip install hatch + - name: Build package + run: | + hatch build + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + - name: Confirm deployment + timeout-minutes: 5 + run: | + VERSION=${GITHUB_REF#refs/tags/v} + until pip download qadence-libs==$VERSION + do + echo "Failed to download from PyPI, will wait for upload and retry." + sleep 1 + done + + deploy_docs: + name: Deploy Qadence Libs docs (ubuntu) + if: startsWith(github.ref, 'refs/tags/v') + needs: test_libs_ubuntu + runs-on: ubuntu-latest + steps: + - name: Checkout Qadence Libs + uses: actions/checkout@v4 + - name: Install JetBrains Mono font + run: | + sudo apt install -y wget unzip fontconfig + wget https://download.jetbrains.com/fonts/JetBrainsMono-2.304.zip + unzip JetBrainsMono-2.304.zip -d JetBrainsMono + mkdir -p /usr/share/fonts/truetype/jetbrains + cp JetBrainsMono/fonts/ttf/*.ttf /usr/share/fonts/truetype/jetbrains/ + fc-cache -f -v + - name: Install graphviz + run: sudo apt-get install -y graphviz + - name: Set up Python 3.10 + uses: actions/setup-python@v5 + with: + python-version: '3.10' + - name: Install Hatch + run: | + pip install hatch + - name: Deploy docs + run: | + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + git fetch origin gh-pages + hatch -v run docs:mike deploy --push --update-aliases ${{ github.ref_name }} latest diff --git a/.gitignore b/.gitignore index 68bc17f..1b9910b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,160 +1,51 @@ +*.DS_Store +test.png +*.swp + +# Default ignored files +/.idea/ +/__pycache__/ +.vscode/ + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - # Unit test / coverage reports htmlcov/ .tox/ -.nox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover -*.py,cover .hypothesis/ .pytest_cache/ -cover/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ +.mypy_cache/ -# PyBuilder -.pybuilder/ -target/ +# Distribution / packaging +.Python +*.egg-info/ +.installed.cfg +*.egg +build/ +dist/ # Jupyter Notebook .ipynb_checkpoints -# IPython -profile_default/ -ipython_config.py - -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -#poetry.lock - -# pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -#pdm.lock -# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it -# in version control. -# https://pdm.fming.dev/#use-with-ide -.pdm.toml - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# Cython debug symbols -cython_debug/ - -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ +# specific +.*.db +*.db +*.eggs +*.env +Pipfile +runs/ +*venv +*~ +*lcov + +# Mkdocs +site/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..5ddb8ad --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,31 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + args: ['--maxkb=600'] + +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: "v0.1.5" + hooks: + - id: ruff + args: [--fix, --show-fixes, --show-source, --exclude, examples/draw.py] + +- repo: https://github.com/ambv/black + rev: 23.11.0 + hooks: + - id: black + +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.7.0 + hooks: + - id: mypy + exclude: examples|docs + +- repo: https://github.com/DanielNoord/pydocstringformatter + rev: v0.7.3 + hooks: + - id: pydocstringformatter diff --git a/README.md b/README.md index 5018175..7b5580f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,63 @@ -# qadence-libs -A collection of libraries to enhance Qadence functionalities. +# Qadence-Libs + +**Qadence-Libs** is a Python package that provides extra functionality for Qadence. + +[![Linting](https://github.com/pasqal-io/qadence-libs/actions/workflows/lint.yml/badge.svg)](https://github.com/pasqal-io/qadence-libs/actions/workflows/lint.yml) +[![Tests](https://github.com/pasqal-io/qadence-libs/actions/workflows/test_fast.yml/badge.svg)](https://github.com/pasqal-io/qadence-libs/actions/workflows/test.yml) +[![Documentation](https://github.com/pasqal-io/qadence-libs/actions/workflows/build_docs.yml/badge.svg)](https://pasqal-io.github.io/qadence-libs/latest) +[![Pypi](https://badge.fury.io/py/qadence-libs.svg)](https://pypi.org/project/qadence-libs/) +[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) + + +## Installation guide + +[PyPI](https://pypi.org/project/qadence-libs/) and can be installed using `pip` as follows: + +```bash +pip install qadence_libs +``` + +## Contributing + +Before making a contribution, please review our [code of conduct](docs/CODE_OF_CONDUCT.md). + +- **Submitting Issues:** To submit bug reports or feature requests, please use our [issue tracker](https://github.com/pasqal-io/qadence-libs/issues). +- **Developing in qadence:** To learn more about how to develop within `qadence`, please refer to [contributing guidelines](docs/CONTRIBUTING.md). + +### Setting up qadence in development mode + +We recommend to use the [`hatch`](https://hatch.pypa.io/latest/) environment manager to install `qadence_libs` from source: + +```bash +python -m pip install hatch + +# get into a shell with all the dependencies +python -m hatch shell + +# run a command within the virtual environment with all the dependencies +python -m hatch run python my_script.py +``` + +**WARNING** +`hatch` will not combine nicely with other environment managers such as Conda. If you still want to use Conda, +install it from source using `pip`: + +```bash +# within the Conda environment +python -m pip install -e . +``` + +## Citation + +If you use Qadence-Libs for a publication, we kindly ask you to cite our work using the following BibTex entry: + +```latex +@misc{qadence-libs2024pasqal, + url = {https://github.com/pasqal-io/qadence-libs}, + title = {Qadence Libs: {A}n {E}xperiment runner for Qadence.}, + year = {2023} +} +``` + +## License +Qadence-Libs is a free and open source software package, released under the Apache License, Version 2.0. diff --git a/docs/css/mkdocstrings.css b/docs/css/mkdocstrings.css new file mode 100644 index 0000000..f8502f7 --- /dev/null +++ b/docs/css/mkdocstrings.css @@ -0,0 +1,11 @@ +/* Indentation. */ +div.doc-contents:not(.first) { + padding-left: 25px; + border-left: 4px solid rgba(230, 230, 230); + margin-bottom: 80px; + } + +/* Avoid breaking parameters name, etc. in table cells. */ +td code { + word-break: normal !important; +} diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..f746b71 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,116 @@ +# Template Python project + +This is a template Python project which can be used to bootstrap a new library in the Pasqal quantum software codebase. + +## Development tools + +The library uses the following tools: + +* [hatch](https://hatch.pypa.io/latest/) for managing virtual environment and dependencies +* [pytest](https://docs.pytest.org/en/7.2.x/contents.html) for building the unit tests suite +* [black](https://black.readthedocs.io/en/stable/), [isort](https://pycqa.github.io/isort/) and [flake8](https://flake8.pycqa.org/en/latest/) for code formatting and linting +* [mypy](https://mypy.readthedocs.io/en/stable/) for static type checking +* [pre-commit](https://pre-commit.com/) for applying linting and formatting automatically before committing new code + +We recommend to use [`pyenv`](https://github.com/pyenv/pyenv) for managing +python versions for managing python versions both globally and locally: +```bash +# System-wide install of a python version. +pyenv install 3.10 + +# Use 3.10 everywhere. +pyenv global 3.10 + +# Or locally in the current directory. +pyenv local 3.10 +``` + + +## Install from registry + +Before you can install the library from the private Pasqal PyPi, make sure to ask for `PYPI_USERNAME` and `PYPI_PASSWORD` on the relevant Slack channel. +You can then set the credentials as environment variables via: + +```bash +export PYPI_USERNAME=MYUSERNAME +export PYPI_PASSWORD=THEPASSWORD +``` + +You are then able to install the latest version of `template-python-project` from the Pasqal private PyPi. + + +## Install from source + +All Pasqal quantum libraries require Python >=3.8. For development, the preferred method to install this package is +to use `hatch`. You can install from source by cloning this repository and run: + +```bash +python -m pip install hatch +python -m hatch -v shell + +# execute any script using the library +python my_script.py +``` + +Alternatively, you can also: + +* install with `pip` in development mode by simply running `pip install -e .`. Notice that in this way + you will install all the dependencies, including extras. +* install it with `conda` by simply using `pip` inside the Conda environment. + + +## Develop + +When developing the package, the recommended way is to create a virtual environment with `hatch` as shown above: + +```bash +python -m pip install hatch +python -m hatch -v shell +``` + +When inside the shell with development dependencies, install first the pre-commit hook: +``` +pre-commit install +``` + +In this way, you will get automatic linting and formatting every time you commit new code. Do not +forget to run the unit test suite by simply running the `pytest` command. + +If you do not want to get into the Hatch shell, you can alternatively do the following: + +```bash +python -m pip install hatch +python -m hatch -v shell + +# install the pre-commit +python -m hatch run pre-commit install + +# commit some code +python -m hatch run git commit -m "My awesome commit" + +# run the unit tests suite +python -m hatch run pytest + +``` + +## Document + +You can improve the documentation of the package by editing this file for the landing page or adding new +markdown or Jupyter notebooks to the `docs/` folder in the root of the project. In order to modify the +table of contents, edit the `mkdocs.yml` file in the root of the project. + +In order to build and serve the documentation locally, you can use `hatch` with the right environment: + +```bash +python -m hatch -v run docs:build +python -m hatch -v run docs:serve +``` + +If you don't want to use `hatch`, just check into your favorite virtual environment and +execute the following commands: + +```bash +python -m pip install -r docs/requirements.txt +mkdocs build +mkdocs serve +``` diff --git a/docs/javascripts/mathjax.js b/docs/javascripts/mathjax.js new file mode 100644 index 0000000..fd764a7 --- /dev/null +++ b/docs/javascripts/mathjax.js @@ -0,0 +1,16 @@ +window.MathJax = { + tex: { + inlineMath: [["\\(", "\\)"]], + displayMath: [["\\[", "\\]"]], + processEscapes: true, + processEnvironments: true + }, + options: { + ignoreHtmlClass: ".*|", + processHtmlClass: "arithmatex" + } +}; + +document$.subscribe(() => { + MathJax.typesetPromise() +}) diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..0c4c5e9 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,7 @@ +mkdocs-material +mkdocstrings +mkdocstrings-python +mkdocs-section-index +mkdocs-jupyter +mkdocs-exclude +markdown-exec diff --git a/docs/sample_page.md b/docs/sample_page.md new file mode 100644 index 0000000..e0726f1 --- /dev/null +++ b/docs/sample_page.md @@ -0,0 +1,8 @@ +This is just a sample notebook to showcase the rendering of Jupyter notebooks in the documentation. + +```python exec="on" source="material-block" session="main" +from qadence_libs.main import main + +msg = main() +print(msg) +``` diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..bf5fc03 --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,79 @@ +site_name: Template Python project +repo_url: "https://github.com/pasqal-io/qadence-libs.git" +repo_name: "qadence_libs" + +nav: + - Overview: index.md + - Sample page: sample_page.md + +theme: + name: material + features: + - content.code.annotate + - content.action.view + - content.action.edit + - navigation.tabs + - navigation.indexes + - navigation.sections + - content.code.copy + + palette: + - media: "(prefers-color-scheme: light)" + scheme: default + primary: light green + accent: purple + toggle: + icon: material/weather-sunny + name: Switch to dark mode + - media: "(prefers-color-scheme: dark)" + scheme: slate + primary: black + accent: light green + toggle: + icon: material/weather-night + name: Switch to light mode + +markdown_extensions: +- admonition # for notes +- pymdownx.arithmatex: # for mathjax + generic: true +- pymdownx.highlight: + anchor_linenums: true +- pymdownx.inlinehilite +- pymdownx.snippets +- pymdownx.superfences + +plugins: +- search +- section-index +- markdown-exec +- mkdocstrings: + default_handler: python + handlers: + python: + selection: + filters: + - "!^_" # exlude all members starting with _ + - "^__init__$" # but always include __init__ modules and methods + options: + show_root_toc_entry: false + heading_level: 3 + merge_init_into_class: true + docstring_section_style: spacy + +watch: + - qadence_libs + +extra: + version: + provider: mike + +# To get nice tabs +extra_css: +- css/mkdocstrings.css + +# For mathjax +extra_javascript: + - javascripts/mathjax.js + - https://polyfill.io/v3/polyfill.min.js?features=es6 + - https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..43829f6 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,164 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "qadence-libs" +description = "Libraries to extend Qadence functionalities." +readme = "README.md" +authors = [ + { name = "Mario Dagrada", email = "mario.dagrada@pasqal.com" }, + { name = "Roland Guichard", email = "roland.guichard@pasqal.com" }, + { name = "Raja Selvarajan", email = "raja.selvarajan@pasqal.com" }, + { name = "Gergana Velikova", email = "gergana.velikova@pasqal.com" }, + +] +requires-python = ">=3.9,<3.12" +license = {text = "Apache 2.0"} +keywords = ["quantum"] +version = "0.1.1" +classifiers=[ + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", +] +dependencies = [ + "torch", + "qutip==4.7.2", + "qadence[braket, pulser, horqrux]==1.2.7", +] + +[tool.hatch.metadata] +allow-direct-references = true +allow-ambiguous-features = true + +[tool.hatch.envs.default] +dependencies = [ + "flaky", + "hypothesis", + "pytest", + "pytest-cov", + "pytest-mypy", + "pytest-xdist", + "ipykernel", + "pre-commit", + "black", + "isort", + "ruff", + "pydocstringformatter", +] + +[tool.hatch.envs.default.scripts] +test = "pytest -n auto --cov-report lcov --cov-config=pyproject.toml --cov=qadence_libs --cov=tests --ignore=./tests/test_examples.py {args}" +test-examples = "pytest ./tests/test_examples.py {args}" +no-cov = "cov --no-cov {args}" +test-docs = "mkdocs build --clean --strict" +test-all = "pytest -n auto {args} && mkdocs build --clean --strict" + +[tool.pytest.ini_options] +testpaths = ["tests"] +addopts = """-vvv""" +xfail_strict = true +filterwarnings = [ + "ignore:Call to deprecated create function FieldDescriptor", + "ignore:Call to deprecated create function Descriptor", + "ignore:Call to deprecated create function EnumDescriptor", + "ignore:Call to deprecated create function EnumValueDescriptor", + "ignore:Call to deprecated create function FileDescriptor", + "ignore:Call to deprecated create function OneofDescriptor", + "ignore:distutils Version classes are deprecated.", + "ignore::DeprecationWarning" +] + + +[tool.hatch.envs.docs] +dependencies = [ + "mkdocs", + "mkdocs-material", + "mkdocstrings", + "mkdocstrings-python", + "mkdocs-section-index", + "mkdocs-exclude", + "markdown-exec", + "mike", +] + +[tool.hatch.envs.docs.scripts] +build = "mkdocs build --clean --strict" +serve = "mkdocs serve --dev-addr localhost:8000" + +[[tool.hatch.envs.test.matrix]] +python = ["39", "310"] + +# [tool.hatch.envs.tests] + +[tool.hatch.build.targets.sdist] +exclude = [ + "/.gitignore", + "/.gitlab-ci-yml", + "/.pre-commit-config.yml", + "/tests", + "/docs", + "/examples", +] + +[tool.hatch.build.targets.wheel] +packages = ["qadence_libs"] + +[tool.coverage.run] +branch = true +parallel = true + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +] + +[tool.ruff] +select = ["E", "F", "I", "Q"] +extend-ignore = ["F841","F403"] +line-length = 100 + +[tool.ruff.isort] +required-imports = ["from __future__ import annotations"] + +[tool.ruff.per-file-ignores] +"__init__.py" = ["F401"] + +[tool.ruff.mccabe] +max-complexity = 15 + +[tool.ruff.flake8-quotes] +docstring-quotes = "double" + +[tool.black] +line-length = 100 +include = '\.pyi?$' +exclude = ''' +/( + \.git + | \.hg + | \.mypy_cache + | \.tox + | \.venv + | _build + | buck-out + | build + | dist +)/ +''' + +[tool.mypy] +python_version = "3.10" +warn_return_any = true +warn_unused_configs = true +disallow_untyped_defs = true +no_implicit_optional = false +ignore_missing_imports = true diff --git a/qadence_libs/__init__.py b/qadence_libs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/qadence_libs/main.py b/qadence_libs/main.py new file mode 100644 index 0000000..6e12d88 --- /dev/null +++ b/qadence_libs/main.py @@ -0,0 +1,15 @@ +from __future__ import annotations + +from typing import Optional + + +def main(str_to_add: Optional[str] = None) -> str: + msg = "Pasqal template Python project" + if str_to_add is not None: + msg += str_to_add + return msg + + +if __name__ == "__main__": + msg = main(str_to_add="from same file") + print(msg) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..a03590f --- /dev/null +++ b/setup.py @@ -0,0 +1,5 @@ +from __future__ import annotations + +from setuptools import setup + +setup() diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..3014d28 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,2 @@ +# use this file for configuring test fixtures and +# functions common to every test diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 0000000..bcb6efe --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,16 @@ +from __future__ import annotations + +from qadence_libs.main import main + +expected_msg = "Pasqal template Python project" + + +def test_main() -> None: + msg = main() + assert msg == expected_msg + + +def test_main_with_str() -> None: + str_to_add = "with added str" + msg = main(str_to_add=str_to_add) + assert msg == expected_msg + str_to_add