From 489807e06bf40f46facf0ce23802a68f2cff8147 Mon Sep 17 00:00:00 2001 From: David Lai Date: Fri, 5 Mar 2021 00:03:49 +0800 Subject: [PATCH] update ephemeral-packages wiki --- wiki/pages/Ephemeral-Packages.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/wiki/pages/Ephemeral-Packages.md b/wiki/pages/Ephemeral-Packages.md index 15c3b0a66..d794fd57d 100644 --- a/wiki/pages/Ephemeral-Packages.md +++ b/wiki/pages/Ephemeral-Packages.md @@ -80,7 +80,7 @@ to the [resolve](Package-Commands#resolve) object. You would typically use the # in package.py def commands() - if intersects(ephemerals.get('enable_tracking', '0'), '1'): + if intersects(ephemerals.get_range('enable_tracking', '0'), '1'): env.TRACKING_ENABLED = 1 In this example, the given package would set the `TRACKING_ENABLED` environment @@ -88,6 +88,11 @@ variable if an ephemeral such as `.enable_tracking-1` (or `.enable_tracking-1.2+ etc) is present in the resolve. Note that the leading `.` is implied and not included when querying the `ephemerals` object. +> [[media/icons/warning.png]] Since `ephemerals` is a dict-like object, so it has +> a `get` function which will return a full request string if key exists. Hence, +> the default value should also be a full request string, not just a version range +> string like `'0'` in `get_range`. Or `intersects` may not work as expect. + ## Ephemeral Use Cases Why would you want to request packages that don't exist? There are two main use @@ -101,7 +106,7 @@ to packages in a resolve. For example, consider the following package definition name = 'bah' def commands(): - if intersects(ephemerals.get('bah.cli', '1'), '1'): + if intersects(ephemerals.get_range('bah.cli', '1'), '1'): env.PATH.append('{root}/bin') This package will disable its command line tools if an ephemeral like `.bah.cli-0` @@ -120,7 +125,7 @@ we introduce a `.cli` ephemeral that acts as a global whitelist: name = 'bah' def commands(): - if intersects(ephemerals.get('cli', ''), 'bah'): + if intersects(ephemerals.get_range('cli', ''), 'bah'): env.PATH.append('{root}/bin') Here, all packages' cli will be enabled if `.cli` is not specified, but if it is