在有共同字段下的pydantic类转换不正确问题
在使用 Pydantic 进行数据验证和设置时,你可能会遇到一个问题:当多个类有共同字段时,Pydantic 可能无法正确地区分这些类。让我通过一个简单的例子来解释这个问题。 ...
在使用 Pydantic 进行数据验证和设置时,你可能会遇到一个问题:当多个类有共同字段时,Pydantic 可能无法正确地区分这些类。让我通过一个简单的例子来解释这个问题。 ...
前因 由于python中没有方便快捷生成美观图片的方案,所以我使用了jinja2模板生成html后交给playwright生成网页图片,这其中,图片资源可以使用base64格式解决,而字体加载就难了。 ...
下面这个例子是,当release分支有commit发生时,自动获取当前应用的版本信息,并使用缓存,分别构建前端和rust,并将构建好的包上传至指定tag的release上。在 platform处定义平台,这里我只选定了Win ...
当你想从Tauri调用终端并运行类似 ls的命令的话,需要使用 @tauri-apps/api/shell的api,步骤如下 编辑 tauri.conf.json下的 tauri.allowlist.shell { "tauri": { "allowlist": { "shell": { "all": true, // enable all shell APIs "execute": true, // enable process spawn APIs "sidecar": true, // enable spawning sidecars "open": true // enable opening files/URLs using the default program } } } } 其他api暂时不讨论,只说 execute,假设我们需要使用git命令(案例来自官网) 编辑 scope定义好需要用到的命令,要是没有定义则无法调用 { "scope": [ { "name": "run-git-commit", "cmd": "git", "args": ["commit", "-m", { "validator": "\\S+" }] } ] } 开始调用该命令 import { Command } from '@tauri-apps/api/shell' const c = new Command('run-git-commit', ['commit', '-m', 'the commit message']) const std = await c.execute(); std.stderr std.stdout std.code std.signal 你可以将 args设置为 true来使js端可以传入任意参数 ...
tauri支持从$APPCONFIG, $APPDATA, $APPLOCALDATA, $APPCACHE, $APPLOG, $AUDIO, $CACHE, $CONFIG, $DATA, $LOCALDATA, $DESKTOP, $DOCUMENT, $DOWNLOAD, $EXE, $FONT, $HOME, $PICTURE, $PUBLIC, $RUNTIME, $TEMPLATE, $VIDEO, $RESOURCE, $APP, $LOG, $TEMP 访问并读或文件夹和文件,具体措施如下 编辑 tauri.conf.json内的tauri.allowlist.fs { "tauri": { "allowlist": { "fs": { "all": true, // enable all FS APIs "readFile": true, "writeFile": true, "readDir": true, "copyFile": true, "createDir": true, "removeDir": true, "removeFile": true, "renameFile": true, "exists": true } } } } 可以直接 all: true 来开放所有tauri文件api,也可以单独开放某个api 编辑 scope开放具体访问权限 { "tauri": { "allowlist": { "fs": { "scope": ["$APPDATA/img/*"] } } } } 注意,这里开放了 $APPDATA下的 database访问权限,这样可以阻止程序访问任何路径,除了 database 从js中访问 import { readBinaryFile, BaseDirectory } from '@tauri-apps/api/fs'; // 可以是任何api // Read the image file in the `$APPDATA/avatar.png` path const contents = await readBinaryFile('img/avatar.png', { dir: BaseDirectory.AppData }); // 注意!一定要加上BaseDirectory.AppData 开放了哪个目录权限,就用 dir: BaseDirectory来指定访问路径,至少用绝对路径访问的方法我还没有找到,当然,这种相对路径访问的方式更加安全 ...
前言 这是一次从创建项目到测试打包上传Pypi的过程,记录一下。 创建项目 这里我是用的是pdm这个包管理工具,创建项目的命令是pdm init,跟着引导一步步走,之后会生成一个pyproject.toml文件,里面有项目的一些基本信息,比如作者、版本号等。下面是一个示例: ...
一般 try: import numpy except ImportError: print("numpy is not installed") 更推荐 from importlib.util import find_spec if find_spec("numpy") is not None: print("numpy is installed") else: print("numpy is not installed")
安装 pip install rich # PDM pdm add rich 文档 & 源码 基础 from rich import print print("Hello World") Rich功能非常丰富,从日志处理到富文本显示甚至动态的终端界面。 要使用Rich用做界面的话,一般是这样的: from rich.console import Console from rich.layout import Layout from rich.panel import console = Console() panel = Panel(name="panel_name") layout = Layout(panel,name="layout_name") 界面Layout和面板Panel是经常要用到的东西,Layout作为界面布局,Panel内展示元素并风格化,比如经常使用的表格Table;要实现动态变化而不是print需要用到Live。 ...
需求 以我的bot来说: Bot: ├─config ├─core ├─modules │ ├─required │ │ ├─BotManager │ │ ├─BotStatus │ │ ├─ExceptionCatch │ │ ├─... │ └─self │ ├─Modules1 │ ├─Modules2 │ ├─... ├─resources ├─service └─utils 模块统一放在modules下,required是bot运行必须的模块,self是可卸载安装的模块。 ...
同步 # sync_session # example(id, name) e = example(name="name1") db.add(e) db.flush() print(e.id) # id = 1 异步 # async_session # example(id, name) e = example(name="name1") db.add(e) await db.flush() await db.commit() await db.refresh(e) print(e.id) # id = 1