Code Monkey home page Code Monkey logo

mina's Introduction

Mina Package Structure

简体中文 | English

Mina 是基于 pdm-backend 的 "模块分包" 实现.

Mina 同样也是 Mina Package Structure 的实现, 作为一门独特的规范, 其具有以下特性:

  • 将整个项目作为工作区环境, 通过现有的设施统一管理所有分包使用的依赖树;
  • 分包各自声明自己的信息和工作区中引用的依赖;
  • pdm-backend 构建发布时所读取的 Metadata 进行修补以复用其构建流程;
  • 通过提供完整的 PEP-517 构建后端 (build backend), 避免了一些潜在的问题.

Mina 提供了名为 mina-buildPEP-517 实现, 同时还提供作为 PDM Plugin 的简易 CLI 实现;

mina-build 仅在配置了需要构建的分包名称时才会注入 pdm-pep517 的构建流程, 其他情况下的行为与 pdm-backend 无异.

CLI 中虽提供了一个 pdm mina build <package> 指令, 但你也可以通过环境变量 MINA_BUILD_TARGET 或是 config-setting 中设置 --mina-target 指定需要打包的分包.

Quick Start

安装 CLI

目前, Mina 仅支持将 pdm 作为主要的用户功能入口, 但或许 poetry 会在之后得到支持?

elaina@localhost $ pip install pdm-mina
# or pdm
elaina@localhost $ pdm add pdm-mina -d

引入 mina-build

在项目的 pyproject.toml 中配置以下项:

[build-system]
requires = ["mina-build>=0.2.5"]
build-backend = "mina.backend"

编辑 pyproject.toml

假设你有如下的目录结构:

mina-example/
├── avilla/
│   ├── core/
│   │   └── __init__.py
│   ├── io/
│   │   └── __init__.py
│   ├── onebot/
│   │   └── __init__.py
│   └── elizabeth/
│       └── __init__.py
└── pyproject.toml

如果需要将 avilla 下的模块发为多个包, 用 Mina 可以简单的做到, 比如上面这种我们就可以在 pyproject.toml 内填入以下几个表来声明分包:

[tool.mina.packages."core"]
[tool.mina.packages."io"]
[tool.mina.packages."onebot"]
[tool.mina.packages."elizabeth"]

Mina 的分包声明沿用了 PEP-621 中的声明方式. 我们这里以配置分包 core 举例.

[tool.mina.packages."core"]
includes = [
    "avilla/core"
]
# 相当于 tool.pdm.includes, 如果不填我不知道会发生什么, 可能就是普通的情况 -- 打包 name 所指向的模块.

# raw-dependencies = [...]
#    这一配置项会在处理完 project.dependencies 后直接排入依赖声明.
#    你可以用这个特性来声明分包之间的依赖.

# override = false

[tool.mina.packages."core".project]
name = "avilla-core"  # 分包在 `pypi` 上的名称, 必填
description = "..."
authors = ["..."]
version = "0.1.0"  # 版本, 不保证支持动态获取(因为我没用过也没试过)
requires-python = ">=3.9"
dependencies = [  # 建议填入
    "aiohttp",  # 这里虽然使用 `PEP-508` 规范, 但所有包都会被重定向至 project.dependencies 上的同名项.
    "starlette",
    "pydantic"
]
optional-dependencies = {
    "amnesia": ["graia-amnesia"]  # optional dependencies 示例
}
entry-points = {pdm = {mina = "mina.plugin:ensure_pdm"}}  # entry-points 的声明方式

填入后, 你可以通过 CLI 的 pdm mina list 简单的检查, 或是直接 pdm mina build <pkg> 测试;

构建发布包

使用 pdm mina build <pkg> 可以构建对应的分包.

如果你希望, 你可以使用 pdm mina build -a/--all 一次性构建所有的分包.

这里推荐使用 twine + keyring 发布到 PyPI 上, 当然 pdm-publish, 或是用 Github Actions 也是可以的.

覆盖工作区配置

如果你希望, 你可以让 Mina 在处理和注入分包的 project 定义时, 使用覆盖工作区配置的形式来获得 Project Spec; 本特性默认不启用:

[tool.mina]
override-global = true  # 全局启用该特性

[tool.mina.packages."core"]
override = true  # 仅在 core 分包启用该特性

开源协议

本项目使用 MIT 协议开源.

mina's People

Contributors

blueglassblock avatar greyelaina avatar programripper avatar rf-tar-railt avatar sena-nana avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mina's Issues

Suggestion to migrate to the new interface of pdm-pep517

Hi, I am going to change the interface of Metadata and relocate the build settings to [tool.pdm.build]. It is not released yet but some changes are necessary to make in this project to avoid any breakage.

In the line to construct the Metadata object

_meta = Metadata(cwd / "pyproject.toml")

since the initialization args are changed, I suggest using a Builder to construct it instead:

from pdm.pep517.base import Builder
metadata = Builder(cwd).meta

When you copy the tool table:

if "includes" in package_conf:
pdm_settings["includes"] = package_conf["includes"]
if "excludes" in package_conf:
pdm_settings["excludes"] = package_conf["excludes"]
if "source-includes" in package_conf:
pdm_settings["source-includes"] = package_conf["source-includes"]
if "is-purelib" in package_conf:
pdm_settings["is-purelib"] = package_conf["is-purelib"]
if "entry-points" in package_conf:
pdm_settings["entry-points"] = package_conf["entry-points"]

You should copy build as well, in this way you can handle both the old build field, and the new [tool.pdm.build] sub-table:

if "build" in package_conf:
    pdm_settings["build"] = package_conf["build"]

These changes will be backward-compatible.

Let me know if you are okay with the changes so that I can cut a new release of pdm-pep517. Thanks

🐞 PEP621ValidationError

pdm.pep517.exceptions.PEP621ValidationError error when run pdm build and pdm mina build test

log:

pdm.pep517.exceptions.PEP621ValidationError: {'includes': ['unknown field'], 'name': ['required field'], 'override': ['unknown field'], 'project': ['unknown field']}

pyproject.toml:

[project]
name = "graiax"
version = "0.1.0"
description = ""
readme = "README.md"
authors = [
    {name = "GraiaCommunity"},
]
dependencies = [
    "pdm-mina>=0.1.0",
    "mina-build>=0.2.0",
]
requires-python = ">=3.9"
license = {text = "MIT"}

[tool.pdm]

[project.entry-points.pdm]
mina = "mina.plugin:ensure_pdm"

[build-system]
requires = ["mina-build>=0.2.0"]
build-backend = "mina.build"

[tool.mina]
enabled = true

[tool.mina.packages."test"]
override = false
includes = [
    "packages/test"
]

[tool.mina.packages."test".project]
name = "test"
version = "0.1.0"
description = ""
readme = "README.md"
authors = [
    {name = "Redlnn", email = "[email protected]"},
]
dependencies = []
requires-python = ">=3.9"
license = {text = "MIT"}

Failture when installing the project as an editable package

[BuildError]: Build backend raised error: Module 'editables' is missing, please make sure it is specified in the 'build-system.requires'       
section. If it is not possible, add it to the project and use '--no-isolation' option.
Showing the last 10 lines of the build output:
    main()
  File "C:\Users\TR\AppData\Local\Programs\Python\Python39\lib\site-packages\pyproject_hooks\_in_process\_in_process.py", line 335, in main    
    json_out['return_val'] = hook(**hook_input['kwargs'])
  File "C:\Users\TR\AppData\Local\Programs\Python\Python39\lib\site-packages\pyproject_hooks\_in_process\_in_process.py", line 273, in
build_editable
    return hook(wheel_directory, config_settings, metadata_directory)
  File "D:\Download\Projects\Alconna-Graia\.venv\Lib\site-packages\mina\backend\__init__.py", line 291, in build_editable
    from pdm.backend.editable import EditableBuilder
  File "D:\Download\Projects\Alconna-Graia\.venv\Lib\site-packages\pdm\backend\editable.py", line 7, in <module>
    from editables import EditableProject
ModuleNotFoundError: No module named 'editables'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.