Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,18 @@ doc = false
name = "_opendal"

[dependencies]
bytes = "1.5.0"
futures = "0.3.28"
jiff = { version = "0.2.15" }
bytes = "1"
futures = "0.3"
jiff = "0.2"
mea = "0.6"
# this crate won't be published, we always use the local version
opendal = { version = ">=0", path = "../../core", features = [
"blocking",
"layers-mime-guess",
] }
pyo3 = { version = "0.27.2", features = ["generate-import-lib", "jiff-02"] }
pyo3-async-runtimes = { version = "0.27.0", features = ["tokio-runtime"] }
pyo3-stub-gen = { version = "0.17" }
pyo3 = { version = "0.27", features = ["generate-import-lib", "jiff-02"] }
pyo3-async-runtimes = { version = "0.27", features = ["tokio-runtime"] }
pyo3-stub-gen = { version = "0.18" }
tokio = "1"

[profile.release]
Expand Down
38 changes: 21 additions & 17 deletions bindings/python/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,39 +38,42 @@ setup:
[group('maintenance')]
clean:
@echo "{{ BOLD }}--- Cleaning Rust build artifacts (Cargo) ---{{ NORMAL }}"
@cargo clean
@echo "{{ BOLD }}--- Removing .venv/, build/, dist/ directories, and other caches ---{{ NORMAL }}"
@rm -rf .venv/ build/ dist/ .pytest_cache/ .mypy_cache/ .hypothesis/ .ruff_cache/
@echo "{{ BOLD }}--- Removing Python bytecode and compiled extensions ---{{ NORMAL }}"
@find . -type f -name '*.py[co]' -delete \
-o -type d -name __pycache__ -exec rm -rf {} + \
-o -type f -name '_opendal*.so' -delete
@cargo clean --quiet
@echo "{{ BOLD }}--- Removing build directories, other caches, python bytecode and compiled extensions ---{{ NORMAL }}"
@find . \
\( -type d \( -name __pycache__ -o -name .venv -o -name .build -o -name dist -o -name .pytest_cache -o -name .mypy_cache -o -name .hypothesis -o -name .ruff_cache \) -prune -exec rm -rf {} + \) \
Comment on lines +42 to +44
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same logic as before, just done in 1 command now

-o \
\( -type f \( -name '*.py[co]' -o -name '_*.so' \) -delete \)

# ==============================================================================
# Dev & Build
# ==============================================================================

# Generate Python type stubs
[group('build')]
[group('dev')]
stub-gen: setup
@echo "{{ BOLD }}--- Generating Python type stubs ---{{ NORMAL }}"
@cargo run --quiet --manifest-path=../../dev/Cargo.toml -- generate -l python
@echo "{{ BOLD }}--- Generating stubs for (opendal) ---{{ NORMAL }}"
@cargo run --quiet --bin stub_gen
@echo "{{ BOLD }}--- Formatting and fixing generated stubs ---{{ NORMAL }}"
@just _post-gen-cleanup

# Internal: Post-generation cleanup (fix linting and formatting)
[private]
_post-gen-cleanup:
-@bash -c 'shopt -s globstar; uv run ruff check **/*.pyi --fix --unsafe-fixes --silent || true'
@just fmt

# Compile and produce a release wheel with optimizations
[group('release')]
build-release *args: stub-gen
@echo "{{ BOLD }}--- Building release wheel ---{{ NORMAL }}"
@echo "{{ BOLD }}--- Building release wheel (opendal) ---{{ NORMAL }}"
@uv run maturin build -m ./Cargo.toml --profile release --strip --release --out dist {{ args }}
@uv run mkdocs build

# Build and install the release wheel in the current venv
[group('release')]
install-release *args: stub-gen
@echo "{{ BOLD }}--- Installing release wheel ---{{ NORMAL }}"
@echo "{{ BOLD }}--- Installing release wheel (opendal) ---{{ NORMAL }}"
@uv run maturin develop -m ./Cargo.toml --profile release --strip --release {{ args }}

# Build and install the release wheel in the current venv
Expand All @@ -84,20 +87,20 @@ bench: install-release
# Build only a source distribution (sdist) without compiling
[group('release')]
sdist *args: stub-gen
@echo "{{ BOLD }}--- Building source distribution without compiling ---{{ NORMAL }}"
@echo "{{ BOLD }}--- Building source distribution without compiling (opendal) ---{{ NORMAL }}"
@uv run maturin sdist -m ./Cargo.toml --out dist {{ args }}

# Compile and produce a development wheel
[group('dev')]
build-dev *args: stub-gen
@echo "{{ BOLD }}--- Building development wheel ---{{ NORMAL }}"
@echo "{{ BOLD }}--- Building development wheel (opendal) ---{{ NORMAL }}"
@uv run maturin build -m ./Cargo.toml --out dist {{ args }}
@uv run mkdocs build

# Build and install the development wheel in the current venv
[group('dev')]
install-dev *args: stub-gen
@echo "{{ BOLD }}--- Installing development wheel ---{{ NORMAL }}"
@echo "{{ BOLD }}--- Installing development wheel (opendal) ---{{ NORMAL }}"
@uv run maturin develop -m ./Cargo.toml {{ args }}

