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
2e33ecd7
Kaydet (Commit)
2e33ecd7
authored
May 28, 2019
tarafından
Joannah Nanjekye
Kaydeden (comit)
Berker Peksag
May 28, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-22640: Add silent mode to py_compile.compile() (GH-12976)
üst
3c8724fc
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
9 deletions
+44
-9
py_compile.rst
Doc/library/py_compile.rst
+10
-0
3.8.rst
Doc/whatsnew/3.8.rst
+7
-0
py_compile.py
Lib/py_compile.py
+15
-9
test_py_compile.py
Lib/test/test_py_compile.py
+9
-0
2019-04-26-22-13-26.bpo-22640.p3rheW.rst
...S.d/next/Library/2019-04-26-22-13-26.bpo-22640.p3rheW.rst
+3
-0
No files found.
Doc/library/py_compile.rst
Dosyayı görüntüle @
2e33ecd7
...
...
@@ -42,6 +42,13 @@ byte-code cache files in the directory containing the source code.
is raised. This function returns the path to byte-compiled file, i.e.
whatever *cfile* value was used.
The *doraise* and *quiet* arguments determine how errors are handled while
compiling file. If *quiet* is 0 or 1, and *doraise* is false, the default
behaviour is enabled: an error string is written to ``sys.stderr``, and the
function returns ``None`` instead of a path. If *doraise* is true,
a :exc:`PyCompileError` is raised instead. However if *quiet* is 2,
no message is written, and *doraise* has no effect.
If the path that *cfile* becomes (either explicitly specified or computed)
is a symlink or non-regular file, :exc:`FileExistsError` will be raised.
This is to act as a warning that import will turn those paths into regular
...
...
@@ -82,6 +89,9 @@ byte-code cache files in the directory containing the source code.
overrides the value of the *invalidation_mode* argument, and determines
its default value instead.
.. versionchanged:: 3.8
The *quiet* parameter was added.
.. class:: PycInvalidationMode
...
...
Doc/whatsnew/3.8.rst
Dosyayı görüntüle @
2e33ecd7
...
...
@@ -537,6 +537,13 @@ NSKeyedArchiver-encoded binary plists.
(Contributed by Jon Janzen in :issue:`26707`.)
py_compile
----------
:func:`py_compile.compile` now supports silent mode.
(Contributed by Joannah Nanjekye in :issue:`22640`.)
socket
------
...
...
Lib/py_compile.py
Dosyayı görüntüle @
2e33ecd7
...
...
@@ -77,7 +77,7 @@ def _get_default_invalidation_mode():
def
compile
(
file
,
cfile
=
None
,
dfile
=
None
,
doraise
=
False
,
optimize
=-
1
,
invalidation_mode
=
None
):
invalidation_mode
=
None
,
quiet
=
0
):
"""Byte-compile one Python source file to Python bytecode.
:param file: The source file name.
...
...
@@ -95,6 +95,8 @@ def compile(file, cfile=None, dfile=None, doraise=False, optimize=-1,
are -1, 0, 1 and 2. A value of -1 means to use the optimization
level of the current interpreter, as given by -O command line options.
:param invalidation_mode:
:param quiet: Return full output with False or 0, errors only with 1,
and no output with 2.
:return: Path to the resulting byte compiled file.
...
...
@@ -143,11 +145,12 @@ def compile(file, cfile=None, dfile=None, doraise=False, optimize=-1,
_optimize
=
optimize
)
except
Exception
as
err
:
py_exc
=
PyCompileError
(
err
.
__class__
,
err
,
dfile
or
file
)
if
doraise
:
raise
py_exc
else
:
sys
.
stderr
.
write
(
py_exc
.
msg
+
'
\n
'
)
return
if
quiet
<
2
:
if
doraise
:
raise
py_exc
else
:
sys
.
stderr
.
write
(
py_exc
.
msg
+
'
\n
'
)
return
try
:
dirname
=
os
.
path
.
dirname
(
cfile
)
if
dirname
:
...
...
@@ -194,10 +197,12 @@ def main(args=None):
compile
(
filename
,
doraise
=
True
)
except
PyCompileError
as
error
:
rv
=
1
sys
.
stderr
.
write
(
"
%
s
\n
"
%
error
.
msg
)
if
quiet
<
2
:
sys
.
stderr
.
write
(
"
%
s
\n
"
%
error
.
msg
)
except
OSError
as
error
:
rv
=
1
sys
.
stderr
.
write
(
"
%
s
\n
"
%
error
)
if
quiet
<
2
:
sys
.
stderr
.
write
(
"
%
s
\n
"
%
error
)
else
:
for
filename
in
args
:
try
:
...
...
@@ -205,7 +210,8 @@ def main(args=None):
except
PyCompileError
as
error
:
# return value to indicate at least one failure
rv
=
1
sys
.
stderr
.
write
(
"
%
s
\n
"
%
error
.
msg
)
if
quiet
<
2
:
sys
.
stderr
.
write
(
"
%
s
\n
"
%
error
.
msg
)
return
rv
if
__name__
==
"__main__"
:
...
...
Lib/test/test_py_compile.py
Dosyayı görüntüle @
2e33ecd7
...
...
@@ -192,6 +192,15 @@ class PyCompileTestsBase:
fp
.
read
(),
'test'
,
{})
self
.
assertEqual
(
flags
,
0
b1
)
def
test_quiet
(
self
):
bad_coding
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'bad_coding2.py'
)
with
support
.
captured_stderr
()
as
stderr
:
self
.
assertIsNone
(
py_compile
.
compile
(
bad_coding
,
doraise
=
False
,
quiet
=
2
))
self
.
assertIsNone
(
py_compile
.
compile
(
bad_coding
,
doraise
=
True
,
quiet
=
2
))
self
.
assertEqual
(
stderr
.
getvalue
(),
''
)
with
self
.
assertRaises
(
py_compile
.
PyCompileError
):
py_compile
.
compile
(
bad_coding
,
doraise
=
True
,
quiet
=
1
)
class
PyCompileTestsWithSourceEpoch
(
PyCompileTestsBase
,
unittest
.
TestCase
,
...
...
Misc/NEWS.d/next/Library/2019-04-26-22-13-26.bpo-22640.p3rheW.rst
0 → 100644
Dosyayı görüntüle @
2e33ecd7
:func:`py_compile.compile` now supports silent mode.
Patch by Joannah Nanjekye
\ No newline at end of file
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