-
Notifications
You must be signed in to change notification settings - Fork 227
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
add length_unit support for wire and cable lengths #171
Conversation
stevegt
commented
Oct 5, 2020
- partial fix for [feature] Using inches and other units #7
- based on and closes Adding support for wire length units #161 and Add support for units to wire lengths. Part 2 #162
Will also be editing dataclasses.py to add the support as well as defaulting units to meters if unpopulated.
Will also be editing harness.py to add the support as well as defaulting units to meters if unpopulated.
- partial fix for wireviz#7 - based on and closes wireviz#161 and wireviz#162
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.
@stevegt Thank you for contributing. I'm just another contributor, like you. @formatc1702 is the owner that approves and merges PRs into dev
when he thinks they are ready. He has been on vacation and busy with other things a few weeks, and I decided to give you a few advices that I believe will help you getting this PR accepted, but remember that @formatc1702 might not share all my opinions.
- Please read the hints in this current draft written by @formatc1702 : https://github.com/formatc1702/WireViz/blob/feature/syntax-description/docs/CONTRIBUTING.md
- I recommend you interactively rebase your PR branch named
length_unit
and fix these issues:- Execute rebase command:
git rebase -i HEAD~3
- Untangle the commit history by this rebase that replaces your merge.
- Reword the first two commit messages:
- Execute rebase command:
reword 30ac03c Adding support for wire length units
reword 2dde3a2 Add support for units to wire lengths. Part 2
pick 684cefb add length_unit
Replace both commit messages with e.g. "Add support for wire length units" to use the imperative form and remove the "Part 2" reference. Personally, I would also consider squashing them together, i.e. write "squash" instead of "reword" for the second commit in the initial rebase step above. Take a look at the commit histories of my demonstration branches kvid:length_unit-reword and kvid:length_unit-squash to see what the results will be.
Edit: After rebasing your branch, you must force-push it (executing git push -f
) to update your PR.
@@ -88,6 +88,7 @@ class Cable: | |||
gauge_unit: Optional[str] = None | |||
show_equiv: bool = False | |||
length: float = 0 | |||
length_unit: Optional[str] = None |
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.
length_unit: Optional[str] = None | |
length_unit: str = 'm' |
When any None
value is always replaced with the same real default string value in __post_init__()
, then there is no reason to have an optional type and None
as default value - see why in my #156 (comment). The same effect is better obtained with the real default string value here in the declaration.
if self.length_unit is None: #Default wire length units to meters if left undeclared | ||
self.length_unit = 'm' | ||
|
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.
if self.length_unit is None: #Default wire length units to meters if left undeclared | |
self.length_unit = 'm' | |
The same effect is better obtained with the real default string value in the declaration above.
@@ -365,7 +365,7 @@ def bom(self): | |||
gauge_name = f' x {shared.gauge} {shared.gauge_unit}' if shared.gauge else ' wires' | |||
shield_name = ' shielded' if shared.shield else '' | |||
name = f'Cable{cable_type}, {shared.wirecount}{gauge_name}{shield_name}' | |||
item = {'item': name, 'qty': round(total_length, 3), 'unit': 'm', 'designators': designators, | |||
item = {'item': name, 'qty': round(total_length, 3), 'unit': shared.length_unit, 'designators': designators, |
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've already commented this code change in my #161 (comment). Choice 2 is the easiest to implement by including c.length_unit
in the tuple returned from the cable_group
lambda just above this loop:
cable_group = lambda c: (c.category, c.type, c.gauge, c.gauge_unit, c.length_unit, c.wirecount, c.shield, c.pn, c.manufacturer, c.mpn)
Then, remember to implement the same changes for bundle wires below as for cables here.
@kvid Thanks for the advice; most of it looks good to me, though I'm concerned that the force push runs the risk of breaking others' repos. I also wouldn't want attribution to be lost -- a Co-authored-by header would seem to be called for if the commits are squashed, so that should probably be included. I know we're kind of stalled here due to lack of alternate committers (I vote for you!), but otherwise I'd be careful about setting the bar too high for PRs, rather than accepting as-is and then allowing others to build on that history. Normally when running a project I'd go ahead and accept these commits as-is and then solicit issues and fixes, particularly if working on a dev branch. In my own case, I urgently needed #161 and #162 late last night, was pleasantly surprised that @zombielinux had already done enough work to satisfy the requirement I had, and was glad that he had make those commits available. His code worked perfectly for my use case, and saved me from having to duplicate his effort. I'd like to see his work included and I'd like to see him get attribution so that others can improve on it. |
As long as you force-push to your own PR branch where you normally are the only one to push contributions, then I don't see what could go wrong. It has been done several times in other PRs (e.g. #163 and #164) to this project. Github discovers the force-push and handles it perfectly. If I have locally fetched commits from the PR branch of another user and he then force-push his branch after a rebase, then I still have the old commits, and when re-fetching, I also get the new commits. Normally, I then reset my local branch to the new remote branch to get in sync again, but under no circumstances I have seen anything broken because of this. Please explain to me how this can break a repo.
I didn't intend to suggest removing any authorship. Squashing two commits from the same author together will keep the author unchanged - see kvid@94f752d that reflects what I suggested. I also suggested a minor rewording of the commit message to follow the commit guidelines linked from https://github.com/formatc1702/WireViz/blob/feature/syntax-description/docs/CONTRIBUTING.md. However, please feel free to ignore any suggestions you don't agree with. I don't want to, and certainly don't have the power to, insist on anything. 😃
As I tried to explain in my review message, that I decided to write a code review and suggest changes that I believe will bring the PR closer to a state where it has the intended functionality and follow most of the project guidelines, but @formatc1702 is the owner that decides what PRs are accepted into One of the reasons for me to suggest changes rather that fix it myself afterwords, is to enable the PR author to keep his authorship on all code that he changes, but he can of course suggest that someone else can do the remaining work if he really wants that, e.g. because he is getting too busy himself.
I fully agree with your opinion here. My intention with the suggestions are here ordered by importance:
You decide what to include in your PR, and @formatc1702 decide what to merge into his project. |
I'm late to the party, but here are my comments :) Re: preserving authorship
I'm still figuring out managing authorships when merging & squashing, but it seems that I have control over it by adding the Side note: Re: when to close PRs
There is no formalized process, or checklist to decide when a PR should be merged.
That's the beauty of distributed version control :) Moving forwardSince I've figured out how to preserve co-authorship, it is up to @stevegt and @kvid to decide who will implement the proposed changes... in @kvid's case he would have to submit a new PR, and I would make sure to credit everyone involved upon merging. Also, I haven't gotten around to testing this PR myself, so expect some review comments from me as well. Thanks for your contribution! |
There's one request that I would like to note. This can also become a separate PR if so desired. A way to parse the |
I agree with this request, but I suggest raising it as a new issue to avoid delaying this PR even more. As @formatc1702 wants to squash this PR, then these issues are remaining:
@stevegt do you want to do this soon, or do you want e.g. me to finish the task? |
👍 Will probably implement this (auto-parsing |
Closed as part of #196. |