Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add import docs about module name with hyphen #389

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading