Jason R. Coombs <jar...@jaraco.com> added the comment:

> It's also easy to bypass that by simply seeding the global cache
> for uname(): _uname_cache. 
> Or you could monkey-patch the platform module
> in your utility to work around the circular reference.

I don't think these options are possible in the general case. It was what I 
attempted to do in the first place, but could not. Consider the situation where 
a namespace package is present or where a script uses pkg_resources to 
bootstrap itself (a very common case), or any other case where 
`platform.(anything)` is invoked before the "bypass" or "monkey-patch" has a 
chance to run. This happens when running the test suite for `cmdix` because 
pytest invokes pkg_resources to search for entry points and that code invokes 
`platform.system` (or similar) to evaluate environment markers long before the 
cmdix code has been imported.

Here's what happens:

`platform.(anything)` runs `platform.uname` and `platform.uname` invokes `uname 
-p` in a subprocess _unconditionally_. Python doesn't provide hooks to 
monkey-patch that out before it gets invoked.

> Or you could call your utility something else.

The point of this utility is to supply "coreutils" using Python. It's derived 
from an abandoned project called "pycoreutils", one purpose of which is to 
provide the core utilities on a minimal Linux distribution that doesn't have 
uname. Another is to supply coreutils on Windows. Having an alternate name 
isn't really viable when the purpose is to supply that interface.


I do think your considerations are reasonable, and I'm close to giving up. I 
look forward to your feedback on the 'resolved-late' branch.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue35967>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to