# Run tests
Expand All @@ -113,11 +116,12 @@ test *args: install-dev
# Run all lint checks for Rust and Python
[group('lint')]
lint: setup
@echo "{{ BOLD }}--- Running Rust linter (Clippy) ---{{ NORMAL }}"
@echo "{{ BOLD }}--- Running Rust linter ---{{ NORMAL }}"
## remove `-A clippy::incompatible_msrv` until https://github.com/rust-lang/rust-clippy/issues/15792 is fixed and released
@cargo clippy -- -D warnings -D clippy::dbg_macro -A clippy::incompatible_msrv
@echo "{{ BOLD }}--- Running Python linter (Ruff) ---{{ NORMAL }}"
@echo "{{ BOLD }}--- Running Python linter ---{{ NORMAL }}"
@uv run ruff check
@uv run ty check ./python

# Format all code (Rust, Python, etc.)
[group('lint')]
Expand Down
5 changes: 1 addition & 4 deletions bindings/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ benchmark = [
"greenlet>=3.1.1",
"pydantic>=2.10.6",
]
dev = ["maturin>=1.8.2"]
dev = ["maturin>=1.9.4,<2.0", "ruff>=0.9.10", "ty>=0.0.15"]
docs = ["mkdocs", "mkdocs-material", "mkdocstrings[python]", "mkdocs-jupyter"]
lint = ["ruff>=0.9.10"]
test = [
"pytest>=8.3.5",
"pytest-asyncio>=0.25.3",
Expand All @@ -57,10 +56,8 @@ test = [
]

[tool.maturin]
features = ["pyo3/extension-module"]
module-name = "opendal._opendal"
python-source = "python"
strip = true

[tool.uv]
cache-keys = [
Expand Down
7 changes: 0 additions & 7 deletions bindings/python/pyrightconfig.json

This file was deleted.

24 changes: 4 additions & 20 deletions bindings/python/python/opendal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,18 @@
# specific language governing permissions and limitations
# under the License.

# ruff: noqa: D104
from __future__ import annotations
# ruff: noqa: D104, F405, F403

from typing import TYPE_CHECKING

if TYPE_CHECKING:
__version__: str
from opendal import capability, exceptions, file, layers, services, types
else:
from opendal._opendal import (
__version__, # noqa: F401
capability,
exceptions,
file,
layers,
services,
types,
)

from opendal.operator import AsyncOperator, Operator # pyright:ignore
from opendal._opendal import * # ty: ignore
from opendal.operator import AsyncOperator, Operator
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frostming as you made some recent changes, can you check this out, if this works ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it reverts my change and the typecheckers can't find types, because opendal._opendal is not typed.

In fact I don't understand why you moved *.pyi into its own package. it looks less clean

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact I don't understand why you moved *.pyi into its own package. it looks less clean

This is done by a recent update of pyo3-stub-gen that is used to generate stubs. the inclusion of all the entries in __all__ is actually working much better for me with both ty and pyright in zed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image


__all__ = [
"capability",
"exceptions",
"file",
"layers",
"services",
"types",
"AsyncOperator",
"Operator",
"__version__",
]
30 changes: 30 additions & 0 deletions bindings/python/python/opendal/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# This file is automatically generated by pyo3_stub_gen
# ruff: noqa: E501, F401, F403, F405

from opendal import capability, exceptions, file, layers, operator, types

__all__ = [
"capability",
"exceptions",
"file",
"layers",
"operator",
"types",
]
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
# under the License.

# This file is automatically generated by pyo3_stub_gen
# ruff: noqa: E501, F401
# ruff: noqa: E501, F401, F403, F405

import builtins
import typing

__all__ = [
"Capability",
]

@typing.final
class Capability:
r"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,24 @@
# under the License.

# This file is automatically generated by pyo3_stub_gen
# ruff: noqa: E501, F401
# ruff: noqa: E501, F401, F403, F405

import builtins

__all__ = [
"AlreadyExists",
"ConditionNotMatch",
"ConfigInvalid",
"Error",
"IsADirectory",
"IsSameFile",
"NotADirectory",
"NotFound",
"PermissionDenied",
"Unexpected",
"Unsupported",
]

class AlreadyExists(builtins.Exception):
r"""Already exists."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# under the License.

# This file is automatically generated by pyo3_stub_gen
# ruff: noqa: E501, F401
# ruff: noqa: E501, F401, F403, F405

import builtins
import collections.abc
Expand All @@ -25,6 +25,11 @@ import typing

import typing_extensions

__all__ = [
"AsyncFile",
"File",
]

@typing.final
class AsyncFile:
r"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@
# under the License.

# This file is automatically generated by pyo3_stub_gen
# ruff: noqa: E501, F401
# ruff: noqa: E501, F401, F403, F405

import builtins
import typing

__all__ = [
"ConcurrentLimitLayer",
"Layer",
"MimeGuessLayer",
"RetryLayer",
]

@typing.final
class ConcurrentLimitLayer(Layer):
r"""
Expand Down
Loading
Loading