Skip to content

Commit

Permalink
Fix zip
Browse files Browse the repository at this point in the history
  • Loading branch information
qTipTip authored and haakonvt committed Sep 5, 2024
1 parent 23c2873 commit b23275e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions cognite/client/_api/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"})

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -1219,21 +1222,21 @@ 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:
"""`Create a schedule associated with a specific project. <https://developer.cognite.com/api#tag/Function-schedules/operation/postFunctionSchedules>`_
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.
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import annotations

__version__ = "7.58.6"
__version__ = "7.58.7"
__api_subversion__ = "20230101"

0 comments on commit b23275e

Please sign in to comment.