python / python/importlib_metadata

Revisit relationship between Distribution and PathDistribution

未关闭
#445 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

help wanted
主要语言
Python
星标
142
派生
97
PR 合并指标
30 天内没有已合并 PR

描述

Should Distribution objects expose a method to resolve paths?

Yes, that is one solution. There is already .locate_file() which is not far off, except that its implementation in PathDistribution precisely removes the metadata directory that we need in this case.

More generally, I wonder if there is just a tad too much coupling between the Distribution and PathDistribution classes?

There is a mix of abstract and concrete methods in the Distribution base class, and several of the concrete methods seem fairly tightly bound to the PathDistribution subclass. For example, the at() static method creates and returns a PathDistribution instance outright, and the metadata(), entry_points(), files(), and requires() methods are all implemented with assumptions as to which files should be available and that the organization should resemble a dist-info or egg-info distribution.

Now, there is (AFAICS) only the one (PathDistribution) subclass of Distribution available in this project, and I don't really have enough experience with this project or its users to really imagine what other Distribution subclasses would or could exist in the wild.

Still, I would suspect that a subclass that was sufficiently different from PathDistribution to rather prefer subclassing Distribution directly, would then find itself not merely implementing the read_text() an locate_file() abstract methods, but would probably also need to _re_implement several of metadata(), entry_points(), files(), or requires() as well.

Hence, I would raise the question whether some of these methods would be better off with their concrete implementations moved into the PathDistribution subclass? (Of course leaving abstract methods behind in Distribution where that makes sense.) This would grant these concrete methods direct access to the stuff they need inside PathDistribution, instead of having to add more interfaces to Distribution for stuff that really only makes sense for PathDistribution.

Still, this is a much bigger refactoring than I set out to do, and I would not feel comfortable starting this without consulting you.

Originally posted by @jherland in https://github.com/python/importlib_metadata/pull/437#discussion_r1141220985

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先阅读 Distribution 和 PathDistribution 类,以及 issue 中提到的方法:at()、metadata()、entry_points()、files()、requires()、read_text() 和 locate_file()。查看所链接 pull request 的讨论,以了解原始背景。要视为完成,需要就分离子类特定行为达成一致的设计,并提供一个保留相关 distribution 功能的实现。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
devtools
Issue 类型
重构
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。