I'm creating a `cookiecutter` (a templating tool -...
# general
b
I'm creating a
cookiecutter
(a templating tool - https://cookiecutter.readthedocs.io/en/1.7.2/) project that creates a Pants project, and is itself a Pants project. Everything works great, but I want to have Pants ignore any
BUILD
files within the body of the template itself (because those
BUILD
files may themselves be templates, and thus not valid files for Pants to process as-is). I can do this with the following stanza in my top-level
pants.toml
file:
Copy code
build_ignore = [
    # Don't want the BUILD files in the template to get treated as
    # though they applied to this project.
    "\\{\\{ cookiecutter.__repo_name \\}\\}"
]
(Yes, that directory name --
{{ cookiecutter.__repo_name }}
-- is a Jinja templating directive; that's just how
cookiecutter
works.) That complicated escaping is the best thing I've been able to come across that is accepted and lets me actually run Pants. However, when I run Pants with this configuration, I get a slew of repeated messages like this:
Copy code
12:50:50.87 [WARN] <string>:1: DeprecationWarning: invalid escape sequence \{
The
pants.toml
is the only place in the project that has this character sequence. I'm not exactly sure what escape sequence would work here (again, nothing else I've thought of seems to be accepted). The
DeprecationWarning
also makes me concerned that the next release of Pants will no longer work with this repository. Anybody else seen anything like this or have any suggestions? Thanks 🙇
h
Have you looked into the usage of raw strings instead of escaping things? I think toml has its own way of supporting that that I hope Pants would honor.
b
Hrmm, interesting idea... let me check
h
https://github.com/toml-lang/toml/issues/80: Here's some similar discussion on that
b
Triple quotes don't seem to work, unfortunately. I do get a new error message, however:
Copy code
Exception: Could not parse glob exclude pattern `"{{ cookiecutter.__repo_name }}"`: Glob { glob: Some("{{ cookiecutter.__repo_name }}"), err: "nested alternate groups are not allowed" }
🤔 I think
'\\{\\{ cookiecutter.__repo_name \\}\\}'
works (i.e., change from double to single quotes, but keep all the escaping)
👍 1
The fun that is escape sequences... thanks for the pointer @high-yak-85899
h
No problem. I'm going to run into this, too, as part of our migration so glad to see something working!
c
There’s some support for referencing config from other files for inclusion.. example from Pants own `pants.toml`:
Copy code
[regex-lint]
config = "@build-support/regexes/config.yaml"
Perrhaps that would be a workable alternative.. ?
💡 1
b
Ooooh, that's interesting; didn't know about that!
@curved-television-6568 Also, what is
regex-lint
? I don't think I've encountered that; is it new?
c
It’s a perhaps little known
validate
goal, that’s moving into the
lint
goal. https://www.pantsbuild.org/docs/reference-validate
b
gotcha; thanks!
👍 1
h
We have some similar cookiecutter-like templates internally at Toolchain, but we sidestepped the issue by having all the template files end in
.template
and the thing that stamps out the cookies strips that suffix
b
sneaky