Add `top_down` parameter to `(i)glob` and `Path.(r)glob` matching `{os,Path}.walk`
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Feature or enhancement
Proposal:
Recursively searching for globs is a common use case when working with the filesystem. In cases where one modifies files while working in them it is useful to specify whether one first wants to recurse into directories or first get all the files in a directory before recursing into subdirs.
One simply example is when one wants to delete all empty directories:
for d in context.root.glob("**/", top_down=False):
if d == context.root:
continue
if not any(d.iterdir()):
d.rmdir()
Currently, one has two alternatives (apart from reimplementing glob) which have their respective drawbacks:
for d in reversed(sorted(context.root.glob("**/"))): ...This eagerly consumes and sorts the iterator. This has the drawback of requiring a lot of memory for large trees and taking additional time for the sorting.for d, _, _ in context.root.walk(top_down=False): ...This works for this simple case but does not allow applying search patterns e.g. only looking for empty directories somewhere under.venv(e.g.**/.venv/**/)
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず既存の (i)glob と Path.(r)glob のエントリポイントを追跡し、その動作を {os,Path}.walk と比較します。再帰的な globbing に対して要求された top_down の動作を実装し、その後、**/ のようなパターンが既存の glob の動作を維持しながらボトムアップ走査をサポートすることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- operating-systems
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100