Use built in string Templating?
dougransom opened this issue · 5 comments
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.
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
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.
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.
Let us do it with the $ sign. Note we call it now natlink_settingsdir !! I look into it...
But... if it is a module, natlinkcore or unimacro, we keep it like this?