Browse Source

Expand `env` value when possible

This commit enables users to pass environment variable as composition
of env variable such as:

```yaml
  - id: yolov5
    operator:
      outputs:
        - bbox
        - ready
      inputs:
        image: oasis_agent/image
        check: oasis_agent/yolov5_check
      python: ../../operators/yolov5_op.py
    env:
      YOLOV5_PATH: $HOME/Documents/dependencies/yolov5
      YOLOV5_WEIGHT_PATH: $DORA_DEP_HOME/dependencies/yolov5/yolov5n.pt
```

Note that this is only for the env field. Expanding env variable for
source path might conflict with using url as source path.
tags/v0.2.0-candidate
haixuanTao 2 years ago
parent
commit
933dadc68b
3 changed files with 16 additions and 0 deletions
  1. +11
    -0
      Cargo.lock
  2. +1
    -0
      libraries/core/Cargo.toml
  3. +4
    -0
      libraries/core/src/descriptor/mod.rs

+ 11
- 0
Cargo.lock View File

@@ -931,6 +931,7 @@ dependencies = [
"eyre",
"once_cell",
"serde",
"serde-with-expand-env",
"serde_yaml 0.9.11",
"uuid 1.2.1",
"which",
@@ -3366,6 +3367,16 @@ dependencies = [
"serde_derive",
]

[[package]]
name = "serde-with-expand-env"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "888d884a3be3a209308d0b66f1918ff18f60e93db837259e53ea7d8dd14e7e98"
dependencies = [
"serde",
"shellexpand",
]

[[package]]
name = "serde_derive"
version = "1.0.144"


+ 1
- 0
libraries/core/Cargo.toml View File

@@ -14,3 +14,4 @@ once_cell = "1.13.0"
zenoh-config = { git = "https://github.com/eclipse-zenoh/zenoh.git", rev = "79a136e4fd90b11ff5d775ced981af53c4f1071b" }
which = "4.3.0"
uuid = { version = "1.2.1", features = ["serde"] }
serde-with-expand-env = "1.1.0"

+ 4
- 0
libraries/core/src/descriptor/mod.rs View File

@@ -1,6 +1,7 @@
use crate::config::{CommunicationConfig, DataId, InputMapping, NodeId, NodeRunConfig, OperatorId};
use eyre::{bail, Result};
use serde::{Deserialize, Serialize};
use serde_with_expand_env::with_expand_envs;
use std::{
collections::{BTreeMap, BTreeSet, HashMap},
env::consts::EXE_EXTENSION,
@@ -222,8 +223,11 @@ pub struct CustomNode {
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EnvValue {
#[serde(deserialize_with = "with_expand_envs")]
Bool(bool),
#[serde(deserialize_with = "with_expand_envs")]
Integer(u64),
#[serde(deserialize_with = "with_expand_envs")]
String(String),
}



Loading…
Cancel
Save