diff --git a/transpile_python/service.go b/transpile_python/service.go index a08e9dd..a0985a2 100644 --- a/transpile_python/service.go +++ b/transpile_python/service.go @@ -458,10 +458,13 @@ func handleImportSpec(spec ast.Spec) string { s := spec.(*ast.ImportSpec) code := "" libName := strings.Trim(s.Path.Value, "\"") - if s.Name == nil { + switch { + case s.Name == nil: code = "import " + libName + "\n" - } else { + case s.Name.Name == ".": code = "from " + libName + " import *\n" + default: + code = "import " + libName + " as " + s.Name.Name + "\n" } return code } diff --git a/transpile_python/service_test.go b/transpile_python/service_test.go index 67d4ea8..8665513 100644 --- a/transpile_python/service_test.go +++ b/transpile_python/service_test.go @@ -62,6 +62,19 @@ main() expected := `import skidl import FreeCAD +main() +` + Compare(source, expected) + }) + + It("Importing with name", func() { + source := `package test + import ( + cq "cadquery" + ) + ` + expected := `import cadquery as cq + main() ` Compare(source, expected)