Skip to content

wheel 未打包 data/,load_data() 对 pip 安装用户不可用 #154

Description

@SongshGeo

现象

load_data()abses/__init__.py__all__ 导出的公开 API,但发行 wheel 里根本没有它要读的数据文件。仓库 checkout 下能用(所以测试全过),pip install abses 之后必崩。

证据

abses/utils/data.py

return Path(str(resources.files("data") / filename))

data仓库根目录的一个顶层包,而 pyproject.toml 只打包两个包:

[tool.hatch.build.targets.wheel]
packages = ["abses", "hydra_plugins"]
include = [
    "abses/icons/*.otf",
    "abses/conf/**/*.yaml",
    "abses/conf/*.py",
]

实测构建产物:

$ uv build --wheel --out-dir /tmp/w
$ python -c "import zipfile,glob; n=zipfile.ZipFile(sorted(glob.glob('/tmp/w/*.whl'))[-1]).namelist(); \
print('data/:', any(x.startswith('data/') for x in n)); \
print('icons/:', any(x.startswith('icons/') for x in n)); \
print('otf:', [x for x in n if x.endswith('.otf')])"
data/: False
icons/: False
otf: []

顺带:include 里有一条死 glob

"abses/icons/*.otf" 指向的 abses/icons/ 目录不存在(实测 False)。真实字体在仓库根目录的 icons/,唯一使用者是 abses/viz/customize_marker.py

FONT = pkg_resources.files("icons") / "fa-regular-400.otf"

customize_marker.py 全仓零 importabses/viz/__init__.py 只从 plotting 导入)、覆盖率 0%,却是 fontawesomeicons 两个硬依赖存在的唯一理由。

建议方案

数据文件(必须修):

  1. 把示例数据移进包内,例如 abses/data/load_data 改用 resources.files("abses.data"),并在 [tool.hatch.build.targets.wheel].include 里加上对应 glob;或
  2. 保留在仓库外,把 load_data 改成「按需下载 + 本地缓存」,并在缺失时给出可操作的报错。

方案 1 更简单;注意 data/ 目前约 8.5 MB(farmland.tif / precipitation.nc / irr_lands.csv / YR_cities.zip),若不想让 wheel 变大则选方案 2。

字体与死模块(建议一并处理):

  1. 删除 abses/viz/customize_marker.py,同时从 [project.dependencies] 移除 fontawesomeicons,并删掉那条死 glob。这是一次公共命名空间的移除,所以需要走弃用流程还是直接删,请先确认。

另外目前没有 [tool.hatch.build.targets.sdist],hatchling 默认会把 data/(8.5 MB)和 examples/ 扫进 sdist——sdist 有、wheel 没有,两者不一致,一并明确一下。

验收标准

  • 在一个干净虚拟环境里 pip install dist/abses-*.whl 后,from abses import load_data; load_data("farmland.tif") 能返回一个存在的路径。
  • CI 增加一步:构建 wheel → 装进干净环境 → 跑一个只用公开 API 的冒烟测试(现有测试都在 checkout 下跑,抓不到这类问题)。
  • pyproject.toml 里不再有指向不存在目录的 include 条目。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions