From 6d703643574459ae156c0a9525db3a1b9bf2f441 Mon Sep 17 00:00:00 2001 From: Softonik Date: Sat, 10 Dec 2022 04:42:03 +0300 Subject: [PATCH] =?UTF-8?q?Python:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=B8=D0=BC=D0=BF=D0=BE=D1=80=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=81=20"as=20NAM?= =?UTF-8?q?E"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- transpile_python/service.go | 7 +++++-- transpile_python/service_test.go | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) 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)