Skip to content

Commit 71f4607

Browse files
authored
Merge pull request #389 from zong-zhe/add-import-doc
feat: add import docs about module name with hyphen
2 parents 0dd122b + 5c47ccb commit 71f4607

File tree

4 files changed

+71
-0
lines changed
  • docs/user_docs/support
  • i18n/zh-CN/docusaurus-plugin-content-docs
  • versioned_docs/version-0.9/user_docs/support

4 files changed

+71
-0
lines changed

docs/user_docs/support/faq-kcl.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,3 +2711,21 @@ returns the output:
27112711
```bash
27122712
foobar: foo.bar
27132713
```
2714+
2715+
## 68. How to "import another-module" in KCL ? Module with hyphens in it
2716+
2717+
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:
2718+
2719+
```toml
2720+
# both supported
2721+
another-module = "0.1.1"
2722+
another_module = "0.1.1"
2723+
```
2724+
2725+
In KCL code, the following import statement is supported:
2726+
2727+
```python
2728+
import another_module
2729+
```
2730+
2731+
Both `another-module = "0.1.1"` and `another_module = "0.1.1"` are equivalent, and using both will result in an error.

i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/support/faq-kcl.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,3 +2625,21 @@ export KCL_CACHE_PATH=/tmp # 或者更改为您想要的路径
26252625
```powershell
26262626
setx KCL_CACHE_PATH "C:\temp" /M
26272627
```
2628+
2629+
## 65. 如何在 KCL 中使用 "import another-module" ? 包名中包含横线 "-"
2630+
2631+
在 KCL 中,import 语句中使用的模块名称中只支持`_`,kcl.mod 中的包名同时支持 `-` 和 `_`,KCL 编译器会自动将包名中的 `-` 替换为 `_`。
2632+
2633+
```toml
2634+
# kcl.mod 中同时支持如下两种写法
2635+
another-module = "0.1.1"
2636+
another_module = "0.1.1"
2637+
```
2638+
2639+
在 KCL 代码中,只支持使用如下 import 语句
2640+
2641+
```python
2642+
import another_module
2643+
```
2644+
2645+
`another-module = "0.1.1"` 和 `another_module = "0.1.1"` 是等价的, 如果同时在 `kcl.mod` 中使用这两种写法会得到一个错误。

i18n/zh-CN/docusaurus-plugin-content-docs/version-0.9/user_docs/support/faq-kcl.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,3 +2625,21 @@ export KCL_CACHE_PATH=/tmp # 或者更改为您想要的路径
26252625
```powershell
26262626
setx KCL_CACHE_PATH "C:\temp" /M
26272627
```
2628+
2629+
## 65. 如何在 KCL 中使用 "import another-module" ? 包名中包含横线 "-"
2630+
2631+
在 KCL 中,import 语句中使用的模块名称中只支持`_`,kcl.mod 中的包名同时支持 `-` 和 `_`,KCL 编译器会自动将包名中的 `-` 替换为 `_`。
2632+
2633+
```toml
2634+
# kcl.mod 中同时支持如下两种写法
2635+
another-module = "0.1.1"
2636+
another_module = "0.1.1"
2637+
```
2638+
2639+
在 KCL 代码中,只支持使用如下 import 语句
2640+
2641+
```python
2642+
import another_module
2643+
```
2644+
2645+
`another-module = "0.1.1"` 和 `another_module = "0.1.1"` 是等价的, 如果同时在 `kcl.mod` 中使用这两种写法会得到一个错误。

versioned_docs/version-0.9/user_docs/support/faq-kcl.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,3 +2712,20 @@ returns the output:
27122712
foobar: foo.bar
27132713
```
27142714

2715+
## 68. How to "import another-module" in KCL ? Module with hyphens in it
2716+
2717+
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:
2718+
2719+
```toml
2720+
# both supported
2721+
another-module = "0.1.1"
2722+
another_module = "0.1.1"
2723+
```
2724+
2725+
In KCL code, the following import statement is supported:
2726+
2727+
```python
2728+
import another_module
2729+
```
2730+
2731+
Both `another-module = "0.1.1"` and `another_module = "0.1.1"` are equivalent, and using both will result in an error.

0 commit comments

Comments
 (0)