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
07930ca7
Commit
07930ca7
authored
May 25, 2000
by
Greg Ward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bastian Kleineidam: the "build_scripts" command.
parent
51eabe3d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
0 deletions
+71
-0
Lib/distutils/command/build_scripts.py
Lib/distutils/command/build_scripts.py
+71
-0
No files found.
Lib/distutils/command/build_scripts.py
0 → 100644
View file @
07930ca7
"""distutils.command.build_scripts
Implements the Distutils 'build_scripts' command."""
# created 2000/05/23, Bastian Kleineidam
__revision__
=
"$Id$"
import
sys
,
os
,
re
from
distutils.core
import
Command
# check if Python is called on the first line with this expression
first_line_re
=
re
.
compile
(
r"^#!.+python(\
s-
\w+)*"
)
class
build_scripts
(
Command
):
description
=
"
\
"
build
\
"
scripts"
user_options
=
[
(
'build-dir='
,
'd'
,
"directory to
\
"
build
\
"
(copy) to"
),
(
'force'
,
'f'
,
"forcibly build everything (ignore file timestamps"
),
]
def
initialize_options
(
self
):
self
.
build_dir
=
None
self
.
scripts
=
None
self
.
force
=
None
self
.
outfiles
=
None
def
finalize_options
(
self
):
self
.
set_undefined_options
(
'build'
,
(
'build_scripts'
,
'build_dir'
),
(
'force'
,
'force'
))
self
.
scripts
=
self
.
distribution
.
scripts
def
run
(
self
):
if
not
self
.
scripts
:
return
self
.
_copy_files
()
self
.
_adjust_files
()
def
_copy_files
(
self
):
"""Copy all the scripts to the build dir"""
self
.
outfiles
=
[]
self
.
mkpath
(
self
.
build_dir
)
for
f
in
self
.
scripts
:
print
self
.
build_dir
if
self
.
copy_file
(
f
,
self
.
build_dir
):
self
.
outfiles
.
append
(
os
.
path
.
join
(
self
.
build_dir
,
f
))
def
_adjust_files
(
self
):
"""If the first line begins with #! and ends with python
replace it with the current python interpreter"""
for
f
in
self
.
outfiles
:
if
not
self
.
dry_run
:
data
=
open
(
f
,
"r"
).
readlines
()
if
not
data
:
self
.
warn
(
"%s is an empty file!"
%
f
)
continue
mo
=
first_line_re
.
match
(
data
[
0
])
if
mo
:
self
.
announce
(
"Adjusting first line of file %s"
%
f
)
data
[
0
]
=
"#!"
+
sys
.
executable
# add optional command line options
if
mo
.
group
(
1
):
data
[
0
]
=
data
[
0
]
+
mo
.
group
(
1
)
else
:
data
[
0
]
=
data
[
0
]
+
"
\
n
"
open
(
f
,
"w"
).
writelines
(
data
)
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