Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
my2to3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Emmy Vouriot
my2to3
Commits
86a52e15
Commit
86a52e15
authored
Jul 08, 2020
by
Bryton Lacquement
🚪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trace: don't use a tempfile in apply_fixers anymore
parent
ed920af2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
29 deletions
+14
-29
my2to3/fixes/__init__.py
my2to3/fixes/__init__.py
+0
-12
my2to3/fixes/fix_division_support.py
my2to3/fixes/fix_division_support.py
+1
-1
my2to3/fixes/fix_division_trace.py
my2to3/fixes/fix_division_trace.py
+1
-1
my2to3/fixes/fix_nested_except_trace.py
my2to3/fixes/fix_nested_except_trace.py
+1
-1
my2to3/trace.py
my2to3/trace.py
+11
-14
No files found.
my2to3/fixes/__init__.py
View file @
86a52e15
import
lib2to3.fixer_base
import
os
class
BaseFix
(
lib2to3
.
fixer_base
.
BaseFix
):
def
start_tree
(
self
,
tree
,
filename
):
# See my2to3.trace.apply_fixers
sep
=
'-'
*
5
# Arbitrary
if
sep
in
filename
:
filename
=
filename
.
split
(
sep
,
1
)[
1
].
replace
(
sep
,
os
.
sep
)
super
(
BaseFix
,
self
).
start_tree
(
tree
,
filename
)
my2to3/fixes/fix_division_support.py
View file @
86a52e15
import
__builtin__
from
collections
import
defaultdict
from
lib2to3.fixer_base
import
BaseFix
import
lib2to3.pgen2
from
lib2to3.pygram
import
python_symbols
as
syms
from
lib2to3.pytree
import
Leaf
,
Node
...
...
@@ -7,7 +8,6 @@ import os
import
re
from
my2to3.util
import
add_future
from
my2to3.fixes
import
BaseFix
trace_file_match
=
re
.
compile
(
r"^(.*)\
|(.*)
\|(.*) <type '(.*)'> / <type '(.*)'>$"
).
match
...
...
my2to3/fixes/fix_division_trace.py
View file @
86a52e15
# https://lab.nexedi.com/nexedi/erp5/snippets/475
from
collections
import
defaultdict
import
inspect
from
lib2to3.fixer_base
import
BaseFix
import
lib2to3.fixer_util
import
lib2to3.pgen2
from
lib2to3.pygram
import
python_symbols
as
syms
from
lib2to3.pytree
import
Node
from
my2to3.fixes
import
BaseFix
from
my2to3.trace
import
create_table
,
register_tracing_function
from
my2to3.util
import
parse_type
...
...
my2to3/fixes/fix_nested_except_trace.py
View file @
86a52e15
from
lib2to3.fixer_base
import
BaseFix
from
lib2to3.pygram
import
python_symbols
as
syms
from
my2to3.fixes
import
BaseFix
from
my2to3.trace
import
create_table
...
...
my2to3/trace.py
View file @
86a52e15
import
__builtin__
,
imp
,
os
,
sqlite3
,
sys
,
t
empfile
,
t
ypes
import
__builtin__
,
imp
,
os
,
sqlite3
,
sys
,
types
from
lib2to3.pgen2
import
tokenize
from
lib2to3.refactor
import
get_fixers_from_package
,
RefactoringTool
database
=
"traces.db"
...
...
@@ -44,20 +45,16 @@ def get_fixers():
def
apply_fixers
(
string
,
name
):
# This function is inspired by refactoring_tool.refactor_file
refactoring_tool
=
RefactoringTool
(
fixer_names
=
get_fixers
())
# A temporary file is used to enjoy the benefits of
# refactoring_tool.refactor_file (unlike directly using
# refactoring_tool.refactor_string).
#
# XXX: We add the original name via the suffix. Fixers are able to handle this
# (see my2to3.fixes.BaseFix). Let's find a better way.
sep
=
'-'
*
5
# Arbitrary
with
tempfile
.
NamedTemporaryFile
(
suffix
=
sep
+
name
.
replace
(
os
.
sep
,
sep
))
as
f
:
f
.
write
(
string
)
f
.
flush
()
refactoring_tool
.
refactor_file
(
f
.
name
,
write
=
True
)
f
.
seek
(
0
)
return
f
.
read
()
encoding
=
tokenize
.
detect_encoding
(
lambda
:
string
)[
0
]
string
+=
"
\
n
"
# Silence certain parse errors
s
=
string
.
decode
(
encoding
)
s
=
refactoring_tool
.
refactor_string
(
s
,
name
)
# The [:-1] is to take off the \n we added earlier
return
unicode
(
s
)[:
-
1
].
encode
(
encoding
)
init_py
=
'__init__'
+
os
.
extsep
+
'py'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment