Martin
Thanks.
My question was all around how to test for an empty tag and update it - 
your code does this with

(tagset or set()) | set((tagged,))

I tried to do a logic test on if tagset == None:   and also  if tagset == 
set():    but neither seemed to work.
I was going to do

if tagset == None:
   tagset = set(tagged,)
else:
   tagset = tagset | set (tagged,)

But failed. So I wondered what you had as your 'empty set'. I'll have a 
look for EMPTY_SET.

Not sure if my adaptation of your example is of use to anyone.

Regards
Paul


On Saturday, 18 February 2017 14:47:16 UTC, Martin Blais wrote:

> entry.tags is supposed to be a set.
> If not set, an empty set.
> I reuse a constant in the codebase (see EMPTY_SET).
>
> TBH I'm not 100% sure what your question is.
>
>
>
>
> On Sat, Feb 18, 2017 at 5:04 AM, <[email protected] <javascript:>> 
> wrote:
>
>> Now it works. 
>> This can flag cash accounts, but is now configurable to flag any 
>> transaction what contains any of the listed accounts.
>>
>> I still don't understand how this works, or what type an empty tag set 
>> is.... (tagset or set()) | set((tagged,))
>>
>> Sample header in journal file:
>>
>> plugin "beancount.plugins.auto_accounts"
>> plugin "tagaccount" "{
>>         'accounts': {
>>               'Assets:Cash:RBS',
>>               'Assets:Cash:MinisFloat',
>>               'Assets:Cash:NatWest' },
>>         'tag': 'cash'
>>   }"
>>
>> Code:
>>
>> """
>>
>> For example, a possible configuration could be:
>>
>> plugin "tagaccount`" "{
>>
>> 'accounts': {
>>
>> 'Assets:Cash:Bank',
>>
>> 'Assets:Cash:Float' },
>>
>> 'tag': 'CASH'
>>
>> }"
>>
>> """
>>
>> __author__ = 'Paul Hamshere'
>>
>> from beancount.core import data
>>
>> from beancount.core import account_types
>>
>> __plugins__ = ['tagaccount']
>>
>> def tagaccount(entries, options_map, config):
>>
>> """
>>
>> Args:
>>
>> entries: a list of entry instances
>>
>> options_map: a dict of options parsed from the file
>>
>> config: A configuration string, which is intended to be a Python dict
>>
>> Returns:
>>
>> A tuple of entries and errors.
>>
>> """
>>
>> # Parse and extract configuration values.
>>
>> config_obj = eval(config, {}, {})
>>
>> if not isinstance(config_obj, dict):
>>
>>      raise RuntimeError("Invalid plugin configuration: should be a single 
>> dict.")
>>
>> accounts = config_obj.pop('accounts', {})
>>
>> tagged = config_obj.pop('tag',{})
>>
>> new_entries = []
>>
>> for entry in entries:
>>
>>      if isinstance(entry, data.Transaction):
>>
>>          orig_entry = entry
>>
>>          for posting in entry.postings:
>>
>>               if (posting.account in accounts):
>>
>>                     tagset = entry.tags
>>
>>                     tagset = (tagset or set()) | set((tagged,))
>>
>>                     entry = entry._replace(tags=tagset)
>>
>>       new_entries.append(entry)
>>
>> return new_entries, []
>>
>> Code completely adapted from the example plugin.
>> Regards
>> Paul 
>>
>> On Friday, 17 February 2017 19:12:41 UTC, [email protected] wrote:
>>
>>> Oops my error should have put 
>>>
>>> entries = entries._replace.....
>>>
>>> Paul
>>>
>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Beancount" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/beancount/68c72034-53d7-4f1c-91f2-3a66ec32aaab%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/beancount/68c72034-53d7-4f1c-91f2-3a66ec32aaab%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/c6267881-9785-42cb-a568-5bf5e52530e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to