While working to move our python build system to p...
# general
l
While working to move our python build system to pants I have encountered an error I can't make sense of - Deep down a dependency tree, my code is erroring on
os.uname()
Copy code
def _syscmd_uname(option, default=''):
    
        """ Interface to the system's uname command.
        """
        if sys.platform in ('dos', 'win32', 'win16'):
            # XXX Others too ?
            return default
        try:
            f = os.popen('uname %s 2> %s' % (option, DEV_NULL))
        except (AttributeError, OSError):
            return default
>       output = f.read().strip()
E       ValueError: I/O operation on closed file.

/Users/ryan.king/.asdf/installs/python/3.6.15/lib/python3.6/platform.py:791: ValueError
This code works fine outside pants and I don't know what about it would fail in the pants env.
w
if this is in the context of a test, you probably want: https://www.pantsbuild.org/docs/reference-test#section-extra-env-vars
but to debug it, you can probably try subprocessing
uname
directly in your test, and rendering its output to see what it is missing
l
I am not sure how setting env variables will help? I till try calling os.uname directly to see if there are any clues
w
yea, just a guess at this point. tests run by default with no environment variables at all set (not even
HOME
or
USER
), and some tools can become … confused by that.
…although this succeeds on macOS at least:
Copy code
$ env -i uname
Darwin
…oh, derp. it’s probably that it can’t find
uname
at all without
PATH
so you could allow
PATH
through with https://www.pantsbuild.org/docs/reference-test#section-extra-env-vars, or change the test
l
ah ok
interestingly , os.uname() works when I call it directly in my test 🤷
I think I am going to have to pick this up on monday
e
That makes sense though since
os.uname
, presumably, does not shell out. The code you reference shells out and needs to 1st find a shell, then find uname, the binary.
w
yea, this was the problematic bit most likely:
Copy code
f = os.popen('uname %s 2> %s' % (option, DEV_NULL))
have a good weekend!
l
Ugh I figured it out. Pants is doing the right thing. This test was only working pre-pants because it was entangled with a different test and its side effects.
🎉 1
🙌 3