Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
650f1472
Commit
650f1472
authored
Nov 20, 2010
by
R. David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#10453: compileall now uses argparse instead of getopt, so -h works.
Patch by Michele Orrù.
parent
a78f74ce
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
111 additions
and
78 deletions
+111
-78
Lib/compileall.py
Lib/compileall.py
+55
-77
Lib/test/test_compileall.py
Lib/test/test_compileall.py
+53
-1
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/compileall.py
View file @
650f1472
...
@@ -153,90 +153,68 @@ def compile_path(skip_curdir=1, maxlevels=0, force=False, quiet=False,
...
@@ -153,90 +153,68 @@ def compile_path(skip_curdir=1, maxlevels=0, force=False, quiet=False,
legacy
=
legacy
)
legacy
=
legacy
)
return
success
return
success
def
expand_args
(
args
,
flist
):
"""read names in flist and append to args"""
expanded
=
args
[:]
if
flist
:
try
:
if
flist
==
'-'
:
fd
=
sys
.
stdin
else
:
fd
=
open
(
flist
)
while
1
:
line
=
fd
.
readline
()
if
not
line
:
break
expanded
.
append
(
line
[:
-
1
])
except
IOError
:
print
(
"Error reading file list %s"
%
flist
)
raise
return
expanded
def
main
():
def
main
():
"""Script main program."""
"""Script main program."""
import
getopt
import
argparse
try
:
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
'lfqd:x:i:b'
)
parser
=
argparse
.
ArgumentParser
(
except
getopt
.
error
as
msg
:
description
=
'Utilities to support installing Python libraries.'
)
print
(
msg
)
parser
.
add_argument
(
'-l'
,
action
=
'store_const'
,
default
=
10
,
const
=
0
,
print
(
"usage: python compileall.py [-l] [-f] [-q] [-d destdir] "
dest
=
'maxlevels'
,
help
=
"don't recurse down"
)
"[-x regexp] [-i list] [directory|file ...]"
)
parser
.
add_argument
(
'-f'
,
action
=
'store_true'
,
dest
=
'force'
,
print
(
"-l: don't recurse down"
)
help
=
'force rebuild even if timestamps are up to date'
)
print
(
"-f: force rebuild even if timestamps are up-to-date"
)
parser
.
add_argument
(
'-q'
,
action
=
'store_true'
,
dest
=
'quiet'
,
print
(
"-q: quiet operation"
)
help
=
'quiet operation'
)
print
(
"-d destdir: purported directory name for error messages"
)
parser
.
add_argument
(
'-b'
,
action
=
'store_true'
,
dest
=
'legacy'
,
print
(
" if no directory arguments, -l sys.path is assumed"
)
help
=
'procude legacy byte-compiled file paths'
)
print
(
"-x regexp: skip files matching the regular expression regexp"
)
parser
.
add_argument
(
'-d'
,
metavar
=
'DESTDIR'
,
dest
=
'ddir'
,
default
=
None
,
print
(
" the regexp is searched for in the full path of the file"
)
help
=
(
'purported directory name for error messages; '
print
(
"-i list: expand list with its content "
'if no directory arguments, -l sys.path '
"(file and directory names)"
)
'is assumed.'
))
print
(
"-b: Produce legacy byte-compile file paths"
)
parser
.
add_argument
(
'-x'
,
metavar
=
'REGEXP'
,
dest
=
'rx'
,
default
=
None
,
sys
.
exit
(
2
)
help
=
(
'skip files matching the regular expression.
\
n
\
t
'
maxlevels
=
10
'The regexp is searched for in the full path'
ddir
=
None
'of the file'
))
force
=
False
parser
.
add_argument
(
'-i'
,
metavar
=
'FILE'
,
dest
=
'flist'
,
quiet
=
False
help
=
'expand the list with the contenent of FILE.'
)
rx
=
None
parser
.
add_argument
(
'compile_dest'
,
metavar
=
'FILE|DIR'
,
nargs
=
'?'
)
flist
=
None
args
=
parser
.
parse_args
()
legacy
=
False
for
o
,
a
in
opts
:
if
(
args
.
ddir
and
args
.
compile_dest
!=
1
and
if
o
==
'-l'
:
maxlevels
=
0
not
os
.
path
.
isdir
(
args
.
compile_dest
)):
if
o
==
'-d'
:
ddir
=
a
raise
argparse
.
ArgumentError
(
"-d destdir require exactly one "
if
o
==
'-f'
:
force
=
True
"directory argument"
)
if
o
==
'-q'
:
quiet
=
True
if
args
.
rx
:
if
o
==
'-x'
:
import
re
import
re
rx
=
re
.
compile
(
a
)
args
.
rx
=
re
.
compile
(
args
.
rx
)
if
o
==
'-i'
:
flist
=
a
if
o
==
'-b'
:
legacy
=
True
# if flist is provided then load it
if
ddir
:
compile_dests
=
[
args
.
compile_dest
]
if
len
(
args
)
!=
1
and
not
os
.
path
.
isdir
(
args
[
0
]):
if
args
.
flist
:
print
(
"-d destdir require exactly one directory argument"
)
with
open
(
args
.
flist
)
as
f
:
sys
.
exit
(
2
)
files
=
f
.
read
().
split
()
success
=
1
compile_dests
.
extend
(
files
)
try
:
if
args
or
flist
:
try
:
try
:
if
flist
:
if
compile_dests
:
args
=
expand_args
(
args
,
flist
)
for
dest
in
compile_dests
:
except
IOError
:
if
os
.
path
.
isdir
(
dest
):
success
=
0
if
not
compile_dir
(
dest
,
args
.
maxlevels
,
args
.
ddir
,
if
success
:
args
.
force
,
args
.
rx
,
args
.
quiet
,
for
arg
in
args
:
args
.
legacy
):
if
os
.
path
.
isdir
(
arg
):
return
0
if
not
compile_dir
(
arg
,
maxlevels
,
ddir
,
force
,
rx
,
quiet
,
legacy
):
success
=
0
else
:
else
:
if
not
compile_file
(
arg
,
ddir
,
force
,
rx
,
if
not
compile_file
(
dest
,
args
.
ddir
,
args
.
force
,
args
.
rx
,
quiet
,
legacy
):
args
.
quiet
,
args
.
legacy
):
success
=
0
return
0
else
:
else
:
success
=
compile_path
(
legacy
=
legacy
)
return
compile_path
(
legacy
=
args
.
legacy
)
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
print
(
"
\
n
[interrupt]"
)
print
(
"
\
n
[interrupt]"
)
success
=
0
return
0
return
success
return
1
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
exit_status
=
int
(
not
main
())
exit_status
=
int
(
not
main
())
...
...
Lib/test/test_compileall.py
View file @
650f1472
...
@@ -7,6 +7,7 @@ import shutil
...
@@ -7,6 +7,7 @@ import shutil
import
struct
import
struct
import
subprocess
import
subprocess
import
tempfile
import
tempfile
import
time
import
unittest
import
unittest
import
io
import
io
...
@@ -112,7 +113,7 @@ class EncodingTest(unittest.TestCase):
...
@@ -112,7 +113,7 @@ class EncodingTest(unittest.TestCase):
class
CommandLineTests
(
unittest
.
TestCase
):
class
CommandLineTests
(
unittest
.
TestCase
):
"""Test
some aspects of
compileall's CLI."""
"""Test compileall's CLI."""
def
setUp
(
self
):
def
setUp
(
self
):
self
.
addCleanup
(
self
.
_cleanup
)
self
.
addCleanup
(
self
.
_cleanup
)
...
@@ -184,6 +185,57 @@ class CommandLineTests(unittest.TestCase):
...
@@ -184,6 +185,57 @@ class CommandLineTests(unittest.TestCase):
self
.
assertTrue
(
os
.
path
.
exists
(
cachedir
))
self
.
assertTrue
(
os
.
path
.
exists
(
cachedir
))
self
.
assertFalse
(
os
.
path
.
exists
(
cachecachedir
))
self
.
assertFalse
(
os
.
path
.
exists
(
cachecachedir
))
def
test_force
(
self
):
retcode
=
subprocess
.
call
(
(
sys
.
executable
,
'-m'
,
'compileall'
,
'-q'
,
self
.
pkgdir
))
self
.
assertEqual
(
retcode
,
0
)
pycpath
=
imp
.
cache_from_source
(
os
.
path
.
join
(
self
.
pkgdir
,
'bar.py'
))
# set atime/mtime backward to avoid file timestamp resolution issues
os
.
utime
(
pycpath
,
(
time
.
time
()
-
60
,)
*
2
)
access
=
os
.
stat
(
pycpath
).
st_mtime
retcode
=
subprocess
.
call
(
(
sys
.
executable
,
'-m'
,
'compileall'
,
'-q'
,
'-f'
,
self
.
pkgdir
))
self
.
assertEqual
(
retcode
,
0
)
access2
=
os
.
stat
(
pycpath
).
st_mtime
self
.
assertNotEqual
(
access
,
access2
)
def
test_legacy
(
self
):
# create a new module
newpackage
=
os
.
path
.
join
(
self
.
pkgdir
,
'spam'
)
os
.
mkdir
(
newpackage
)
with
open
(
os
.
path
.
join
(
newpackage
,
'__init__.py'
),
'w'
):
pass
with
open
(
os
.
path
.
join
(
newpackage
,
'ham.py'
),
'w'
):
pass
sourcefile
=
os
.
path
.
join
(
newpackage
,
'ham.py'
)
retcode
=
subprocess
.
call
(
(
sys
.
executable
,
'-m'
,
'compileall'
,
'-q'
,
'-l'
,
self
.
pkgdir
))
self
.
assertEqual
(
retcode
,
0
)
self
.
assertFalse
(
os
.
path
.
exists
(
imp
.
cache_from_source
(
sourcefile
)))
retcode
=
subprocess
.
call
(
(
sys
.
executable
,
'-m'
,
'compileall'
,
'-q'
,
self
.
pkgdir
))
self
.
assertEqual
(
retcode
,
0
)
self
.
assertTrue
(
os
.
path
.
exists
(
imp
.
cache_from_source
(
sourcefile
)))
def
test_quiet
(
self
):
noise
=
subprocess
.
getoutput
(
'{} -m compileall {}'
.
format
(
sys
.
executable
,
self
.
pkgdir
))
quiet
=
subprocess
.
getoutput
((
'{} -m compileall {}'
.
format
(
sys
.
executable
,
self
.
pkgdir
)))
self
.
assertTrue
(
len
(
noise
)
>
len
(
quiet
))
def
test_regexp
(
self
):
retcode
=
subprocess
.
call
(
(
sys
.
executable
,
'-m'
,
'compileall'
,
'-q'
,
'-x'
,
'bar.*'
,
self
.
pkgdir
))
self
.
assertEqual
(
retcode
,
0
)
sourcefile
=
os
.
path
.
join
(
self
.
pkgdir
,
'bar.py'
)
self
.
assertFalse
(
os
.
path
.
exists
(
imp
.
cache_from_source
(
sourcefile
)))
sourcefile
=
os
.
path
.
join
(
self
.
pkgdir
,
'__init__.py'
)
self
.
assertTrue
(
os
.
path
.
exists
(
imp
.
cache_from_source
(
sourcefile
)))
def
test_main
():
def
test_main
():
support
.
run_unittest
(
support
.
run_unittest
(
...
...
Misc/NEWS
View file @
650f1472
...
@@ -30,6 +30,9 @@ Core and Builtins
...
@@ -30,6 +30,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #10453: compileall now uses argparse instead of getopt, and thus
provides clean output when called with '-h'.
- Issue #8078: Add constants for higher baud rates in the termios module.
- Issue #8078: Add constants for higher baud rates in the termios module.
Patch by Rodolpho Eckhardt.
Patch by Rodolpho Eckhardt.
...
...
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