From b23275e1ce2a98e130b6c4baf40695ba83b12b5d Mon Sep 17 00:00:00 2001 From: Ivar Stangeby Date: Thu, 5 Sep 2024 14:45:56 +0200 Subject: [PATCH] Fix zip --- cognite/client/_api/functions.py | 21 ++++++++++++--------- cognite/client/_version.py | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/cognite/client/_api/functions.py b/cognite/client/_api/functions.py index 094cb0249e..9e120e2e86 100644 --- a/cognite/client/_api/functions.py +++ b/cognite/client/_api/functions.py @@ -58,7 +58,8 @@ MAX_RETRIES = 5 REQUIREMENTS_FILE_NAME = "requirements.txt" -REQUIREMENTS_REG = re.compile(r"(\[\/?requirements\]){1}$", flags=re.M) # Matches [requirements] and [/requirements] +# Matches [requirements] and [/requirements] +REQUIREMENTS_REG = re.compile(r"(\[\/?requirements\]){1}$", flags=re.M) UNCOMMENTED_LINE_REG = re.compile(r"^[^\#]]*.*") ALLOWED_HANDLE_ARGS = frozenset({"data", "client", "secrets", "function_call_info"}) @@ -157,7 +158,7 @@ def __call__( file_id (int | None): The file ID of the zip-file used to create the function. status (FunctionStatus | None): Status of the function. Possible values: ["Queued", "Deploying", "Ready", "Failed"]. external_id_prefix (str | None): External ID prefix to filter on. - created_time (dict[Literal["min", "max"], int] | TimestampRange | None): Range between two timestamps. Possible keys are `min` and `max`, with values given as time stamps in ms. + created_time (dict[Literal['min', 'max'], int] | TimestampRange | None): Range between two timestamps. Possible keys are `min` and `max`, with values given as time stamps in ms. metadata (dict[str, str] | None): No description. limit (int | None): Maximum number of functions to return. Defaults to yielding all functions. @@ -414,7 +415,7 @@ def list( file_id (int | None): The file ID of the zip-file used to create the function. status (FunctionStatus | None): Status of the function. Possible values: ["Queued", "Deploying", "Ready", "Failed"]. external_id_prefix (str | None): External ID prefix to filter on. - created_time (dict[Literal["min", "max"], int] | TimestampRange | None): Range between two timestamps. Possible keys are `min` and `max`, with values given as time stamps in ms. + created_time (dict[Literal['min', 'max'], int] | TimestampRange | None): Range between two timestamps. Possible keys are `min` and `max`, with values given as time stamps in ms. metadata (dict[str, str] | None): Custom, application-specific metadata. String key -> String value. Limits: Maximum length of key is 32, value 512 characters, up to 16 key-value pairs. Maximum size of entire metadata is 4096 bytes. limit (int | None): Maximum number of functions to return. Pass in -1, float('inf') or None to list all. @@ -597,7 +598,7 @@ def _zip_and_upload_folder( try: with TemporaryDirectory() as tmpdir: zip_path = Path(tmpdir, "function.zip") - with ZipFile(zip_path, "w") as zf: + with ZipFile(zip_path, "w", strict_timestamps=False) as zf: for root, dirs, files in os.walk("."): zf.write(root) @@ -638,7 +639,7 @@ def _zip_and_upload_handle( f.write(f"{req}\n") zip_path = Path(tmpdir, "function.zip") - with ZipFile(zip_path, "w") as zf: + with ZipFile(zip_path, "w", strict_timestamps=False) as zf: zf.write(handle_path, arcname=HANDLER_FILE_NAME) if docstr_requirements: zf.write(requirements_path, arcname=REQUIREMENTS_FILE_NAME) @@ -788,10 +789,12 @@ def _validate_function_handle(handle_obj: Callable | ast.FunctionDef) -> None: accepts_args = set(signature(handle_obj).parameters) if name != "handle": - raise TypeError(f"Function is named '{name}' but must be named 'handle'.") + raise TypeError(f"Function is named '{ + name}' but must be named 'handle'.") if not accepts_args <= ALLOWED_HANDLE_ARGS: - raise TypeError(f"Arguments {accepts_args} to the function must be a subset of {ALLOWED_HANDLE_ARGS}.") + raise TypeError(f"Arguments {accepts_args} to the function must be a subset of { + ALLOWED_HANDLE_ARGS}.") def _extract_requirements_from_file(file_name: str) -> list[str]: @@ -1219,10 +1222,10 @@ def list( def create( self, name: str | FunctionScheduleWrite, + client_credentials: dict | ClientCredentials, cron_expression: str | None = None, function_id: int | None = None, function_external_id: str | None = None, - client_credentials: dict | ClientCredentials | None = None, description: str | None = None, data: dict | None = None, ) -> FunctionSchedule: @@ -1230,10 +1233,10 @@ def create( Args: name (str | FunctionScheduleWrite): Name of the schedule or FunctionSchedule object. If a function schedule object is passed, the other arguments are ignored except for the client_credentials argument. + client_credentials (dict | ClientCredentials): Instance of ClientCredentials or a dictionary containing client credentials: 'client_id' and 'client_secret'. cron_expression (str | None): Cron expression. function_id (int | None): Id of the function to attach the schedule to. function_external_id (str | None): External id of the function to attach the schedule to. Will be converted to (internal) ID before creating the schedule. - client_credentials (dict | ClientCredentials | None): Instance of ClientCredentials or a dictionary containing client credentials: 'client_id' and 'client_secret'. description (str | None): Description of the schedule. data (dict | None): Data to be passed to the scheduled run. diff --git a/cognite/client/_version.py b/cognite/client/_version.py index ccd04ba038..34b3d83317 100644 --- a/cognite/client/_version.py +++ b/cognite/client/_version.py @@ -1,4 +1,4 @@ from __future__ import annotations -__version__ = "7.58.6" +__version__ = "7.58.7" __api_subversion__ = "20230101"