ignore .pyi if .py.o exist

support load py.o

add cjon_test.pyi
This commit is contained in:
pikastech 2022-10-21 11:50:27 +08:00
parent 6bb5adde37
commit e72d1efa36
8 changed files with 83 additions and 18 deletions

Binary file not shown.

View File

@ -0,0 +1,4 @@
import pika_cjson as cjson
def test_start(): ...

View File

@ -480,7 +480,36 @@ int pikaMaker_getDependencies(PikaMaker* self, char* module_name) {
strsAppend(&buffs, imp_module_path, ".py"), "rb");
FILE* imp_file_pyi = __platform_fopen(
strsAppend(&buffs, imp_module_path, ".pyi"), "rb");
if (NULL != imp_file_py) {
FILE* imp_file_pyo = __platform_fopen(
strsAppend(&buffs, imp_module_path, ".py.o"), "rb");
if (NULL != imp_file_pyo) {
__platform_printf(" loading %s.py.o...\r\n",
imp_module_path);
/* found *.py.o, push to compiled list */
pikaMaker_setState(self, imp_module_name, "compiled");
char* imp_api_path = strsAppend(
&buffs, obj_getStr(self, "pwd"), "pikascript-api/");
imp_api_path =
strsAppend(&buffs, imp_api_path, imp_module_name);
FILE* imp_file_pyo_api = __platform_fopen(
strsAppend(&buffs, imp_api_path, ".py.o"), "wb+");
/* copy imp_file_pyo to imp_api_path */
uint8_t* buff = (uint8_t*)__platform_malloc(128);
size_t read_size = 0;
while (1) {
read_size =
__platform_fread(buff, 1, 128, imp_file_pyo);
if (read_size > 0) {
__platform_fwrite(buff, 1, read_size,
imp_file_pyo_api);
} else {
break;
}
}
__platform_free(buff);
__platform_fclose(imp_file_pyo);
__platform_fclose(imp_file_pyo_api);
} else if (NULL != imp_file_py) {
/* found *.py, push to nocompiled list */
pikaMaker_setState(self, imp_module_name, "nocompiled");
__platform_fclose(imp_file_py);
@ -490,8 +519,9 @@ int pikaMaker_getDependencies(PikaMaker* self, char* module_name) {
__platform_fclose(imp_file_pyi);
} else {
__platform_printf(
" [warning]: file: '%s.pyi' or '%s.py' no found\n",
imp_module_name, imp_module_name);
" [warning]: file: '%s.pyi', '%s.py' or '%s.py.o' "
"no found\n",
imp_module_name, imp_module_name, imp_module_name);
}
}
}

View File

@ -2,4 +2,4 @@
#define PIKA_VERSION_MINOR 11
#define PIKA_VERSION_MICRO 5
#define PIKA_EDIT_TIME "2022/10/20 22:50:44"
#define PIKA_EDIT_TIME "2022/10/21 12:27:40"

View File

@ -2,6 +2,7 @@ import PikaStdLib
import test, module
import TemplateDevice
import test_pyo
from pika_cjson import cJSON
print('hello pikascript!')
mem = PikaStdLib.MemChecker()

View File

@ -96,7 +96,7 @@ impl Compiler {
let package_items: Vec<&str> = package_list.split(',').collect();
for item in package_items {
compiler = Compiler::analyse_package_from_py(compiler, item.to_string());
compiler = Compiler::analyse_py_or_pyi_or_pyo(compiler, item.to_string());
}
return compiler;
}
@ -114,7 +114,7 @@ impl Compiler {
class_now.script_list.add(&line);
}
return Compiler::analyse_package_from_py(compiler, package_name.to_string());
return Compiler::analyse_py_or_pyi_or_pyo(compiler, package_name.to_string());
}
if is_top_pkg {
@ -152,7 +152,26 @@ impl Compiler {
return self.__do_analyse_file(file_name, PackageType::CPackageInner);
}
pub fn analyse_package_from_py(mut self: Compiler, file_name: String) -> Compiler {
pub fn analyse_py_or_pyi_or_pyo(mut self: Compiler, file_name: String) -> Compiler {
/* check py.o */
let suffix = String::from("py.o");
/* open file */
let file: std::result::Result<std::fs::File, std::io::Error>;
file = Compiler::open_file(format!("{}{}.{}", self.source_path, file_name, suffix));
match file {
/* py import py.o => do nothing */
Ok(_) => {
println!(
" found {}{}.{}...",
self.source_path, file_name, suffix
);
return self;
}
/* continue */
Err(_) => {}
}
/* check pyi */
let suffix = String::from("pyi");
/* open file */
let file: std::result::Result<std::fs::File, std::io::Error>;
@ -171,11 +190,12 @@ impl Compiler {
return Compiler::analyse_c_package_top(self, file_name);
}
Err(_) => {
/* py import py => inner_py */
return self.analyse_py_package_inner(file_name.clone());
}
/* continue */
Err(_) => {}
};
/* py import py => inner_py */
return self.analyse_py_package_inner(file_name.clone());
}
fn __do_analyse_file(mut self: Compiler, file_name: String, pkg_type: PackageType) -> Compiler {
@ -205,15 +225,15 @@ impl Compiler {
let mut file = match file {
Ok(file) => file,
Err(_) => {
if suffix == "pyi" {
/* if .pyi no exist, check .py exist */
return self.analyse_py_package_inner(file_name.clone());
}
/* .py no exist, error */
println!(
" [warning]: file: '{}{}.pyi' or '{}{}.py' no found",
self.source_path, file_name, self.source_path, file_name
" [warning]: file: '{}{}.pyi', '{}{}.py' or '{}{}.py.o' no found",
self.source_path,
file_name,
self.source_path,
file_name,
self.source_path,
file_name
);
return self;
}
@ -318,6 +338,7 @@ impl Compiler {
if line.starts_with("import ") {
let tokens: Vec<&str> = line.split(" ").collect();
let file = tokens[1];
/* cmodule cannot import pymodule */
return Compiler::analyse_c_package_inner(compiler, file.to_string());
}

View File

@ -165,6 +165,15 @@ func checkout_requestments(path string, repo *git.Repository, requerments []Requ
CheckIfError(os.Rename(pyFileSource, pyFileName))
}
pyiFileList, _ := FilterDirsGlob(dirPath, "*.py.o")
for i := range pyiFileList {
pyFileSource := strings.ReplaceAll(pyiFileList[i], "\\", "/")
pyFilePath := strings.Split(pyFileSource, "/")
pyFileName := pyFilePath[len(pyFilePath)-1]
fmt.Println("Installed: " + pyFileName + ": " + requerment.Version)
CheckIfError(os.Rename(pyFileSource, pyFileName))
}
}
err := workTree.Checkout(&git.CheckoutOptions{
Hash: plumbing.NewHash("master"),