Skip to content
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

Large scale refactoring #251

Open
wants to merge 111 commits into
base: dev
Choose a base branch
from
Open

Large scale refactoring #251

wants to merge 111 commits into from

Conversation

formatc1702
Copy link
Collaborator

@formatc1702 formatc1702 commented Oct 20, 2021

This is a project wide refactoring effort.
I have decided to address it as one large chunk because the fundamental structure of the code needs to be rebuilt at once for this to work.

Goals:

  • Shorter, more atomic functions
  • Shallower indentation
  • More object-oriented (HTML tags, pins, wires, mates, colors, ...)
  • Less hand-crafted HTML, fewer hacky tricks
  • Less convoluted code
  • Less code repetition

Issues being addressed/solved:

A better description will follow once the code is presentable.
I am sharing the work in progress for transparency's sake.

@formatc1702 formatc1702 self-assigned this Oct 20, 2021
@formatc1702 formatc1702 added the WIP Work in progress label Oct 21, 2021
@formatc1702 formatc1702 force-pushed the refactor/big-refactor branch 7 times, most recently from b3fd091 to b45d0ae Compare October 22, 2021 16:22
@amotl
Copy link
Member

amotl commented Oct 22, 2021

Dear Daniel,

I just wanted to drop you a line that I appreciate your efforts on this task very much.

With kind regards,
Andreas.

@formatc1702
Copy link
Collaborator Author

formatc1702 commented Aug 5, 2022

I have resumed work on the refactoring after a longer period of inactivity. and I would like to propose a course of action to get the bulk of this code integrated into dev, and return to incremental improvements through smaller PRs.

Thank you for your patience and understanding.

@kvid
Copy link
Collaborator

kvid commented Aug 8, 2022

@formatc1702 wrote:

I have resumed work on the refactoring after a longer period of inactivity. and I would like to propose a course of action to get the bulk of this code integrated into dev, and return to incremental improvements through smaller PRs.

  • @kvid if you have time, please check that there are no glaring errors when building the example/tutorial files, regarding the graphical output and the BOM.

I'd be happy to do that, but the installation failes as described in #287.

  • Even if the examples build without errors, the code will probably be rough around the edges. Nevertheless, I would then like to merge this PR into dev to make it "visible" to the larger group of contributors. And, importantly, this will take a big mental load off of me to know we are back to working in manageable chunks 😺

I agree this sounds like a wise decision.

OK

@formatc1702
Copy link
Collaborator Author

One thing I still want to add is updated documentation / changelog. And I might rearrange some code blocks to make more sense.. but no further actual development.

@kvid
Copy link
Collaborator

kvid commented Aug 13, 2022

I've not yet had time to test all new code, but I list here a few issues I've noticed so far:

  • The code building examples still use the .bom.tsv extension. I suggest we use a common tuple of supported extensions that also can be available for applications using WireViz as a library.
  • I don't like that I now must run wv_cli.py from the command line instead of the much more intuitive wireviz.py.
  • It seems the GV HTML are generated differently now, and I can see some more attributes are generated. We should perhaps create a test case with bgcolor declared in all possible ways to verify that the intended logic with default values inherited from the more general level still holds, etc.

@formatc1702
Copy link
Collaborator Author

formatc1702 commented Aug 13, 2022

  • I don't like that I now must run wv_cli.py from the command line instead of the much more intuitive wireviz.py.

The idea is that wireviz.py contains the core parsing and output functions (both file and return type), and it's what you would import when using WireViz as a module.
wv_cli.py splits off the CLI handling. In practice, users would not call python3 wv_cli.py, but simply invoke wireviz directly using the entry point after installing with pip. This is also how the usage is described now in the Readme.

I agree that testing bgcolor etc. is a good idea, since it's not in the current examples and I haven't used it much myself.

@amotl
Copy link
Member

amotl commented Oct 13, 2022

The idea is that wireviz.py contains the core parsing and output functions (both file and return type), and it's what you would import when using WireViz as a module. On the other hand, wv_cli.py splits off the CLI handling, and gets materialized as wireviz program using a console script entry point, when installing the package with pip.

I like it!

@kvid: I don't know if it's in the documentation yet, but the recommended way to "install" that entrypoint, while in development/sandbox mode, is to invoke pip install --editable=. in the repository root directory, where your setup.py, setup.cfg, or pyproject.toml resides.

