From 1ceaaac7d7e8af70cf51f2c6132ebde6ab3e8807 Mon Sep 17 00:00:00 2001 From: Christoph Kappestein Date: Sat, 6 Apr 2024 18:27:17 +0200 Subject: [PATCH] add dot for local imports --- src/Generator/Python.php | 2 +- tests/Generator/resource/python/python.py | 10 +-- .../resource/python/python_complex.py | 84 +++++++++---------- .../resource/python/python_import.py | 6 +- .../resource/python/python_import_ns.py | 6 +- tests/Generator/resource/python/python_oop.py | 10 +-- .../Generator/resource/python/python_union.py | 8 +- 7 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/Generator/Python.php b/src/Generator/Python.php index a3abd00d..918a5218 100644 --- a/src/Generator/Python.php +++ b/src/Generator/Python.php @@ -167,7 +167,7 @@ private function getImports(TypeAbstract $origin): array foreach ($refs as $ref) { [$ns, $name] = TypeUtil::split($ref); - $imports[] = 'from ' . $this->normalizer->file($name) . ' import ' . $this->normalizer->class($name); + $imports[] = 'from .' . $this->normalizer->file($name) . ' import ' . $this->normalizer->class($name); } return $imports; diff --git a/tests/Generator/resource/python/python.py b/tests/Generator/resource/python/python.py index 698c36b4..a80af8b3 100644 --- a/tests/Generator/resource/python/python.py +++ b/tests/Generator/resource/python/python.py @@ -23,7 +23,7 @@ class Web: from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config from typing import List -from location import Location +from .location import Location # An simple author element with some description @@ -48,10 +48,10 @@ class Meta(Dict[str, str]): from typing import List from typing import Dict from typing import Union -from meta import Meta -from author import Author -from location import Location -from web import Web +from .meta import Meta +from .author import Author +from .location import Location +from .web import Web # An general news entry diff --git a/tests/Generator/resource/python/python_complex.py b/tests/Generator/resource/python/python_complex.py index a53f53bf..e16454ed 100644 --- a/tests/Generator/resource/python/python_complex.py +++ b/tests/Generator/resource/python/python_complex.py @@ -14,7 +14,7 @@ class CommonType: from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config -from common_type import CommonType +from .common_type import CommonType # Represents an any type @@ -26,13 +26,13 @@ class AnyType(CommonType): from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config from typing import Union -from common_type import CommonType -from boolean_type import BooleanType -from number_type import NumberType -from string_type import StringType -from reference_type import ReferenceType -from generic_type import GenericType -from any_type import AnyType +from .common_type import CommonType +from .boolean_type import BooleanType +from .number_type import NumberType +from .string_type import StringType +from .reference_type import ReferenceType +from .generic_type import GenericType +from .any_type import AnyType # Represents an array type. An array type contains an ordered list of a specific type @@ -48,7 +48,7 @@ class ArrayType(CommonType): from dataclasses_json import dataclass_json, config from typing import List from typing import Union -from common_type import CommonType +from .common_type import CommonType # Represents a scalar type @@ -61,7 +61,7 @@ class ScalarType(CommonType): from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config -from scalar_type import ScalarType +from .scalar_type import ScalarType # Represents a boolean type @@ -95,7 +95,7 @@ class GenericType: from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config from typing import List -from reference_type import ReferenceType +from .reference_type import ReferenceType # Represents an intersection type @@ -108,16 +108,16 @@ class IntersectionType: from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config from typing import Union -from common_type import CommonType -from boolean_type import BooleanType -from number_type import NumberType -from string_type import StringType -from array_type import ArrayType -from union_type import UnionType -from intersection_type import IntersectionType -from reference_type import ReferenceType -from generic_type import GenericType -from any_type import AnyType +from .common_type import CommonType +from .boolean_type import BooleanType +from .number_type import NumberType +from .string_type import StringType +from .array_type import ArrayType +from .union_type import UnionType +from .intersection_type import IntersectionType +from .reference_type import ReferenceType +from .generic_type import GenericType +from .any_type import AnyType # Represents a map type. A map type contains variable key value entries of a specific type @@ -131,7 +131,7 @@ class MapType(CommonType): from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config -from scalar_type import ScalarType +from .scalar_type import ScalarType # Represents a number type (contains also integer) @@ -159,7 +159,7 @@ class ReferenceType: from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config -from scalar_type import ScalarType +from .scalar_type import ScalarType # Represents a string type @@ -176,17 +176,17 @@ class StringType(ScalarType): from typing import List from typing import Dict from typing import Union -from common_type import CommonType -from map_type import MapType -from array_type import ArrayType -from boolean_type import BooleanType -from number_type import NumberType -from string_type import StringType -from any_type import AnyType -from intersection_type import IntersectionType -from union_type import UnionType -from reference_type import ReferenceType -from generic_type import GenericType +from .common_type import CommonType +from .map_type import MapType +from .array_type import ArrayType +from .boolean_type import BooleanType +from .number_type import NumberType +from .string_type import StringType +from .any_type import AnyType +from .intersection_type import IntersectionType +from .union_type import UnionType +from .reference_type import ReferenceType +from .generic_type import GenericType # Represents a struct type. A struct type contains a fix set of defined properties @@ -203,9 +203,9 @@ class StructType(CommonType): from dataclasses_json import dataclass_json, config from typing import Dict from typing import Union -from struct_type import StructType -from map_type import MapType -from reference_type import ReferenceType +from .struct_type import StructType +from .map_type import MapType +from .reference_type import ReferenceType # The root TypeSchema @@ -220,11 +220,11 @@ class TypeSchema: from dataclasses_json import dataclass_json, config from typing import List from typing import Union -from discriminator import Discriminator -from number_type import NumberType -from string_type import StringType -from boolean_type import BooleanType -from reference_type import ReferenceType +from .discriminator import Discriminator +from .number_type import NumberType +from .string_type import StringType +from .boolean_type import BooleanType +from .reference_type import ReferenceType # Represents an union type. An union type can contain one of the provided types diff --git a/tests/Generator/resource/python/python_import.py b/tests/Generator/resource/python/python_import.py index 882ba84e..76f1dd37 100644 --- a/tests/Generator/resource/python/python_import.py +++ b/tests/Generator/resource/python/python_import.py @@ -1,7 +1,7 @@ from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config -from student_map import StudentMap -from student import Student +from .student_map import StudentMap +from .student import Student @dataclass_json @dataclass class Import: @@ -10,7 +10,7 @@ class Import: from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config -from student import Student +from .student import Student @dataclass_json @dataclass class MyMap(Student): diff --git a/tests/Generator/resource/python/python_import_ns.py b/tests/Generator/resource/python/python_import_ns.py index 2093968b..445be85d 100644 --- a/tests/Generator/resource/python/python_import_ns.py +++ b/tests/Generator/resource/python/python_import_ns.py @@ -1,7 +1,7 @@ from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config -from student_map import StudentMap -from student import Student +from .student_map import StudentMap +from .student import Student @dataclass_json @dataclass class Import: @@ -10,7 +10,7 @@ class Import: from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config -from student import Student +from .student import Student @dataclass_json @dataclass class MyMap(My.Import.Student): diff --git a/tests/Generator/resource/python/python_oop.py b/tests/Generator/resource/python/python_oop.py index 3a54988b..3068b5df 100644 --- a/tests/Generator/resource/python/python_oop.py +++ b/tests/Generator/resource/python/python_oop.py @@ -1,6 +1,6 @@ from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config -from human import Human +from .human import Human @dataclass_json @dataclass class Human: @@ -9,7 +9,7 @@ class Human: from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config -from human import Human +from .human import Human @dataclass_json @dataclass class Student(Human): @@ -17,8 +17,8 @@ class Student(Human): from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config -from map import Map -from student import Student +from .map import Map +from .student import Student @dataclass_json @dataclass class StudentMap(Map[Student]): @@ -35,7 +35,7 @@ class Map: from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config -from student_map import StudentMap +from .student_map import StudentMap @dataclass_json @dataclass class RootSchema: diff --git a/tests/Generator/resource/python/python_union.py b/tests/Generator/resource/python/python_union.py index 699a6d26..67b18b82 100644 --- a/tests/Generator/resource/python/python_union.py +++ b/tests/Generator/resource/python/python_union.py @@ -7,7 +7,7 @@ class Creature: from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config -from creature import Creature +from .creature import Creature @dataclass_json @dataclass class Human(Creature): @@ -15,7 +15,7 @@ class Human(Creature): from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config -from creature import Creature +from .creature import Creature @dataclass_json @dataclass class Animal(Creature): @@ -24,8 +24,8 @@ class Animal(Creature): from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config from typing import Union -from human import Human -from animal import Animal +from .human import Human +from .animal import Animal @dataclass_json @dataclass class Union: