Skip to content

Commit bd882f7

Browse files
committed
Merge branch 'main' into nk/websocket_dynamic
2 parents d6f288c + 1054f5c commit bd882f7

18 files changed

+93
-978
lines changed

.github/workflows/build.yml

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
name: Build Status
22

3+
env:
4+
# Run full CI Monday and Thursday at 3:25am EST (08:25 UTC)
5+
# Note: do not run scheduled jobs on the hour exactly, per:
6+
# https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#schedule
7+
# GitHub Actions schedules can sometimes delay by up to 15 minutes due to platform load
8+
FULL_CI_SCHEDULE: '25 8 * * 1,4'
9+
310
on:
411
push:
512
branches:
@@ -26,6 +33,8 @@ on:
2633
required: false
2734
type: boolean
2835
default: false
36+
schedule:
37+
- cron: '25 8 * * 1,4'
2938

3039
concurrency:
3140
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
@@ -60,7 +69,7 @@ jobs:
6069

6170
outputs:
6271
COMMIT_MESSAGE: ${{ steps.setup.outputs.COMMIT_MSG }}
63-
FULL_RUN: ${{ steps.setuppush.outputs.FULL_RUN || steps.setuppr.outputs.FULL_RUN || steps.setupmanual.outputs.FULL_RUN }}
72+
FULL_RUN: ${{ steps.setuppush.outputs.FULL_RUN || steps.setuppr.outputs.FULL_RUN || steps.setupmanual.outputs.FULL_RUN || steps.setupschedule.outputs.FULL_RUN }}
6473

6574
steps:
6675
- name: Checkout
@@ -109,6 +118,17 @@ jobs:
109118
env:
110119
FULL_RUN: ${{ github.event.inputs.ci-full }}
111120
if: ${{ github.event_name == 'workflow_dispatch' }}
121+
122+
- name: Display and Setup Build Args (Schedule)
123+
id: setupschedule
124+
run: |
125+
echo "Commit Message: $COMMIT_MSG"
126+
echo "Full Run: $FULL_RUN"
127+
echo "COMMIT_MSG=$COMMIT_MSG" >> $GITHUB_OUTPUT
128+
echo "FULL_RUN=$FULL_RUN" >> $GITHUB_OUTPUT
129+
env:
130+
FULL_RUN: ${{ github.event.schedule == env.FULL_CI_SCHEDULE }}
131+
if: ${{ github.event_name == 'schedule' }}
112132

113133
########################################################
114134
#......................................................#
@@ -174,7 +194,7 @@ jobs:
174194
matrix:
175195
os:
176196
- ubuntu-24.04 # https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md
177-
- macos-12 # https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md
197+
- macos-13 # https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md
178198
- macos-14 # https://github.com/actions/runner-images/blob/main/images/macos/macos-14-arm64-Readme.md
179199
- windows-2019 # https://github.com/actions/runner-images/blob/main/images/windows/Windows2019-Readme.md
180200
python-version:
@@ -267,7 +287,7 @@ jobs:
267287

268288
# avoid unnecessary use of mac resources
269289
- is-full-run: false
270-
os: macos-12
290+
os: macos-13
271291

272292
- is-full-run: false
273293
os: macos-14
@@ -323,7 +343,7 @@ jobs:
323343
CIBW_ENVIRONMENT_MACOS: CCACHE_DIR="/Users/runner/work/csp/csp/.ccache" VCPKG_DEFAULT_BINARY_CACHE="${{ env.VCPKG_DEFAULT_BINARY_CACHE }}" VCPKG_DOWNLOADS="${{ env.VCPKG_DOWNLOADS }}"
324344
CIBW_ARCHS_MACOS: x86_64
325345
CIBW_BUILD_VERBOSITY: 3
326-
if: ${{ matrix.os == 'macos-12' }}
346+
if: ${{ matrix.os == 'macos-13' }}
327347

328348
- name: Python Build Steps (Macos arm)
329349
run: make dist-py-cibw
@@ -439,7 +459,7 @@ jobs:
439459
matrix:
440460
os:
441461
- ubuntu-24.04
442-
- macos-12
462+
- macos-13
443463
- macos-14
444464
- windows-2019
445465
python-version:
@@ -479,7 +499,7 @@ jobs:
479499

480500
# avoid unnecessary use of mac resources
481501
- is-full-run: false
482-
os: macos-12
502+
os: macos-13
483503

