Skip to content

Commit d996edf

Browse files
chore(internal): codegen related update
1 parent e9fa4aa commit d996edf

File tree

6 files changed

+93
-1
lines changed

6 files changed

+93
-1
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,30 @@ jobs:
3030
- name: Run lints
3131
run: ./scripts/lint
3232

33+
upload:
34+
if: github.repository == 'stainless-sdks/open-transit-python'
35+
timeout-minutes: 10
36+
name: upload
37+
permissions:
38+
contents: read
39+
id-token: write
40+
runs-on: depot-ubuntu-24.04
41+
steps:
42+
- uses: actions/checkout@v4
43+
44+
- name: Get GitHub OIDC Token
45+
id: github-oidc
46+
uses: actions/github-script@v6
47+
with:
48+
script: core.setOutput('github_token', await core.getIDToken());
49+
50+
- name: Upload tarball
51+
env:
52+
URL: https://pkg.stainless.com/s
53+
AUTH: ${{ steps.github-oidc.outputs.github_token }}
54+
SHA: ${{ github.sha }}
55+
run: ./scripts/utils/upload-artifact.sh
56+
3357
test:
3458
timeout-minutes: 10
3559
name: test

scripts/utils/upload-artifact.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
set -exuo pipefail
3+
4+
RESPONSE=$(curl -X POST "$URL" \
5+
-H "Authorization: Bearer $AUTH" \
6+
-H "Content-Type: application/json")
7+
8+
SIGNED_URL=$(echo "$RESPONSE" | jq -r '.url')
9+
10+
if [[ "$SIGNED_URL" == "null" ]]; then
11+
echo -e "\033[31mFailed to get signed URL.\033[0m"
12+
exit 1
13+
fi
14+
15+
UPLOAD_RESPONSE=$(tar -cz . | curl -v -X PUT \
16+
-H "Content-Type: application/gzip" \
17+
--data-binary @- "$SIGNED_URL" 2>&1)
18+
19+
if echo "$UPLOAD_RESPONSE" | grep -q "HTTP/[0-9.]* 200"; then
20+
echo -e "\033[32mUploaded build to Stainless storage.\033[0m"
21+
echo -e "\033[32mInstallation: pip install 'https://pkg.stainless.com/s/open-transit-python/$SHA'\033[0m"
22+
else
23+
echo -e "\033[31mFailed to upload artifact.\033[0m"
24+
exit 1
25+
fi

src/onebusaway/__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
@@ -78,6 +80,9 @@
7880
"DefaultAsyncHttpxClient",
7981
]
8082

83+
if not _t.TYPE_CHECKING:
84+
from ._utils._resources_proxy import resources as resources
85+
8186
_setup_logging()
8287

8388
# Update the __module__ attribute for exported symbols so that

src/onebusaway/_utils/_proxy.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ def __dir__(self) -> Iterable[str]:
4646
@property # type: ignore
4747
@override
4848
def __class__(self) -> type: # pyright: ignore
49-
proxied = self.__get_proxied__()
49+
try:
50+
proxied = self.__get_proxied__()
51+
except Exception:
52+
return type(self)
5053
if issubclass(type(proxied), LazyProxy):
5154
return type(proxied)
5255
return proxied.__class__
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 `onebusaway.resources` module.
11+
12+
This is used so that we can lazily import `onebusaway.resources` only when
13+
needed *and* so that users can just import `onebusaway` and reference `onebusaway.resources`
14+
"""
15+
16+
@override
17+
def __load__(self) -> Any:
18+
import importlib
19+
20+
mod = importlib.import_module("onebusaway.resources")
21+
return mod
22+
23+
24+
resources = ResourcesProxy().__as_proxied__()

tests/test_utils/test_proxy.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,14 @@ def test_recursive_proxy() -> None:
2121
assert dir(proxy) == []
2222
assert type(proxy).__name__ == "RecursiveLazyProxy"
2323
assert type(operator.attrgetter("name.foo.bar.baz")(proxy)).__name__ == "RecursiveLazyProxy"
24+
25+
26+
def test_isinstance_does_not_error() -> None:
27+
class AlwaysErrorProxy(LazyProxy[Any]):
28+
@override
29+
def __load__(self) -> Any:
30+
raise RuntimeError("Mocking missing dependency")
31+
32+
proxy = AlwaysErrorProxy()
33+
assert not isinstance(proxy, dict)
34+
assert isinstance(proxy, LazyProxy)

0 commit comments

Comments
 (0)