Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
7822e123
Kaydet (Commit)
7822e123
authored
Haz 15, 2013
tarafından
Brett Cannon
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #17177: stop using imp for compileall.
üst
0b16b0d3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
32 deletions
+29
-32
compileall.py
Lib/compileall.py
+6
-5
test_compileall.py
Lib/test/test_compileall.py
+23
-27
No files found.
Lib/compileall.py
Dosyayı görüntüle @
7822e123
...
...
@@ -13,7 +13,7 @@ See module py_compile for details of the actual byte-compilation.
import
os
import
sys
import
errno
import
imp
import
imp
ortlib.util
import
py_compile
import
struct
...
...
@@ -91,17 +91,18 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=False,
cfile
=
fullname
+
(
'c'
if
__debug__
else
'o'
)
else
:
if
optimize
>=
0
:
cfile
=
imp
.
cache_from_source
(
fullname
,
debug_override
=
not
optimize
)
cfile
=
imp
ortlib
.
util
.
cache_from_source
(
fullname
,
debug_override
=
not
optimize
)
else
:
cfile
=
imp
.
cache_from_source
(
fullname
)
cfile
=
imp
ortlib
.
util
.
cache_from_source
(
fullname
)
cache_dir
=
os
.
path
.
dirname
(
cfile
)
head
,
tail
=
name
[:
-
3
],
name
[
-
3
:]
if
tail
==
'.py'
:
if
not
force
:
try
:
mtime
=
int
(
os
.
stat
(
fullname
)
.
st_mtime
)
expect
=
struct
.
pack
(
'<4sl'
,
imp
.
get_magic
(),
mtime
)
expect
=
struct
.
pack
(
'<4sl'
,
importlib
.
util
.
MAGIC_NUMBER
,
mtime
)
with
open
(
cfile
,
'rb'
)
as
chandle
:
actual
=
chandle
.
read
(
8
)
if
expect
==
actual
:
...
...
Lib/test/test_compileall.py
Dosyayı görüntüle @
7822e123
import
sys
import
compileall
import
imp
import
imp
ortlib.util
import
os
import
py_compile
import
shutil
import
struct
import
subprocess
import
sys
import
tempfile
import
time
import
unittest
...
...
@@ -18,11 +19,11 @@ class CompileallTests(unittest.TestCase):
def
setUp
(
self
):
self
.
directory
=
tempfile
.
mkdtemp
()
self
.
source_path
=
os
.
path
.
join
(
self
.
directory
,
'_test.py'
)
self
.
bc_path
=
imp
.
cache_from_source
(
self
.
source_path
)
self
.
bc_path
=
imp
ortlib
.
util
.
cache_from_source
(
self
.
source_path
)
with
open
(
self
.
source_path
,
'w'
)
as
file
:
file
.
write
(
'x = 123
\n
'
)
self
.
source_path2
=
os
.
path
.
join
(
self
.
directory
,
'_test2.py'
)
self
.
bc_path2
=
imp
.
cache_from_source
(
self
.
source_path2
)
self
.
bc_path2
=
imp
ortlib
.
util
.
cache_from_source
(
self
.
source_path2
)
shutil
.
copyfile
(
self
.
source_path
,
self
.
source_path2
)
self
.
subdirectory
=
os
.
path
.
join
(
self
.
directory
,
'_subdir'
)
os
.
mkdir
(
self
.
subdirectory
)
...
...
@@ -36,7 +37,7 @@ class CompileallTests(unittest.TestCase):
with
open
(
self
.
bc_path
,
'rb'
)
as
file
:
data
=
file
.
read
(
8
)
mtime
=
int
(
os
.
stat
(
self
.
source_path
)
.
st_mtime
)
compare
=
struct
.
pack
(
'<4sl'
,
imp
.
get_magic
()
,
mtime
)
compare
=
struct
.
pack
(
'<4sl'
,
imp
ortlib
.
util
.
MAGIC_NUMBER
,
mtime
)
return
data
,
compare
def
recreation_check
(
self
,
metadata
):
...
...
@@ -57,7 +58,8 @@ class CompileallTests(unittest.TestCase):
def
test_mtime
(
self
):
# Test a change in mtime leads to a new .pyc.
self
.
recreation_check
(
struct
.
pack
(
'<4sl'
,
imp
.
get_magic
(),
1
))
self
.
recreation_check
(
struct
.
pack
(
'<4sl'
,
importlib
.
util
.
MAGIC_NUMBER
,
1
))
def
test_magic_number
(
self
):
# Test a change in mtime leads to a new .pyc.
...
...
@@ -97,14 +99,14 @@ class CompileallTests(unittest.TestCase):
# interpreter's creates the correct file names
optimize
=
1
if
__debug__
else
0
compileall
.
compile_dir
(
self
.
directory
,
quiet
=
True
,
optimize
=
optimize
)
cached
=
imp
.
cache_from_source
(
self
.
source_path
,
debug_override
=
not
optimize
)
cached
=
imp
ortlib
.
util
.
cache_from_source
(
self
.
source_path
,
debug_override
=
not
optimize
)
self
.
assertTrue
(
os
.
path
.
isfile
(
cached
))
cached2
=
imp
.
cache_from_source
(
self
.
source_path2
,
debug_override
=
not
optimize
)
cached2
=
imp
ortlib
.
util
.
cache_from_source
(
self
.
source_path2
,
debug_override
=
not
optimize
)
self
.
assertTrue
(
os
.
path
.
isfile
(
cached2
))
cached3
=
imp
.
cache_from_source
(
self
.
source_path3
,
debug_override
=
not
optimize
)
cached3
=
imp
ortlib
.
util
.
cache_from_source
(
self
.
source_path3
,
debug_override
=
not
optimize
)
self
.
assertTrue
(
os
.
path
.
isfile
(
cached3
))
...
...
@@ -152,10 +154,12 @@ class CommandLineTests(unittest.TestCase):
return
rc
,
out
,
err
def
assertCompiled
(
self
,
fn
):
self
.
assertTrue
(
os
.
path
.
exists
(
imp
.
cache_from_source
(
fn
)))
path
=
importlib
.
util
.
cache_from_source
(
fn
)
self
.
assertTrue
(
os
.
path
.
exists
(
path
))
def
assertNotCompiled
(
self
,
fn
):
self
.
assertFalse
(
os
.
path
.
exists
(
imp
.
cache_from_source
(
fn
)))
path
=
importlib
.
util
.
cache_from_source
(
fn
)
self
.
assertFalse
(
os
.
path
.
exists
(
path
))
def
setUp
(
self
):
self
.
addCleanup
(
self
.
_cleanup
)
...
...
@@ -190,8 +194,8 @@ class CommandLineTests(unittest.TestCase):
[
'-m'
,
'compileall'
,
'-q'
,
self
.
pkgdir
]))
# Verify the __pycache__ directory contents.
self
.
assertTrue
(
os
.
path
.
exists
(
self
.
pkgdir_cachedir
))
expected
=
sorted
(
base
.
format
(
imp
.
get_tag
(),
ext
)
for
base
in
(
'__init__.{}.{}'
,
'bar.{}.{}'
))
expected
=
sorted
(
base
.
format
(
sys
.
implementation
.
cache_tag
,
ext
)
for
base
in
(
'__init__.{}.{}'
,
'bar.{}.{}'
))
self
.
assertEqual
(
sorted
(
os
.
listdir
(
self
.
pkgdir_cachedir
)),
expected
)
# Make sure there are no .pyc files in the source directory.
self
.
assertFalse
([
fn
for
fn
in
os
.
listdir
(
self
.
pkgdir
)
...
...
@@ -224,7 +228,7 @@ class CommandLineTests(unittest.TestCase):
def
test_force
(
self
):
self
.
assertRunOK
(
'-q'
,
self
.
pkgdir
)
pycpath
=
imp
.
cache_from_source
(
self
.
barfn
)
pycpath
=
imp
ortlib
.
util
.
cache_from_source
(
self
.
barfn
)
# set atime/mtime backward to avoid file timestamp resolution issues
os
.
utime
(
pycpath
,
(
time
.
time
()
-
60
,)
*
2
)
mtime
=
os
.
stat
(
pycpath
)
.
st_mtime
...
...
@@ -288,7 +292,7 @@ class CommandLineTests(unittest.TestCase):
bazfn
=
script_helper
.
make_script
(
self
.
pkgdir
,
'baz'
,
'raise Exception'
)
self
.
assertRunOK
(
'-q'
,
'-d'
,
'dinsdale'
,
self
.
pkgdir
)
fn
=
script_helper
.
make_script
(
self
.
pkgdir
,
'bing'
,
'import baz'
)
pyc
=
imp
.
cache_from_source
(
bazfn
)
pyc
=
imp
ortlib
.
util
.
cache_from_source
(
bazfn
)
os
.
rename
(
pyc
,
os
.
path
.
join
(
self
.
pkgdir
,
'baz.pyc'
))
os
.
remove
(
bazfn
)
rc
,
out
,
err
=
script_helper
.
assert_python_failure
(
fn
)
...
...
@@ -299,7 +303,7 @@ class CommandLineTests(unittest.TestCase):
'-i'
,
os
.
path
.
join
(
self
.
directory
,
'nosuchfile'
),
self
.
pkgdir
)
self
.
assertRegex
(
out
,
b
'rror.*nosuchfile'
)
self
.
assertNotRegex
(
err
,
b
'Traceback'
)
self
.
assertFalse
(
os
.
path
.
exists
(
imp
.
cache_from_source
(
self
.
assertFalse
(
os
.
path
.
exists
(
imp
ortlib
.
util
.
cache_from_source
(
self
.
pkgdir_cachedir
)))
def
test_include_file_with_arg
(
self
):
...
...
@@ -356,13 +360,5 @@ class CommandLineTests(unittest.TestCase):
self
.
assertRegex
(
out
,
b
"Can't list 'badfilename'"
)
def
test_main
():
support
.
run_unittest
(
CommandLineTests
,
CompileallTests
,
EncodingTest
,
)
if
__name__
==
"__main__"
:
test_
main
()
unittest
.
main
()
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