Skip to content

Absl flags pathlib support #165

@bsarden

Description

@bsarden

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:

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions