Skip to content

Commit

Permalink
Merge branch 'main' into nk/websocket_dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
NeejWeej committed Dec 15, 2024
2 parents d6f288c + 1054f5c commit bd882f7
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 978 deletions.
32 changes: 26 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
name: Build Status

env:
# Run full CI Monday and Thursday at 3:25am EST (08:25 UTC)
# Note: do not run scheduled jobs on the hour exactly, per:
# https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#schedule
# GitHub Actions schedules can sometimes delay by up to 15 minutes due to platform load
FULL_CI_SCHEDULE: '25 8 * * 1,4'

on:
push:
branches:
Expand All @@ -26,6 +33,8 @@ on:
required: false
type: boolean
default: false
schedule:
- cron: '25 8 * * 1,4'

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand Down Expand Up @@ -60,7 +69,7 @@ jobs:

outputs:
COMMIT_MESSAGE: ${{ steps.setup.outputs.COMMIT_MSG }}
FULL_RUN: ${{ steps.setuppush.outputs.FULL_RUN || steps.setuppr.outputs.FULL_RUN || steps.setupmanual.outputs.FULL_RUN }}
FULL_RUN: ${{ steps.setuppush.outputs.FULL_RUN || steps.setuppr.outputs.FULL_RUN || steps.setupmanual.outputs.FULL_RUN || steps.setupschedule.outputs.FULL_RUN }}

steps:
- name: Checkout
Expand Down Expand Up @@ -109,6 +118,17 @@ jobs:
env:
FULL_RUN: ${{ github.event.inputs.ci-full }}
if: ${{ github.event_name == 'workflow_dispatch' }}

- name: Display and Setup Build Args (Schedule)
id: setupschedule
run: |
echo "Commit Message: $COMMIT_MSG"
echo "Full Run: $FULL_RUN"
echo "COMMIT_MSG=$COMMIT_MSG" >> $GITHUB_OUTPUT
echo "FULL_RUN=$FULL_RUN" >> $GITHUB_OUTPUT
env:
FULL_RUN: ${{ github.event.schedule == env.FULL_CI_SCHEDULE }}
if: ${{ github.event_name == 'schedule' }}

########################################################
#......................................................#
Expand Down Expand Up @@ -174,7 +194,7 @@ jobs:
matrix:
os:
- ubuntu-24.04 # https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md
- macos-12 # https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md
- macos-13 # https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md
- macos-14 # https://github.com/actions/runner-images/blob/main/images/macos/macos-14-arm64-Readme.md
- windows-2019 # https://github.com/actions/runner-images/blob/main/images/windows/Windows2019-Readme.md
python-version:
Expand Down Expand Up @@ -267,7 +287,7 @@ jobs:

# avoid unnecessary use of mac resources
- is-full-run: false
os: macos-12
os: macos-13

- is-full-run: false
os: macos-14
Expand Down Expand Up @@ -323,7 +343,7 @@ jobs:
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 }}"
CIBW_ARCHS_MACOS: x86_64
CIBW_BUILD_VERBOSITY: 3
if: ${{ matrix.os == 'macos-12' }}
if: ${{ matrix.os == 'macos-13' }}

- name: Python Build Steps (Macos arm)
run: make dist-py-cibw
Expand Down Expand Up @@ -439,7 +459,7 @@ jobs:
matrix:
os:
- ubuntu-24.04
- macos-12
- macos-13
- macos-14
- windows-2019
python-version:
Expand Down Expand Up @@ -479,7 +499,7 @@ jobs:

# avoid unnecessary use of mac resources
- is-full-run: false
os: macos-12
os: macos-13

- is-full-run: false
os: macos-14
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
os:
- ubuntu-24.04
- macos-14
- macos-12
- macos-13
- windows-2019
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Project Configuration #
#########################
cmake_minimum_required(VERSION 3.20.0)
project(csp VERSION "0.0.5")
project(csp VERSION "0.0.6")
set(CMAKE_CXX_STANDARD 20)

###################################################################################################################################################
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ dependencies-fedora: ## install dependencies for linux
dependencies-vcpkg: ## install dependencies via vcpkg
cd vcpkg && ./bootstrap-vcpkg.sh && ./vcpkg install

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

############################################################################################
# Thanks to Francoise at marmelab.com for this
Expand Down
2 changes: 1 addition & 1 deletion csp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

from . import stats

__version__ = "0.0.5"
__version__ = "0.0.6"


def get_include_path():
Expand Down
2 changes: 1 addition & 1 deletion csp/impl/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __new__(cls, name, bases, dct):
# Lists need to be normalized too as potentially we need to add a boolean flag to use FastList
if v == FastList:
raise TypeError(f"{v} annotation is not supported without args")
if CspTypingUtils.is_generic_container(v):
if CspTypingUtils.is_generic_container(v) or CspTypingUtils.is_union_type(v):
actual_type = ContainerTypeNormalizer.normalized_type_to_actual_python_type(v)
if CspTypingUtils.is_generic_container(actual_type):
raise TypeError(f"{v} annotation is not supported as a struct field [{actual_type}]")
Expand Down
20 changes: 18 additions & 2 deletions csp/impl/types/container_type_normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,28 @@ def _convert_containers_to_typing_generic_meta(cls, typ, is_within_container):
def normalized_type_to_actual_python_type(cls, typ, level=0):
if isinstance(typ, typing_extensions._AnnotatedAlias):
typ = CspTypingUtils.get_origin(typ)

