This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2016年07月04日 20:09 by terry.reedy, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| config-clean.diff | terry.reedy, 2016年07月04日 20:09 | review | ||
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 14577 | merged | cheryl.sabella, 2019年07月03日 22:45 | |
| PR 14802 | merged | miss-islington, 2019年07月16日 20:58 | |
| PR 14803 | merged | miss-islington, 2019年07月16日 21:01 | |
| Messages (13) | |||
|---|---|---|---|
| msg269809 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2016年07月04日 20:09 | |
The config module code can be improved even without changing behavior. While working on #27380, I noticed these two: IdleUserConfParser.RemoveFile is a simple one-liner called once. Put it inline. IdleConf.CreateConfigHandlers: A) As near as I can tell, __file__ is now always the absolute path of the file regardless if executed directly or imported. B) Creating two dicts of file names that are immediately used and deleted is useless and to me makes the code less readable. I intend these changes only for 3.6 and will not apply until after the new unix keys patch. Serhiy, have you noticed any similar cleanups that would be appropriate to add? |
|||
| msg269852 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2016年07月05日 20:55 | |
If config.py is just executed, __file__ can be a relative path. RemoveFile() looks as a part of public API. If you are sure that nobody needs to remove a config file, you can remove this method. |
|||
| msg269855 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2016年07月05日 22:07 | |
How can you get a relative path in 3.6 (or other current Python)? To test, I wrote file.py containing "print(__file__)". Executing from IDLE, with "python path/to/file.py", "path/to/file.py", "file.py" in the path/to directory, and "python -m to.file" (where path is on sys.path) all resulted in the absolute path. After adding "input()" to suspend execution, double clicking in Explorer gives the same result. Have I forgotten something? Do any of these result is something different on Linux? (or Mac?, for that matter) The only reason to execute rather than import config.py is to run the test at the end of the file after editing the file. In the absence of a thorough automated test, I occasionally do so. The approximately 500 lines of output is too much to read in detail (although one might check one specific part), but that it runs and produces the same number of lines before and after a change is reassuring. I should add a line counter and checksum to the dump function. As for removing RemoveFile: idlelib in 3.6 is, with a few exceptions, a private API. |
|||
| msg269856 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2016年07月05日 22:24 | |
$ ./python -m file /home/serhiy/py/cpython/file.py $ ./python file.py file.py |
|||
| msg269859 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2016年07月06日 00:12 | |
New changeset da83e115afea by Terry Jan Reedy in branch '2.7': Issue #27452: add line counter and crc to IDLE configHandler test dump. https://hg.python.org/cpython/rev/da83e115afea New changeset 127569004538 by Terry Jan Reedy in branch '3.5': Issue #27452: add line counter and crc to IDLE configHandler test dump. https://hg.python.org/cpython/rev/127569004538 New changeset c2e21bc83066 by Terry Jan Reedy in branch 'default': Issue #27452: add line counter and crc to IDLE config test dump. https://hg.python.org/cpython/rev/c2e21bc83066 |
|||
| msg269864 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2016年07月06日 01:52 | |
New changeset adbeef96ae95 by Terry Jan Reedy in branch 'default': Issue #27452: make command line idle-test> python test_help.py work. https://hg.python.org/cpython/rev/adbeef96ae95 |
|||
| msg269865 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2016年07月06日 01:55 | |
Ah, the invocation I did not test ;-). It does not matter in this case because "os.path.dirname('config.py')" is '' and the join leaves relative names for the config files that work fine for opening them.
F:\Python\dev36円\Lib\idlelib>..\..\pcbuild\win32\python_d.exe config.py
{'keys': <__main__.IdleConfParser object at 0x000002633B200080>,
...
At one time, I thought, sys.path[0] was '', representing the current directory, and not the absolute path of the starting directory. I am not sure if there are any cross platform, cross implementation, guarantees.
There are 12 other idlelib files using __file__. I ran each in either idlelib or idle_test as appropriate. 11 run. test_help.py fails at this line (which I wrote)
helpfile = join(abspath(dirname(dirname(__file__))), 'help.html')
as the double dirname does not have the expected effect. A version of the conditional from config, with dirname(sys.path[0]), would work. However, taking the abspath first is easier.
helpfile = join(dirname(dirname(abspath(__file__))), 'help.html')
The comment in config appears to refer to the exec command/function. I don't know what either does with __name__, __file__, or sys.path.
---
With the two IdleConf dict keys sorted, the first patch results in consistent output. configparser.ConfigParser uses OrderedDicts by default, so re-running on unchanged files results in unchanged iteration order.
|
|||
| msg269870 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2016年07月06日 07:59 | |
In this case it works, because os.join('', filename) returns filename.
|
|||
| msg348040 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2019年07月16日 20:58 | |
New changeset f8d4cc7dbbf54b9c5435c3080582a4aa421a067d by Terry Jan Reedy (Cheryl Sabella) in branch 'master': bpo-27452: IDLE: Cleanup config.py code (GH-14577) https://github.com/python/cpython/commit/f8d4cc7dbbf54b9c5435c3080582a4aa421a067d |
|||
| msg348041 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2019年07月16日 21:03 | |
As near as I can tell, 'python file.py' results in absolute __file__ in 3.9 versus still relative in 3.8. |
|||
| msg348043 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2019年07月16日 21:19 | |
New changeset 178f09f8b7d25348d46751a774666dd4ec32f3e6 by Terry Jan Reedy (Miss Islington (bot)) in branch '3.8': bpo-27452: IDLE: Cleanup config.py code (GH-14577) (GH-14802) https://github.com/python/cpython/commit/178f09f8b7d25348d46751a774666dd4ec32f3e6 |
|||
| msg348044 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2019年07月16日 21:31 | |
New changeset efd23a199b1415a9850a914d525a1e5711fdd6d8 by Terry Jan Reedy (Miss Islington (bot)) in branch '3.7': bpo-27452: IDLE: Cleanup config.py code (GH-14577) (GH-14803) https://github.com/python/cpython/commit/efd23a199b1415a9850a914d525a1e5711fdd6d8 |
|||
| msg348045 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2019年07月16日 21:32 | |
Thanks for preparing the PR. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:33 | admin | set | github: 71639 |
| 2019年07月16日 21:32:41 | terry.reedy | set | status: open -> closed versions: + Python 3.7 messages: + msg348045 resolution: fixed stage: patch review -> resolved |
| 2019年07月16日 21:31:50 | terry.reedy | set | messages: + msg348044 |
| 2019年07月16日 21:19:16 | terry.reedy | set | messages: + msg348043 |
| 2019年07月16日 21:03:58 | terry.reedy | set | messages: + msg348041 |
| 2019年07月16日 21:01:07 | miss-islington | set | pull_requests: + pull_request14599 |
| 2019年07月16日 20:58:57 | miss-islington | set | pull_requests: + pull_request14598 |
| 2019年07月16日 20:58:31 | terry.reedy | set | messages: + msg348040 |
| 2019年07月03日 22:49:14 | cheryl.sabella | set | versions: + Python 3.8, Python 3.9, - Python 3.6 |
| 2019年07月03日 22:45:38 | cheryl.sabella | set | stage: test needed -> patch review pull_requests: + pull_request14396 |
| 2017年06月19日 18:44:33 | terry.reedy | set | components: + IDLE |
| 2016年07月06日 07:59:07 | serhiy.storchaka | set | messages: + msg269870 |
| 2016年07月06日 01:55:37 | terry.reedy | set | messages: + msg269865 |
| 2016年07月06日 01:52:17 | python-dev | set | messages: + msg269864 |
| 2016年07月06日 00:12:03 | python-dev | set | nosy:
+ python-dev messages: + msg269859 |
| 2016年07月05日 22:24:08 | serhiy.storchaka | set | messages: + msg269856 |
| 2016年07月05日 22:07:47 | terry.reedy | set | messages: + msg269855 |
| 2016年07月05日 20:55:28 | serhiy.storchaka | set | messages: + msg269852 |
| 2016年07月04日 20:09:51 | terry.reedy | create | |