diff options
author | Richard Levasseur <rlevasseur@google.com> | 2018-09-10 11:26:20 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-09-10 11:26:37 -0700 |
commit | 074fe5602e085cba46cf8bba14ea2a36d60d3dbd (patch) | |
tree | 8543664c62ddcada7b5e7e8b3c3267c918c5ba34 /third_party | |
parent | 288cbaaad761a6645943a3081c8985e614d4f312 (diff) | |
download | absl-py-074fe5602e085cba46cf8bba14ea2a36d60d3dbd.tar.gz |
Allow enum.Enum classes to be used directly with flags.
This adds a new flags define, `enum_class`, which is like `enum`, but uses
an `enum.Enum` class as the source of valid values. The resulting parsed
value is the corresponding Enum value.
Using enum_class is recommended over plain enum.
Python 2.7 note: The `enum` module is not required for absl in general, but
is required to use `enum_class`, or for absl tests to fully pass. If the
`enum` module isn't available, then absl flags can still be used, just not
the `enum_class` function. The enum34 package on PyPI is the suggested
package to use for enum support, and is the one absl assumes is used under
Python 2.7.
Python 2.7 and Bazel note: Because of how Bazel modifies PYTHONPATH, absl has
to do do some special sys.path import manipulation to make the enum module
work. In short, third party deps go before the stdlib on sys.path, so enum34's
enum module shadows Python 3's enum module, which causes problems because
enum34 is a subset of later Python 3's enum. So some sys.path futzing is done
to account for this under Bazel. This only happens if 'import enum' initially
fails, and only under Python 2.7.
PiperOrigin-RevId: 212301566
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/enum34.BUILD | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/third_party/enum34.BUILD b/third_party/enum34.BUILD new file mode 100644 index 0000000..a5ac255 --- /dev/null +++ b/third_party/enum34.BUILD @@ -0,0 +1,13 @@ +# Description: +# enum34 provides a backport of the enum module for Python 2. + +licenses(["notice"]) # MIT + +exports_files(["LICENSE"]) + +py_library( + name = "enum", + srcs = ["enum34-1.1.6/enum/__init__.py"], + srcs_version = "PY2AND3", + visibility = ["//visibility:public"], +) |