Add multi enum class flag to absl.flags.

This change enables the use of enum.Enum objects in multi_* style labels.

Previously the multi_enum flag in absl.flags only accepted strings. The new multi_enum_class flag accepts (lists of) Enum class members.

The text format of lists of enums when serializing into XML differs from the list format in other multi_* types of flags. This is because all other multi_* types rely on repr() to turn a list into a string (since all other multi_* types have primitive contents). With multi_enum_class, repr() prints out a list of the repr()'s of Enum objects, which are rather unsightly for public consumption (e.g., they contain the integer value of the enum flags). This change does some acrobatics to ensure XML representation of flag usage looks reasonable for lists, but those rendered lists look a little different from repr()'ed lists.

This change fixes the way multi_* flags are serialized when saved for future re-ingestion via a command line. It makes each flag value appear on a separate line, by modifying the list separator of all MultiFlag and subclasses to be '\n'.

PiperOrigin-RevId: 224405076
9 files changed
tree: 0e7c3a9caf20ad6cbe953e4bbbe8dc2301b14863
  1. absl/
  2. smoke_tests/
  3. third_party/
  4. AUTHORS
  5. CONTRIBUTING.md
  6. LICENSE
  7. README.md
  8. setup.py
  9. WORKSPACE
README.md

Abseil Python Common Libraries

This repository is a collection of Python library code for building Python applications. The code is collected from Google's own Python code base, and has been extensively tested and used in production.

Features

  • Simple application startup
  • Distributed commandline flags system
  • Custom logging module with additional features
  • Testing utilities

Getting Started

Installation

To install the package, simply run:

pip install absl-py

Or install from source:

python setup.py install

Running Tests

To run Abseil tests, you can clone the git repo and run bazel:

git clone https://github.com/abseil/abseil-py.git
cd abseil-py
bazel test absl/...

Example Code

Please refer to smoke_tests/sample_app.py as an example to get started.

Documentation

Full documentation is forthcoming on https://abseil.io. For now, please refer to the in-code Python docstrings.

Future Releases

The current repository includes an initial set of libraries for early adoption. More components and interoperability with Abseil C++ Common Libraries will come in future releases.

License

The Abseil Python library is licensed under the terms of the Apache license. See LICENSE for more information.