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

Docs: 升级新版 NonePress 主题 #2375

Merged
merged 23 commits into from Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintignore
@@ -0,0 +1,6 @@
dist
node_modules
.yarn
.history
build
lib
85 changes: 85 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,85 @@
module.exports = {
root: true,
env: {
browser: true,
commonjs: true,
node: true,
},
parser: "@typescript-eslint/parser",
parserOptions: {
tsconfigRootDir: __dirname,
project: ["./tsconfig.json", "./website/tsconfig.json"],
},
globals: {
JSX: true,
},
extends: [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/recommended",
"plugin:regexp/recommended",
"plugin:prettier/recommended",
],
settings: {
"import/resolver": {
node: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
},
typescript: true,
},
react: {
version: "detect",
},
},
overrides: [
{
files: ["*.ts", "*.tsx"],
rules: {
"import/no-unresolved": "off",
},
},
{
files: ["*.js", "*.cjs"],
rules: {
"@typescript-eslint/no-var-requires": "off",
},
},
],
plugins: ["@typescript-eslint"],
rules: {
"linebreak-style": ["error", "unix"],
quotes: ["error", "double", { avoidEscape: true }],
semi: ["error", "always"],
"@typescript-eslint/no-non-null-assertion": "off",
"import/order": [
"error",
{
groups: [
"builtin",
"external",
"internal",
"parent",
"sibling",
"index",
],
pathGroups: [
{ pattern: "react", group: "builtin", position: "before" },
{ pattern: "fs-extra", group: "builtin" },
{ pattern: "lodash", group: "external", position: "before" },
{ pattern: "clsx", group: "external", position: "before" },
{ pattern: "@theme/**", group: "internal" },
{ pattern: "@site/**", group: "internal" },
{ pattern: "@theme-init/**", group: "internal" },
{ pattern: "@theme-original/**", group: "internal" },
],
pathGroupsExcludedImportTypes: [],
"newlines-between": "always",
alphabetize: {
order: "asc",
},
},
],
},
};
12 changes: 2 additions & 10 deletions .github/actions/setup-node/action.yml
Expand Up @@ -7,15 +7,7 @@ runs:
- uses: actions/setup-node@v3
with:
node-version: "18"
cache: "yarn"

- id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
shell: bash

- uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

- run: yarn install
- run: yarn install --frozen-lockfile
shell: bash
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -139,7 +139,7 @@ fabric.properties
.LSOverride

# Icon must end with two \r
Icon
# Icon

# Thumbnails
._*
Expand Down
31 changes: 31 additions & 0 deletions .stylelintrc.js
@@ -0,0 +1,31 @@
module.exports = {
extends: ["stylelint-config-standard", "stylelint-prettier/recommended"],
overrides: [
{
files: ["*.css"],
rules: {
"function-no-unknown": [true, { ignoreFunctions: ["theme"] }],
"selector-class-pattern": [
"^([a-z][a-z0-9]*)(-[a-z0-9]+)*$",
{
resolveNestedSelectors: true,
message: (selector) =>
`Expected class selector "${selector}" to be kebab-case`,
},
],
},
},
{
files: ["*.module.css"],
rules: {
"selector-class-pattern": [
"^[a-z][a-zA-Z0-9]+$",
{
message: (selector) =>
`Expected class selector "${selector}" to be lowerCamelCase`,
},
],
},
},
],
};
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -207,7 +207,7 @@ NoneBot2 不是 NoneBot1 的替代品。事实上,它们都在被积极的维

