I have several fields that need to be formatted `n...
# plugins
p
I have several fields that need to be formatted
name <email@domain>
. Validating email seems like a pretty common thing, but a quick search for email in the pants codebase didn’t turn up anything. Are there any helpful utils I should use? Or is regex the way to go?
1
b
Are they being passed along to another tool? Is consuming them as a string in pants, and surfacing the tool's validation sufficient?
p
This is for the nfpm backend which generates system packages (like rpm, deb). It is a string in pants, and a string in nfpm. I expect any errors to show up at package install time, so I thought of adding the validation to catch that before it goes through the chain of tools.
c
I'm guessing it would be a email field on a target? if so, regular field validation seems legit for the email field, using regex or something..
1
b
Ah, okay. I think Pants adding additional validation beyond the underlying tool can be a bit annoying in some cases, e.g. being strict about PEX's pip version blocked using newer pips, if a user updated to a newer PEX than the one built-in to Pants. https://github.com/pantsbuild/pants/pull/19643 . Without knowing much about nfpm, I guess something similar could come up if it grew a backend that expected an
@github_username
reference instead of an email (or something). So, I'd personally lean towards putting the validation in nfpm (if it's not already) and ensuring pants exposes that to users nicely. This isn't exactly an answer to your original question... but it at least might explain why there doesn't appear to be a helper for it already
p
Some very good points @broad-processor-92400, thank you. I'll leave linting those strings up to something else then--though nFPM would probably not be the right place. Maybe there are tools to lint deb or rpm files. Hmm.