if CspTypingUtils.is_generic_container(typ):
if CspTypingUtils.get_origin(typ) is FastList and level == 0:
origin = CspTypingUtils.get_origin(typ)
if origin is FastList and level == 0:
return [cls.normalized_type_to_actual_python_type(typ.__args__[0], level + 1), True]
if CspTypingUtils.get_origin(typ) is typing.List and level == 0:
if origin is typing.List and level == 0:
return [cls.normalized_type_to_actual_python_type(typ.__args__[0], level + 1)]
if origin in (typing.Literal, typing_extensions.Literal): # Not the same in python 3.8/3.9
# Import here to prevent circular import
from csp.impl.types.instantiation_type_resolver import UpcastRegistry

args = typing.get_args(typ)
typ = type(args[0])
for arg in args[1:]:
typ = UpcastRegistry.instance().resolve_type(typ, type(arg), raise_on_error=False)
if typ:
return typ
else:
return object
return cls._NORMALIZED_TYPE_MAPPING.get(CspTypingUtils.get_origin(typ), typ)
elif CspTypingUtils.is_union_type(typ):
return object
else:
return typ

Expand Down
12 changes: 0 additions & 12 deletions csp/impl/wiring/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,8 @@ def parse_inputs(self, forced_tvars, *args, allow_none_ts=False, **kwargs):
if USE_PYDANTIC:
return self._parse_inputs_pydantic(forced_tvars, *args, allow_none_ts=allow_none_ts, **kwargs)

from csp.utils.object_factory_registry import Injected

flat_args = self.flatten_args(*args, **kwargs)

for i, arg in enumerate(flat_args):
if isinstance(arg, Injected):
flat_args[i] = arg.value

type_resolver = InputInstanceTypeResolver(
function_name=self._name,
input_definitions=self._inputs[self._num_alarms :],
Expand Down Expand Up @@ -214,8 +208,6 @@ def parse_inputs(self, forced_tvars, *args, allow_none_ts=False, **kwargs):
return tuple(type_resolver.ts_inputs), tuple(type_resolver.scalar_inputs), type_resolver.tvars

def _parse_inputs_pydantic(self, forced_tvars, *args, allow_none_ts=False, **kwargs):
from csp.utils.object_factory_registry import Injected

new_kwargs = {}
for k, v in kwargs.items():
new_kwargs[f"{INPUT_PREFIX}{k}"] = v
Expand All @@ -227,10 +219,6 @@ def _parse_inputs_pydantic(self, forced_tvars, *args, allow_none_ts=False, **kwa

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

for name, arg in new_kwargs.items():
if isinstance(arg, Injected):
new_kwargs[name] = arg.value

context = TVarValidationContext(forced_tvars=forced_tvars, allow_none_ts=allow_none_ts)
try:
input_model = self._input_model.model_validate(new_kwargs, context=context)
Expand Down
2 changes: 1 addition & 1 deletion csp/tests/adapters/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from contextlib import contextmanager
from datetime import datetime, timedelta
from tornado.testing import bind_unused_port
from typing import List, Optional, Type
from typing import List

import csp
from csp import ts
Expand Down
3 changes: 2 additions & 1 deletion csp/tests/impl/test_pandas_perspective.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import pandas as pd
import pyarrow as pa
import sys
import unittest
from datetime import date, datetime, timedelta
from packaging import version
Expand Down Expand Up @@ -220,7 +221,7 @@ def test_run_types(self):
"index": pd.StringDtype(),
"timestamp": np.dtype("datetime64[ns]"),
"s_str": pd.StringDtype(),
"s_int": pd.Int64Dtype(),
"s_int": pd.Int64Dtype() if sys.platform != "win32" else pd.Int32Dtype(),
"s_float": floatDtype,
"s_bool": pd.BooleanDtype(),
"s_date": np.dtype("datetime64[ns]"),
Expand Down
37 changes: 36 additions & 1 deletion csp/tests/impl/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import typing
import unittest
from datetime import date, datetime, time, timedelta
from typing import Dict, List, Set, Tuple
from typing import Dict, List, Literal, Optional, Set, Tuple, Union
from typing_extensions import Annotated

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

def test_literal(self):
simple_class0 = SimpleClass(0)
simple_class1 = SimpleClass(1)

class StructWithLiteral(csp.Struct):
s: Literal["foo", "bar"]
f: Literal[0, 1.0]
o: Literal["foo", 0]
c: Literal[simple_class0, simple_class1]

self.assertEqual(
StructWithLiteral.metadata(typed=True),
{
"s": Literal["foo", "bar"],
"f": Literal[0, 1.0],
"o": Literal["foo", 0],
"c": Literal[simple_class0, simple_class1],
},
)
self.assertEqual(StructWithLiteral.metadata(typed=False), {"s": str, "f": float, "o": object, "c": SimpleClass})

def test_union(self):
class StructWithUnion(csp.Struct):
o1: Union[int, float]
o2: Optional[str]

self.assertEqual(
StructWithUnion.metadata(typed=True),
{
"o1": Union[int, float],
"o2": Optional[str],
},
)
self.assertEqual(StructWithUnion.metadata(typed=False), {"o1": object, "o2": object})


if __name__ == "__main__":
unittest.main()
Loading

0 comments on commit bd882f7

Please sign in to comment.