Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
596342c2
"tests/git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "8c249d1401f12d55a59a7bdb2329b29921ae864e"
Unverified
Commit
596342c2
authored
Sep 22, 2020
by
Sylvain Gugger
Committed by
GitHub
Sep 22, 2020
Browse files
Support for Windows in check_copies (#7316)
parent
89edf504
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
+5
-5
utils/check_copies.py
utils/check_copies.py
+5
-5
No files found.
utils/check_copies.py
View file @
596342c2
...
@@ -40,7 +40,7 @@ def find_code_in_transformers(object_name):
...
@@ -40,7 +40,7 @@ def find_code_in_transformers(object_name):
f
"`object_name` should begin with the name of a module of transformers but got
{
object_name
}
."
f
"`object_name` should begin with the name of a module of transformers but got
{
object_name
}
."
)
)
with
open
(
os
.
path
.
join
(
TRANSFORMERS_PATH
,
f
"
{
module
}
.py"
),
"r"
)
as
f
:
with
open
(
os
.
path
.
join
(
TRANSFORMERS_PATH
,
f
"
{
module
}
.py"
),
"r"
,
encoding
=
"utf-8"
)
as
f
:
lines
=
f
.
readlines
()
lines
=
f
.
readlines
()
# Now let's find the class / func in the code!
# Now let's find the class / func in the code!
...
@@ -80,10 +80,10 @@ def blackify(code):
...
@@ -80,10 +80,10 @@ def blackify(code):
code
=
f
"class Bla:
\n
{
code
}
"
code
=
f
"class Bla:
\n
{
code
}
"
with
tempfile
.
TemporaryDirectory
()
as
d
:
with
tempfile
.
TemporaryDirectory
()
as
d
:
fname
=
os
.
path
.
join
(
d
,
"tmp.py"
)
fname
=
os
.
path
.
join
(
d
,
"tmp.py"
)
with
open
(
fname
,
"w"
)
as
f
:
with
open
(
fname
,
"w"
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
code
)
f
.
write
(
code
)
os
.
system
(
f
"black -q --line-length 119 --target-version py35
{
fname
}
"
)
os
.
system
(
f
"black -q --line-length 119 --target-version py35
{
fname
}
"
)
with
open
(
fname
,
"r"
)
as
f
:
with
open
(
fname
,
"r"
,
encoding
=
"utf-8"
)
as
f
:
result
=
f
.
read
()
result
=
f
.
read
()
return
result
[
len
(
"class Bla:
\n
"
)
:]
if
has_indent
else
result
return
result
[
len
(
"class Bla:
\n
"
)
:]
if
has_indent
else
result
...
@@ -94,7 +94,7 @@ def is_copy_consistent(filename, overwrite=False):
...
@@ -94,7 +94,7 @@ def is_copy_consistent(filename, overwrite=False):
Return the differences or overwrites the content depending on `overwrite`.
Return the differences or overwrites the content depending on `overwrite`.
"""
"""
with
open
(
filename
)
as
f
:
with
open
(
filename
,
"r"
,
encoding
=
"utf-8"
)
as
f
:
lines
=
f
.
readlines
()
lines
=
f
.
readlines
()
found_diff
=
False
found_diff
=
False
line_index
=
0
line_index
=
0
...
@@ -152,7 +152,7 @@ def is_copy_consistent(filename, overwrite=False):
...
@@ -152,7 +152,7 @@ def is_copy_consistent(filename, overwrite=False):
if
overwrite
and
found_diff
:
if
overwrite
and
found_diff
:
# Warn the user a file has been modified.
# Warn the user a file has been modified.
print
(
f
"Detected changes, rewriting
{
filename
}
."
)
print
(
f
"Detected changes, rewriting
{
filename
}
."
)
with
open
(
filename
,
"w"
)
as
f
:
with
open
(
filename
,
"w"
,
encoding
=
"utf-8"
)
as
f
:
f
.
writelines
(
lines
)
f
.
writelines
(
lines
)
return
not
found_diff
return
not
found_diff
...
...
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