aboutsummaryrefslogtreecommitdiff
path: root/absl/flags
AgeCommit message (Collapse)Author
2022-10-03Fix typo in documentationAbseil Team
PiperOrigin-RevId: 478521309 Change-Id: Ica34fdda749b928fcf73e030bc3fa4e1585a753c
2022-09-20Add a flags.set_default function.Abseil Team
PiperOrigin-RevId: 475611494 Change-Id: I9facdfcaece0b3c0bd2b0b38364ecd41cb06d79c
2022-09-13Support FlagHolders in flag module-level functions.Abseil Team
PiperOrigin-RevId: 474195462 Change-Id: I2b57d8ea6b8eb66d1f777f026fb19e5401983789
2022-09-09Remove Python 2 compat code.Abseil Team
PiperOrigin-RevId: 473306343 Change-Id: I4c166f7fa34ce2f1b0bcacafbf790d4f932886d1
2022-08-24Expose the public APIs as the `__all__` attribute in `absl/flags/__init__.py`.Yilei Yang
This also makes sphinx autodoc generate docs for exposed APIs. Also make `absl.flags`'s docstring compatible with reST. PiperOrigin-RevId: 469768218 Change-Id: I6fd3807de05d6803a0aa73b3872555e53d504e8d
2022-08-19Update some of the docstrings to be compatible with `reST`, in preparation ↵Yilei Yang
to add generated docs by Sphinx/readthedocs. This is just an initial pass, far from great documentations. PiperOrigin-RevId: 468721475 Change-Id: I5b4f9b2127add933d7eb56414b4fa1751cdacb3d
2022-07-18Work around a Pytype issue in `DEFINE_multi_enum_class`'s return value where ↵Yilei Yang
an iterable of concrete enum values are used as the default. PiperOrigin-RevId: 461656002 Change-Id: Ic6d0699ad4f507d9f6ae24ab4aad0d7b8b19bd63
2022-06-08Remove the unnecessary Python 2 related future imports.Yilei Yang
PiperOrigin-RevId: 453697925 Change-Id: I24a9fbbe2a690d7101b7190f4b4976d16bd0942f
2022-05-23Make FlagHolder unconditionally generic.John Aslanides
Now that we've dropped Python 2 support, we can drop the conditional import of `typing`. PiperOrigin-RevId: 450471818 Change-Id: I6c4efc7b6943b9794b2a3cf1eba90d330d6b73fd
2022-05-06Remove the py2/py3 compatibility module _collections_abc.Yilei Yang
PiperOrigin-RevId: 447005334 Change-Id: Iea86a969093640a18663d3d135648329c45e9954
2022-05-05Remove the use of six in absl.flags.Yilei Yang
PiperOrigin-RevId: 446842401 Change-Id: Ic66c537d810dda858318a95e5f7b2242f58f7c75
2022-03-22Remove the use of third party `mock` package and future imports in these tests.Yilei Yang
Also remove the mock package in bazel WORKSPACE file. PiperOrigin-RevId: 436585035 Change-Id: I7f8eafac5f7b10dc8f580db20c7ae60711dfdf12
2022-03-21Remove comments, license is declared in the LICENSE file.Yilei Yang
PiperOrigin-RevId: 436293697 Change-Id: I4ebf90127a781162636fa728c8899d76937dbca6
2022-02-22Enumerate possible values in multi_enum flag help.Abseil Team
PiperOrigin-RevId: 430280700 Change-Id: I62ca45c7b794989f9e8ee66094fb73c5ac7a6840
2022-02-08Prevent the truthiness of absl.flags Flag instances from being tested in a ↵Gregory P. Smith
bool context (not useful) to avoid situations where someone really wanted to refer to `their_flag.value` instead. This prevents logic bugs. There were ~10 problems found by this and cleaned up in our internal codebase. PiperOrigin-RevId: 427295923 Change-Id: Ifc9e086133986cc14d052a06889a93c1ab0ff688
2022-01-24Remove PY2-ism in absl's own unit tests.Yilei Yang
PiperOrigin-RevId: 423878454 Change-Id: Iadc82651ecd39954cfd2af6b4bae2a98388fd75b
2022-01-20Merge changes from github.Yilei Yang
PiperOrigin-RevId: 423095241 Change-Id: Ie78fb886746b11320e777587bf50c938d9054e37
2021-11-05Set the stacklevel=2 in those UserWarnings, so that they are emitted where ↵Yilei Yang
these functions are not, not in _validators.py. PiperOrigin-RevId: 407853170 Change-Id: Iff13f2a1ca391109f9a7e85f2a91abbe3cba3c53
2021-10-25Drop the support of Python 2.7, 3.4, and 3.5. All versions have reached ↵Yilei Yang
end-of-life for more than a year now. PiperOrigin-RevId: 405511743 Change-Id: Id0f78693a6de9474576c3cfa879caf2cc177d8f6
2021-09-29Remove these exports_files, those LICENSE files no longer exist in their ↵Yilei Yang
directory after #159 (#160). PiperOrigin-RevId: 399810236 Change-Id: Ia78c6e27fbcf65c2c9e0de0d1c171c7a172f450a
2021-07-26absl: Expose the `.present` property from `Flag` on `FlagHolder`Abseil Team
The `FlagHolder` object is returned from `flags.DEFINE_*()` to allow type-safe and fully-declared access via `myflag.value`, instead of requiring users to write `FLAGS.myflag`. Additionally, this proxies the `.default` property from the `Flag` object underlying the `FlagHolder`, so `FLAGS['myflag'].default` can instead be written as simply `myflag.default`. However, the `.present` property is not easily available today without writing `FLAGS['myflag'].present` or `FLAGS[myflag.name].present`, despite being relatively commonly used. Since it intuitively makes sense for this to be available, let's proxy it through `FlagHolder` to the underlying `Flag` object. PiperOrigin-RevId: 386901861 Change-Id: I29e3173668080957b796c8634527382b792aa4ec
2021-07-19Fix #171: add an ignored `default=` argument to our custom actions.Yilei Yang
This is a required argument for custom argparse.Action classes, and is used when the `ArgumentParse` is created with a `argument_default=`. PiperOrigin-RevId: 385601086 Change-Id: I01ef4870aa4f0e92f7e8f9be0125c9a0dba16c6f
2021-06-14Stop testing Python 2 in absl.Yilei Yang
PiperOrigin-RevId: 379363540 Change-Id: Ic67abe5de18ad10764007066ea0ecb2bedf1f1da
2021-06-08Update docstring.Yilei Yang
PiperOrigin-RevId: 378281281 Change-Id: Id11546b04a8f21ea65b3a22bbd79e348b7217f5e
2021-04-30Shows all missing required flags in error message, instead of just the first ↵Abseil Team
missing required flag. Given these required flags of float values with default value of None: flags.mark_flags_as_required(["x", "y", "z"]) If none of the required flags are passed as arguments, the resulting error will only show the first missing required flag as an issue: FATAL Flags parsing error: flag --x=None: Flag --x must have a value other than None. The user will then add this required flag "x" and try again, but then get the error for "y" as a missing requirement. This loops until the user finally passes all the required flags as arguments. Since we already know which flags are required, this changes the error message shows all missing required flags at once, so the user can make the necessary changes in a single pass with the error message showing this: FATAL Flags parsing error: flag --x=None: Flag --x must have a value other than None. flag --y=None: Flag --y must have a value other than None. flag --z=None: Flag --z must have a value other than None. To achieve the formatting change, `app.parse_flags_with_usage` now puts the error message on a new line and adds indentation if the message is multi-line string. PiperOrigin-RevId: 371414012 Change-Id: Id7456e9c293fb95d7b4551fd28441610af9b3030
2021-04-19Add the missing syntactic_help attribute annotation on ArgumentParserYilei Yang
PiperOrigin-RevId: 369277659 Change-Id: I2f77b2b73abebd3cfc6558e0e8088623702d1d5a
2021-04-16Add the missing annotation `Flag.default_as_str`.Yilei Yang
PiperOrigin-RevId: 368897376 Change-Id: Ie4797bf9c2323c985e506dea0238f2d632508111
2021-03-30Add `Flag.default_unparsed` to annotations.Yilei Yang
PiperOrigin-RevId: 365814855 Change-Id: Idd59a6052f36b1e6b54f998094e58866242f54ea
2021-03-04Expose the --test_tmpdir and --test_srcdir flags as public flag holders.Yilei Yang
They are considered as public flags and callers should use them instead of accessing FLAGS.test_tmpdir and FLAGS.test_srcdir. PiperOrigin-RevId: 360948844 Change-Id: Ib3673ae55ad9b55000fb80ba60647a93fdfc0426
2021-02-26Add EnumClassListSerializer to the public namespaceAbseil Team
This is to (formally) allow using it in extension libraries. Also add a test to cover non-comma separators. PiperOrigin-RevId: 359820150 Change-Id: I3a384083a1634d1429b6a01b10571ebfb7ee9ac1
2021-02-12Fix CsvListSerializer to honor its list_sep parameter.Abseil Team
PiperOrigin-RevId: 357245847 Change-Id: I7637199f61f23e78646720ad406f539c89962fe3
2021-02-09Add type annotations for `EnumClassSerializer`Abseil Team
PiperOrigin-RevId: 356499864 Change-Id: I729590e449d14420622b6aaae08b13894ce973d6
2021-02-08Expose EnumClassSerializer.Abseil Team
PiperOrigin-RevId: 356337920 Change-Id: I6bcef41b5137945a1977148bafd622dc0be59cda
2021-01-29Fix the type annotation for DEFINE_xxx functions where the intention for the ↵Yilei Yang
first `@overload` is to only match when `required=` is passed True. Previously, omitting `required=` (all most all the calls) matches it, resulting in `_FLAG.value` being non-optional when `default=None`. PiperOrigin-RevId: 354557367 Change-Id: I05e8b705ed0b02189f6d5e09bef4095b87499cad
2021-01-20Fixed some pyi errors in flags/_define.pyiAbseil Team
PiperOrigin-RevId: 352859771 Change-Id: Id087eeec5837d76935d05d3596048c8f2ee0f124
2021-01-19Remove obsolete comments, default values don't belong to `.pyi` files anyway.Yilei Yang
PiperOrigin-RevId: 352689567 Change-Id: Ic0b50423f238ae9b685822a8eecc1ef0997db59d
2021-01-06Replace the default values in `.pyi` files with `...` as they don't belong ↵Yilei Yang
there. PiperOrigin-RevId: 350446790 Change-Id: Iafcb21051f8c3cedf96524fa02ad38a36ff548b2
2020-12-23Add a required argument to DEFINE_* methods.Abseil Team
Setting it to true, is functionally equivalent to calling `flags.mark_flag_as_required(flag_name)`, but changes the type of returned flagholder. ``` _A : FlagHolder[Optional[str]] = flags.DEFINE_string( name='a', default=None, help='help') flags.mark_flag_as_required('a') ``` v/s ``` _A : FlagHolder[str] = flags.DEFINE_string( name='a', default=None, help='help', required=True) ``` PiperOrigin-RevId: 348825600 Change-Id: Ia7610af1b5c4649c20aba5cbb620eae1359ad592
2020-12-15Use better annotations for the FlagValues magic methods.Yilei Yang
PiperOrigin-RevId: 347713086 Change-Id: Ib5c2a08b76a78c75b5db4d72e04049d5446e1c55
2020-12-02Fix #159: Remove the unnecessary LICENSE files in non-third-party ↵Yilei Yang
sub-directories. PiperOrigin-RevId: 345268951 Change-Id: I26871ecb3ad35b9a74ca5668dd9b2c74ddb77c15
2020-11-20Fix absl flagvalues pyi to use python-compatible syntaxAbseil Team
PiperOrigin-RevId: 343548107 Change-Id: I0dbd95804ce720b9ff3cd82bb821bd9e5f26b83c
2020-11-19Fix absl flagvalues pyi to use python-compatible syntaxPeter Hawkins
PiperOrigin-RevId: 343411193 Change-Id: I7f934a0841a37bb561d5237ac32ed525e05cb696
2020-11-19Fix absl flagvalues pyi to use python-compatible syntaxAbseil Team
PiperOrigin-RevId: 343384654 Change-Id: I6da1be2d0208fdbe7bcdb3bc1e1b06d666e429a2
2020-10-22Surface inappropriate usage of a `FlagHolder` object as a runtime errorMatt McDonald
With the aim of steering users away from potential pitfalls in usage of the `FlagHolder` API, this change introduces implementation overrides for the class `__eq__` and `__bool__` methods which turn any such usage into a `TypeError` at runtime. This is to help avoid situations where a user neglects to use the `FlagHolder.value` property in cases where they intended to, e.g., ``` >>> SOME_FLAG = flags.DEFINE_boolean(...) >>> if SOME_FLAG: do_something() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: bool() not supported for instances of type 'FlagHolder' (did you mean to use 'FlagHolder.value' instead?) ``` PiperOrigin-RevId: 338473759 Change-Id: If3b6505a3bdca03db6d96ec7cc28e7214cb1a5e7
2020-09-30In flagsaver, set multiple flags together before their validators run.Karol M. Langner
This resolves an issue where multi-flag validators rely on specific flag combinations. PiperOrigin-RevId: 334625442 Change-Id: I7e6b625637a70356df57a4d9cbb01c203f14df4c
2020-08-24Amend comments on mark_flag_as_required and mark_flags_as_required so they ↵Near Privman
do not encourage dual use of modules as both directly executable and importable. PiperOrigin-RevId: 328193869 Change-Id: I4fa1d43c6e226b1239bd8bc66900c99cf5ce6abe
2020-08-03Make `DEFINE_enum_class` values case-insensitive by default.Abseil Team
This is to bridge the gap between lower case being idiomatic for command line values, and upper case for values defined in an `Enum`. It also makes it more consistent with `DEFINE_enum` usage, which usually uses lower case values. Case sensitivity can be restored by passing `case_sensitive=True`. When `case_sensitive=False` (the default), the associated flag serializers will lowercase enum member names. This seemed reasonable since help text that SCREAMS at you is inconsistent with the fact that member names will be provided most often in lowercase format. Internally, EnumParser is re-used for simplicity. PiperOrigin-RevId: 324594299 Change-Id: I2e15448ad00a095212756c5277b08219a9e84d55
2020-06-23Remove unused private method.Yilei Yang
PiperOrigin-RevId: 317893235 Change-Id: I7b9ccd1fc92a1313efcba0528018bd47327e0585
2020-06-09The generic parameter of FlagHolder now represents the type of value().Abseil Team
(a) For a flag with default None, define_* will return a FlagHolder[Optional[T]] (b) For a flag with default != None, define_* will return a FlagHolder[T] When we are unable to express "default != None", we always return FlagHolder[Optional[T]] This assumes that the type of default() and value() will be the same. This assumption holds, till we want the type system to understand that a "required" flag with a None default cannot return a None value. Changes: - When exact types for default is known, add @overloads for the DEFINE_* methods for the None case and remaining cases. - When exact types for default is now known, change return type to FlagHolder[Optional[T]] -- which has same semantics of what FlagHolder[T] used to have. PiperOrigin-RevId: 315519341 Change-Id: I88dc63b3c5271e12f3274b7246eb602b91b84caf
2020-05-28Add type annotations for absl flags (Take 2)Abseil Team
PiperOrigin-RevId: 313600007 Change-Id: I7a095f2f2dd334e8be777c558a1075cc181d7b69