Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions cognite/extractorutils/unstable/core/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,14 @@ def _try_get_application_config(

return application_config, current_config_revision

def _try_change_cwd(self, cwd: Path | None) -> None:
if cwd is not None:
def _try_set_cwd(self, args: Namespace) -> None:
if args.cwd is not None and len(args.cwd) > 0:
try:
os.chdir(cwd)
self.logger.info(f"Changed working directory to {cwd}")
os.chdir(args.cwd[0])
self.logger.info(f"Changed working directory to {args.cwd[0]}")
except OSError as e:
self.logger.critical(f"Could not change working directory to {cwd}: {e}")
raise InvalidConfigError(f"Could not change working directory to {cwd}") from e
self.logger.critical(f"Could not change working directory to {args.cwd[0]}: {e}")
raise InvalidConfigError(f"Could not change working directory to {args.cwd[0]}") from e

self.logger.info(f"Using {os.getcwd()} as working directory")

Expand Down Expand Up @@ -278,7 +278,7 @@ def _verify_connection_config(self, connection_config: ConnectionConfig) -> bool
self._cognite_client.post(
f"/api/v1/projects/{self._cognite_client.config.project}/odin/checkin",
json={
"externalId": connection_config.integration,
"externalId": connection_config.integration.external_id,
},
headers={"cdf-version": "alpha"},
)
Expand Down Expand Up @@ -332,7 +332,7 @@ def run(self) -> None:
self.logger.info(f"Started runtime with PID {os.getpid()}")

try:
self._try_change_cwd(args.cwd[0])
self._try_set_cwd(args)
connection_config = load_file(args.connection_config[0], ConnectionConfig)
except InvalidConfigError as e:
self.logger.error(str(e))
Expand Down
7 changes: 6 additions & 1 deletion tests/test_unstable/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,15 @@ def cancel_after_delay() -> None:
assert "No configuration found for the given integration" in errors["items"][0]["description"]


def test_verify_connection_config(connection_config: ConnectionConfig) -> None:
runtime = Runtime(TestExtractor)
assert runtime._verify_connection_config(connection_config)


def test_changing_cwd() -> None:
runtime = Runtime(TestExtractor)
original_cwd = os.getcwd()
runtime._try_change_cwd(Path(__file__).parent)
runtime._try_set_cwd(args=Namespace(cwd=(Path(__file__).parent.as_posix(),)))

assert os.getcwd() == str(Path(__file__).parent)
assert os.getcwd() != original_cwd
Loading