Skip to content

Commit

Permalink
minor fixes!
Browse files Browse the repository at this point in the history
  • Loading branch information
jessekrubin committed Feb 20, 2025
1 parent 9252c89 commit 7e70e17
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 13 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# CHANGELOG

## v0.0.31

- `ryo3-core`
- got rid of `ryo3-types` and moved into `ryo3-core`
- `ryo3-tokio`
- `read_async` and `write_async` async functions
- `ryo3-which`
- `which_re` functions accepts `ry.Regex` or `str` now
- `ryo3-std`
- `read` and `write` functions which take/return `ry.Bytes` objects

___

## v0.0.30 [2025-02-18]

- `jiff`
Expand Down
31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ from pathlib import Path

import typing_extensions as te

from ry._types import Buffer

from . import http as http
from ._bytes import Bytes as Bytes
from ._jiff import Date as Date
Expand Down Expand Up @@ -151,6 +153,8 @@ from .reqwest import ReqwestError as ReqwestError
from .reqwest import Response as Response
from .reqwest import ResponseStream as ResponseStream
from .reqwest import fetch as fetch
from .tokio import read_async as read_async
from .tokio import write_async as write_async

__version__: str
__authors__: str
Expand Down Expand Up @@ -515,10 +519,12 @@ async def asleep(seconds: float) -> float:
# =============================================================================
# FILESYSTEM
# =============================================================================
def read_text(path: FsPathLike) -> str: ...
def read(path: FsPathLike) -> Bytes: ...
def read_bytes(path: FsPathLike) -> bytes: ...
def write_text(path: FsPathLike, data: str) -> None: ...
def read_text(path: FsPathLike) -> str: ...
def write(path: FsPathLike, data: Buffer | str) -> None: ...
def write_bytes(path: FsPathLike, data: bytes) -> None: ...
def write_text(path: FsPathLike, data: str) -> None: ...


# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -562,7 +568,7 @@ class Regex:
# =============================================================================
def which(cmd: str, path: None | str = None) -> str | None: ...
def which_all(cmd: str, path: None | str = None) -> list[str]: ...
def which_re(regex: Regex, path: None | str = None) -> list[str]: ...
def which_re(regex: str | Regex, path: None | str = None) -> list[str]: ...


# =============================================================================
Expand Down Expand Up @@ -940,9 +946,9 @@ import sys
from typing import overload

if sys.version_info >= (3, 12):
from collections.abc import Buffer
from collections.abc import Buffer as Buffer
else:
from typing_extensions import Buffer
from typing_extensions import Buffer as Buffer


class Bytes(Buffer):
Expand Down Expand Up @@ -1073,6 +1079,9 @@ class Bytes(Buffer):
def fromhex(cls, hexstr: str) -> Bytes:
"""Construct a `Bytes` object from a hexadecimal string."""


BytesLike = Buffer | bytes | bytearray | memoryview | Bytes

```
## `ry._dev`

Expand Down Expand Up @@ -3073,6 +3082,18 @@ async def fetch(
headers: dict[str, str] | None = None,
) -> Response: ...

```
## `ry.tokio`

```python
from ry import Bytes
from ry._types import Buffer
from ry.ryo3 import FsPathLike


async def read_async(path: FsPathLike) -> Bytes: ...
async def write_async(path: FsPathLike, data: Buffer) -> None: ...

```
## `ry.xxhash`

Expand Down
31 changes: 26 additions & 5 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ from pathlib import Path

import typing_extensions as te

from ry._types import Buffer

from . import http as http
from ._bytes import Bytes as Bytes
from ._jiff import Date as Date
Expand Down Expand Up @@ -48,6 +50,8 @@ from .reqwest import ReqwestError as ReqwestError
from .reqwest import Response as Response
from .reqwest import ResponseStream as ResponseStream
from .reqwest import fetch as fetch
from .tokio import read_async as read_async
from .tokio import write_async as write_async

__version__: str
__authors__: str
Expand Down Expand Up @@ -412,10 +416,12 @@ async def asleep(seconds: float) -> float:
# =============================================================================
# FILESYSTEM
# =============================================================================
def read_text(path: FsPathLike) -> str: ...
def read(path: FsPathLike) -> Bytes: ...
def read_bytes(path: FsPathLike) -> bytes: ...
def write_text(path: FsPathLike, data: str) -> None: ...
def read_text(path: FsPathLike) -> str: ...
def write(path: FsPathLike, data: Buffer | str) -> None: ...
def write_bytes(path: FsPathLike, data: bytes) -> None: ...
def write_text(path: FsPathLike, data: str) -> None: ...


# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -459,7 +465,7 @@ class Regex:
# =============================================================================
def which(cmd: str, path: None | str = None) -> str | None: ...
def which_all(cmd: str, path: None | str = None) -> list[str]: ...
def which_re(regex: Regex, path: None | str = None) -> list[str]: ...
def which_re(regex: str | Regex, path: None | str = None) -> list[str]: ...


# =============================================================================
Expand Down Expand Up @@ -837,9 +843,9 @@ import sys
from typing import overload

if sys.version_info >= (3, 12):
from collections.abc import Buffer
from collections.abc import Buffer as Buffer
else:
from typing_extensions import Buffer
from typing_extensions import Buffer as Buffer


class Bytes(Buffer):
Expand Down Expand Up @@ -970,6 +976,9 @@ class Bytes(Buffer):
def fromhex(cls, hexstr: str) -> Bytes:
"""Construct a `Bytes` object from a hexadecimal string."""


BytesLike = Buffer | bytes | bytearray | memoryview | Bytes

```
## `ry._dev`

Expand Down Expand Up @@ -2970,6 +2979,18 @@ async def fetch(
headers: dict[str, str] | None = None,
) -> Response: ...

```
## `ry.tokio`

```python
from ry import Bytes
from ry._types import Buffer
from ry.ryo3 import FsPathLike


async def read_async(path: FsPathLike) -> Bytes: ...
async def write_async(path: FsPathLike, data: Buffer) -> None: ...

```
## `ry.xxhash`

Expand Down
4 changes: 2 additions & 2 deletions python/ry/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from typing import TypedDict

if sys.version_info >= (3, 12):
from collections.abc import Buffer as Buffer
from collections.abc import Buffer
else:
from typing_extensions import Buffer as Buffer
from typing_extensions import Buffer
__all__ = (
"Buffer",
"DateTimeTypedDict",
Expand Down
2 changes: 1 addition & 1 deletion python/ry/ryo3/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ class Regex:
# =============================================================================
def which(cmd: str, path: None | str = None) -> str | None: ...
def which_all(cmd: str, path: None | str = None) -> list[str]: ...
def which_re(regex: Regex, path: None | str = None) -> list[str]: ...
def which_re(regex: str | Regex, path: None | str = None) -> list[str]: ...

# =============================================================================
# HECK
Expand Down
16 changes: 16 additions & 0 deletions tests/which/test_which_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ def test_which_regex_existing_exe(tmp_path: Path) -> None:
assert len(result) > 0, "Expected a match for executables starting with 'uwot'"


def test_which_regex_existing_exe_accepts_string(tmp_path: Path) -> None:
"""
Test `which_re` with an existing executable using a regex pattern.
"""
test_bin_dirs = _mk_test_bin_dirs(tmp_path)

# Modify PATH to include test_bin_dirs
original_path = os.environ["PATH"]
search_path = os.pathsep.join(test_bin_dirs) + os.pathsep + original_path
regex = r"^uwot.*"
result = ry.which_re(regex, search_path)
assert isinstance(result, list)
assert result is not None
assert len(result) > 0, "Expected a match for executables starting with 'uwot'"


def test_which_regex_nonexistent_exe(tmp_path: Path) -> None:
"""
Test `which_re` with a regex pattern that matches no executables.
Expand Down

0 comments on commit 7e70e17

Please sign in to comment.