kcl-lang / kcl

KCL Programming Language (CNCF Sandbox Project). https://kcl-lang.io
https://kcl-lang.io
Apache License 2.0
1.41k stars 110 forks source link

how to change the module's name #1449

Closed LinYunling closed 6 days ago

LinYunling commented 6 days ago

use "kcl mod init modame" command init a module and I need to change the module name from "modame" to "modname" I modify the kcl.mod file:

[package]
name = "modame"  
edition = "v0.9.0"
version = "0.0.1"

to

[package]
name = "modname"  
edition = "v0.9.0"
version = "0.0.1"

But it doesn't work

Peefy commented 6 days ago

Hello @LinYunling

Sorry, what does it doesn't work means? Could you please provider more information?

LinYunling commented 6 days ago

before modify:

kcl.mod
[package]
name = "mod1"  
edition = "v0.9.0"
version = "0.0.1"

main.k
import mod1

a = mod1.test1 {
    name = "hello"
}

I find the module name is wrong, so I need to modify it And I modify the kcl.mod file and main.k (just modify the module name)

kcl.mod
[package]
name = "mod1change"  
edition = "v0.9.0"
version = "0.0.1"

main.k
import mod1change

a = mod1change.test1 {
    name = "hello"
}

run main.k report the error:

kcl main.k
Error: error[E2F04]: CannotFindModule
 --> D:\code\kcltest\main.k:1:1
  |
1 | import mod1change
  | ^ pkgpath mod1change not found in the program
  |

suggestion: try 'kcl mod add mod1change' to download the package not found

suggestion: find more package on 'https://artifacthub.io'

error[E2F04]: CannotFindModule
 --> D:\code\kcltest\main.k:1:1
  |
1 | import mod1change
  | ^ Cannot find the module mod1change from mod1change
  |

suggestion: try 'kcl mod add mod1change' to download the package not found

suggestion: find more package on 'https://artifacthub.io'

error[E2G22]: TypeError
 --> D:\code\kcltest\main.k:3:5
  |
3 | a = mod1change.test1 {
  |     ^ attribute 'test1' not found in 'module 'mod1change''
  |
Peefy commented 6 days ago

I see. You need to change the folder name same time Because you don't add a relative dependency between main.k and mod1change.

|- mod1change
|   |- kcl.mod
|- main.k
LinYunling commented 6 days ago

got it, I forgot, thank you very much