484504
- is-full-run: false
485505
os: macos-14

.github/workflows/conda.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
os:
3535
- ubuntu-24.04
3636
- macos-14
37-
- macos-12
37+
- macos-13
3838
- windows-2019
3939
runs-on: ${{ matrix.os }}
4040
steps:

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Project Configuration #
33
#########################
44
cmake_minimum_required(VERSION 3.20.0)
5-
project(csp VERSION "0.0.5")
5+
project(csp VERSION "0.0.6")
66
set(CMAKE_CXX_STANDARD 20)
77

88
###################################################################################################################################################

Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,10 @@ dependencies-fedora: ## install dependencies for linux
203203
dependencies-vcpkg: ## install dependencies via vcpkg
204204
cd vcpkg && ./bootstrap-vcpkg.sh && ./vcpkg install
205205

206+
## TODO remove pin on cmake below once we identify why 3.31.2 is failing OR cmake releases a new version which installs properly
206207
dependencies-win: ## install dependencies via windows
207-
choco install cmake curl winflexbison ninja unzip zip --no-progress -y
208+
choco install cmake --version=3.31.1
209+
choco install curl winflexbison ninja unzip zip --no-progress -y
208210

209211
############################################################################################
210212
# Thanks to Francoise at marmelab.com for this

csp/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
from . import stats
3333

34-
__version__ = "0.0.5"
34+
__version__ = "0.0.6"
3535

3636

3737
def get_include_path():

csp/impl/struct.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __new__(cls, name, bases, dct):
3434
# Lists need to be normalized too as potentially we need to add a boolean flag to use FastList
3535
if v == FastList:
3636
raise TypeError(f"{v} annotation is not supported without args")
37-
if CspTypingUtils.is_generic_container(v):
37+
if CspTypingUtils.is_generic_container(v) or CspTypingUtils.is_union_type(v):
3838
actual_type = ContainerTypeNormalizer.normalized_type_to_actual_python_type(v)
3939
if CspTypingUtils.is_generic_container(actual_type):
4040
raise TypeError(f"{v} annotation is not supported as a struct field [{actual_type}]")

csp/impl/types/container_type_normalizer.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,28 @@ def _convert_containers_to_typing_generic_meta(cls, typ, is_within_container):
7373
def normalized_type_to_actual_python_type(cls, typ, level=0):
7474
if isinstance(typ, typing_extensions._AnnotatedAlias):
7575
typ = CspTypingUtils.get_origin(typ)
76+
7677
if CspTypingUtils.is_generic_container(typ):
77-
if CspTypingUtils.get_origin(typ) is FastList and level == 0:
78+
origin = CspTypingUtils.get_origin(typ)
79+
if origin is FastList and level == 0:
7880
return [cls.normalized_type_to_actual_python_type(typ.__args__[0], level + 1), True]
79-
if CspTypingUtils.get_origin(typ) is typing.List and level == 0:
81+
if origin is typing.List and level == 0:
8082
return [cls.normalized_type_to_actual_python_type(typ.__args__[0], level + 1)]
83+
if origin in (typing.Literal, typing_extensions.Literal): # Not the same in python 3.8/3.9
84+
# Import here to prevent circular import
85+
from csp.impl.types.instantiation_type_resolver import UpcastRegistry
86+
87+
args = typing.get_args(typ)
88+
typ = type(args[0])
89+
for arg in args[1:]:
90+
typ = UpcastRegistry.instance().resolve_type(typ, type(arg), raise_on_error=False)
91+
if typ:
92+
return typ
93+
else:
94+
return object
8195
return cls._NORMALIZED_TYPE_MAPPING.get(CspTypingUtils.get_origin(typ), typ)
96+
elif CspTypingUtils.is_union_type(typ):
97+
return object
8298
else:
8399
return typ
84100

csp/impl/wiring/signature.py

-12
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,8 @@ def parse_inputs(self, forced_tvars, *args, allow_none_ts=False, **kwargs):
166166
if USE_PYDANTIC:
167167
return self._parse_inputs_pydantic(forced_tvars, *args, allow_none_ts=allow_none_ts, **kwargs)
168168

169-
from csp.utils.object_factory_registry import Injected
170-
171169
flat_args = self.flatten_args(*args, **kwargs)
172170

173-
for i, arg in enumerate(flat_args):
174-
if isinstance(arg, Injected):
175-
flat_args[i] = arg.value
176-
177171
type_resolver = InputInstanceTypeResolver(
178172
function_name=self._name,
179173
input_definitions=self._inputs[self._num_alarms :],
@@ -214,8 +208,6 @@ def parse_inputs(self, forced_tvars, *args, allow_none_ts=False, **kwargs):
214208
return tuple(type_resolver.ts_inputs), tuple(type_resolver.scalar_inputs), type_resolver.tvars
215209

216210
def _parse_inputs_pydantic(self, forced_tvars, *args, allow_none_ts=False, **kwargs):
217-
from csp.utils.object_factory_registry import Injected
218-
219211
new_kwargs = {}
220212
for k, v in kwargs.items():
221213
new_kwargs[f"{INPUT_PREFIX}{k}"] = v
@@ -227,10 +219,6 @@ def _parse_inputs_pydantic(self, forced_tvars, *args, allow_none_ts=False, **kwa
227219

228220
new_kwargs[f"{INPUT_PREFIX}{inp.name}"] = arg
229221

230-
for name, arg in new_kwargs.items():
231-
if isinstance(arg, Injected):
232-
new_kwargs[name] = arg.value
233-
234222
context = TVarValidationContext(forced_tvars=forced_tvars, allow_none_ts=allow_none_ts)
235223
try:
236224
input_model = self._input_model.model_validate(new_kwargs, context=context)

csp/tests/adapters/test_websocket.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from contextlib import contextmanager
99
from datetime import datetime, timedelta
1010
from tornado.testing import bind_unused_port
11-
from typing import List, Optional, Type
11+
from typing import List
1212

1313
import csp
1414
from csp import ts

csp/tests/impl/test_pandas_perspective.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
import pandas as pd
33
import pyarrow as pa
4+
import sys
45
import unittest
56
from datetime import date, datetime, timedelta
67
from packaging import version
@@ -220,7 +221,7 @@ def test_run_types(self):
220221
"index": pd.StringDtype(),
221222
"timestamp": np.dtype("datetime64[ns]"),
222223
"s_str": pd.StringDtype(),
223-
"s_int": pd.Int64Dtype(),
224+
"s_int": pd.Int64Dtype() if sys.platform != "win32" else pd.Int32Dtype(),
224225
"s_float": floatDtype,
225226
"s_bool": pd.BooleanDtype(),
226227
"s_date": np.dtype("datetime64[ns]"),

csp/tests/impl/test_struct.py

+36-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import typing
77
import unittest
88
from datetime import date, datetime, time, timedelta
9-
from typing import Dict, List, Set, Tuple
9+
from typing import Dict, List, Literal, Optional, Set, Tuple, Union
1010
from typing_extensions import Annotated
1111

1212
import csp
@@ -2960,6 +2960,41 @@ class StructWithAnnotations(csp.Struct):
29602960
)
29612961
self.assertEqual(StructWithAnnotations.metadata(typed=False), {"b": float, "d": dict, "s": str})
29622962

2963+
def test_literal(self):
2964+
simple_class0 = SimpleClass(0)
2965+
simple_class1 = SimpleClass(1)
2966+
2967+
class StructWithLiteral(csp.Struct):
2968+
s: Literal["foo", "bar"]
2969+
f: Literal[0, 1.0]
2970+
o: Literal["foo", 0]
2971+
c: Literal[simple_class0, simple_class1]
2972+
2973+
self.assertEqual(
2974+
StructWithLiteral.metadata(typed=True),
2975+
{
2976+
"s": Literal["foo", "bar"],
2977+
"f": Literal[0, 1.0],
2978+
"o": Literal["foo", 0],
2979+
"c": Literal[simple_class0, simple_class1],
2980+
},
2981+
)
2982+
self.assertEqual(StructWithLiteral.metadata(typed=False), {"s": str, "f": float, "o": object, "c": SimpleClass})
2983+
2984+
def test_union(self):
2985+
class StructWithUnion(csp.Struct):
2986+
o1: Union[int, float]
2987+
o2: Optional[str]
2988+
2989+
self.assertEqual(
2990+
StructWithUnion.metadata(typed=True),
2991+
{
2992+
"o1": Union[int, float],
2993+
"o2": Optional[str],
2994+
},
2995+
)
2996+
self.assertEqual(StructWithUnion.metadata(typed=False), {"o1": object, "o2": object})
2997+
29632998

29642999
if __name__ == "__main__":
29653000
unittest.main()

0 commit comments

Comments
 (0)