[issue20035] Suppress 'os.environ was modified' warning on Tcl/Tk tests
Zachary Ware added the comment: Here's a slightly less ugly version of the patch. I would really appreciate some review on this; this should solve a test_idle issue that was exacerbated by issue #15968 (for unknown reasons). -- priority: low - normal Added file: http://bugs.python.org/file34564/issue20035.v2.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20035 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20035] Suppress 'os.environ was modified' warning on Tcl/Tk tests
Changes by Zachary Ware zachary.w...@gmail.com: Removed file: http://bugs.python.org/file33233/suppress_environ_warning.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20035 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20035] Suppress 'os.environ was modified' warning on Tcl/Tk tests
Changes by Zachary Ware zachary.w...@gmail.com: Removed file: http://bugs.python.org/file33235/suppress_environ_warning.v2.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20035 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20035] Suppress 'os.environ was modified' warning on Tcl/Tk tests
Roundup Robot added the comment: New changeset c12cc78d59c1 by Zachary Ware in branch 'default': Issue #15968: Temporarily revert change to PCbuild/rt.bat http://hg.python.org/cpython/rev/c12cc78d59c1 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20035 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20035] Suppress 'os.environ was modified' warning on Tcl/Tk tests
Zachary Ware added the comment: Here's a patch that seems to work; with it applied, I can run `PCbuild\python_d.exe -m test -uall -rF test_tcl test_tk test_ttk_textonly test_ttk_guionly test_idle` through at least 115 rounds of testing with no warnings or errors aside from a locale warning from test_idle the first time around. Hacking up my rc1 install with a fresh _tkinter.pyd and patched tkinter/__init__.py, the tests all pass, but I still get the 'can't invoke event command: application has been destroyed' message from test_ttk_guionly. Terry, would you mind checking how this impacts all of the Tkinter test interaction issues you're seeing? Since this is the first non-superficial semantic C patch I've submitted, I have no doubt that it can use a lot of work :). There are a few comments in places where I'm not really sure how best to do things that I'd really appreciate input on. It seems to work for common cases, though. -- Added file: http://bugs.python.org/file34286/issue20035.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20035 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20035] Suppress 'os.environ was modified' warning on Tcl/Tk tests
Zachary Ware added the comment: Terry J. Reedy added the comment: However, rather than require a tearDowmnodule for every module that imports tkinter, lets fix the root problem. I agree that that would be the ideal solution. I thought of having the environment change warning function ignore changes to TCL/TK/TIX_LIBRARY, but even better would be to not change them. Rename _fix to _dirs and redefine its mission as setting and holding three module attributes: tcldir, tkdir, and tixdir. They would be set from either the environment or the alternate search code. Any other modules that need the info should get it from _dirs rather the environment. Unfortunately, environment variables are the easiest way to tell Tcl/Tk where to find init.tcl/tk.tcl. Digging around in tclBasic.c and tkWindow.c, it looks like it should be possible to provide our own values for where to find the libraries, but it doesn't look especially easy. It looks like it has to be done somewhere between Tcl_CreateInterp() and Tcl_Init(), which means it has to be done in _tkinter.c. I believe this part of _fix is buggy. +if TCL_LIBRARY not in os.environ: +for name in os.listdir(prefix): +if name.startswith(tcl): +tcldir = os.path.join(prefix,name) +if os.path.isdir(tcldir): +os.environ[TCL_LIBRARY] = tcldir Both base/tcl and base/../tcktk/lib contain (for 3.4) directories named tcl8 and tcl8.6. Since only tcl8.6 works, the code above depends on listdir presenting it second. The 'if name' clause could be augmented with 'and name[-2] == '.'. Actually, setting TCL_LIBRARY to either one (full path to tcl8 or tcl8.6) or, in fact, the same path without any version qualifier at all, works (tested by manually setting the variables before calling tkinter.Tk()). It looks like Tcl checks for a folder with the right version number on its own. Also, from testing with installed 2.7, 3.3, and 3.4rc1, it looks like we only really need to set TCL_LIBRARY anyway: setting TK_LIBRARY and TIX_LIBRARY to '.', properly setting TCL_LIBRARY, and then calling tkinter.Tk(), the expected toplevel window pops up and root.tk.eval('package require Tix') returns the expected version number from Tix. I'm convinced that my initial patches in this issue are the wrong way to attack the problem. I'll look into changing _tkinter.c to do the job of tkinter._fix without changing environment variables, hopefully we can just do away with _fix entirely. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20035 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20035] Suppress 'os.environ was modified' warning on Tcl/Tk tests
Terry J. Reedy added the comment: The patch works to suppress the message for test_ttk_guionly. However, unfix_environ does not undo everything that needs to be undone, as evidenced by #20800. The patch does not fix test_idle. I suspect that this is because test_idle pulls in tests from numerous modules, none of which has the unfix call. However, rather than require a tearDowmnodule for every module that imports tkinter, lets fix the root problem. I thought of having the environment change warning function ignore changes to TCL/TK/TIX_LIBRARY, but even better would be to not change them. Rename _fix to _dirs and redefine its mission as setting and holding three module attributes: tcldir, tkdir, and tixdir. They would be set from either the environment or the alternate search code. Any other modules that need the info should get it from _dirs rather the environment. I believe this part of _fix is buggy. +if TCL_LIBRARY not in os.environ: +for name in os.listdir(prefix): +if name.startswith(tcl): +tcldir = os.path.join(prefix,name) +if os.path.isdir(tcldir): +os.environ[TCL_LIBRARY] = tcldir Both base/tcl and base/../tcktk/lib contain (for 3.4) directories named tcl8 and tcl8.6. Since only tcl8.6 works, the code above depends on listdir presenting it second. The 'if name' clause could be augmented with 'and name[-2] == '.'. -- nosy: +terry.reedy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20035 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20035] Suppress 'os.environ was modified' warning on Tcl/Tk tests
New submission from Zachary Ware: The attached patch refactors tkinter._fix's main logic into a function called 'fix_environ' which is called unconditionally on import, and adds a function 'unfix_environ' to undo the effects of fix_environ. fix/unfix_environ are then used in all test files that import tkinter (test___all__, test_tcl, test_tk, test_ttk_guionly, test_ttk_textonly, test_idle) to ensure that the environment is properly set to allow Tcl to load and to suppress regrtest's warning that os.environ has been modified. Since tkinter._fix is an implementation detail, I assume this change isn't against the 'no new features' policy of all currently open branches, but if this needs to wait until 3.5, that's ok with me. -- components: Tests, Tkinter files: suppress_environ_warning.diff keywords: patch messages: 206692 nosy: zach.ware priority: low severity: normal stage: patch review status: open title: Suppress 'os.environ was modified' warning on Tcl/Tk tests type: behavior versions: Python 3.4 Added file: http://bugs.python.org/file33233/suppress_environ_warning.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20035 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20035] Suppress 'os.environ was modified' warning on Tcl/Tk tests
Serhiy Storchaka added the comment: This looks fragile. What if some test will import tkinter after other test unfix the environment? I suggest unload the tkinter._fix module in unfix_environ(). Then next import should implicitly fix the environment. And explicit fix_environ() will be not needed. -- nosy: +serhiy.storchaka ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20035 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20035] Suppress 'os.environ was modified' warning on Tcl/Tk tests
Changes by R. David Murray rdmur...@bitdance.com: -- nosy: +r.david.murray ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20035 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20035] Suppress 'os.environ was modified' warning on Tcl/Tk tests
Zachary Ware added the comment: I like that idea, though I'm a bit wary of messing around is sys.modules. Is there another way to unload a module that I'm not aware of? Here's a new patch that does that. -- Added file: http://bugs.python.org/file33235/suppress_environ_warning.v2.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20035 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com