Skip to content

Commit 2fa0eca

Browse files
author
stonebig
committed
Julia "usb" patch
1 parent b12c479 commit 2fa0eca

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

winpython/utils.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,67 @@ def patch_sourcefile(fname, in_text, out_text, silent_mode=False):
328328
with io.open(fname, 'wt') as fh:
329329
fh.write(new_content)
330330

331+
# =============================================================================
332+
# Patch sourcelines (instead of forking packages)
333+
# =============================================================================
334+
def patch_sourcelines(fname, in_line_start, out_line, endline='\n', silent_mode=False):
335+
"""Replace the middle of lines between in_line_start and endline """
336+
import io
337+
import os.path as osp
338+
if osp.isfile(fname):
339+
with io.open(fname, 'r') as fh:
340+
contents = fh.readlines()
341+
content = "".join(contents)
342+
for l in range(len(contents)):
343+
if contents[l].startswith(in_line_start):
344+
begining , middle = in_line_start , contents[l][len(in_line_start):]
345+
ending = ""
346+
if middle.find(endline)>0:
347+
ending = endline + endline.join(middle.split(endline)[1:])
348+
middle = middle.split(endline)[0]
349+
middle = out_line
350+
new_line = begining + middle + ending
351+
if not new_line == contents[l]:
352+
if not silent_mode:
353+
print("patching ", fname, " from\n", contents[l], "\nto\n", new_line)
354+
contents[l] = new_line
355+
new_content = "".join(contents)
356+
if not new_content == content:
357+
# if not silent_mode:
358+
# print("patching ", fname, "from", content, "to", new_content)
359+
with io.open(fname, 'wt') as fh:
360+
try:
361+
fh.write(new_content)
362+
except:
363+
print("impossible to patch", fname, "from", content,
364+
"to", new_content)
365+
366+
def patch_julia03():
367+
"""Ugly patch of Julia/ZMQ and Julia/Nettle to make them movable"""
368+
import io
369+
import os.path as osp
370+
out_line ='"'+ os.path.dirname(os.environ["WINPYDIR"]).replace("\\" ,"\\\\")
371+
end_line = r"\\settings\\.julia"
372+
from winpython.utils import patch_sourcelines
373+
374+
in_line_start = '@checked_lib zmq ';
375+
376+
fname= os.path.dirname(os.environ["WINPYDIR"]) + r"\settings\.julia\v0.3\ZMQ\deps\deps.jl";
377+
patch_sourcelines (fname, in_line_start, out_line, end_line);
378+
fname= os.path.dirname(os.environ["WINPYDIR"]) + r"\settings\.julia\v0.4\ZMQ\deps\deps.jl";
379+
patch_sourcelines (fname, in_line_start, out_line, end_line);
380+
fname= os.path.dirname(os.environ["WINPYDIR"]) + r"\settings\.julia\v0.5\ZMQ\deps\deps.jl";
381+
patch_sourcelines (fname, in_line_start, out_line, end_line);
382+
383+
in_line_start = '@checked_lib nettle ';
384+
385+
fname= os.path.dirname(os.environ["WINPYDIR"]) + r"\settings\.julia\v0.3\Nettle\deps\deps.jl";
386+
patch_sourcelines (fname, in_line_start, out_line, end_line);
387+
fname= os.path.dirname(os.environ["WINPYDIR"]) + r"\settings\.julia\v0.4\Nettle\deps\deps.jl";
388+
patch_sourcelines (fname, in_line_start, out_line, end_line);
389+
fname= os.path.dirname(os.environ["WINPYDIR"]) + r"\settings\.julia\v0.5\Nettle\deps\deps.jl";
390+
patch_sourcelines (fname, in_line_start, out_line, end_line);
391+
331392

332393
# =============================================================================
333394
# Extract functions

0 commit comments

Comments
 (0)