Skip to content

Commit

Permalink
feat: add support for toml config files (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
julesbertrand authored Oct 6, 2023
1 parent e942add commit b997e69
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,23 +216,23 @@ def pipeline():

#### Configs

Config file can be either `.py` files or `.json` files.
Config file can be either `.py`, `.json` or `.toml` files.
They must be located in the `config/{pipeline_name}` folder.

**Why two formats?**

`.py` files are useful to define complex configs (e.g. a list of dicts) while `.json` files are useful to define simple configs (e.g. a string).
`.py` files are useful to define complex configs (e.g. a list of dicts) while `.json` / `.toml` files are useful to define simple configs (e.g. a string).

**How to format them?**
- `.json` files must be valid json files containing only one dict of key: value.
- `.json` and `.toml` files must be valid json files containing only one dict of key: value representing parameter values.
- `.py` files must be valid python files with two important elements:
- `parameter_values` to pass arguments to your pipeline
- `input_artifacts` if you want to retrieve and create input artifacts to your pipeline.
See [Vertex Documentation](https://cloud.google.com/python/docs/reference/aiplatform/latest/google.cloud.aiplatform.PipelineJob) for more information.

**How to name them?**

`{config_name}.json` or `{config_name}.py`. config_name is free but must be unique for a given pipeline.
`{config_name}.py` or `{config_name}.json` or `{config_name}.toml`. config_name is free but must be unique for a given pipeline.


#### Settings
Expand Down Expand Up @@ -325,7 +325,9 @@ vertex-deployer --log-level DEBUG deploy ...
├─ .github
│ ├─ ISSUE_TEMPLATE/
│ ├─ workflows
│ │ └─ ci.yaml
│ │ ├─ ci.yaml
│ │ ├─ pr_agent.yaml
│ │ └─ release.yaml
│ ├─ CODEOWNERS
│ └─ PULL_REQUEST_TEMPLATE.md
├─ deployer
Expand All @@ -350,7 +352,9 @@ vertex-deployer --log-level DEBUG deploy ...
│ │ ├─ broken_pipeline
│ │ │ └─ config_test.json
│ │ └─ dummy_pipeline
│ │ └─ config_test.json
│ │ ├─ config_test.json
│ │ ├─ config.py
│ │ └─ config.toml
│ ├─ deployment
│ ├─ lib
│ └─ pipelines
Expand Down
6 changes: 6 additions & 0 deletions deployer/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
from typing import List, Optional, Tuple, Union

import toml
from pydantic import ValidationError
from pydantic_settings import BaseSettings, SettingsConfigDict

Expand Down Expand Up @@ -39,6 +40,7 @@ def load_vertex_settings(env_file: Optional[Path] = None) -> VertexPipelinesSett
class ConfigType(str, Enum): # noqa: D101
json = "json"
py = "py"
toml = "toml"


def list_config_filepaths(config_root_path: Union[Path, str], pipeline_name: str) -> List[Path]:
Expand Down Expand Up @@ -85,6 +87,10 @@ def load_config(config_filepath: Path) -> Tuple[Optional[dict], Optional[dict]]:
parameter_values = json.load(f)
return parameter_values, None

if config_filepath.suffix == ".toml":
parameter_values = toml.load(config_filepath)
return parameter_values, None

if config_filepath.suffix == ".py":
parameter_values, input_artifacts = _load_config_python(config_filepath)
return parameter_values, input_artifacts
Expand Down
3 changes: 3 additions & 0 deletions example/vertex/configs/dummy_pipeline/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parameter_values = {"name": "John Doe in python config"}

input_artifacts = {}
1 change: 1 addition & 0 deletions example/vertex/configs/dummy_pipeline/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name = "John Doe in toml"
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ loguru = "^0.7.2"
pydantic-settings = "^2.0.3"
pydantic = "^2.3.0"
pyinstrument = { version = "^4.5.3", optional = true }
toml = "^0.10.2"

[tool.poetry.group.dev.dependencies]
black = "^23.7.0"
Expand Down

0 comments on commit b997e69

Please sign in to comment.