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

Implements tomlkit in place of toml dependency #372

Closed

Conversation

LexiconCode
Copy link
Member

@LexiconCode LexiconCode commented Jan 18, 2019

A work in progress is not ready for testing.

Fixes non-ASCII characters in clipboard
#357

Implements sorting keys
#323

@LexiconCode LexiconCode added Bug Unexpected behavior from existing features. Enhancement Enhancement of an existing feature WIP An work in progress labels Jan 18, 2019
@comodoro
Copy link
Contributor

from tomlkit import dumps, parse, not parser, according to docs. Sorry I have no time to try it, going to hospital Monday.

@LexiconCode
Copy link
Member Author

Oh my goodness. Not a problem. Yep that's probably the issue small typo on my part.

@LexiconCode LexiconCode self-assigned this Jan 18, 2019
@LexiconCode
Copy link
Member Author

LexiconCode commented Jan 19, 2019

Error loading _caster from "C:\NatLink\NatLink\MacroSystem\_caster.py"
Traceback (most recent call last):
  File "C:\NatLink\NatLink\MacroSystem\core\natlinkmain.py", line 331, in loadFile
    imp.load_module(modName,fndFile,fndName,fndDesc)
  File "C:\NatLink\NatLink\MacroSystem\_caster.py", line 168, in <module>
    _NEXUS.merger.merge(MergeInf.BOOT)
  File "C:\NatLink\NatLink\MacroSystem\caster\lib\dfplus\merge\ccrmerger.py", line 352, in merge
    self._add_grammar(base, True, negation_context)
  File "C:\NatLink\NatLink\MacroSystem\caster\lib\dfplus\merge\ccrmerger.py", line 215, in _add_grammar
    repeater = self._create_repeat_rule(rule)
  File "C:\NatLink\NatLink\MacroSystem\caster\lib\dfplus\merge\ccrmerger.py", line 402, in _create_repeat_rule
    sequence = Repetition(single_action, min=1, max=max, name=SEQ)
  File "C:\Python27\lib\site-packages\dragonfly\grammar\elements_basic.py", line 555, in __init__
    assert max is None or isinstance(max, int)
AssertionError

So a bit of debugging on this aspect. It appears that there's differences between tomlkit api and json/toml read keys.

"caster\lib\dfplus\merge\ccrmerger.py", line 401
max = settings.SETTINGS["miscellaneous"]["max_ccr_repetitions"]
print type(max)# <class 'tomlkit.items.Integer'> vs expected <type 'int'>

@LexiconCode
Copy link
Member Author

LexiconCode commented Jan 24, 2019

It appears that tomlkit has special types for (String, Integer, Float, Bool, etc.) hence the differences between <class 'tomlkit.items.Integer'> vs expected <type 'int'>. unlike the previous toml Implementation.

That being said I think that tomlkit maybe only for editing and creating toml documentation not
in code. It would be helpful if someone could give a second opinion on that.

@LexiconCode LexiconCode added Will Not Fix or Implement The issue will not be Fixed or Implemented at this time. and removed Bug Unexpected behavior from existing features. Enhancement Enhancement of an existing feature WIP An work in progress labels Mar 11, 2019
@LexiconCode LexiconCode deleted the sorted_settings branch April 27, 2019 02:17
@comodoro
Copy link
Contributor

@LexiconCode Where did you get that exception? I am trying to just change the import and have not noticed any problems yet. Could you please, eventually, try version 0.5.5?

@comodoro
Copy link
Contributor

(I am revisiting this because I am realizing English also suffers from incorrect toml saving, albeit just slightly, with loanwords)

@LexiconCode
Copy link
Member Author

LexiconCode commented Aug 10, 2019

That's great news, I'll look into it soon. As for the exception it was triggered simply after changing all the imports. It was a while back so I don't remember the specifics.

@LexiconCode
Copy link
Member Author

(I am revisiting this because I am realizing English also suffers from incorrect toml saving, albeit just slightly, with loanwords)

I'll be looking into this issue next!

@LexiconCode
Copy link
Member Author

LexiconCode commented Aug 13, 2019

@LexiconCode Where did you get that exception? I am trying to just change the import and have not noticed any problems yet. Could you please, eventually, try version 0.5.5?

@comodoro I've created a branch with the changes. The following error happens during startup.

Caster User Directory: C:\Users\Laptop\.caster
Caster: dragonfly is up-to-date
Error loading _caster from C:\Users\Laptop\Documents\Caster\_caster.py
Traceback (most recent call last):
  File "C:\NatLink\NatLink\MacroSystem\core\natlinkmain.py", line 331, in loadFile
    imp.load_module(modName,fndFile,fndName,fndDesc)
  File "C:\Users\Laptop\Documents\Caster\_caster.py", line 49, in <module>
    _NEXUS.merger.merge(MergeInf.BOOT)
  File "C:\Users\Laptop\Documents\Caster\castervoice\lib\dfplus\merge\ccrmerger.py", line 371, in merge
    self._add_grammar(base, True, negation_context)
  File "C:\Users\Laptop\Documents\Caster\castervoice\lib\dfplus\merge\ccrmerger.py", line 223, in _add_grammar
    repeater = self._create_repeat_rule(rule)
  File "C:\Users\Laptop\Documents\Caster\castervoice\lib\dfplus\merge\ccrmerger.py", line 425, in _create_repeat_rule
    sequence = Repetition(single_action, min=1, max=max, name=SEQ)
  File "C:\Python27\lib\site-packages\dragonfly\grammar\elements_basic.py", line 564, in __init__
    assert max is None or isinstance(max, int)
AssertionError

@LexiconCode
Copy link
Member Author

So a bit of debugging on this aspect. It appears that there's differences between tomlkit api and json/toml read keys.

"caster\lib\dfplus\merge\ccrmerger.py", line 401
max = settings.SETTINGS["miscellaneous"]["max_ccr_repetitions"]
print type(max)# <class 'tomlkit.items.Integer'> vs expected <type 'int'>

Function to convert everything to plain old python objects
python-poetry/tomlkit#43

@LexiconCode
Copy link
Member Author

LexiconCode commented Aug 13, 2019

@comodoro With tomlkit if user directory is deleted then caster loads fine the first time. the 2nd load the assertion error appears.

@comodoro
Copy link
Contributor

Oops, I had not actually changed it in settings, sorry. Your link actually solves it - the value property, Dragonfly is a bit overzealous in type checking in this case, but the remedy is quite straightforward

@comodoro
Copy link
Contributor

dictation-toolbox/dragonfly#125 (value uses long)

@LexiconCode
Copy link
Member Author

@comodoro can you give an example of how the value method would be used in loading toml?

@comodoro
Copy link
Contributor

Just using it on the loaded dictionary:

data = tomlkit.loads(toml_file.read()).value

Only right now Dragonfly expects int where tomlkit returns long (the exception above). I hope there are no more problems, at least I have not encountered any.

@LexiconCode
Copy link
Member Author

Just using it on the loaded dictionary:

data = tomlkit.loads(toml_file.read()).value

Only right now Dragonfly expects int where tomlkit returns long (the exception above). I hope there are no more problems, at least I have not encountered any.

Alright thanks for that! Indeed does work. I will make a new pull request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Will Not Fix or Implement The issue will not be Fixed or Implemented at this time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants