<@U02KAN6061E> there's a new subsystem `preamble` ...
# development
f
@bitter-ability-32190 there's a new subsystem
preamble
which isn't yet used it seems. 🧵
In the
Copy code
[preamble]
template_by_globs = "@build-support/preambles/config.yaml"
in the
pants.toml
, I think this was supposed to be
[preamble].config
?
I am not sure if that's WIP, but there's no
config
property declared for the subsystem in contrast to other subsystems such as
[mypy]
or
[pytest]
, so JSON schema is incomplete 🙂
image.png
b
It's certainly used. We're using it to stamp and to check for copyright headers. (Try it, remove one and run lint or fmt)
f
Right. How is it possible that you pass a string when it's expecting a dict? :/
b
Also, don't forget that an invalid config will make pants error (unless told otherwise) so we can be pretty sure it's valid 😉
c
The
"@…
is significant here…
b
Yeah sorry, I was replying while rocking my son 😅
So dict option allows loading from a file, and we know because the value is a string that starts with
@
f
ah I am doing such a terrible job explaining what is it that concerns me! 😄 I am familiar with the
@
notation; that's what's used in the https://www.pantsbuild.org/docs/reference-regex-lint as well. It's the type of the option as seen by the Pants
help-all
goal:
Copy code
{
          "choices": null,
          "comma_separated_choices": null,
          "comma_separated_display_args": "--preamble-template-by-globs=\"{'key1': val1, 'key2': val2, ...}\"",
          "config_key": "template_by_globs",
          "default": {},
          "deprecated_message": null,
          "deprecation_active": false,
          "display_args": [
            "--preamble-template-by-globs=\"{'key1': val1, 'key2': val2, ...}\""
          ],
          "env_var": "PANTS_PREAMBLE_TEMPLATE_BY_GLOBS",
          "help": "Which preamble template to use based on the path globs (relative to the build root).\n\nExample:\n\n    {\n        '*.rs': '// Copyright (c) $year\n// Line 2 '\n        '*.py:!__init__.py': '# Copyright (c) $year\n# Line 2 ',\n    }\n\nIt might be helpful to load this config from a JSON or YAML file. To do that, set `[preamble].config = '@path/to/config.yaml'`, for example.",
          "removal_hint": null,
          "removal_version": null,
          "scoped_cmd_line_args": [
            "--preamble-template-by-globs"
          ],
          "target_field_name": null,
          "typ": "dict",
          "unscoped_cmd_line_args": [
            "--template-by-globs"
          ],
As far as JSON schema concerned, the property is supposed to be an object (the Python
dict
). But clearly it can also be a string (with the
@
) that will load the data from a file turning it into a
dict
at runtime
c
Ah… yes, seems the
fromfile
property of this option is not reflected here, as not all options support it we can’t even assume that is an option for all.. er, options 😉
1
f
right, but is there anything in the source code that can tell us (so that we could mark an option somehow in the
all-help
output) that an option could be of multiple types (a dict and a string in this case)? 😕
b
This case is special. I believe it's just dict options with fromfile that also allows strings 🤔
c
there’s a way to include the support for fromfile syntax in the all-help info output…
there’s a way to include the support for fromfile syntax in the all-help info output…
perfect, let me fire up a ticket...
c
Copy code
--preamble-template-by-globs="{'key1': val1, 'key2': val2, ...}"
  PANTS_PREAMBLE_TEMPLATE_BY_GLOBS
  template_by_globs
      default: {}
      current value: {
          "**/*.py:!**/__init__.py:**/BUILD:**/BUILD.*": "# Copyright $year Pants project contributors (see CONTRIBUTORS.md).\n# Licensed under the Apache License, Version 2.0 (see LICENSE).\n",
          "**/*.rs": "// Copyright $year Pants project contributors (see CONTRIBUTORS.md).\n// Licensed under the Apache License, Version 2.0 (see LICENSE).\n"
      } (from pants.toml)
-- FROMFILE: True
      Which preamble template to use based on the path globs (relative to the build root).

      Example:
Copy code
diff --git a/src/python/pants/help/help_formatter.py b/src/python/pants/help/help_formatter.py
index 699a7bb2d..70a38f80b 100644
--- a/src/python/pants/help/help_formatter.py
+++ b/src/python/pants/help/help_formatter.py
@@ -148,6 +148,7 @@ class HelpFormatter(MaybeColor):
             *default_lines,
             *curr_value_lines,
             *value_derivation_lines,
+            f"-- FROMFILE: {ohi.fromfile}",
             *deprecated_lines,
             *description_lines,
         ]
diff --git a/src/python/pants/help/help_info_extracter.py b/src/python/pants/help/help_info_extracter.py
index e5a235a41..da386d90c 100644
--- a/src/python/pants/help/help_info_extracter.py
+++ b/src/python/pants/help/help_info_extracter.py
@@ -115,7 +115,7 @@ class OptionHelpInfo:
     choices: tuple[str, ...] | None
     comma_separated_choices: str | None
     value_history: OptionValueHistory | None
-
+    fromfile: bool

 @dataclass(frozen=True)
 class OptionScopeHelpInfo:
@@ -974,6 +974,8 @@ class HelpInfoExtracter:
         target_field_name = f"{self._scope_prefix}_{option_field_name_for(args)}".replace("-", "_")
         environment_aware = kwargs.get("environment_aware") is True

+        fromfile = kwargs.get("fromfile", False)
+
         ret = OptionHelpInfo(
             display_args=tuple(display_args),
             comma_separated_display_args=", ".join(display_args),
@@ -992,5 +994,6 @@ class HelpInfoExtracter:
             choices=choices,
             comma_separated_choices=None if choices is None else ", ".join(choices),
             value_history=None,
+            fromfile=fromfile,
         )
         return ret
b
Oh although lists and dicta also allow the +/- prefix
But that might be illegal in toml
f
yes, indeed! • The special Pants only
.add
syntax as in:
Copy code
extra_requirements.add = [
  "mypy-typing-asserts",
  "strawberry-graphql>=0.95.1,<0.96",
]
is considered a violation:
{"add":["mypy-typing-asserts","strawberry-graphql>=0.95.1,<0.96"]} is not of type "array"
I think we'll have to live with it as we override the TOML semantics with the
.add
- legal thing, just a different interpretation lol
b
So using .add isn't a toml violation, we just need the schema to be smarter
f
sorry, I meant schema violation, not TOML specs 🙂
@curved-television-6568 thank you so much for the patch, it worked great. https://github.com/pantsbuild/pants/pull/17944
👍 1