Skip to content

Commit

Permalink
Release 0.2.0b3 (#607)
Browse files Browse the repository at this point in the history
# Description

Please describe the change you have made.

## Checklist

- [ ] Tests added/updated.
- [ ] Run Demo Job Locally.
- [ ] Documentation updated.
- [ ] Changelogs updated in
[CHANGELOG.cdf-tk.md](https://github.com/cognitedata/toolkit/blob/main/CHANGELOG.cdf-tk.md).
- [ ] Template changelogs updated in
[CHANGELOG.templates.md](https://github.com/cognitedata/toolkit/blob/main/CHANGELOG.templates.md).
- [ ] Version bumped.

[_version.py](https://github.com/cognitedata/toolkit/blob/main/cognite/cognite_toolkit/_version.py)
and

[pyproject.toml](https://github.com/cognitedata/toolkit/blob/main/pyproject.toml)
per [semantic versioning](https://semver.org/).
  • Loading branch information
doctrino authored Jun 4, 2024
2 parents 6180e53 + 66113ca commit 5f66b97
Show file tree
Hide file tree
Showing 46 changed files with 1,717 additions and 1,554 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
- id: ruff-format
args:
- --line-length=120
rev: v0.4.6
rev: v0.4.7

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
Expand Down
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
//"--dry-run",
//"--env=local",
//"--include=transformations"
//"--init-dir=foo"
],
"console": "integratedTerminal",
"justMyCode": false
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.cdf-tk.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ Changes are grouped as follows:
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [0.2.0b3] - 2024-06-04

### Added

- Support for resource type `Label` in the `labels` folder.

### Fixed

- The toolkit now ensures `Transformations` and `Functions` are deployed before `Workflows`
- The toolkit now ensures `TimeSeries` and `Groups` are deployed before `DatapointSubscriptions`.

## [0.2.0b2] - 2024-06-03

### Fixed
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ Changes are grouped as follows:
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [0.2.0b3] - 2024-06-04

### Added

- Extended `cognite_modules/examples/my_example_module` with a `Label` case.

## [0.2.0b2] - 2024-06-03

No changes to templates.
Expand Down
6 changes: 3 additions & 3 deletions cognite_toolkit/_api/run_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from cognite.client import CogniteClient

from cognite_toolkit._cdf_tk.commands.run import run_function, run_transformation
from cognite_toolkit._cdf_tk.commands import RunFunctionCommand, RunTransformationCommand
from cognite_toolkit._cdf_tk.utils import CDFToolConfig


Expand All @@ -16,13 +16,13 @@ def _create_tool_config(self) -> CDFToolConfig:
return cdf_tool_config

def transformation(self, external_id: str) -> bool:
return run_transformation(
return RunTransformationCommand().run_transformation(
self._create_tool_config(),
external_id,
)

def function(self, external_id: str, payload: dict, follow: bool = False) -> bool:
return run_function(
return RunFunctionCommand().run_function(
self._create_tool_config(),
external_id,
json.dumps(payload),
Expand Down
130 changes: 50 additions & 80 deletions cognite_toolkit/_cdf.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
#!/usr/bin/env python
# The Typer parameters get mixed up if we use the __future__ import annotations in the main file.
import contextlib

import os
import sys
from collections.abc import Sequence
from dataclasses import dataclass
from importlib import resources
from pathlib import Path
from typing import Annotated, NoReturn, Optional, Union, cast
from typing import Annotated, NoReturn, Optional, Union

import typer
from cognite.client.data_classes.data_modeling import DataModelId, NodeId
from dotenv import load_dotenv
from rich import print
from rich.panel import Panel

from cognite_toolkit._cdf_tk.commands import BuildCommand, CleanCommand, DeployCommand, auth
from cognite_toolkit._cdf_tk.commands.describe import describe_datamodel
from cognite_toolkit._cdf_tk.commands.dump import dump_datamodel_command
from cognite_toolkit._cdf_tk.commands.pull import pull_command
from cognite_toolkit._cdf_tk.commands.run import run_function, run_local_function, run_transformation
from cognite_toolkit._cdf_tk.commands import (
AuthCommand,
BuildCommand,
CleanCommand,
DeployCommand,
DescribeCommand,
DumpCommand,
PullCommand,
RunFunctionCommand,
RunTransformationCommand,
)
from cognite_toolkit._cdf_tk.exceptions import (
ToolkitError,
ToolkitFileNotFoundError,
Expand All @@ -32,9 +37,6 @@
TransformationLoader,
)
from cognite_toolkit._cdf_tk.prototypes import featureflag
from cognite_toolkit._cdf_tk.templates import (
COGNITE_MODULES,
)
from cognite_toolkit._cdf_tk.templates.data_classes import (
ProjectDirectoryInit,
ProjectDirectoryUpgrade,
Expand Down Expand Up @@ -430,32 +432,8 @@ def auth_verify(
The default bootstrap group configuration is admin.readwrite.group.yaml from the cdf_auth_readwrite_all common module.
"""
# TODO: Check if groupsAcl.UPDATE does nothing?
if create_group is not None and update_group != 0:
raise ToolkitInvalidSettingsError("--create-group and --update-group are mutually exclusive.")
with contextlib.redirect_stdout(None):
# Remove the Error message from failing to load the config
# This is verified in check_auth
ToolGlobals = CDFToolConfig.from_context(ctx)

if group_file is None:
template_dir = cast(Path, resources.files("cognite_toolkit"))
group_path = template_dir.joinpath(
Path(f"./{COGNITE_MODULES}/common/cdf_auth_readwrite_all/auth/admin.readwrite.group.yaml")
)
else:
group_path = Path(group_file)
auth.check_auth(
ToolGlobals,
group_file=group_path,
update_group=update_group,
create_group=create_group,
interactive=interactive,
dry_run=dry_run,
verbose=ctx.obj.verbose,
)
if ToolGlobals.failed:
raise ToolkitValidationError("Failure to verify access rights.")
cmd = AuthCommand()
cmd.execute(ctx, dry_run, interactive, group_file, update_group, create_group)


@_app.command("init" if not featureflag.enabled("FF_INTERACTIVE_INIT") else "_init")
Expand Down Expand Up @@ -550,14 +528,14 @@ def describe_main(ctx: typer.Context) -> None:
def describe_datamodel_cmd(
ctx: typer.Context,
space: Annotated[
Optional[str],
str,
typer.Option(
"--space",
"-s",
prompt=True,
help="Space where the data model to describe is located.",
),
] = None,
],
data_model: Annotated[
Optional[str],
typer.Option(
Expand All @@ -570,11 +548,8 @@ def describe_datamodel_cmd(
) -> None:
"""This command will describe the characteristics of a data model given the space
name and datamodel name."""
if space is None or len(space) == 0:
raise ToolkitValidationError("--space is required.")
ToolGlobals = CDFToolConfig.from_context(ctx)
describe_datamodel(ToolGlobals, space, data_model)
return None
cmd = DescribeCommand()
cmd.execute(CDFToolConfig.from_context(ctx), space, data_model)


@run_app.callback(invoke_without_command=True)
Expand All @@ -588,33 +563,32 @@ def run_main(ctx: typer.Context) -> None:
def run_transformation_cmd(
ctx: typer.Context,
external_id: Annotated[
Optional[str],
str,
typer.Option(
"--external-id",
"-e",
prompt=True,
help="External id of the transformation to run.",
),
] = None,
],
) -> None:
"""This command will run the specified transformation using a one-time session."""
ToolGlobals = CDFToolConfig.from_context(ctx)
external_id = cast(str, external_id).strip()
run_transformation(ToolGlobals, external_id)
cmd = RunTransformationCommand()
cmd.run_transformation(CDFToolConfig.from_context(ctx), external_id)


@run_app.command("function")
def run_function_cmd(
ctx: typer.Context,
external_id: Annotated[
Optional[str],
str,
typer.Option(
"--external-id",
"-e",
prompt=True,
help="External id of the function to run.",
),
] = None,
],
payload: Annotated[
Optional[str],
typer.Option(
Expand Down Expand Up @@ -679,32 +653,19 @@ def run_function_cmd(
] = "dev",
) -> None:
"""This command will run the specified function using a one-time session."""
ToolGlobals = CDFToolConfig.from_context(ctx)
external_id = cast(str, external_id).strip()
if not local:
run_function(ToolGlobals, external_id=external_id, payload=payload or "", follow=follow)
return None
if follow:
print(" [bold yellow]WARNING:[/] --follow is not supported when running locally and should not be specified.")
if source_dir is None:
source_dir = "./"
source_path = Path(source_dir)
system_yaml = Path(source_path / "cognite_modules/_system.yaml")
if not source_path.is_dir() or not system_yaml.is_file():
raise ToolkitValidationError(
f"{source_path} is not a valid project directory. Expecting to find in {system_yaml}."
)
ToolGlobals = CDFToolConfig.from_context(ctx)
run_local_function(
ToolGlobals=ToolGlobals,
source_path=source_path,
external_id=external_id,
payload=payload or "{}",
schedule=schedule,
build_env_name=build_env_name,
rebuild_env=rebuild_env,
verbose=ctx.obj.verbose,
no_cleanup=no_cleanup,
cmd = RunFunctionCommand()
cmd.execute(
CDFToolConfig.from_context(ctx),
external_id,
payload,
follow,
local,
rebuild_env,
no_cleanup,
source_dir,
schedule,
build_env_name,
ctx.obj.verbose,
)


Expand Down Expand Up @@ -752,7 +713,7 @@ def pull_transformation_cmd(
] = False,
) -> None:
"""This command will pull the specified transformation and update its YAML file in the module folder"""
pull_command(
PullCommand().execute(
source_dir, external_id, env, dry_run, ctx.obj.verbose, CDFToolConfig.from_context(ctx), TransformationLoader
)

Expand Down Expand Up @@ -803,7 +764,7 @@ def pull_node_cmd(
] = False,
) -> None:
"""This command will pull the specified node and update its YAML file in the module folder."""
pull_command(
PullCommand().execute(
source_dir,
NodeId(space, external_id),
env,
Expand All @@ -814,6 +775,14 @@ def pull_node_cmd(
)


@dump_app.callback(invoke_without_command=True)
def dump_main(ctx: typer.Context) -> None:
"""Commands to dump resource configurations from CDF into a temporary directory."""
if ctx.invoked_subcommand is None:
print("Use [bold yellow]cdf-tk dump --help[/] for more information.")
return None


@dump_app.command("datamodel")
def dump_datamodel_cmd(
ctx: typer.Context,
Expand Down Expand Up @@ -860,7 +829,8 @@ def dump_datamodel_cmd(
] = "tmp",
) -> None:
"""This command will dump the selected data model as yaml to the folder specified, defaults to /tmp."""
dump_datamodel_command(
cmd = DumpCommand()
cmd.execute(
CDFToolConfig.from_context(ctx),
DataModelId(space, external_id, version),
Path(output_dir),
Expand Down
17 changes: 16 additions & 1 deletion cognite_toolkit/_cdf_tk/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
from .auth import AuthCommand
from .build import BuildCommand
from .clean import CleanCommand
from .deploy import DeployCommand
from .describe import DescribeCommand
from .dump import DumpCommand
from .pull import PullCommand
from .run import RunFunctionCommand, RunTransformationCommand

__all__ = ["BuildCommand", "CleanCommand", "DeployCommand"]
__all__ = [
"AuthCommand",
"BuildCommand",
"CleanCommand",
"DeployCommand",
"DescribeCommand",
"DumpCommand",
"PullCommand",
"RunFunctionCommand",
"RunTransformationCommand",
]
Loading

0 comments on commit 5f66b97

Please sign in to comment.