diff --git a/docs/modules/array2d.md b/docs/modules/array2d.md index eb78eaf6..eeae1f7e 100644 --- a/docs/modules/array2d.md +++ b/docs/modules/array2d.md @@ -5,15 +5,6 @@ label: array2d Efficient general-purpose 2D array. -https://github.com/pocketpy/pocketpy/blob/main/include/typings/array2d.pyi +#### Source code -## Example - -```python -from array2d import array2d - -a = array2d(3, 4, default=0) - -a[1, 2] = 5 -print(a[1, 2]) # 5 -``` \ No newline at end of file +:::code source="../../include/typings/array2d.pyi" ::: \ No newline at end of file diff --git a/docs/modules/dataclasses.md b/docs/modules/dataclasses.md index 31705ca3..66dd02c1 100644 --- a/docs/modules/dataclasses.md +++ b/docs/modules/dataclasses.md @@ -11,4 +11,6 @@ A decorator that is used to add special method to classes, including `__init__`, Convert a dataclass instance to a dictionary. +#### Source code +:::code source="../../python/dataclasses.py" ::: \ No newline at end of file diff --git a/docs/modules/io.md b/docs/modules/io.md deleted file mode 100644 index c73a69b9..00000000 --- a/docs/modules/io.md +++ /dev/null @@ -1,42 +0,0 @@ ---- -icon: package-dependencies -label: io ---- - -!!! -This module is optional. Set `PK_ENABLE_OS` to `1` to enable it. -!!! - -### `io.FileIO.read(size=-1) -> bytes | str` - -Read up to `size` bytes from the file. If `size` is negative or omitted, read until EOF. - -### `io.FileIO.write(data: bytes | str)` - -Write the given data to the file. - -### `io.FileIO.seek(offset, whence=0) -> int` - -Change the file position to the given offset. The `whence` argument is optional and defaults to `0` (absolute file positioning); other values are `1` (seek relative to the current position) and `2` (seek relative to the file's end). - -### `io.FileIO.tell() -> int` - -Return the current file position. - -### `io.FileIO.close()` - -Close the file. - - -### `io.SEEK_SET` - -Seek from the beginning of the file. - -### `io.SEEK_CUR` - -Seek from the current position. - -### `io.SEEK_END` - -Seek from the end of the file. - diff --git a/docs/modules/linalg.md b/docs/modules/linalg.md index cb46a3cc..e33603da 100644 --- a/docs/modules/linalg.md +++ b/docs/modules/linalg.md @@ -7,6 +7,6 @@ Provide `mat3x3`, `vec2`, `vec3` and `vec4` types. This classes adopt `torch`'s naming convention. Methods with `_` suffix will modify the instance itself. -https://github.com/pocketpy/pocketpy/blob/main/include/typings/linalg.pyi +#### Source code :::code source="../../include/typings/linalg.pyi" ::: \ No newline at end of file diff --git a/docs/modules/os.md b/docs/modules/os.md deleted file mode 100644 index b5504a55..00000000 --- a/docs/modules/os.md +++ /dev/null @@ -1,72 +0,0 @@ ---- -icon: package-dependencies -label: os ---- - -!!! -This module is optional. Set `PK_ENABLE_OS` to `1` to enable it. -!!! - -### `os.getcwd()` - -Returns the current working directory. - -### `os.chdir(path: str)` - -Changes the current working directory to the given path. - -### `os.listdir(path: str)` - -Returns a list of files and directories in the given path. - -### `os.remove(path: str)` - -Removes the file at the given path. - -### `os.mkdir(path: str)` - -Creates a directory at the given path. - -### `os.rmdir(path: str)` - -Removes the directory at the given path. - -### `os.path.join(*paths: str)` - -Joins the given paths together. - -### `os.path.exists(path: str)` - -Check if the given path exists. - -### `os.path.basename(path: str)` - -Returns the basename of the given path. - -### `os.path.isdir(path: str)` - -Check if the given path is a directory. - -### `os.path.isfile(path: str)` - -Check if the given path is a file. - -### `os.path.abspath(path: str)` - -Returns the absolute path of the given path. - - -## Other functions - -You can add other functions to `os` module via normal binding if you need them. -For example, add `os.system`: - -```cpp -PyVar mod = vm->_modules["os"]; - -vm->bind(mod, "system(cmd: str) -> int", [](VM* vm, ArgsView args){ - const char* cmd = py_cast(vm, args[0]); - int code = system(cmd); - return py_var(vm, code); -}); -``` diff --git a/docs/modules/textwrap.md b/docs/modules/textwrap.md new file mode 100644 index 00000000..936a05d7 --- /dev/null +++ b/docs/modules/textwrap.md @@ -0,0 +1,10 @@ +--- +icon: package +label: textwrap +--- + +Text wrapping and filling. + +#### Source code + +:::code source="../../python/textwrap.py" ::: \ No newline at end of file diff --git a/docs/modules/typing.md b/docs/modules/typing.md index 3eaca5c9..9b312c80 100644 --- a/docs/modules/typing.md +++ b/docs/modules/typing.md @@ -5,4 +5,6 @@ label: typing Placeholder module for type hints. +#### Source code + :::code source="../../python/typing.py" ::: \ No newline at end of file diff --git a/python/textwrap.py b/python/textwrap.py new file mode 100644 index 00000000..e69de29b