Skip to content

remove unsused utils.patch_sourcelines() #1527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2025
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
58 changes: 0 additions & 58 deletions winpython/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ def patch_shebang_line(fname, pad=b" ", to_movable=True, targetdir=""):


def patch_shebang_line_py(fname, to_movable=True, targetdir=""):
"""Changes shebang line in '.py' file to relative or absolue path"""
"""Changes shebang line in '.py' file to relative or absolue path"""
import fileinput
import re
Expand Down Expand Up @@ -419,63 +418,6 @@ def patch_sourcefile(fname, in_text, out_text, silent_mode=False):
fh.write(new_content)


def patch_sourcelines(
fname,
in_line_start,
out_line,
endline="\n",
silent_mode=False,
):
"""Replace the middle of lines between in_line_start and endline"""
import io

if Path(fname).is_file():
the_encoding = guess_encoding(fname)[0]
with io.open(fname, "r", encoding=the_encoding) as fh:
contents = fh.readlines()
content = "".join(contents)
for l in range(len(contents)):
if contents[l].startswith(in_line_start):
begining, middle = (
in_line_start,
contents[l][len(in_line_start) :],
)
ending = ""
if middle.find(endline) > 0:
ending = endline + endline.join(middle.split(endline)[1:])
middle = middle.split(endline)[0]
middle = out_line
new_line = begining + middle + ending
if not new_line == contents[l]:
if not silent_mode:
print(
"patching ",
fname,
" from\n",
contents[l],
"\nto\n",
new_line,
)
contents[l] = new_line
new_content = "".join(contents)
if not new_content == content:
# if not silent_mode:
# print("patching ", fname, "from", content, "to", new_content)

with io.open(fname, "wt", encoding=the_encoding) as fh:
try:
fh.write(new_content)
except:
print(
"impossible to patch",
fname,
"from",
content,
"to",
new_content,
)


def _create_temp_dir():
"""Create a temporary directory and remove it at exit"""
tmpdir = tempfile.mkdtemp(prefix='wppm_')
Expand Down