Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
1b8d985f
Commit
1b8d985f
authored
Apr 13, 2009
by
Tarek Ziadé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pep8-fied
parent
f27b9ed7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
42 deletions
+23
-42
cmd.py
cmd.py
+23
-42
No files found.
cmd.py
View file @
1b8d985f
...
@@ -46,7 +46,7 @@ class Command:
...
@@ -46,7 +46,7 @@ class Command:
# -- Creation/initialization methods -------------------------------
# -- Creation/initialization methods -------------------------------
def
__init__
(
self
,
dist
):
def
__init__
(
self
,
dist
):
"""Create and initialize a new Command object. Most importantly,
"""Create and initialize a new Command object. Most importantly,
invokes the 'initialize_options()' method, which is the real
invokes the 'initialize_options()' method, which is the real
initializer and depends on the actual command being
initializer and depends on the actual command being
...
@@ -93,12 +93,8 @@ class Command:
...
@@ -93,12 +93,8 @@ class Command:
# always calls 'finalize_options()', to respect/update it.
# always calls 'finalize_options()', to respect/update it.
self
.
finalized
=
0
self
.
finalized
=
0
# __init__ ()
# XXX A more explicit way to customize dry_run would be better.
# XXX A more explicit way to customize dry_run would be better.
def
__getattr__
(
self
,
attr
):
def
__getattr__
(
self
,
attr
):
if
attr
==
'dry_run'
:
if
attr
==
'dry_run'
:
myval
=
getattr
(
self
,
"_"
+
attr
)
myval
=
getattr
(
self
,
"_"
+
attr
)
if
myval
is
None
:
if
myval
is
None
:
...
@@ -108,13 +104,11 @@ class Command:
...
@@ -108,13 +104,11 @@ class Command:
else
:
else
:
raise
AttributeError
,
attr
raise
AttributeError
,
attr
def
ensure_finalized
(
self
):
def
ensure_finalized
(
self
):
if
not
self
.
finalized
:
if
not
self
.
finalized
:
self
.
finalize_options
()
self
.
finalize_options
()
self
.
finalized
=
1
self
.
finalized
=
1
# Subclasses must define:
# Subclasses must define:
# initialize_options()
# initialize_options()
# provide default values for all options; may be customized by
# provide default values for all options; may be customized by
...
@@ -128,7 +122,7 @@ class Command:
...
@@ -128,7 +122,7 @@ class Command:
# run the command: do whatever it is we're here to do,
# run the command: do whatever it is we're here to do,
# controlled by the command's various option values
# controlled by the command's various option values
def
initialize_options
(
self
):
def
initialize_options
(
self
):
"""Set default values for all the options that this command
"""Set default values for all the options that this command
supports. Note that these defaults may be overridden by other
supports. Note that these defaults may be overridden by other
commands, by the setup script, by config files, or by the
commands, by the setup script, by config files, or by the
...
@@ -141,7 +135,7 @@ class Command:
...
@@ -141,7 +135,7 @@ class Command:
raise
RuntimeError
,
\
raise
RuntimeError
,
\
"abstract method -- subclass %s must override"
%
self
.
__class__
"abstract method -- subclass %s must override"
%
self
.
__class__
def
finalize_options
(
self
):
def
finalize_options
(
self
):
"""Set final values for all the options that this command supports.
"""Set final values for all the options that this command supports.
This is always called as late as possible, ie. after any option
This is always called as late as possible, ie. after any option
assignments from the command-line or from other commands have been
assignments from the command-line or from other commands have been
...
@@ -170,7 +164,7 @@ class Command:
...
@@ -170,7 +164,7 @@ class Command:
self
.
announce
(
indent
+
"%s = %s"
%
(
option
,
value
),
self
.
announce
(
indent
+
"%s = %s"
%
(
option
,
value
),
level
=
log
.
INFO
)
level
=
log
.
INFO
)
def
run
(
self
):
def
run
(
self
):
"""A command's raison d'etre: carry out the action it exists to
"""A command's raison d'etre: carry out the action it exists to
perform, controlled by the options initialized in
perform, controlled by the options initialized in
'initialize_options()', customized by other commands, the setup
'initialize_options()', customized by other commands, the setup
...
@@ -180,17 +174,16 @@ class Command:
...
@@ -180,17 +174,16 @@ class Command:
This method must be implemented by all command classes.
This method must be implemented by all command classes.
"""
"""
raise
RuntimeError
,
\
raise
RuntimeError
,
\
"abstract method -- subclass %s must override"
%
self
.
__class__
"abstract method -- subclass %s must override"
%
self
.
__class__
def
announce
(
self
,
msg
,
level
=
1
):
def
announce
(
self
,
msg
,
level
=
1
):
"""If the current verbosity level is of greater than or equal to
"""If the current verbosity level is of greater than or equal to
'level' print 'msg' to stdout.
'level' print 'msg' to stdout.
"""
"""
log
.
log
(
level
,
msg
)
log
.
log
(
level
,
msg
)
def
debug_print
(
self
,
msg
):
def
debug_print
(
self
,
msg
):
"""Print 'msg' to stdout if the global DEBUG (taken from the
"""Print 'msg' to stdout if the global DEBUG (taken from the
DISTUTILS_DEBUG environment variable) flag is true.
DISTUTILS_DEBUG environment variable) flag is true.
"""
"""
...
@@ -200,7 +193,6 @@ class Command:
...
@@ -200,7 +193,6 @@ class Command:
sys
.
stdout
.
flush
()
sys
.
stdout
.
flush
()
# -- Option validation methods -------------------------------------
# -- Option validation methods -------------------------------------
# (these are very handy in writing the 'finalize_options()' method)
# (these are very handy in writing the 'finalize_options()' method)
#
#
...
@@ -279,14 +271,13 @@ class Command:
...
@@ -279,14 +271,13 @@ class Command:
# -- Convenience methods for commands ------------------------------
# -- Convenience methods for commands ------------------------------
def
get_command_name
(
self
):
def
get_command_name
(
self
):
if
hasattr
(
self
,
'command_name'
):
if
hasattr
(
self
,
'command_name'
):
return
self
.
command_name
return
self
.
command_name
else
:
else
:
return
self
.
__class__
.
__name__
return
self
.
__class__
.
__name__
def
set_undefined_options
(
self
,
src_cmd
,
*
option_pairs
):
def
set_undefined_options
(
self
,
src_cmd
,
*
option_pairs
):
"""Set the values of any "undefined" options from corresponding
"""Set the values of any "undefined" options from corresponding
option values in some other command object. "Undefined" here means
option values in some other command object. "Undefined" here means
"is None", which is the convention used to indicate that an option
"is None", which is the convention used to indicate that an option
...
@@ -311,7 +302,7 @@ class Command:
...
@@ -311,7 +302,7 @@ class Command:
getattr
(
src_cmd_obj
,
src_option
))
getattr
(
src_cmd_obj
,
src_option
))
def
get_finalized_command
(
self
,
command
,
create
=
1
):
def
get_finalized_command
(
self
,
command
,
create
=
1
):
"""Wrapper around Distribution's 'get_command_obj()' method: find
"""Wrapper around Distribution's 'get_command_obj()' method: find
(create if necessary and 'create' is true) the command object for
(create if necessary and 'create' is true) the command object for
'command', call its 'ensure_finalized()' method, and return the
'command', call its 'ensure_finalized()' method, and return the
...
@@ -323,19 +314,18 @@ class Command:
...
@@ -323,19 +314,18 @@ class Command:
# XXX rename to 'get_reinitialized_command()'? (should do the
# XXX rename to 'get_reinitialized_command()'? (should do the
# same in dist.py, if so)
# same in dist.py, if so)
def
reinitialize_command
(
self
,
command
,
reinit_subcommands
=
0
):
def
reinitialize_command
(
self
,
command
,
reinit_subcommands
=
0
):
return
self
.
distribution
.
reinitialize_command
(
return
self
.
distribution
.
reinitialize_command
(
command
,
reinit_subcommands
)
command
,
reinit_subcommands
)
def
run_command
(
self
,
command
):
def
run_command
(
self
,
command
):
"""Run some other command: uses the 'run_command()' method of
"""Run some other command: uses the 'run_command()' method of
Distribution, which creates and finalizes the command object if
Distribution, which creates and finalizes the command object if
necessary and then invokes its 'run()' method.
necessary and then invokes its 'run()' method.
"""
"""
self
.
distribution
.
run_command
(
command
)
self
.
distribution
.
run_command
(
command
)
def
get_sub_commands
(
self
):
def
get_sub_commands
(
self
):
"""Determine the sub-commands that are relevant in the current
"""Determine the sub-commands that are relevant in the current
distribution (ie., that need to be run). This is based on the
distribution (ie., that need to be run). This is based on the
'sub_commands' class attribute: each tuple in that list may include
'sub_commands' class attribute: each tuple in that list may include
...
@@ -351,19 +341,17 @@ class Command:
...
@@ -351,19 +341,17 @@ class Command:
# -- External world manipulation -----------------------------------
# -- External world manipulation -----------------------------------
def
warn
(
self
,
msg
):
def
warn
(
self
,
msg
):
log
.
warn
(
"warning: %s: %s
\
n
"
%
log
.
warn
(
"warning: %s: %s
\
n
"
%
(
self
.
get_command_name
(),
msg
))
(
self
.
get_command_name
(),
msg
))
def
execute
(
self
,
func
,
args
,
msg
=
None
,
level
=
1
):
def
execute
(
self
,
func
,
args
,
msg
=
None
,
level
=
1
):
util
.
execute
(
func
,
args
,
msg
,
dry_run
=
self
.
dry_run
)
util
.
execute
(
func
,
args
,
msg
,
dry_run
=
self
.
dry_run
)
def
mkpath
(
self
,
name
,
mode
=
0777
):
def
mkpath
(
self
,
name
,
mode
=
0777
):
dir_util
.
mkpath
(
name
,
mode
,
dry_run
=
self
.
dry_run
)
dir_util
.
mkpath
(
name
,
mode
,
dry_run
=
self
.
dry_run
)
def
copy_file
(
self
,
infile
,
outfile
,
def
copy_file
(
self
,
infile
,
outfile
,
preserve_mode
=
1
,
preserve_times
=
1
,
link
=
None
,
level
=
1
):
preserve_mode
=
1
,
preserve_times
=
1
,
link
=
None
,
level
=
1
):
"""Copy a file respecting verbose, dry-run and force flags. (The
"""Copy a file respecting verbose, dry-run and force flags. (The
former two default to whatever is in the Distribution object, and
former two default to whatever is in the Distribution object, and
...
@@ -376,8 +364,7 @@ class Command:
...
@@ -376,8 +364,7 @@ class Command:
link
,
link
,
dry_run
=
self
.
dry_run
)
dry_run
=
self
.
dry_run
)
def
copy_tree
(
self
,
infile
,
outfile
,
def
copy_tree
(
self
,
infile
,
outfile
,
preserve_mode
=
1
,
preserve_times
=
1
,
preserve_symlinks
=
0
,
preserve_mode
=
1
,
preserve_times
=
1
,
preserve_symlinks
=
0
,
level
=
1
):
level
=
1
):
"""Copy an entire directory tree respecting verbose, dry-run,
"""Copy an entire directory tree respecting verbose, dry-run,
...
@@ -403,7 +390,6 @@ class Command:
...
@@ -403,7 +390,6 @@ class Command:
return
archive_util
.
make_archive
(
return
archive_util
.
make_archive
(
base_name
,
format
,
root_dir
,
base_dir
,
dry_run
=
self
.
dry_run
)
base_name
,
format
,
root_dir
,
base_dir
,
dry_run
=
self
.
dry_run
)
def
make_file
(
self
,
infiles
,
outfile
,
func
,
args
,
def
make_file
(
self
,
infiles
,
outfile
,
func
,
args
,
exec_msg
=
None
,
skip_msg
=
None
,
level
=
1
):
exec_msg
=
None
,
skip_msg
=
None
,
level
=
1
):
"""Special case of 'execute()' for operations that process one or
"""Special case of 'execute()' for operations that process one or
...
@@ -438,17 +424,12 @@ class Command:
...
@@ -438,17 +424,12 @@ class Command:
else
:
else
:
log
.
debug
(
skip_msg
)
log
.
debug
(
skip_msg
)
# make_file ()
# class Command
# XXX 'install_misc' class not currently used -- it was the base class for
# XXX 'install_misc' class not currently used -- it was the base class for
# both 'install_scripts' and 'install_data', but they outgrew it. It might
# both 'install_scripts' and 'install_data', but they outgrew it. It might
# still be useful for 'install_headers', though, so I'm keeping it around
# still be useful for 'install_headers', though, so I'm keeping it around
# for the time being.
# for the time being.
class
install_misc
(
Command
):
class
install_misc
(
Command
):
"""Common base class for installing some files in a subdirectory.
"""Common base class for installing some files in a subdirectory.
Currently used by install_data and install_scripts.
Currently used by install_data and install_scripts.
"""
"""
...
@@ -459,10 +440,10 @@ class install_misc (Command):
...
@@ -459,10 +440,10 @@ class install_misc (Command):
self
.
install_dir
=
None
self
.
install_dir
=
None
self
.
outfiles
=
[]
self
.
outfiles
=
[]
def
_install_dir_from
(
self
,
dirname
):
def
_install_dir_from
(
self
,
dirname
):
self
.
set_undefined_options
(
'install'
,
(
dirname
,
'install_dir'
))
self
.
set_undefined_options
(
'install'
,
(
dirname
,
'install_dir'
))
def
_copy_files
(
self
,
filelist
):
def
_copy_files
(
self
,
filelist
):
self
.
outfiles
=
[]
self
.
outfiles
=
[]
if
not
filelist
:
if
not
filelist
:
return
return
...
@@ -471,5 +452,5 @@ class install_misc (Command):
...
@@ -471,5 +452,5 @@ class install_misc (Command):
self
.
copy_file
(
f
,
self
.
install_dir
)
self
.
copy_file
(
f
,
self
.
install_dir
)
self
.
outfiles
.
append
(
os
.
path
.
join
(
self
.
install_dir
,
f
))
self
.
outfiles
.
append
(
os
.
path
.
join
(
self
.
install_dir
,
f
))
def
get_outputs
(
self
):
def
get_outputs
(
self
):
return
self
.
outfiles
return
self
.
outfiles
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