Skip to content

Commit 8060fea

Browse files
committed
Fix path
1 parent 0f821dd commit 8060fea

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

libs/python/core/src/py_utils.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,22 @@ pub fn get_cwd() -> PyResult<String> {
3939
pub fn convert_to_route_path(path: &str) -> String {
4040
let mut result = path.replace("\\", "/");
4141

42-
if result.starts_with("routes/") {
43-
result = result[7..].to_string();
42+
if result.starts_with("./") {
43+
result = result[2..].to_string();
44+
}
45+
if result.starts_with(".\\") {
46+
result = result[2..].to_string();
47+
}
48+
49+
if result.starts_with("/") {
50+
result = result[1..].to_string();
51+
}
52+
53+
if result.starts_with("\\") {
54+
result = result[1..].to_string();
55+
}
56+
if result.starts_with("routes") {
57+
result = result[6..].to_string();
4458
}
4559

4660
while let Some(start) = result.find("/(") {
@@ -79,6 +93,10 @@ mod tests {
7993
#[test]
8094
fn test_convert_to_route_path() {
8195
assert_eq!(convert_to_route_path("routes/crud.py"), "/crud");
96+
assert_eq!(convert_to_route_path("/routes/a/crud.py"), "/a/crud");
97+
assert_eq!(convert_to_route_path("\\routes/a/crud.py"), "/a/crud");
98+
assert_eq!(convert_to_route_path("./routes/a/crud.py"), "/a/crud");
99+
assert_eq!(convert_to_route_path(".\\routes/a/crud.py"), "/a/crud");
82100
assert_eq!(convert_to_route_path("routes\\crud.py"), "/crud");
83101
assert_eq!(convert_to_route_path("routes/a/b/c/crud.py"), "/a/b/c/crud");
84102
assert_eq!(
@@ -89,6 +107,14 @@ mod tests {
89107
assert_eq!(convert_to_route_path("routes/a/(b)/(c)/crud.py"), "/a/crud");
90108

91109
assert_eq!(convert_to_route_path("routes/a/(b)/(c)/__init__.py"), "/a");
110+
assert_eq!(
111+
convert_to_route_path("routes/(singleton)/global_info.py"),
112+
"/global-info"
113+
);
114+
assert_eq!(
115+
convert_to_route_path("routes\\(singleton)\\global_info.py"),
116+
"/global-info"
117+
);
92118

93119
assert_eq!(convert_to_route_path("routes/__init__.py"), "/");
94120

libs/python/core/src/router/singleton_router.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ impl PySingletonRouter {
1212
#[new]
1313
fn new(model: &Bound<'_, PyType>) -> PyResult<Self> {
1414
let model_name = model.getattr("name")?.extract::<String>()?;
15+
println!("get_route_path: {}", get_route_path()?);
1516
let path = convert_to_route_path(get_route_path()?.as_str());
17+
println!("path: {}", path);
1618
Ok(Self(
1719
add_singleton_router(SingletonRouter {
1820
path,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"build": "node build.js",
66
"setup:project": "pnpm build && node project-install.js",
77
"project:fastapi": "cd project/python/fastapi && uvicorn main:app --reload",
8-
"test": "node test.js",
8+
"test": "cargo test && node test.js",
99
"test:vitest": "vitest --run"
1010
},
1111
"devDependencies": {

0 commit comments

Comments
 (0)