- [文档镜像(中国境内)](https://nb2.baka.icu)

- 其他插件请查看 [商店](https://nonebot.dev/store)
- 其他插件请查看 [商店](https://nonebot.dev/store/plugins)

## 许可证

Expand Down
20 changes: 10 additions & 10 deletions nonebot/internal/driver/__init__.py
@@ -1,30 +1,30 @@
from .model import URL as URL
from .driver import Mixin as Mixin
from .model import RawURL as RawURL
from .driver import Driver as Driver
from .abstract import Mixin as Mixin
from .model import Cookies as Cookies
from .model import Request as Request
from .abstract import Driver as Driver
from .model import FileType as FileType
from .model import Response as Response
from .model import DataTypes as DataTypes
from .model import FileTypes as FileTypes
from .model import WebSocket as WebSocket
from .driver import ASGIMixin as ASGIMixin
from .model import FilesTypes as FilesTypes
from .model import QueryTypes as QueryTypes
from .abstract import ASGIMixin as ASGIMixin
from .model import CookieTypes as CookieTypes
from .model import FileContent as FileContent
from .model import HTTPVersion as HTTPVersion
from .model import HeaderTypes as HeaderTypes
from .model import SimpleQuery as SimpleQuery
from .model import ContentTypes as ContentTypes
from .driver import ForwardMixin as ForwardMixin
from .driver import ReverseMixin as ReverseMixin
from .model import QueryVariable as QueryVariable
from .driver import ForwardDriver as ForwardDriver
from .driver import ReverseDriver as ReverseDriver
from .driver import combine_driver as combine_driver
from .abstract import ForwardMixin as ForwardMixin
from .abstract import ReverseMixin as ReverseMixin
from .abstract import ForwardDriver as ForwardDriver
from .abstract import ReverseDriver as ReverseDriver
from .combine import combine_driver as combine_driver
from .model import HTTPServerSetup as HTTPServerSetup
from .driver import HTTPClientMixin as HTTPClientMixin
from .abstract import HTTPClientMixin as HTTPClientMixin
from .model import WebSocketServerSetup as WebSocketServerSetup
from .driver import WebSocketClientMixin as WebSocketClientMixin
from .abstract import WebSocketClientMixin as WebSocketClientMixin
Expand Up @@ -2,18 +2,7 @@
import asyncio
from typing_extensions import TypeAlias
from contextlib import AsyncExitStack, asynccontextmanager
from typing import (
TYPE_CHECKING,
Any,
Set,
Dict,
Type,
Union,
TypeVar,
Callable,
AsyncGenerator,
overload,
)
from typing import TYPE_CHECKING, Any, Set, Dict, Type, Callable, AsyncGenerator

from nonebot.log import logger
from nonebot.config import Env, Config
Expand All @@ -33,8 +22,6 @@
from nonebot.internal.adapter import Bot, Adapter


D = TypeVar("D", bound="Driver")

BOT_HOOK_PARAMS = [DependParam, BotParam, DefaultParam]


Expand Down Expand Up @@ -295,44 +282,3 @@ def setup_websocket_server(self, setup: "WebSocketServerSetup") -> None:

**Deprecated**,请使用 {ref}`nonebot.drivers.ReverseMixin` 或其子类代替。
"""


if TYPE_CHECKING:

class CombinedDriver(Driver, Mixin):
...


@overload
def combine_driver(driver: Type[D]) -> Type[D]:
...


@overload
def combine_driver(driver: Type[D], *mixins: Type[Mixin]) -> Type["CombinedDriver"]:
...


def combine_driver(
driver: Type[D], *mixins: Type[Mixin]
) -> Union[Type[D], Type["CombinedDriver"]]:
"""将一个驱动器和多个混入类合并。"""
# check first
assert issubclass(driver, Driver), "`driver` must be subclass of Driver"
assert all(
issubclass(m, Mixin) for m in mixins
), "`mixins` must be subclass of Mixin"

if not mixins:
return driver

def type_(self: "CombinedDriver") -> str:
return (
driver.type.__get__(self)
+ "+"
+ "+".join(x.type.__get__(self) for x in mixins)
)

return type(
"CombinedDriver", (*mixins, driver), {"type": property(type_)}
) # type: ignore
45 changes: 45 additions & 0 deletions nonebot/internal/driver/combine.py
@@ -0,0 +1,45 @@
from typing import TYPE_CHECKING, Type, Union, TypeVar, overload

from .abstract import Mixin, Driver

D = TypeVar("D", bound="Driver")

if TYPE_CHECKING:

class CombinedDriver(Driver, Mixin):
...


@overload
def combine_driver(driver: Type[D]) -> Type[D]:
...


@overload
def combine_driver(driver: Type[D], *mixins: Type[Mixin]) -> Type["CombinedDriver"]:
...


def combine_driver(
driver: Type[D], *mixins: Type[Mixin]
) -> Union[Type[D], Type["CombinedDriver"]]:
"""将一个驱动器和多个混入类合并。"""
# check first
if not issubclass(driver, Driver):
raise TypeError("`driver` must be subclass of Driver")

Check warning on line 29 in nonebot/internal/driver/combine.py

View check run for this annotation

Codecov / codecov/patch

nonebot/internal/driver/combine.py#L29

Added line #L29 was not covered by tests
if not all(issubclass(m, Mixin) for m in mixins):
raise TypeError("`mixins` must be subclass of Mixin")

Check warning on line 31 in nonebot/internal/driver/combine.py

View check run for this annotation

Codecov / codecov/patch

nonebot/internal/driver/combine.py#L31

Added line #L31 was not covered by tests

if not mixins:
return driver

Check warning on line 34 in nonebot/internal/driver/combine.py

View check run for this annotation

Codecov / codecov/patch

nonebot/internal/driver/combine.py#L34

Added line #L34 was not covered by tests

def type_(self: "CombinedDriver") -> str:
return (
driver.type.__get__(self)
+ "+"
+ "+".join(x.type.__get__(self) for x in mixins)
)

return type(
"CombinedDriver", (*mixins, driver), {"type": property(type_)}
) # type: ignore
10 changes: 5 additions & 5 deletions nonebot/plugin/__init__.py
Expand Up @@ -29,7 +29,7 @@
- `load_builtin_plugins` =>
{ref}``load_builtin_plugins` <nonebot.plugin.load.load_builtin_plugins>`
- `require` => {ref}``require` <nonebot.plugin.load.require>`
- `PluginMetadata` => {ref}``PluginMetadata` <nonebot.plugin.plugin.PluginMetadata>`
- `PluginMetadata` => {ref}``PluginMetadata` <nonebot.plugin.model.PluginMetadata>`

FrontMatter:
sidebar_position: 0
Expand Down Expand Up @@ -77,7 +77,7 @@ def get_plugin(name: str) -> Optional["Plugin"]:
如果为 `load_plugins` 文件夹导入的插件,则为文件(夹)名。

参数:
name: 插件名,即 {ref}`nonebot.plugin.plugin.Plugin.name`。
name: 插件名,即 {ref}`nonebot.plugin.model.Plugin.name`。
"""
return _plugins.get(name)

Expand All @@ -88,7 +88,7 @@ def get_plugin_by_module_name(module_name: str) -> Optional["Plugin"]:
如果提供的模块名为某个插件的子模块,同样会返回该插件。

参数:
module_name: 模块名,即 {ref}`nonebot.plugin.plugin.Plugin.module_name`。
module_name: 模块名,即 {ref}`nonebot.plugin.model.Plugin.module_name`。
"""
loaded = {plugin.module_name: plugin for plugin in _plugins.values()}
has_parent = True
Expand All @@ -111,9 +111,9 @@ def get_available_plugin_names() -> Set[str]:
from .on import on as on
from .manager import PluginManager
from .on import on_type as on_type
from .model import Plugin as Plugin
from .load import require as require
from .on import on_regex as on_regex
from .plugin import Plugin as Plugin
from .on import on_notice as on_notice
from .on import on_command as on_command
from .on import on_keyword as on_keyword
Expand All @@ -129,8 +129,8 @@ def get_available_plugin_names() -> Set[str]:
from .on import on_startswith as on_startswith
from .load import load_from_json as load_from_json
from .load import load_from_toml as load_from_toml
from .model import PluginMetadata as PluginMetadata
from .on import on_shell_command as on_shell_command
from .plugin import PluginMetadata as PluginMetadata
from .load import load_all_plugins as load_all_plugins
from .load import load_builtin_plugin as load_builtin_plugin
from .load import load_builtin_plugins as load_builtin_plugins
Expand Down
4 changes: 2 additions & 2 deletions nonebot/plugin/load.py
Expand Up @@ -12,7 +12,7 @@

from nonebot.utils import path_to_module_name

from .plugin import Plugin
from .model import Plugin
from .manager import PluginManager
from . import _managers, get_plugin, _current_plugin_chain, _module_name_to_plugin_name

Expand Down Expand Up @@ -160,7 +160,7 @@ def require(name: str) -> ModuleType:
如果为 `load_plugins` 文件夹导入的插件,则为文件(夹)名。

参数:
name: 插件名,即 {ref}`nonebot.plugin.plugin.Plugin.name`。
name: 插件名,即 {ref}`nonebot.plugin.model.Plugin.name`。

异常:
RuntimeError: 插件无法加载
Expand Down
2 changes: 1 addition & 1 deletion nonebot/plugin/manager.py
Expand Up @@ -20,7 +20,7 @@
from nonebot.log import logger
from nonebot.utils import escape_tag, path_to_module_name

from .plugin import Plugin, PluginMetadata
from .model import Plugin, PluginMetadata
from . import (
_managers,
_new_plugin,
Expand Down