dictation-toolbox / natlinkcore

Other
4 stars 4 forks source link

Use built in string Templating? #45

Open dougransom opened 1 year ago

dougransom commented 1 year ago

Wonder if we can simply some of the natlink.ini dealing with multiple directories with the build in string templating https://docs.python.org/3.10/library/string.html#template-strings

maybe instead of special strings like natlink_userdir you replace, you could use $natlink_userdir?

I just figured out Template strings when working on conftest.py in unimacro tests.

quintijn commented 1 year ago

Hmmm, even more magic coming in? Maybe. I don't immediately see the advantage of a $ sign in such a config file.

Now the magic is restricted to "natlink_userdir" (which should be changed to "natlink_settingdir") (or "natlink_settingsdir"?). and names of packages which can be imported by python (unimacro, vocola2, ...)

Here is my directories section of natlink.ini:

[directories] dragonflyuserdirectory = ~\Documents\DragonflyUser vocoladirectory = vocola2 vocolagrammarsdirectory = natlink_userdir\vocolagrammars unimacrodirectory = unimacro unimacrogrammarsdirectory = unimacro\unimacrogrammars samplegrammars = natlinkcore\SampleMacros

dougransom commented 1 year ago

magic to us maybe, this has been a built in method for string substitution since at least python 2.7. https://docs.python.org/2.7/library/string.html#template-strings

It might simplify the code since the python library would do all the work for substitution. I used this to build a natlink.ini at runtime in https://github.com/dougransom/unimacro/blob/control_grammars/tests/conftest.py.

i am not saying you should change to this approach just that you could.

dougransom commented 1 year ago

vocolagrammarsdirectory = natlink_userdir\vocolagrammars vs vocolagrammarsdirectory = $natlink_userdir\vocolagrammars

the $ makes it clear that this is a substitution. However, I don't think it is terribly important.

quintijn commented 1 year ago

Let us do it with the $ sign. Note we call it now natlink_settingsdir !! I look into it...

quintijn commented 1 year ago

But... if it is a module, natlinkcore or unimacro, we keep it like this?