classification
Title: 2to3 call for file in current directory yields error
Type: behavior Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, denis-osipov, jabdo, lukasz.langa, r.david.murray
Priority: normal Keywords: patch

Created on 2017-09-26 04:58 by denis-osipov, last changed 2018-11-04 18:06 by denis-osipov. This issue is now closed.

Files
File name Uploaded Description Edit
2to3bugpython.png jabdo, 2017-10-03 18:20
Pull Requests
URL Status Linked Edit
PR 3758 merged denis-osipov, 2017-09-26 05:01
PR 6528 merged miss-islington, 2018-04-18 23:51
PR 6529 merged miss-islington, 2018-04-18 23:52
Messages (9)
msg303001 - (view) Author: Denis Osipov (denis-osipov) * Date: 2017-09-26 04:58
2to3 doesn't work if called for file in current directory with --add-suffix option.
	
$ /d/repos/cpython/python.bat /d/repos/cpython/Tools/scripts/2to3 -n -W --add-suffix=3 test2to3.py
Running Debug|x64 interpreter...
WARNING: --write-unchanged-files/-W implies -w.
RefactoringTool: Skipping optional fixer: buffer
RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: set_literal
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: Refactored test2to3.py
--- test2to3.py (original)
+++ test2to3.py (refactored)

--some changes--

Traceback (most recent call last):
  File "D:/repos/cpython/Tools/scripts/2to3", line 5, in <module>
    sys.exit(main("lib2to3.fixes"))
  File "D:\repos\cpython\lib\lib2to3\main.py", line 259, in main
    options.processes)
  File "D:\repos\cpython\lib\lib2to3\refactor.py", line 687, in refactor
    items, write, doctests_only)
  File "D:\repos\cpython\lib\lib2to3\refactor.py", line 282, in refactor
    self.refactor_file(dir_or_file, write, doctests_only)
  File "D:\repos\cpython\lib\lib2to3\refactor.py", line 728, in refactor_file
    *args, **kwargs)
  File "D:\repos\cpython\lib\lib2to3\refactor.py", line 339, in refactor_file
    write=write, encoding=encoding)
  File "D:\repos\cpython\lib\lib2to3\refactor.py", line 505, in processed_file
    self.write_file(new_text, filename, old_text, encoding)
  File "D:\repos\cpython\lib\lib2to3\main.py", line 84, in write_file
    os.makedirs(output_dir)
  File "D:\repos\cpython\\lib\os.py", line 221, in makedirs
    mkdir(name, mode)
FileNotFoundError: [WinError 3] The system cannot find the path specified: ''


It works well if I use absolute path for target file or set -o:

$ /d/repos/cpython/python.bat /d/repos/cpython/Tools/scripts/2to3 -n -W --add-suffix=3 /d/MyPythonScripts/test2to3.py

$ /d/repos/cpython/python.bat /d/repos/cpython/Tools/scripts/2to3 -n -W --add-suffix=3 -o . test2to3.py
msg303635 - (view) Author: Jonathan Abdo (jabdo) Date: 2017-10-03 18:20
Issue also effects 3.5
msg303636 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-10-03 18:27
3.5 is in security-fix-only mode, and we use versions to indicate which versions we plan to fix the bug in.
msg303637 - (view) Author: Jonathan Abdo (jabdo) Date: 2017-10-03 18:29
Gotcha, sorry about that. Active uses 3.5, so I guess I would take it up
with them?

On Oct 3, 2017 2:27 PM, "R. David Murray" <report@bugs.python.org> wrote:

>
> R. David Murray <rdmurray@bitdance.com> added the comment:
>
> 3.5 is in security-fix-only mode, and we use versions to indicate which
> versions we plan to fix the bug in.
>
> ----------
> nosy: +r.david.murray
> versions:  -Python 3.5
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue31583>
> _______________________________________
>
msg303639 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-10-03 18:55
Yes, redistributors sometimes backport non-security fixes if they consider them important enough.

Note that I haven't evaluated the merits of this issue, and there is a related issue about how 2to3 finds its fixers that this may overlap with.
msg303647 - (view) Author: Jonathan Abdo (jabdo) Date: 2017-10-03 20:14
Inserting (with 12 spaces)

            if not output_dir:
                output_dir = "./"

at lines 83 and 84 works as a temporary workaround.  `StdoutRefactoringTool` is not receiving an `output_dir` from `option`, which seems to only be an issue when `--add-sufix` is used.
msg315469 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2018-04-18 23:50
New changeset e3a523a0fa16aec880880928303bfcbd1fb74bc2 by Łukasz Langa (Denis Osipov) in branch 'master':
bpo-31583: Fix 2to3 for using with --add-suffix option (GH-3758)
https://github.com/python/cpython/commit/e3a523a0fa16aec880880928303bfcbd1fb74bc2
msg315470 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2018-04-19 00:15
New changeset 67067d85eb1df8c52399f9fc74dc4c1a32ec86cd by Łukasz Langa (Miss Islington (bot)) in branch '3.7':
bpo-31583: Fix 2to3 for using with --add-suffix option (GH-3758) (#6528)
https://github.com/python/cpython/commit/67067d85eb1df8c52399f9fc74dc4c1a32ec86cd
msg315474 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2018-04-19 05:10
New changeset 1957e7b76a1319995360492223a4dfe1cd5d105c by Łukasz Langa (Miss Islington (bot)) in branch '3.6':
bpo-31583: Fix 2to3 for using with --add-suffix option (GH-3758) (GH-6529)
https://github.com/python/cpython/commit/1957e7b76a1319995360492223a4dfe1cd5d105c
History
Date User Action Args
2018-11-04 18:06:16denis-osipovsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-04-19 05:10:01lukasz.langasetmessages: + msg315474
2018-04-19 00:15:12lukasz.langasetmessages: + msg315470
2018-04-18 23:52:34miss-islingtonsetpull_requests: + pull_request6223
2018-04-18 23:51:35miss-islingtonsetpull_requests: + pull_request6222
2018-04-18 23:50:27lukasz.langasetnosy: + lukasz.langa
messages: + msg315469
2017-10-03 20:14:56jabdosetmessages: + msg303647
2017-10-03 18:55:21r.david.murraysetmessages: + msg303639
2017-10-03 18:29:33jabdosetmessages: + msg303637
2017-10-03 18:27:26r.david.murraysetnosy: + r.david.murray

messages: + msg303636
versions: - Python 3.5
2017-10-03 18:20:43jabdosetfiles: + 2to3bugpython.png
versions: + Python 3.5
nosy: + jabdo

messages: + msg303635
2017-09-29 22:42:41terry.reedysetnosy: + benjamin.peterson
2017-09-26 05:01:14denis-osipovsetkeywords: + patch
stage: patch review
pull_requests: + pull_request3744
2017-09-26 04:58:01denis-osipovcreate