https://pantsbuild.org/ logo
#development
Title
# development
f

fresh-cat-90827

01/07/2023, 5:05 AM
@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

bitter-ability-32190

01/07/2023, 8:00 AM
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

fresh-cat-90827

01/07/2023, 8:04 AM
Right. How is it possible that you pass a string when it's expecting a dict? :/
b

bitter-ability-32190

01/07/2023, 8:20 AM
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

curved-television-6568

01/07/2023, 2:11 PM
The
"@…
is significant here…
b

bitter-ability-32190

01/07/2023, 2:13 PM
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

fresh-cat-90827

01/07/2023, 3:08 PM
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

curved-television-6568

01/07/2023, 3:14 PM
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

fresh-cat-90827

01/07/2023, 3:18 PM
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

bitter-ability-32190

01/07/2023, 3:18 PM
This case is special. I believe it's just dict options with fromfile that also allows strings 🤔
c

curved-television-6568

01/07/2023, 3:22 PM
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

curved-television-6568

01/07/2023, 3:26 PM
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

bitter-ability-32190

01/07/2023, 3:27 PM
Oh although lists and dicta also allow the +/- prefix
But that might be illegal in toml
f

fresh-cat-90827

01/07/2023, 3:29 PM
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

bitter-ability-32190

01/07/2023, 3:51 PM
So using .add isn't a toml violation, we just need the schema to be smarter
f

fresh-cat-90827

01/07/2023, 3:52 PM
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