I have the following code (pants 2.11 rc0) to migr...
# plugins
p
I have the following code (pants 2.11 rc0) to migrate to the new options system
and I see this error:
Copy code
File "/Users/asher/.cache/pants/setup/bootstrap-Darwin-x86_64/2.11.0rc0_py38/lib/python3.8/site-packages/pants/init/extension_loader.py", line 130, in load_backend
    module = importlib.import_module(backend_module)
  File "/Users/asher/.pyenv/versions/3.8.12/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/asher/projects/toolchain/src/python/toolchain/pants/register.py", line 10, in <module>
    from toolchain.pants.auth.rules import get_auth_rules
  File "/Users/asher/projects/toolchain/src/python/toolchain/pants/auth/rules.py", line 36, in <module>
    from toolchain.pants.common.toolchain_setup import ToolchainSetup
  File "/Users/asher/projects/toolchain/src/python/toolchain/pants/common/toolchain_setup.py", line 26, in <module>
    class ToolchainSetup(Subsystem):
  File "/Users/asher/projects/toolchain/src/python/toolchain/pants/common/toolchain_setup.py", line 37, in ToolchainSetup
    org = StrOption(
TypeError: __new__() missing 1 required positional argument: 'flag_name'

Use -ldebug for more logs.
See <https://www.pantsbuild.org/v2.11/docs/troubleshooting> for common issues.
Consider reaching out for help: <https://www.pantsbuild.org/v2.11/docs/getting-help>
grepped the pants code base for the usage of
flag_name
and didn't find any...
what am I missing ? @bitter-ability-32190
b
You're missing the positional argument(s)
E.g.
"--repo"
or
"--org"
basically treat
StrOption
constructor as if you were calling
register
b
See the other usages of `StrOption`and related option types
f
StrOption("--some-opt", ...)
b
Yup!
p
oh... I assumed those will be inferred from the attribute name...
b
(my internet is acting up, my messages might be coming at weird times)
p
(like django ORM, for example)
b
The Django ORM works in a slightly different way. It uses metaclasses to collect the attributes of the class. Pants doesn't. It could in the future, but this solution tries to keep the magic to a minimum. Really the change just de-duplicates the class property and the register call. And does so in a way that introduces concrete option types. Everything else from the existing option registration system has just been carried along.
p
Django is an example... many frameworks use this pattern and it is I think it is more pythonic... just my 2c... I'll update my code.
f
There is a few places in Pants where the option is assigned to an attribute with an underscore prefix, and then a
@property
function is used to do some derived calculation for use in rest of Pants.
coke 2
How does Django handle (or not handle) that use case?
b
It's certainly a possible future direction, but we'd need to figure out how to handle the following examples:
Copy code
# Conflicts with builtin keyword
frm = StrOption("--from", ...)
# Don't make the property public, use different property instead
_myopt = StrOption("--foo", ...)
FWIW I really do want to do this. It's just not trivial and given the amount of changes that went into this new system, I've tried to minimize friction as much as possible.
👍 1
For Django, I believe the attribute name just provides the default for
db_column
parameter: https://docs.djangoproject.com/en/4.0/ref/models/fields/#db-column We 100% could do something similar (the attribute name seeds the flag name if not explicitly provided)