Skip to content

Commit

Permalink
feat: add import docs about module name with hyphen
Browse files Browse the repository at this point in the history
Signed-off-by: zongz <zongzhe1024@163.com>
  • Loading branch information
zong-zhe committed Jun 18, 2024
1 parent 0dd122b commit 5c47ccb
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/user_docs/support/faq-kcl.md
Original file line number Diff line number Diff line change
Expand Up @@ -2711,3 +2711,21 @@ returns the output:
```bash
foobar: foo.bar
```

## 68. How to "import another-module" in KCL ? Module with hyphens in it

In KCL, only module names with `_` are supported in the import statements, while package names in `kcl.mod` support both `-` and `_`. The KCL compiler will automatically replace `-` with `_`. Therefore, in `kcl.mod`, the following dependencies are both supported:

```toml
# both supported
another-module = "0.1.1"
another_module = "0.1.1"
```

In KCL code, the following import statement is supported:

```python
import another_module
```

Both `another-module = "0.1.1"` and `another_module = "0.1.1"` are equivalent, and using both will result in an error.
Original file line number Diff line number Diff line change
Expand Up @@ -2625,3 +2625,21 @@ export KCL_CACHE_PATH=/tmp # 或者更改为您想要的路径
```powershell
setx KCL_CACHE_PATH "C:\temp" /M
```

## 65. 如何在 KCL 中使用 "import another-module" ? 包名中包含横线 "-"

在 KCL 中,import 语句中使用的模块名称中只支持`_`,kcl.mod 中的包名同时支持 `-``_`,KCL 编译器会自动将包名中的 `-` 替换为 `_`

```toml
# kcl.mod 中同时支持如下两种写法
another-module = "0.1.1"
another_module = "0.1.1"
```

在 KCL 代码中,只支持使用如下 import 语句

```python
import another_module
```

`another-module = "0.1.1"``another_module = "0.1.1"` 是等价的, 如果同时在 `kcl.mod` 中使用这两种写法会得到一个错误。
Original file line number Diff line number Diff line change
Expand Up @@ -2625,3 +2625,21 @@ export KCL_CACHE_PATH=/tmp # 或者更改为您想要的路径
```powershell
setx KCL_CACHE_PATH "C:\temp" /M
```

## 65. 如何在 KCL 中使用 "import another-module" ? 包名中包含横线 "-"

在 KCL 中,import 语句中使用的模块名称中只支持`_`,kcl.mod 中的包名同时支持 `-``_`,KCL 编译器会自动将包名中的 `-` 替换为 `_`

```toml
# kcl.mod 中同时支持如下两种写法
another-module = "0.1.1"
another_module = "0.1.1"
```

在 KCL 代码中,只支持使用如下 import 语句

```python
import another_module
```

`another-module = "0.1.1"``another_module = "0.1.1"` 是等价的, 如果同时在 `kcl.mod` 中使用这两种写法会得到一个错误。
17 changes: 17 additions & 0 deletions versioned_docs/version-0.9/user_docs/support/faq-kcl.md
Original file line number Diff line number Diff line change
Expand Up @@ -2712,3 +2712,20 @@ returns the output:
foobar: foo.bar
```

## 68. How to "import another-module" in KCL ? Module with hyphens in it

In KCL, only module names with `_` are supported in the import statements, while package names in `kcl.mod` support both `-` and `_`. The KCL compiler will automatically replace `-` with `_`. Therefore, in `kcl.mod`, the following dependencies are both supported:

```toml
# both supported
another-module = "0.1.1"
another_module = "0.1.1"
```

In KCL code, the following import statement is supported:

```python
import another_module
```

Both `another-module = "0.1.1"` and `another_module = "0.1.1"` are equivalent, and using both will result in an error.

0 comments on commit 5c47ccb

Please sign in to comment.