-
Notifications
You must be signed in to change notification settings - Fork 92
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 support for variants of the Value field #150
Conversation
Hi @eeintech ! |
@set-soft I'm a little confused by your proposal, do you mean controlling the format of the For the test part and example, do you want me to add this to the |
Sorry if I wasn't clear @eeintech Your solution only changes the KiCad 6 changes the schematic file format. In the new file format this problem is addressed. Even when KiCad 6 won't support variants, we don't even know if KiCad 7 will do. But the format was designed to support field names like this What I say is why not implementing it in a similar way. I think KiCad 7 will hide the variant part to the user, showing only the filed name when the user selects the I personally think that About the example: I'm just asking if you have any real life example that can be used for tests. Not a regression test for KiBoM, just some schematic to play with the concept. We can create some artificial test case. But most bugs pops up in real life examples ;-) I maintain a tool called KiBot. KiBot can generate BoMs using KiBoM or an internal BoM generator. Today I committed an implementation of what I'm describing: INTI-CMNB/KiBot@986f0c7 I added a very silly regression test to check this is working. The configuration file is: # Example KiBot config file
kibot:
version: 1
variants:
- name: 'production'
comment: 'Production variant'
type: kibom
file_id: '_(production)'
variant: production
- name: 'test'
comment: 'Test variant'
type: kibom
file_id: '_(test)'
variant: test
field_changer: true
field_variant_separator: ':'
outputs:
- name: 'bom_internal'
comment: "Bill of Materials in CSV format"
type: bom
dir: BoM
- name: 'bom_internal_production'
comment: "Bill of Materials in CSV format for production"
type: bom
dir: BoM
options:
variant: production
- name: 'bom_internal_test'
comment: "Bill of Materials in CSV format for test"
type: bom
dir: BoM
options:
variant: test This generates 3 BoM files for the Component R1 is a 1k resistor, but contains a field named
With R1 different than what you get in the
|
@set-soft Totally understood your proposal and really like it! I've just pushed an update which should match your expectation 😃 Here is a test project: test_variants.zip
For For It is a simple but real world use-case which hope satisfy what you had in mind! EDIT: I forgot to mention that KiBOM does not like duplicate entries in the |
… now going through the DNP check (no break)
I was looking at the code and the example. One thing that I'm not really sure is why you need to add another mechanism to exclude components from some variant. I understand that the mechanism you use is the "natural" one when using But KiBoM already has a mechanism for it. Taking the example you sent: R2 and D2 has "PROD=dnp", but KiBoM is designed to use "Config=-PROD". I'm not against having more than one mechanism, but I'm not sure about it enabled by default. Also I got the impression that the code allows using "PROD:XXX=dnp". Again, I'm not saying this is wrong or bad. Just sounds too fuzzy. It would be nice to know what @SchrodingersGat thinks about it. |
@set-soft Thanks for taking a look!
You are right, I'm allowing this behavior because there is a tiny step from
Sounds safe to disable it by default. Do you mind if I add a
I'm going to fix that immediately 👍 |
I'm merging your patches with my fork to check some details. # Check if variants were defined in configuration
try:
variants = pref.pcbConfig
except:
variants = [None] Using it I'm getting I think you can't copy Also: the result of indicating more than one variant in the bom.ini is not the same as indicating the same list in the command line. The command line option uses the variants one by one, the |
Why isn't this a "good thing"? One of my colleagues requested that we always append the variant, but I have to admit this was unintentional.
I was under the impression that a list of variants in the |
Hi @eeintech !
Over than 90% of people doesn't even know about variants. IMHO the options are:
I think @SchrodingersGat should decide what to do. Changing the default behavior is not a good idea, this is what I mean.
Nope. In fact all the code makes reference to if variant_name.lower() in preferences.pcbConfig: The command line option is copied at the beginning of if variant is not None:
preferences.pcbConfig = variant.strip().lower().split(',') Here variant is an argument passed from for variant in variants:
result = writeVariant(input_file, output_dir, output_file, variant, pref) Note that the command line option uses In the The default |
I think this is a good idea. Also note that defining a field named |
I'm personally (strongly) voting for this one, because that way one can control the output name with the variant list from the Regarding how to declare variants, there are two ways:
As explained above, our favorite way reason is the later so this is why I added this piece of code: # Check if variants were defined in configuration
try:
variants = pref.pcbConfig
except:
variants = [None] In current master, it wouldn't load the variants from the
I do not understand this part, do you have examples? Do you mean one can run: python KiBOM_CLI.py -r v01_a,v02_a;v01_b,v02_b "project.xml" . What is the use-case for handling two separators?
Ok great, I'll add this variable in the mix.
This is a useful note, thanks for the reminder 😃 |
Related to a discussion in SchrodingersGat#150
Hi @eeintech !
I tried it in my fork and it works. The only problem is with the name, it doesn't contain the variant. But it works. Note that I applied your patches to my fork, but then I removed this part of the code because it makes the regression tests to fail. This is because a lot of outputs changes their name adding
They take effect, check the I modified one of my regression tests to verify that variants can be selected from the .ini You can try it running: make single_test SINGLE_TEST=test_variants_issue_SG136_production
Yes you can.
The above example will generate two files:
|
I'm commiting a patch to my fork implementing it. Is just an adaptation of your patch: --- a/kibom/__main__.py
+++ b/kibom/__main__.py
@@ -234,7 +234,11 @@ def main():
if args.variant is not None:
variants = args.variant.split(';')
else:
- variants = [None]
+ # Check if variants were defined in configuration
+ if pref.pcbConfig != ['default']:
+ variants = pref.pcbConfig
+ else:
+ variants = [None]
# Generate BOMs for each specified variant
for variant in variants: BTW: here is what KiBot can do with variants: https://inti-cmnb.github.io/kibot_variants_arduprog/ |
@set-soft Holy molly, I just went through the KiBot variant example page you sent, very impressive tool! I did not grasp the power of KiBot the first time around, just looking at the GitHub page. It does look like 100 times better than this little patch for variants, because, in addition to the BOM, it manipulates schematic PDFs, fabrication layer outputs and 3D models too. And that, we would love it ❤️ Now regarding this PR, I'm mostly committed to finish the work started without disrupting any current KiBOM behavior. Let me know if you think of anything else. |
…ariant processing
@set-soft I integrated your change into this PR and added the preference option for enabling this new behavior. Besides the README, does this |
I think updating it is not necesary. Now we need @SchrodingersGat review. |
Awesome 😄 Let's give Oliver some time, he's a busy person! Merry Christmas! |
I found a small missing detail (while incorporating the last changes to my fork). --- a/kibom/preferences.py
+++ b/kibom/preferences.py
@@ -42,6 +42,7 @@ class BomPref:
OPT_DEFAULT_BOARDS = "number_boards"
OPT_DEFAULT_PCBCONFIG = "board_variant"
OPT_CONFIG_FIELD = "fit_field"
+ OPT_COMPLEX_VARIANT = "complex_variant"
OPT_HIDE_HEADERS = "hide_headers"
OPT_HIDE_PCB_INFO = "hide_pcb_info"
OPT_DATASHEET_AS_LINK = "datasheet_as_link" # (#112)
@@ -70,6 +71,7 @@ class BomPref:
self.hidePcbInfo = False
self.configField = "Config" # Default field used for part fitting config
self.pcbConfig = ["default"]
+ self.complexVariant = False # To enable complex variant processing
self.refSeparator = " "
self.backup = "%O.tmp" # If no .INI file is provided we create *.tmp back-ups
@@ -172,6 +174,7 @@ class BomPref:
self.hideHeaders = self.checkOption(self.OPT_HIDE_HEADERS, default=False)
self.hidePcbInfo = self.checkOption(self.OPT_HIDE_PCB_INFO, default=False)
self.configField = self.checkStr(self.OPT_CONFIG_FIELD, default=self.configField).lower()
+ self.complexVariant = self.checkOption(self.OPT_COMPLEX_VARIANT, default=False)
self.boards = self.checkInt(self.OPT_DEFAULT_BOARDS, default=1)
self.refSeparator = self.checkStr(self.OPT_REF_SEPARATOR, default=self.refSeparator).strip("\'\"")
self.pcbConfig = self.checkStr(self.OPT_DEFAULT_PCBCONFIG, default=self.pcbConfig[0])
@@ -269,6 +272,7 @@ class BomPref:
cf.set(self.SECTION_GENERAL, '; Default PCB variant if none given on CLI with -r')
cf.set(self.SECTION_GENERAL, self.OPT_DEFAULT_PCBCONFIG, ','.join(self.pcbConfig))
+ self.addOption(cf, self.OPT_COMPLEX_VARIANT, self.complexVariant, comment="If '{opt}' option is set to 1, the complex variant field processing is enabled".format(opt=self.OPT_COMPLEX_VARIANT))
self.addOption(cf, self.OPT_HIDE_HEADERS, self.hideHeaders, comment="If '{opt}' option is set to 1, column headers aren't included in the output file".format(opt=self.OPT_HIDE_HEADERS))
self.addOption(cf, self.OPT_HIDE_PCB_INFO, self.hidePcbInfo, comment="If '{opt}' option is set to 1, PCB info isn't included in the output file".format(opt=self.OPT_HIDE_PCB_INFO)) Merry Christmas! |
@set-soft Sorry for the late response, I've just added the missing piece 😃 Happy new year! |
Seems like the Travis build passed but GitHub hasn't updated the status... |
@SchrodingersGat Green light on my side! @set-soft Is there any chance KiBot can get the same feature for variant management? You mentioned it earlier, not sure if you actually pulled it to master. My question is: can schematic PDF also be showing different component values depending on the variant? |
Current KiBOM code supports loading/unloading a part depending on the exported variant.
However, it does not support changing the value of
Value
field to support different component values in different variants.This is a straight forward implementation to handle this, so no hurt feeling if you see potential flaws 😄
Happy to resolve feedback as necessary.