The native `setup_pantsd_logger` requires that ext...
# development
a
The native
setup_pantsd_logger
requires that externs have been init’d before it can be called; this is done by initialising the memoized
native.context
in Python… Is there a good way to encode this dependency in code?
Right now I’ve added a
_context = self.context
to native.py’s
setup_pantsd_logger
but that feels much less good than actually passing a value somewhere…
a
what should
setup_pantsd_logger()
do if the externs haven’t yet been initialized?
a
It panics
(Because it has no way of returning an error to the python if it doesn’t have externs)
a
a contextmanager is what i’m thinking of, possibly at the site where
setup_pantsd_logger()
is called
a
What would the contextmanager do?
Actually, looking at it, I suspect just the
Native
constructor should do the initialising that the
context
property currently does…
👍 1
a
provide access to the Native instance and ensure the context is accessed before yielding it, so whatever calls setup_pantsd_logger() will be sure that the context is setup
there’s more initialization that needs to be moved around in that file too, your suspicion is probably right
w
moving the initialization out to the module level might work too... ie, rather than making Native a singleton via the class-level stuff, could make it a singleton as a static field in the module
@average-vr-56795: ^
a
Ooh, sounds good 🙂 Thanks
w
in theory that could still fail to initialize, but it would be preeetty hard.
(since we do relatively little import-time anything)
a
Yeah
w
the only other obvious import-time thing is ExceptionSink
a
(or
@rule
parsing, but we try to keep that pretty slim)
w
mm
... speaking of which. i wonder if we're triggering that during a RemotePantsRunner run.
a
we should be able to avoid it if we are doing that right now
w
there is a lazy import that is supposed to avoid it. but anyway.
later 😃
a
then that probably works