Skip to content

Commit

Permalink
feat(flow-python): add version (#56)
Browse files Browse the repository at this point in the history
Co-authored-by: MegEngine <megengine@megvii.com>
  • Loading branch information
tpoisonooo and megvii-mge authored Jan 9, 2022
1 parent c8a46d3 commit ae65843
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 23 deletions.
2 changes: 1 addition & 1 deletion flow-debugger/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flow-debugger"
version = "0.1.0"
version = "0.3.5"
edition = "2018"
authors = ["megvii"]

Expand Down
2 changes: 1 addition & 1 deletion flow-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flow-derive"
version = "0.3.2"
version = "0.3.5"
authors = ["megvii"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion flow-message/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flow-message"
version = "0.3.2"
version = "0.3.5"
edition = "2018"

[features]
Expand Down
2 changes: 1 addition & 1 deletion flow-plugins/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flow-plugins"
version = "0.3.2"
version = "0.3.5"
authors = ["megvii"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion flow-python/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flow-python"
version = "0.3.2"
version = "0.3.5"
authors = ["megvii"]
edition = "2018"

Expand Down
6 changes: 3 additions & 3 deletions flow-python/examples/basis_function/nest/nest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ connections = [

[[graphs.nodes]]
name = "n1"
ty = "noop"
ty = "Noop"

[[graphs.nodes]]
name = "n2"
ty = "noop"

[[graphs.nodes]]
name = "n3"
ty = "noop"
ty = "Noop"

[[graphs.nodes]]
name = "n4"
ty = "noop"

[[graphs.nodes]]
name = "n5"
ty = "noop"
ty = "Noop"

[[graphs]]
name = "nest"
Expand Down
7 changes: 4 additions & 3 deletions flow-python/examples/basis_function/nest/op.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

@map_def(exclusive=True)
def noop(x):
print('send', x)
# print('send', x)
return x


@source_def()
def gen(context=None):
for i in range(context.n):
print('first', i)
# print('first', i)
yield i


@sink_def()
def printer(x):
print('last', x)
pass
# print('last', x)
2 changes: 2 additions & 0 deletions flow-python/megflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@

from .registry import register, collect, res_register
from .megflow import *

__version__ = version()
5 changes: 3 additions & 2 deletions flow-python/megflow/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ def megflow_run():
sys.exit(1)

import argparse
from megflow import Graph
import megflow

parser = argparse.ArgumentParser(prog='megflow_run', description='run a pipeline with plugins.')
parser.add_argument('--dump', help='the path to dump graph', action='store_true')
parser.add_argument('-p', '--plugin', required=True, type=str, help='plugin path')
parser.add_argument('-m', '--module', type=str, help='module path')
parser.add_argument('-c', '--config', type=str, help='config path')
parser.add_argument('--dynamic', type=str, help='dynamic config path')
parser.add_argument('--version', action='version', version='%(prog)s {version}'.format(version=megflow.__version__))

args = parser.parse_args()

Graph(
megflow.Graph(
dump=args.dump,
plugin_path=args.plugin,
module_path=args.module,
Expand Down
13 changes: 9 additions & 4 deletions flow-python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@
elif system == 'windows':
dyn_ext = 'dll'

devel_version = os.environ.get("DEVEL_VERSION")
debug = os.environ.get("DEBUG")
target_dir = os.environ.get("CARGO_TARGET_DIR")

if not devel_version:
devel_version = "0.3.2" # fall back
if not debug:
debug = False
if not target_dir:
Expand Down Expand Up @@ -120,14 +117,22 @@ def run(self):
pattern = re.compile(f'.*?{dyn_ext}\.[0-9]*')
ext_modules.append(CopyExtension(pattern, f"{ffmpeg_dir}/lib/*.{dyn_ext}.*", "lib/"))

current_dir = os.getcwd()
with open(current_dir+'/Cargo.toml') as f:
pattern = re.compile(r'\d+\.(?:\d+\.)*\d+')
for line in f:
if line.startswith('version'):
version = re.search(pattern, line).group()
break

setup(
options={
'bdist_wheel': {
'py_limited_api': "cp36",
}
},
name="megflow",
version=devel_version,
version=version,
packages=["megflow"],
author="Megvii IPU-SDK Team",
author_email="megengine@megvii.com",
Expand Down
15 changes: 11 additions & 4 deletions flow-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use flow_rs::loader::python::envelope::envelope_register;
use flow_rs::loader::python::utils::utils_register;
use flow_rs::prelude::*;
use pyo3::prelude::*;
use pyo3::wrap_pyfunction;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::{Arc, Once};
Expand All @@ -28,6 +29,11 @@ pub struct Graph {

static ONCE_INIT: Once = Once::new();

#[pyfunction]
fn version() -> &'static str {
env!("CARGO_PKG_VERSION")
}

#[pymethods]
impl Graph {
fn wait(&mut self, py: Python) {
Expand Down Expand Up @@ -80,9 +86,9 @@ impl Graph {
)]
fn new(
mut config_path: Option<PathBuf>,
config_str: Option<&str>,
config_str: Option<String>,
dynamic_path: Option<PathBuf>,
dynamic_str: Option<&str>,
dynamic_str: Option<String>,
plugin_path: Option<PathBuf>,
module_path: Option<PathBuf>,
dump: bool,
Expand Down Expand Up @@ -133,15 +139,15 @@ impl Graph {
.unwrap_or_else(|_| panic!("file[{:?}] not found", config_path));
}
if let Some(config_str) = config_str {
builder = builder.template(config_str.to_owned());
builder = builder.template(config_str);
}
if let Some(dynamic_path) = dynamic_path {
builder = builder
.dynamic_file(&dynamic_path)
.unwrap_or_else(|_| panic!("file[{:?}] not found", dynamic_path));
}
if let Some(dynamic_str) = dynamic_str {
builder = builder.dynamic(dynamic_str.to_owned());
builder = builder.dynamic(dynamic_str);
}

let mut graph = builder.load_plugins(plugin_cfg).build().unwrap();
Expand Down Expand Up @@ -179,6 +185,7 @@ impl Graph {
#[pymodule]
fn megflow(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<Graph>()?;
m.add_function(wrap_pyfunction!(version, m)?)?;
utils_register(m)?;
envelope_register(m)?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion flow-quickstart/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flow-quickstart"
version = "0.1.0"
version = "0.3.5"
edition = "2018"
authors = ["megvii"]

Expand Down
2 changes: 1 addition & 1 deletion flow-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flow-rs"
version = "0.3.2"
version = "0.3.5"
authors = ["megvii"]
edition = "2018"

Expand Down

0 comments on commit ae65843

Please sign in to comment.