Browse Source

Remove explicit statement to `python3`and resolve it instead

tags/v0.3.1-rc5
haixuanTao 2 years ago
parent
commit
68ecf89b61
7 changed files with 63 additions and 15 deletions
  1. +3
    -3
      apis/python/node/README.md
  2. +1
    -1
      binaries/cli/src/template/python/dataflow-template.yml
  3. +15
    -3
      examples/python-dataflow/run.rs
  4. +15
    -3
      examples/python-operator-dataflow/run.rs
  5. +14
    -3
      examples/python-ros2-dataflow/run.rs
  6. +2
    -1
      libraries/core/src/descriptor/validate.rs
  7. +13
    -1
      libraries/core/src/lib.rs

+ 3
- 3
apis/python/node/README.md View File

@@ -4,9 +4,9 @@ This crate corresponds to the Node API for Dora.

To build the Python module for development:

````bash
python3 -m venv .env
```bash
python -m venv .env
source .env/bin/activate
pip install maturin
maturin develop
````
```

+ 1
- 1
binaries/cli/src/template/python/dataflow-template.yml View File

@@ -16,7 +16,7 @@ nodes:

- id: custom-node_1
custom:
source: python3
source: python
args: ./node_1/node_1.py
inputs:
tick: dora/timer/secs/1


+ 15
- 3
examples/python-dataflow/run.rs View File

@@ -1,3 +1,4 @@
use dora_core::get_python_path;
use eyre::{ContextCompat, WrapErr};
use std::path::Path;
use tracing_subscriber::{
@@ -14,9 +15,20 @@ async fn main() -> eyre::Result<()> {
std::env::set_current_dir(root.join(file!()).parent().unwrap())
.wrap_err("failed to set working dir")?;

run(&["python3", "-m", "venv", "../.env"], None)
.await
.context("failed to create venv")?;
run(
&[
get_python_path()
.context("Could not get python binary")?
.to_str()
.context("Could not convert python path to string")?,
"-m",
"venv",
"../.env",
],
None,
)
.await
.context("failed to create venv")?;
let venv = &root.join("examples").join(".env");
std::env::set_var(
"VIRTUAL_ENV",


+ 15
- 3
examples/python-operator-dataflow/run.rs View File

@@ -1,3 +1,4 @@
use dora_core::get_python_path;
use eyre::{ContextCompat, WrapErr};
use std::path::Path;
use tracing_subscriber::{
@@ -14,9 +15,20 @@ async fn main() -> eyre::Result<()> {
std::env::set_current_dir(root.join(file!()).parent().unwrap())
.wrap_err("failed to set working dir")?;

run(&["python3", "-m", "venv", "../.env"], None)
.await
.context("failed to create venv")?;
run(
&[
get_python_path()
.context("Could not get python binary")?
.to_str()
.context("Could not convert python path to string")?,
"-m",
"venv",
"../.env",
],
None,
)
.await
.context("failed to create venv")?;
let venv = &root.join("examples").join(".env");
std::env::set_var(
"VIRTUAL_ENV",


+ 14
- 3
examples/python-ros2-dataflow/run.rs View File

@@ -14,9 +14,20 @@ async fn main() -> eyre::Result<()> {
std::env::set_current_dir(root.join(file!()).parent().unwrap())
.wrap_err("failed to set working dir")?;

run(&["python3", "-m", "venv", "../.env"], None)
.await
.context("failed to create venv")?;
run(
&[
get_python_path()
.context("Could not get python binary")?
.to_str()
.context("Could not convert python path to string")?,
"-m",
"venv",
"../.env",
],
None,
)
.await
.context("failed to create venv")?;
let venv = &root.join("examples").join(".env");
std::env::set_var(
"VIRTUAL_ENV",


+ 2
- 1
libraries/core/src/descriptor/validate.rs View File

@@ -2,6 +2,7 @@ use crate::{
adjust_shared_library_path,
config::{DataId, Input, InputMapping, OperatorId, UserInputMapping},
descriptor::{self, source_is_url, CoreNodeKind, OperatorSource},
get_python_path,
};

use eyre::{bail, eyre, Context};
@@ -152,7 +153,7 @@ fn check_python_runtime() -> eyre::Result<()> {
// Check if python dora-rs is installed and match cli version
let reinstall_command =
format!("Please reinstall it with: `pip install dora-rs=={VERSION} --force`");
let mut command = Command::new("python3");
let mut command = Command::new(get_python_path().context("Could not get python binary")?);
command.args([
"-c",
&format!(


+ 13
- 1
libraries/core/src/lib.rs View File

@@ -1,4 +1,4 @@
use eyre::{bail, eyre};
use eyre::{bail, eyre, Context};
use std::{
env::consts::{DLL_PREFIX, DLL_SUFFIX},
path::Path,
@@ -30,3 +30,15 @@ pub fn adjust_shared_library_path(path: &Path) -> Result<std::path::PathBuf, eyr
let path = path.with_file_name(library_filename);
Ok(path)
}

// Search for python binary.
// First search for `python3` of python as for ubuntu <20, `python` resolves to `python2,7`
// Then search for `python`, this will resolve for windows.
pub fn get_python_path() -> Result<std::path::PathBuf, eyre::ErrReport> {
let python = match which::which("python3") {
Ok(python) => python,
Err(_) => which::which("python")
.context("failed to find `python` or `python3` in dora-daemon path. Make sure that python is available for the daemon.")?,
};
Ok(python)
}

Loading…
Cancel
Save