generated from childmindresearch/template-python-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
174 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
# Styx definitions and minimal runtime | ||
# Styx type definitions and minimal runtime | ||
|
||
[![Build](https://github.com/childmindresearch/styxdefs/actions/workflows/test.yaml/badge.svg?branch=main)](https://github.com/childmindresearch/styxdefs/actions/workflows/test.yaml?query=branch%3Amain) | ||
[![codecov](https://codecov.io/gh/childmindresearch/styxdefs/branch/main/graph/badge.svg?token=22HWWFWPW5)](https://codecov.io/gh/childmindresearch/styxdefs) | ||
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) | ||
![stability-stable](https://img.shields.io/badge/stability-stable-green.svg) | ||
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/childmindresearch/styxdefs/blob/main/LICENSE) | ||
[![pages](https://img.shields.io/badge/api-docs-blue)](https://childmindresearch.github.io/styxdefs) | ||
|
||
Type definitions and minimal runtime for [Styx](https://github.com/childmindresearch/styx) generated wrappers and | ||
Styx Runners. This package defines the common API for all Styx generated code. | ||
|
||
## Installation | ||
|
||
```bash | ||
pip install styxdefs | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"""Global state for the Styx library.""" | ||
|
||
from .local_runner import LocalRunner | ||
from .types import Runner | ||
|
||
_STYX_GLOBAL_RUNNER: Runner | None = None | ||
|
||
|
||
def get_global_runner() -> Runner: | ||
"""Get the default runner.""" | ||
global _STYX_GLOBAL_RUNNER | ||
if _STYX_GLOBAL_RUNNER is None: | ||
_STYX_GLOBAL_RUNNER = LocalRunner() | ||
return _STYX_GLOBAL_RUNNER | ||
|
||
|
||
def set_global_runner(runner: Runner) -> None: | ||
"""Set the default runner.""" | ||
global _STYX_GLOBAL_RUNNER | ||
_STYX_GLOBAL_RUNNER = runner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""Test global state.""" | ||
|
||
import styxdefs | ||
|
||
|
||
def test_global_runner() -> None: | ||
"""Test the global runner.""" | ||
runner = styxdefs.get_global_runner() | ||
assert hasattr(runner, "start_execution") | ||
assert isinstance(runner, styxdefs.LocalRunner) | ||
|
||
styxdefs.set_global_runner(styxdefs.LocalRunner(data_dir="xyz")) | ||
runner = styxdefs.get_global_runner() | ||
assert isinstance(runner, styxdefs.LocalRunner) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Test the local runner.""" | ||
|
||
import os | ||
import pathlib | ||
|
||
import styxdefs | ||
|
||
|
||
def test_local_runner(tmp_path: pathlib.Path) -> None: | ||
"""Test the local runner.""" | ||
runner = styxdefs.LocalRunner(data_dir=tmp_path / "xyz") | ||
|
||
x = runner.start_execution( | ||
styxdefs.Metadata( | ||
id="123", | ||
name="test", | ||
) | ||
) | ||
|
||
input_file = x.input_file("abc") | ||
output_file = x.output_file("def") | ||
if os.name == "posix": | ||
x.run(["ls"]) | ||
|
||
assert pathlib.Path(input_file).name == "abc" | ||
assert output_file.is_relative_to(tmp_path / "xyz") | ||
assert output_file.name == "def" |
Oops, something went wrong.