Skip to content

Python: Moved PubSubMsg class to a shared module #3861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: python-sync-client
Choose a base branch
from
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
1 change: 1 addition & 0 deletions benchmarks/python/python_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import redis.asyncio as redispy # type: ignore
from glide import (
GlideClient,
TGlideClient,
GlideClientConfiguration,
GlideClusterClient,
GlideClusterClientConfiguration,
Expand Down
2 changes: 1 addition & 1 deletion docs/markdown/python/base_batch.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
::: glide.async_commands.batch.BaseBatch
::: glide.commands.batch.BaseBatch
2 changes: 1 addition & 1 deletion docs/markdown/python/cluster_batch.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
::: glide.async_commands.batch.ClusterBatch
::: glide.commands.batch.ClusterBatch
2 changes: 1 addition & 1 deletion docs/markdown/python/cluster_transaction.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
::: glide.async_commands.batch.ClusterTransaction
::: glide.commands.batch.ClusterTransaction
2 changes: 1 addition & 1 deletion docs/markdown/python/standalone_batch.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
::: glide.async_commands.batch.Batch
::: glide.commands.batch.Batch
2 changes: 1 addition & 1 deletion docs/markdown/python/standalone_transaction.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
::: glide.async_commands.batch.Transaction
::: glide.commands.batch.Transaction
8 changes: 4 additions & 4 deletions examples/python/ft_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
RequestError,
)
from glide import TimeoutError as GlideTimeoutError
from glide.async_commands.server_modules import ft, glide_json
from glide.async_commands.server_modules.ft_options.ft_create_options import (
from glide.shared.commands.server_modules import ft, glide_json
from glide.shared.commands.server_modules.ft_options.ft_create_options import (
DataType,
FtCreateOptions,
NumericField,
)
from glide.async_commands.server_modules.ft_options.ft_search_options import (
from glide.shared.commands.server_modules.ft_options.ft_search_options import (
FtSearchOptions,
ReturnField,
)
from glide.constants import OK, FtSearchResponse, TEncodable
from glide.shared.constants import OK, FtSearchResponse, TEncodable


async def create_client(
Expand Down
2 changes: 1 addition & 1 deletion examples/python/json_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
RequestError,
)
from glide import TimeoutError as GlideTimeoutError
from glide.async_commands.server_modules import glide_json
from glide.shared.commands.server_modules import glide_json


async def create_client(
Expand Down
2 changes: 1 addition & 1 deletion ffi/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[env]
GLIDE_NAME = { value = "GlideFFI", force = true }
GLIDE_NAME = { value = "GlideGo", force = true }
GLIDE_VERSION = "0.1.0"
# Suppress error
# > ... was built for newer 'macOS' version (14.5) than being linked (14.0)
Expand Down
2 changes: 1 addition & 1 deletion ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "Apache-2.0"
authors = ["Valkey GLIDE Maintainers"]

[lib]
crate-type = ["staticlib", "rlib"]
crate-type = ["staticlib", "rlib", "cdylib"]

[dependencies]
protobuf = { version = "3", features = [] }
Expand Down
4 changes: 2 additions & 2 deletions ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ pub unsafe extern "C" fn command(
};

// Create the command outside of the task to ensure that the command arguments passed
// from "go" are still valid
// from the caller are still valid
let mut cmd = command_type
.get_command()
.expect("Couldn't fetch command type");
Expand All @@ -950,7 +950,7 @@ pub unsafe extern "C" fn command(
} else {
Routes::default()
};

let mut client = client_adapter.core.client.clone();
client_adapter.execute_command(channel, async move {
client
Expand Down
31 changes: 25 additions & 6 deletions python/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ def find_project_root() -> Path:

# Constants
PROTO_REL_PATH = "glide-core/src/protobuf"
PYTHON_CLIENT_PATH = "python/python/glide"
VENV_NAME = ".env"
GLIDE_ROOT = find_project_root()
PYTHON_DIR = GLIDE_ROOT / "python"
VENV_DIR = PYTHON_DIR / VENV_NAME
PYTHON_CLIENT_PATH = PYTHON_DIR / "glide"
ASYNC_CLIENT_DIR = PYTHON_CLIENT_PATH / "glide_async"
SYNC_CLIENT_DIR = PYTHON_CLIENT_PATH / "glide_sync"
VENV_DIR = ASYNC_CLIENT_DIR / VENV_NAME
VENV_BIN_DIR = VENV_DIR / "bin"
PYTHON_EXE = VENV_BIN_DIR / "python"
FFI_DIR = GLIDE_ROOT / "ffi"


def check_dependencies() -> None:
Expand Down Expand Up @@ -95,7 +98,7 @@ def get_venv_env() -> Dict[str, str]:

def generate_protobuf_files() -> None:
proto_src = GLIDE_ROOT / PROTO_REL_PATH
proto_dst = GLIDE_ROOT / PYTHON_CLIENT_PATH
proto_dst = PYTHON_CLIENT_PATH
proto_files = list(proto_src.glob("*.proto"))

if not proto_files:
Expand Down Expand Up @@ -139,10 +142,19 @@ def build_async_client(release: bool, no_cache: bool = False) -> None:
if release:
cmd += ["--release", "--strip"]

run_command(cmd, cwd=PYTHON_DIR, env=env, label="maturin develop")
run_command(cmd, cwd=ASYNC_CLIENT_DIR, env=env, label="maturin develop")
print("[OK] Async client build completed")


def build_sync_client() -> None:
print("[INFO] Building sync client...")
generate_protobuf_files()

run_command(["cargo", "build"], cwd=FFI_DIR, label="cargo build ffi")

print("[OK] Sync client build completed")


def run_command(
cmd: List[str],
cwd: Optional[Path] = None,
Expand Down Expand Up @@ -220,6 +232,7 @@ def main() -> None:
Examples:
python dev.py build # Build the async client in debug mode
python dev.py build --client async --mode release # Build the async client in release mode
python dev.py build --client sync # Build the sync client
python dev.py protobuf # Generate Python protobuf files (.py and .pyi)
python dev.py lint # Run Python linters
python dev.py test # Run all tests
Expand All @@ -231,7 +244,10 @@ def main() -> None:

build_parser = subparsers.add_parser("build", help="Build the Python clients")
build_parser.add_argument(
"--client", default="async", choices=["async"], help="Which client to build"
"--client",
default="all",
choices=["async", "sync", "all"],
help="Which client to build: 'async', 'sync', or 'all' to build both.",
)
build_parser.add_argument(
"--mode", choices=["debug", "release"], default="debug", help="Build mode"
Expand Down Expand Up @@ -279,9 +295,12 @@ def main() -> None:
elif args.command == "build":
release = args.mode == "release"
no_cache = args.no_cache
if args.client in ("async"):
if args.client in ["async", "all"]:
print(f"🛠 Building async client ({args.mode} mode)...")
build_async_client(release, no_cache)
if args.client in ["sync", "all"]:
print("🛠 Building sync client...")
build_sync_client()

print("[✅ DONE] Task completed successfully.")

Expand Down
4 changes: 4 additions & 0 deletions python/dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ sphinx >= 7.4.7
sphinx-rtd-theme
deprecated
types-Deprecated

# Sync
cffi
types-cffi
1 change: 1 addition & 0 deletions python/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"glide.protobuf",
"pytest",
"google",
"cffi",
] # Prevents confusion in sphinx with imports

autodoc_typehints = "description"
Expand Down
2 changes: 1 addition & 1 deletion python/docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ Welcome to the documentation page for Valkey GLIDE!
:caption: Contents:

glide
glide.async_commands
glide.commands.async_commands
modules
6 changes: 3 additions & 3 deletions python/Cargo.toml → python/glide/glide_async/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ crate-type = ["cdylib"]
[dependencies]
pyo3 = { version = "^0.24", features = ["extension-module", "num-bigint"] }
bytes = { version = "^1.8" }
redis = { path = "../glide-core/redis-rs/redis", features = [
redis = { path = "../../../glide-core/redis-rs/redis", features = [
"aio",
"tokio-comp",
"connection-manager",
"tokio-rustls-comp",
] }
glide-core = { path = "../glide-core", features = ["socket-layer"] }
logger_core = { path = "../logger_core" }
glide-core = { path = "../../../glide-core", features = ["socket-layer"] }
logger_core = { path = "../../../logger_core" }

[package.metadata.maturin]
python-source = "python"
Expand Down
39 changes: 39 additions & 0 deletions python/glide/glide_async/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[build-system]
requires = ["maturin==0.14.17"]
build-backend = "maturin"

[project]
name = "test-glide-async"
description = "An open source Valkey client library that supports Valkey and Redis open source 6.2, 7.0, 7.2 and 8.0."
requires-python = ">=3.9"
dependencies = [
# Note: If you add a dependency here, make sure to also add it to requirements.txt
# Once issue https://github.com/aboutcode-org/python-inspector/issues/197 is resolved, the requirements.txt file can be removed.
"async-timeout>=4.0.2; python_version < '3.11'",
"typing-extensions>=4.8.0; python_version < '3.11'",
"protobuf>=3.20",
]

classifiers = [
"Topic :: Database",
"Topic :: Utilities",
"License :: OSI Approved :: Apache Software License",
"Intended Audience :: Developers",
"Topic :: Software Development",
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]

[tool.isort]
profile = "black"
skip = [
".env",
"python/glide/protobuf"
]

[tool.black]
target-version = ['py39', 'py310', 'py311', 'py312', 'py313']

[tool.mypy]
exclude = "^(.*\\/)?(\\.env|python/python/glide/protobuf|utils/release-candidate-testing|target|ort)(\\/|$)"
5 changes: 5 additions & 0 deletions python/glide/glide_async/python/glide/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0

from .glide_client import BaseClient, GlideClient, GlideClusterClient, TGlideClient

__all__ = ["BaseClient", "GlideClient", "GlideClusterClient", "TGlideClient"]
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@

from typing import Dict, List, Mapping, Optional, Union, cast

from glide.async_commands.batch import ClusterBatch
from glide.async_commands.command_args import ObjectType
from glide.async_commands.core import (
CoreCommands,
FlushMode,
FunctionRestorePolicy,
InfoSection,
)
from glide.constants import (
from ..async_commands.core import CoreCommands
from glide.shared.commands.batch import ClusterBatch
from glide.shared.commands.command_args import ObjectType
from glide.shared.commands.core_options import FlushMode, FunctionRestorePolicy, InfoSection
from glide.shared.constants import (
TOK,
TClusterResponse,
TEncodable,
Expand All @@ -21,10 +17,10 @@
TResult,
TSingleNodeRoute,
)
from glide.protobuf.command_request_pb2 import RequestType
from glide.routes import Route
from glide.shared.protobuf.command_request_pb2 import RequestType
from glide.shared.routes import Route

from ..glide import ClusterScanCursor, Script
from glide.glide_async.python.glide.glide import ClusterScanCursor, Script


class ClusterCommands(CoreCommands):
Expand Down
Loading