mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Some nits...
Add the script directory to the path. Fix the sanity checks on the arguments so they don't mess up the -m option; remove the requirement that the script must have a .py extension.
This commit is contained in:
parent
a5568d349b
commit
1e07403bbf
1 changed files with 9 additions and 8 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
"""Freeze a Python script into a binary.
|
"""Freeze a Python script into a binary.
|
||||||
|
|
||||||
usage: freeze [options...] script.py [module]...
|
usage: freeze [options...] script [module]...
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
|
||||||
|
@ -43,8 +43,7 @@ Options:
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
||||||
script.py: The Python script to be executed by the resulting binary.
|
script: The Python script to be executed by the resulting binary.
|
||||||
It *must* end with a .py suffix!
|
|
||||||
|
|
||||||
module ...: Additional Python modules (referenced by pathname)
|
module ...: Additional Python modules (referenced by pathname)
|
||||||
that will be included in the resulting binary. These
|
that will be included in the resulting binary. These
|
||||||
|
@ -88,7 +87,7 @@ def main():
|
||||||
prefix = None # settable with -p option
|
prefix = None # settable with -p option
|
||||||
exec_prefix = None # settable with -P option
|
exec_prefix = None # settable with -P option
|
||||||
extensions = []
|
extensions = []
|
||||||
path = sys.path
|
path = sys.path[:]
|
||||||
modargs = 0
|
modargs = 0
|
||||||
debug = 1
|
debug = 1
|
||||||
odir = ''
|
odir = ''
|
||||||
|
@ -195,16 +194,16 @@ def main():
|
||||||
if not args:
|
if not args:
|
||||||
usage('at least one filename argument required')
|
usage('at least one filename argument required')
|
||||||
|
|
||||||
# check that the script name ends in ".py"
|
|
||||||
if args[0][-3:] != ".py":
|
|
||||||
usage('the script name must have a .py suffix')
|
|
||||||
|
|
||||||
# check that file arguments exist
|
# check that file arguments exist
|
||||||
for arg in args:
|
for arg in args:
|
||||||
|
if arg == '-m':
|
||||||
|
break
|
||||||
if not os.path.exists(arg):
|
if not os.path.exists(arg):
|
||||||
usage('argument %s not found' % arg)
|
usage('argument %s not found' % arg)
|
||||||
if not os.path.isfile(arg):
|
if not os.path.isfile(arg):
|
||||||
usage('%s: not a plain file' % arg)
|
usage('%s: not a plain file' % arg)
|
||||||
|
if modargs:
|
||||||
|
break
|
||||||
|
|
||||||
# process non-option arguments
|
# process non-option arguments
|
||||||
scriptfile = args[0]
|
scriptfile = args[0]
|
||||||
|
@ -238,6 +237,8 @@ def main():
|
||||||
# Actual work starts here...
|
# Actual work starts here...
|
||||||
|
|
||||||
# collect all modules of the program
|
# collect all modules of the program
|
||||||
|
dir = os.path.dirname(scriptfile)
|
||||||
|
path[0] = dir
|
||||||
mf = modulefinder.ModuleFinder(path, debug)
|
mf = modulefinder.ModuleFinder(path, debug)
|
||||||
for mod in implicits:
|
for mod in implicits:
|
||||||
mf.import_hook(mod)
|
mf.import_hook(mod)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue