Conversation
| for i in reversed(range(len(components))): | ||
| c = components[i] | ||
| if c.count('-') == 1: # if we have a - for a range (for example R3-R9) | ||
| m = re.match(r'(\w*?)(\d+)-(\w*?)(\d+)$', c) | ||
| try: | ||
| prefix = m.group(1) | ||
| if prefix != m.group(3): # if the first and second prefix don't match, ignore | ||
| continue | ||
| start_n = int(m.group(2)) | ||
| end_n = int(m.group(4)) | ||
| except (IndexError, ValueError): | ||
| # if we either didn't have a full regex match, or the numbers weren't integers somehow? | ||
| continue | ||
| if start_n > end_n: # check that the first number is the lower limit (R6-R2 is not valid) | ||
| continue | ||
| # Replace XY-XZ with [XY, X(Y+1), X(Y+2), ..., X(Z-1), ZX] | ||
| components += [f"{prefix}{i}" for i in range(start_n, end_n+1)] | ||
| components.pop(i) |
There was a problem hiding this comment.
Just an idea - wouldn't it be cleaner to modify PcbDraw to accept ranges as well for filtering and highlighting? We would cover another use case.
There was a problem hiding this comment.
yeah that's fair. I'll look into incorporating it directly in plot
| plot_args += ["--filter", ",".join(components)] | ||
| plot_args += ["--highlight", ",".join(active)] | ||
| plot_args += [boardfilename, outputfile] | ||
| tmp_std = sys.stdout # make a copy of stdout |
There was a problem hiding this comment.
I understand that Click changes stdout. But I have two questions:
- why it matters?
- the comment "make a copy of stdout" adds no information. I can see you make it. But why? This is what should be in the comment.
There was a problem hiding this comment.
- in case there are any temporary debug print statements (yes I know the debugger exists, but at times it's easier for quick debug sessions)
- can iterate in the comment if it's worth keeping
51ee017 to
d2af9d4
Compare
| for i in reversed(range(len(components))): | ||
| c = components[i] | ||
| if c.count('-') == 1: # if we have a - for a range (for example R3-R9) | ||
| m = re.match(r'(\w*?)(\d+)-(\w*?)(\d+)$', c) |
There was a problem hiding this comment.
Why (\w*?)? This will match things like 1-10, is this desirable?
There was a problem hiding this comment.
not intentional. Will replace with [a-zA-Z]
There was a problem hiding this comment.
Also force "1 or more", don't allow 0.
There was a problem hiding this comment.
Fixed. Also re-based with master
- In the `show_components` and `highlight` options. - So one entry can be something like *R10-R20*. - Can be disabled using the global option `allow_component_ranges`. Idea from yaqwsx/PcbDraw#159
…le R1-R10). Added an stdout copy so that print statement can work
c822fb2 to
eea9aec
Compare
This PR adds the ability for
populateto take a series of components with a start and end reference delimited with a-, and use all the ones in between.For example,
R3-R20will be treated likeR3,R4,R5...R19,R20This PR also makes a copy of stdout and replaces it back. This is because during debugging, I noticed that when the click application is called, stdout no longer points to the terminal's stdout after the execution is completed.