-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
Populate Series of Components #159
base: master
Are you sure you want to change the base?
Conversation
pcbdraw/populate.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that's fair. I'll look into incorporating it directly in plot
pcbdraw/populate.py
Outdated
@@ -244,11 +263,13 @@ def generate_image(boardfilename: str, side: str, components: List[str], | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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
pcbdraw/populate.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why (\w*?)
? This will match things like 1-10, is this desirable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not intentional. Will replace with [a-zA-Z]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also force "1 or more", don't allow 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
populate
to take a series of components with a start and end reference delimited with a-
, and use all the ones in between.For example,
R3-R20
will be treated likeR3,R4,R5...R19,R20
This 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.