Absl flags pathlib support
- 主要語言
- Python
- 星號
- 2.5k
- 分支
- 279
- 平均合併
- 2 天 1 小時
- 30 天內合併 PR
- 1
描述
Are there any plans to support a `flags.DEFINE_path` or something similar that utilizes python's `pathlib` module to support declaring `os.PathLike` operations for the default option?
For context, I often find myself doing the following:
```py
from absl import app, flags
from pathlib import Path
FLAGS = flags.FLAGS
flags.DEFINE_string("filepath", "path/to/some.txt", "Input filepath for program")
def main(argv_):
# Override FLAGS.filepath with a pathlib.Path version
FLAGS.filepath = Path(FLAGS.filepath)
# Rest of program uses pathlib for path operations
if __name__ == "__main__":
app.run(main)
```
It would be awesome if there was an easy way to define a `Path` object from the `DEFINE_` definition in the first place. If adding such a feature is not feasible, I'm curious how other people are using `pathlib` with `absl.flags` as well.
Thanks!
貢獻指南
研究方向
Look at the absl/flags/_defines.py module to see how flag types like DEFINE_string are implemented. Understand the validator and parser pattern. The new flag type should accept a string and convert it to a pathlib.Path object. Check existing tests in absl/flags/tests/ to see how to add a test for the new DEFINE_path flag.
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- cli, developer-experience
- Issue 類型
- 功能
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 65/100