Skip to content

Commit 8b1b0da

Browse files
fix(package): support direct resource imports
1 parent 9881bd2 commit 8b1b0da

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/codex/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3+
import typing as _t
4+
35
from . import types
46
from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes
57
from ._utils import file_from_path
@@ -80,6 +82,9 @@
8082
"DefaultAsyncHttpxClient",
8183
]
8284

85+
if not _t.TYPE_CHECKING:
86+
from ._utils._resources_proxy import resources as resources
87+
8388
_setup_logging()
8489

8590
# Update the __module__ attribute for exported symbols so that

src/codex/_utils/_resources_proxy.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from __future__ import annotations
2+
3+
from typing import Any
4+
from typing_extensions import override
5+
6+
from ._proxy import LazyProxy
7+
8+
9+
class ResourcesProxy(LazyProxy[Any]):
10+
"""A proxy for the `codex.resources` module.
11+
12+
This is used so that we can lazily import `codex.resources` only when
13+
needed *and* so that users can just import `codex` and reference `codex.resources`
14+
"""
15+
16+
@override
17+
def __load__(self) -> Any:
18+
import importlib
19+
20+
mod = importlib.import_module("codex.resources")
21+
return mod
22+
23+
24+
resources = ResourcesProxy().__as_proxied__()

0 commit comments

Comments
 (0)