This will run the installation process in development mode (what was python setup.py develop up until recently) and will link the defined entrypoints with your local working tree, so you can run wireviz and invoke the code you are currently editing. It is always recommended to do all of that within a Python virtualenv, but I am sure I am telling no news here.

Edit: I see that [1] may be a bit thin. Let me replicate a full sandbox installation example here if you don't mind:

git clone https://github.com/formatc1702/WireViz --branch=refactor/big-refactor
cd WireViz
python3 -m venv .venv
source .venv/bin/activate
pip install --editable=.
wireviz --version
WireViz 0.4-dev

[1] https://github.com/formatc1702/WireViz/blob/master/docs/README.md#installing-the-development-version

Allow absent "prefix" in group entries to simplify the code
@kvid
Copy link
Collaborator

kvid commented Sep 13, 2023

I pushed yesterday a couple of commits I'm using to:

  • Correct .tsv filename references to match the rename earlier in this PR. I reported parts of this earlier in Large scale refactoring #251 (comment).
  • Include extra YAML input files when building examples - to detect errors and for verifying the code after rebasing.

I'm currently investigating some strange generated HTML.

@formatc1702
Copy link
Collaborator Author

I think the biggest issues that should probably remain inside the scope of this PR (based on a project-wide search for TODO) are:

  • Part number strings in gv_additional_component_table(), create_graph()
  • Handling additional components in _add_to_internal_bom()(see TODO there, I can't recall why bundles require a special treatment)
  • BOM hash for bundles in bom_hash()
  • The above-mentioned packaging flaw

Overall I agree with @amotl 's and @kvid 's assessments. All other TODOs can become separate PRs

Bug: 0x112233:0x445566 in YAML input didn't convert such colors
to #112233:#445566 and the strings where just passed as uppercase
to the .gv file. Hence Graphviz printed warnings about unknown
colors and used black as color instead.

Add test for int as string. Re-ordered if statements to give an
exception when a color has an unknown type.
Comment on lines +188 to +189
amount: Optional[NumberAndUnit] = None
sum_amounts_in_bom: bool = True
Copy link
Collaborator

@kvid kvid Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me how to use amount and sum_amounts_in_bom. They are not mentioned in syntax.md and not used in any example/tutorial/test harness. I hope @formatc1702 can provide some examples.

If these and qty are not supported in the Connector class, why are they all defined in this common superclass?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the confusion. It stems from a wish to be able to specify how to handle lengths in the BOM.

Example:
A harness contains two identical cables of 1m each, another cable of same type but 5m, and two bundles of four identical wires of 1m each.

  1. sum_amounts_in_bom = True would show the BOM requiring 7m of cable + 8m of wire
    (that is the current behavior)
  2. sum_amounts_in_bom = False would show the BOM requiring 2 pcs. of cable (1m) + 1 pcs. of cable (5m) + 8 pcs. of wire (1m)

In a workflow where the person asssembling the harness is expecting to cut the cables themselves, option 1 is fine. If they are expecting to receive all cables/wires cut to length, option 2 is the way to go.

Another typical example is heatshrink: If there is a connector that requires 10mm of heatshrink on each of its 15 pins, and 30mm of the same heatshrink on the shield, the BOM could show either

  1. 180mm of heatshrink, or
  2. 15 pcs. of 10mm heatshrink + 1 pc. of 30mm heatshrink, which is much more understandable in context.

This is where the amount property comes in. The heatshrink would be defined as an additional component with qty: 15 and amount: 10 mm, and a separate additional component would have qty: 1 and amount: 30 mm.

If these and qty are not supported in the Connector class, why are they all defined in this common superclass?

Because they are also intended for use with AdditionalComponent, as in the heatshrink example.

src/wireviz/wv_dataclasses.py Outdated Show resolved Hide resolved
src/wireviz/wv_dataclasses.py Outdated Show resolved Hide resolved
src/wireviz/wv_dataclasses.py Outdated Show resolved Hide resolved
src/wireviz/wv_dataclasses.py Outdated Show resolved Hide resolved
src/wireviz/wv_dataclasses.py Outdated Show resolved Hide resolved
src/wireviz/wv_dataclasses.py Outdated Show resolved Hide resolved
.github/workflows/main.yml Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants