-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Modify parallelization to use Horace parallel_config * Add a python patch routine and store diffs wrt 3.6.2 * Add parallelization documentation * Fix input pars to `disp2sqw_plot` bug #9 * Add auto conv to double of small np.ndarrays #11 * Fix spyder deletion of imports bug #12 * Fix getdoc error string in Spyder/IPython help #12
- Loading branch information
Showing
9 changed files
with
351 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import sys, os, re | ||
|
||
FUZZ = 10 | ||
|
||
def patch_files(diff_file, base_dir): | ||
# Patches files in `base_dir` with unified diff in `diff_file` | ||
with open(diff_file, 'r') as f: | ||
df = f.read() | ||
for diffs in df.split('diff'): | ||
if '@@' in diffs: | ||
filename = os.path.join(base_dir, diffs.split('+++ b/')[1].split('\n')[0]) | ||
with open(filename, 'r') as f: | ||
t0 = f.read() | ||
t0 = t0.split('\n') | ||
for p in diffs.split('\n@@')[1:]: | ||
ll = p.split('\n') | ||
m = re.match(r'-(\d+),?(\d*) \+(\d+),?(\d*) @@', ll[0].strip()) | ||
if not m: | ||
raise ValueError(f'Invalid diff hunk header {ll[0]}') | ||
l0 = int(m.group(3)) | ||
# Search for start of hunk in original file | ||
found = False | ||
for ii in range(l0 - FUZZ, l0 + FUZZ): | ||
if t0[ii] == ll[1][1:] and t0[ii+1] == ll[2][1:] and t0[ii+2] == ll[3][1:]: | ||
found = True | ||
break | ||
if not found: | ||
raise ValueError('Invalid Hunk:\n@@ %s' % ("\n".join(ll))) | ||
l1 = ii | ||
if t0[l1] != ll[1][1:]: | ||
raise ValueError('File %s\nHunk failed: @@ %s' % (filename, "\n".join(ll))) | ||
for ii in range(1, len(ll)): | ||
print(f'{ii, l1}: {ll[ii]}') | ||
if 'No newline at end of file' in ll[ii]: | ||
continue | ||
if len(ll[ii]) < 1: | ||
l1 += 1 | ||
elif ll[ii][0] == '-': | ||
if t0[l1] == ll[ii][1:]: | ||
t0.pop(l1) | ||
else: | ||
raise ValueError('Unmatched hunk: %s\n%s' % (t0[l1], ll[ii])) | ||
elif ll[ii][0] == '+': | ||
t0.insert(l1, ll[ii][1:]) | ||
l1 += 1 | ||
else: | ||
if t0[l1] != ll[ii][1:]: | ||
raise ValueError('Unmatched hunk: %s\n%s' % (t0[l1], ll[ii])) | ||
l1 += 1 | ||
with open(filename, 'w') as f: | ||
f.write('\n'.join(t0)) | ||
|
||
|
||
if __name__ == '__main__': | ||
# Recursively applies all diffs in a given folder w.r.t. an input base dir | ||
for root, _, files in os.walk(sys.argv[1]): | ||
for fl in [f for f in files if f.endswith('.diff')]: | ||
patch_files(os.path.join(root, fl), sys.argv[2]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
diff --git a/HORACE-build/Horace/disp2sqw_plot.m b/HORACE-build/Horace/disp2sqw_plot.m | ||
index 43af671..12faa0e 100644 | ||
--- a/Horace/disp2sqw_plot.m | ||
+++ b/Horace/disp2sqw_plot.m | ||
@@ -119,6 +119,7 @@ else | ||
end | ||
|
||
pars=args{noff+3}; | ||
+if ~iscell(pars), pars = {pars}; end | ||
|
||
if isnumeric(args{noff+4}) && numel(args{noff+4})==3 | ||
ecent=args{noff+4}; |
Oops, something went wrong.