Skip to content

Commit

Permalink
Python 3.12 support (#767)
Browse files Browse the repository at this point in the history
* adding upper bound for python version.

* adding 3.12 to CI

* fixing bug with imports in 3.12

* removing return result.

* removing print.

* removing comma

* locking doc dependencies

* update actions.

* removing token

* adding token back. removing token from yml file.
  • Loading branch information
weinbe58 authored Feb 26, 2024
1 parent 725599c commit fc05000
Show file tree
Hide file tree
Showing 9 changed files with 845 additions and 498 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/cov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.9
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.12
- uses: pdm-project/setup-pdm@v4
name: Setup PDM
with:
python-version: 3.9 # Version range or exact version of a Python version to use, the same as actions/setup-python
python-version: 3.12 # Version range or exact version of a Python version to use, the same as actions/setup-python
# well we use virtualenv here
# prerelease: true # Allow prerelease versions to be installed
# enable-pep582: true # Enable PEP 582 package loading globally
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml # optional
fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)
token: ${{ secrets.CODECOV_TOKEN }} # required
6 changes: 3 additions & 3 deletions .github/workflows/deploy_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.11
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.11
python-version: 3.12
- uses: pdm-project/setup-pdm@v4
name: Setup PDM
with:
python-version: 3.11
python-version: 3.12
- name: Install dependencies
run: pdm install -G doc
- name: Set up build cache
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/deploy_latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: 3.12
- uses: pdm-project/setup-pdm@v4
name: Setup PDM
with:
python-version: 3.11
python-version: 3.12
- name: Install dependencies
run: pdm install -G doc
- name: Set up build cache
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 10
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: 3.12
- uses: pdm-project/setup-pdm@v4
name: Setup PDM
with:
python-version: 3.11
python-version: 3.12
- name: Install dependencies
run: pdm install -G doc
- name: Set up build cache
Expand Down
2 changes: 0 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ coverage:
default:
target: auto
threshold: 4%
codecov:
token: 3910fc22-c1a3-4da6-9a0f-a7cfcface6cb
1,272 changes: 801 additions & 471 deletions pdm.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11"
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12"
]
dependencies = [
"juliacall>=0.9.14",
Expand All @@ -30,12 +31,13 @@ dependencies = [
"plum-dispatch>=2.2.2",
"numba>=0.58.0",
]
requires-python = ">=3.9,<3.12"
requires-python = ">=3.9,<3.13"
readme = "README.md"
license = {text = "MIT"}

[project.optional-dependencies]
doc = [
"mkdocs>=1.4.3",
"mkdocs>=1.5.3",
"mkdocs-material>=9.1.9",
"mkdocstrings[python]>=0.21.2",
"mkdocs-minify-plugin>=0.6.4",
Expand Down
33 changes: 25 additions & 8 deletions src/bloqade/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,35 @@
from typing import Any
from beartype.typing import Type, Callable, Dict, Union, TextIO
from beartype import beartype

import importlib
import pkgutil

__bloqade_package_loaded__ = False


def _import_submodules(package, recursive=True):
"""Import all submodules of a module, recursively,
including subpackages
:param package: package (name or actual module)
:type package: str | module
:rtype: dict[str, types.ModuleType]
"""

if isinstance(package, str):
package = importlib.import_module(package)

for loader, name, is_pkg in pkgutil.walk_packages(package.__path__):
full_name = package.__name__ + "." + name
try:
importlib.import_module(full_name)
except ModuleNotFoundError:
continue
if recursive and is_pkg:
_import_submodules(full_name)


def load_bloqade():
import pkgutil
import os

# call this function to load all modules in this package
# required because if no other modules are imported, the
Expand All @@ -19,11 +40,7 @@ def load_bloqade():
# multiple calls

if not __bloqade_package_loaded__:
path = os.path.abspath(os.path.join(os.path.dirname(__file__)))

for loader, module_name, _ in pkgutil.walk_packages([path]):
_module = loader.find_module(module_name).load_module(module_name)
globals()[module_name] = _module
_import_submodules("bloqade")

globals()["__bloqade_package_loaded__"] = True

Expand Down

0 comments on commit fc05000

Please sign in to comment.