KusionStack / konfig

Shared repository of application models and components, and CI suite for GitOps workflows
Apache License 2.0
27 stars 32 forks source link

When import same module name in two package, it reports: `Attribute error occurs during compiling` #26

Closed LeoLiuYan closed 1 year ago

LeoLiuYan commented 2 years ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

konfig/appops/guestbook-frontend/test/main.k

import base.pkg.kusion_models.test.frontend

appConfiguration: frontend.Server {
}

konfig/appops/guestbook-frontend/test/kcl.yaml

kcl_cli_configs:
  file:
    - main.k
    - ${KCL_MOD}/base/pkg/kusion_models/test/render/render.k

konfig/base/pkg/kusion_models/test/frontend/server.k

schema NewServer:
  a: str

konfig/base/pkg/kusion_models/test/render/render.k

import base.pkg.kusion_models.test.frontend as testFrontend
import base.pkg.kusion_models.kube.frontend

__renderTestServerInstances__ = [inst for inst in testFrontend.NewServer.instances()]
__renderServerFrontendInstances__ = [inst for inst in frontend.Server.instances() if typeof(inst) == "Server"]

2. What did you expect to see? (Required)

kusion compile success.

3. What did you see instead (Required)

3 |appConfiguration: frontend.NewServer {
                        19 ^  -> Failure
      module 'base.pkg.kusion_models.kube.frontend' has no attribute 'NewServer'

4. What is your KusionStack components version? (Required)

releaseVersion: v0.4.4
gitInfo:
    latestTag: v0.4.4
    commit: fd58099d9d38495eabd0dbf78f779c4f5cad0553
    treeState: clean
buildInfo:
    goVersion: go1.17.11
    GOOS: linux
    GOARCH: amd64
    numCPU: 2
    compiler: gc
    buildTime: "2022-06-24 08:40:18"
dependency:
    kclvmgoVersion: v0.4.2-alpha.9
    kclPluginVersion: v0.4.1-alpha2
Peefy commented 2 years ago

Misspell? s/Server/NewServer

Peefy commented 2 years ago

Besides, U can use schema single inheritance:

schema NewServer(frontend.Server):
Peefy commented 2 years ago

change konfig/appops/guestbook-frontend/test/main.k as follows:

import base.pkg.kusion_models.test.frontend as testFrontend

appConfiguration: testFrontend.Server {}

Becase files in kcl.yaml are seen as the same package, where the frontend package alias is overridden.

howieyuen commented 1 year ago

fixed, closed the issue