Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Spack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
eic_tools
Spack
Commits
2a9d6b9f
Unverified
Commit
2a9d6b9f
authored
5 years ago
by
Gregory L. Lee
Committed by
Todd Gamblin
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
sbang: use utf-8 for encoding when patching (#13490)
This fixes a UnicodeDecodeError in the sbang patching function.
parent
eb286bb8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/spack/spack/hooks/sbang.py
+13
-4
13 additions, 4 deletions
lib/spack/spack/hooks/sbang.py
with
13 additions
and
4 deletions
lib/spack/spack/hooks/sbang.py
+
13
−
4
View file @
2a9d6b9f
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
import
os
import
os
import
stat
import
stat
import
re
import
re
import
sys
import
llnl.util.tty
as
tty
import
llnl.util.tty
as
tty
...
@@ -33,8 +34,12 @@ def shebang_too_long(path):
...
@@ -33,8 +34,12 @@ def shebang_too_long(path):
def
filter_shebang
(
path
):
def
filter_shebang
(
path
):
"""
Adds a second shebang line, using sbang, at the beginning of a file.
"""
"""
Adds a second shebang line, using sbang, at the beginning of a file.
"""
with
open
(
path
,
'
r
'
)
as
original_file
:
with
open
(
path
,
'
r
b
'
)
as
original_file
:
original
=
original_file
.
read
()
original
=
original_file
.
read
()
if
sys
.
version_info
>=
(
2
,
7
):
original
=
original
.
decode
(
encoding
=
'
UTF-8
'
)
else
:
original
=
original
.
decode
(
'
UTF-8
'
)
# This line will be prepended to file
# This line will be prepended to file
new_sbang_line
=
'
#!/bin/bash %s/bin/sbang
\n
'
%
spack
.
paths
.
prefix
new_sbang_line
=
'
#!/bin/bash %s/bin/sbang
\n
'
%
spack
.
paths
.
prefix
...
@@ -61,9 +66,13 @@ def filter_shebang(path):
...
@@ -61,9 +66,13 @@ def filter_shebang(path):
saved_mode
=
st
.
st_mode
saved_mode
=
st
.
st_mode
os
.
chmod
(
path
,
saved_mode
|
stat
.
S_IWRITE
)
os
.
chmod
(
path
,
saved_mode
|
stat
.
S_IWRITE
)
with
open
(
path
,
'
w
'
)
as
new_file
:
with
open
(
path
,
'
wb
'
)
as
new_file
:
new_file
.
write
(
new_sbang_line
)
if
sys
.
version_info
>=
(
2
,
7
):
new_file
.
write
(
original
)
new_file
.
write
(
new_sbang_line
.
encode
(
encoding
=
'
UTF-8
'
))
new_file
.
write
(
original
.
encode
(
encoding
=
'
UTF-8
'
))
else
:
new_file
.
write
(
new_sbang_line
.
encode
(
'
UTF-8
'
))
new_file
.
write
(
original
.
encode
(
'
UTF-8
'
))
# Restore original permissions.
# Restore original permissions.
if
saved_mode
is
not
None
:
if
saved_mode
is
not
None
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment