aboutsummaryrefslogtreecommitdiff
path: root/absl
AgeCommit message (Collapse)Author
2021-06-14Preparing the release of absl-py 0.13.0.Yilei Yang
PiperOrigin-RevId: 379349640 Change-Id: Id2e4cf0c1aff39194978b54a5f836feda1bb99bb
2021-06-08Update docstring.Yilei Yang
PiperOrigin-RevId: 378281281 Change-Id: Id11546b04a8f21ea65b3a22bbd79e348b7217f5e
2021-05-03Add a classmethod variant of enter_context.Abseil Team
PiperOrigin-RevId: 371692599 Change-Id: I6c86e34e798749459b1f38fc86a94c5d3ce8c814
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-04-12Add `@absltest.skipThisClass` to skip specific classes during testing.Stephen Thorne
This decorator marks a test in a way that it will be skipped, but none of its subclasses are. Suggested usage is for where you want to share functionality between tests, by having an 'abstract' base class: ``` @absltest.skipThisClass class _BaseTestCase(absltest.TestCase): def test_foo(self): self.assertEqual(self.object_under_test.method() class FooTest(_BaseTestCase): def setUp(self): self.object_under_test = Foo() class BarTest(_BaseTestCase): def setUp(self): self.object_under_test = Bar() ``` There are alternatives, but they have drawbacks: * Having `_BaseTestCase` subclass object, and `FooTest` multiple-inherit from both `absltest.TestCase` and `_BaseTestCase`. However, this ends up being problematic for type checking. * Repeating the same logic in `absltest.skipThisClass` within `setUpClass` for every class to skip. However, that is repetitive logic that is best put into a utility function. While `skipThisClass` is similar to `@unittest.skip`, it has an important distinction: regular `skip` will skip the decorated class and all subclasses; `skipThisClass` only skips the decorated class, allowing base classes to be correctly skipped while sub-classes are run as tests. PiperOrigin-RevId: 367965048 Change-Id: Ie050c43c7f2e5dbc5af731171259c27084d1ba12
2021-03-31Add .pyi type annotations to absl/app.py.Abseil Team
Also document that `flags_parser` in `app.run` should be passed as keyword-only. This will become mandatory in a future release. PiperOrigin-RevId: 366074388 Change-Id: I15dfe0c8bcaaa227a2a06141ef01c46cceb2c3b7
2021-03-30Add `Flag.default_unparsed` to annotations.Yilei Yang
PiperOrigin-RevId: 365814855 Change-Id: Idd59a6052f36b1e6b54f998094e58866242f54ea
2021-03-17Annotate in type comments that `absl.logging.fatal` does not return.Yilei Yang
`absl.logging.fatal` causes program to abort, unless in rare cases that absl's root logger is overridden. PiperOrigin-RevId: 363431400 Change-Id: Iaab774451502abe696c66d4396685106151e839a
2021-03-08Preparing the release of absl-py 0.12.0.Yilei Yang
PiperOrigin-RevId: 361632901 Change-Id: Ic102ad3537096dd25fac85c09854f02f4c2712d1
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-03-01Move type comment for `enter_context` to before docstringAbseil Team
Otherwise, typed_ast will consider it misplaced and fail to parse the module PiperOrigin-RevId: 360204546 Change-Id: Ic15ac1173f101c2eb06b078d471d820b16f3bf2b
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-19Add missing parameter to @parameterized.product() example.Abseil Team
PiperOrigin-RevId: 358404122 Change-Id: Ieede31a31a87dbadddf383ab26db43b71c9f0093
2021-02-12Fix CsvListSerializer to honor its list_sep parameter.Abseil Team
PiperOrigin-RevId: 357245847 Change-Id: I7637199f61f23e78646720ad406f539c89962fe3
2021-02-09More general parameterized.product, supporting products of dicts as well as ↵Abseil Team
products of single parameters. PiperOrigin-RevId: 356556227 Change-Id: Ie476d2e971e75e6f5cce88d359e9512228003af7
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 a typo: the flag name is `test_tmpdir` not `test_tempdir`.Yilei Yang
PiperOrigin-RevId: 354595127 Change-Id: I6273e602bcb17be26ce1cf948710c6f3688f98e2
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-23Document the new `required=` parameter in changelog.Yilei Yang
PiperOrigin-RevId: 348838294 Change-Id: I9eace41fa653b3b9c7d104084cfe2e3c114bb22d
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-14Support using flagholder in flagsaver.Abseil Team
`(HOLDER, value)` pairs can now be specified in positional arguments. It is equivalent to specifying `**{HOLDER.name: value}` We can mix and match holder and non-holder overrides. So usages like `flagsaver((HOLDER1, value1), (HOLDER2, value2), flag_name=value)` are legal as well. PiperOrigin-RevId: 347450631 Change-Id: I45bdf7bd56ad1d65d62ff34536ef09e47fce7ae8
2020-12-04Adds `parameterized.product`: generates the Cartesian product of tests from ↵Abseil Team
multiple parameters. This makes it easier to take a test grid of parameters and generate tests for each combination. While the usual `parameters` function _can_ do this, it usually can't be fit into the decorator expression, and the extra logic to produce the product obscures the intention. Example usage: ``` class TestModuloExample(parameterized.TestCase): @parameterized.product( num=[0, 10, 20], modulo=[2, 4], expected=[0] ) def testModuloResult(self, num, modulo, expected): self.assertEqual(expected, num % modulo) ``` PiperOrigin-RevId: 345657677 Change-Id: I7a3dfc868dba291a48c9d3b0e9b77921a3db494f
2020-12-02Fix #159: Remove the unnecessary LICENSE files in non-third-party ↵Yilei Yang
sub-directories. PiperOrigin-RevId: 345268951 Change-Id: I26871ecb3ad35b9a74ca5668dd9b2c74ddb77c15
2020-12-02Fix #158: Remove the executable bits in these filesYilei Yang
PiperOrigin-RevId: 345253573 Change-Id: Icaf22a5e11465398985187dcf1c6d9283c17faa6
2020-11-24Catch unittest.case.SkipTest when running tests for debugging.Gregory P. Smith
This prevents dropping into the debugger on skipped tests. PiperOrigin-RevId: 344119505 Change-Id: I775d8acdfe593c29315d0a1468bf000fb9958546
2020-11-23Catch unittest.case.SkipTest when running tests for debugging.Abseil Team
This prevents dropping into the debugger on skipped tests. PiperOrigin-RevId: 343998913 Change-Id: I2bf16cafabf420d4b3060ad7bc349af1e4d8cca3
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-27Preparing the release of absl-py 0.11.0.Yilei Yang
PiperOrigin-RevId: 339298457 Change-Id: I5d99150a42492bd60077225e5c4eabc7ead70818
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-09-25Explicitly document that `app.run(main)` essentially does ↵Devin Jeanpierre
`sys.exit(main(...))`. This makes the behavior of `return "some string"` documented and supported. I wasn't sure how much of the original wording to keep, but opted to change it as it seems misleading -- on my system, for example, `return 0` and `return 256` do the same thing (eeek). PiperOrigin-RevId: 333770740 Change-Id: Ifcac0a03793b1b3cf8818443ce8c4f86afe51a4b
2020-09-22Change to raise an exception when no logging directory is found, instead of ↵Yilei Yang
calling logging.fatal PiperOrigin-RevId: 333114647 Change-Id: I68ddc9dbc9ebc2a8942d61e79e4a2097666826d5
2020-09-18Suppress surplus entries in AssertionError stack traces from absltest.py.Abseil Team
Use the base _exc_info_to_string everywhere a test attribute is available so that the stack trace obeys __unittest = True filtering protocol. PiperOrigin-RevId: 332527642 Change-Id: Ia6bd671e820c3f3a5ff6ff1fbeecf6855d4eccd3
2020-09-14Update absltest_test.py so it works better on Windows running under msys2, ↵Yilei Yang
the PATH environment variable needs to be inherited so it can find out /usr/bin. PiperOrigin-RevId: 331635980 Change-Id: I97393bde898eefa55ba083c54da0f15c5de2c098
2020-08-31*Really* ignore errors in `_rmtree_ignore_errors`.Devin Jeanpierre
I encountered this in a Windows-specific `OSError` because I made the file to be deleted unwritable, and I guess in Unix you can delete unwritable files, but not Windows. Unfortunately, Windows isn't really a supported platform AIUI, so-- the test will go un-exercised unless I can reproduce on unixy OSes somehow. It turns out that on Unix, too, a file can be made un-deletable, but it's far more obscure -- the directory needs to be missing the write bit. (And to hit the right branch, where absltest thinks it's a file, it must still have the execute bit.) Of course, the file *should* be deletable, and this is a bug in my test, which should ideally clean up after itself properly. But it says "ignore_errors" right there! NOTE: this was not actually tested on windows, although the same circumstance should be replicated. YMMV. (I'm kind of wondering right now if the test itself is cross-platform, or if that `os.chmod(dirname, IEXEC)` will throw.) PiperOrigin-RevId: 329339802 Change-Id: Ib1ec36d754c34a5a10520b8b105269e3c4681fd6
2020-08-26Add a py3-compatible tag to py2py3_test_binary() generated targets.Gregory P. Smith
PiperOrigin-RevId: 328551738 Change-Id: I52ef76addf79199992c746e39ab5f3be7efdd4c5
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-19Preparing the release of absl-py 0.10.0.Yilei Yang
PiperOrigin-RevId: 327465554 Change-Id: I352f1db0ce220aed63b102af033c78e7eac7f06f
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-07-31Internal changeAbseil Team
PiperOrigin-RevId: 324312895 Change-Id: I772ebb7b1c7c6adc1ebb742daa051de2a0fdba66
2020-07-21Doc/suggest fspath usage over .full_path usageRichard Levasseur
Someone noticed that TempDir implements PathLike, but the docs don't clearly state its supported or suggest its usage. Since the feature replaces using `.full_path` for most cases, add some docs so people are better aware of it. PiperOrigin-RevId: 322398162 Change-Id: Iaee1be057cc0f2cec17cd9821f47bb4a5385cec0