Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions src/reuse/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com>
# SPDX-FileCopyrightText: 2021 Alvar Penning
# SPDX-FileCopyrightText: 2021 Alliander N.V. <https://alliander.com>
# SPDX-FileCopyrightText: 2021 Robin Vobruba <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -37,6 +38,7 @@
CommentParseError,
CommentStyle,
EmptyCommentStyle,
HtmlCommentStyle,
PythonCommentStyle,
UncommentableCommentStyle,
)
Expand Down Expand Up @@ -259,23 +261,31 @@ def find_and_replace_header(
_LOGGER.debug(f"header = {repr(header)}")
_LOGGER.debug(f"after = {repr(after)}")

# Extract shebang from header and put it in before. It's a bit messy, but
# it ends up working.
if header.startswith("#!") and not before.strip():
before = ""
for line in header.splitlines():
if line.startswith("#!"):
before = before + "\n" + line
header = header.replace(line, "", 1)
else:
break
elif after.startswith("#!") and not any((before, header)):
for line in after.splitlines():
if line.startswith("#!"):
before = before + "\n" + line
after = after.replace(line, "", 1)
else:
break
# Keep special first-line-of-file lines as the first line in the file,
# or say, move our comments after it.
for (com_style, prefix) in [
(PythonCommentStyle, "#!"),
(HtmlCommentStyle, "<?xml"),
]:
# Extract shebang from header and put it in before. It's a bit messy, but
# it ends up working.
if style is not com_style:
continue
if header.startswith(prefix) and not before.strip():
before = ""
for line in header.splitlines():
if line.startswith(prefix):
before = before + "\n" + line
header = header.replace(line, "", 1)
else:
break
elif after.startswith(prefix) and not any((before, header)):
for line in after.splitlines():
if line.startswith(prefix):
before = before + "\n" + line
after = after.replace(line, "", 1)
else:
break

header = create_header(
spdx_info,
Expand Down