-
Notifications
You must be signed in to change notification settings - Fork 94
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
build documentation into cylc.flow.cfgspec
modules
#3253
Comments
We can have a single SPEC, but reduce it to the essential Python data structure (or generate the data structure) at deployment/installation time? So the commands only loads the essential stuffs? |
My two cents worth:
If the extra text - quite a lot of it I suppose - does cause a problem, maybe @matthewrmshin's idea is good: at install time, dump a text-stripped version of the SPEC for use at run time. |
I might just have a quick experiment and see what kind of performance hit we get from method (1), if it's too small to care about, just do it? If it becomes a problem later, compile as Matt suggests. |
Might we be able to use a @dataclass
class Specification():
"""Description
Blah blah blady blah blah bla!
"""
meta: CylcMeta()
@dataclass
class CylcMeta():
"""
A multi-line description of the suite. It can be retrieved
at run time with the cylc show command.
"""
description: [VDR.V_STRING, '']
group: [VDR.V_STRING, '']
title: [VDR.V_STRING, '']
URL: [VDR.V_STRING, ''] |
Sounds plausible @wxtim |
Another option might be Python "properties" (a bit ungainly though?):
result:
|
Attribute docstrings rejected years ago: https://www.python.org/dev/peps/pep-0224/ |
PEP 257 Docstring Conventions says:
Does Sphinx support these? |
Sphinx along with some other Python auto-doc systems do support attribute docstrings, but, they do so by implementing their own lightweight Python parsers which is somewhat messy. |
It is a possibility but it would change the way Cylc's config system works. At present the
|
OK so here's a really simple test to see what the impact of those docstrings might be. I took the content of the suite config reference material as plain text and put it in a python file $ /usr/bin/time -v python file.py
User time (seconds): 0.04
System time (seconds): 0.01
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.11
Maximum resident set size (kbytes): 6724 Then compared that to an empty file $ /usr/bin/time -v python blankfile.py
Command being timed: "python blank.py"
User time (seconds): 0.04
System time (seconds): 0.01
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.10
Maximum resident set size (kbytes): 6340 There is a 6724 - 6340 = 384kb increase in memory which isn't great, though this memory does not need to persist for the life of a suite. However, the overheads are pretty small really. |
@oliver-sanders - reading back through this issue we seemed to have agreed on your suggestion number-1., which was adding documentation in the spec dictionary. In light of that, can you explain the rationale for your non-dict POC/suggestion above, here in the issue? |
You managed to reply to a post after I had sneakily deleted it whilst I went back to think some more. Short answer, we need to document both settings and sections and that will break the current dictionary approach. Not quite sure which way I lean ATM, option 3 is actually pretty easy (I've already written the tree node stuff for another purpose, I tried it out with parsec, working) so it's about which is the best solution not which is the easiest. BTW if you fancy messing around with context nodes try this gist: https://gist.github.com/oliver-sanders/6959c41341ed3e4ffca3061ef84b6b9c Option 1 - Dictionaries
SPEC = {
'name': 'suite',
'help': 'Configure a workflow',
'children': [
{
'name': 'scheduling',
'help': 'What and when',
'chilren': [ ... ]
# ^ whoops this typo will cause a hard-to-debug error
}
]
}
# getting configs becomes a total mess
>>> SPEC['children']['scheduling']['children']['initial cycle point']['type']
'V_STRING'
# but we can use a function to get stuff
>>>> getc(SPEC, ['scheduling', 'initial cycle point'])['type']
'V_STRING' Option 2 - Named Tuples
SPEC = {
'scheduling': Section(
help: 'What and When',
children={
'initial cycle point': Setting(type=V_CYCLE_POINT, default=None),
}
)
}
# Still have the children mess
>>> SPEC['scheduling'].children['initial cycle point']['type'] Option 3 - Context Managers
with Conf('suite', help='Configure a workflow') as SPEC:
with Conf('scheduling', help='What and when'):
Conf('initial cycle point', type=V_STRING, default=None)
Conf('final cycle point', type=V_STRING, default=None)
>>> SPEC['scheduling']['dependencies']['initial cycle point'].type
'V_STRING'
>>> SPEC['a']
KeyError
>>> str(SPEC['scheduling'])
'[scheduling]'
>>> str(SPEC['scheduling'].children()])
['[scheduling]initial cycle point', '[scheduling]final cycle point']
>>> SPEC.tree()
[scheduling] # What and when
initial cycle point # V_STRING
final cycle point # V_STRING
[[dependencies]] # Whatever
# Can easily serialise
>>> SPEC_DICT = dict(SPEC)
>>> SPEC_DICT
{
'name': 'suite',
'help': 'Configure a workflow',
'children': [
{
'name': 'scheduling',
'help': 'What and when',
'children': [ ... ]
}
]
}
# That said could easily go the other way too
>>> Conf(SPEC_DICT).tree()
[scheduling] # What and when
initial cycle point # V_STRING
final cycle point # V_STRING
[[dependencies]] # Whatever
# Tree nodes are objects which know their position in the tree so can be passed around the program which could have bonuses.
>>> config.get(SPEC['scheduling']['initial cycle point'])
1234
>>> SPEC['scheduling']['some deprecated setting']
WARNING: making use of deprecated setting
>>> SPEC['scheduling']['some removed setting']
KeyError Other Options
|
Option 3 is pretty damned cool. |
Describe exactly what you would like to see in an upcoming release
Take the configuration documentation out of cylc-doc and write it into the source code so that the documentation can be auto-generated.
See "Auto-Documentation" section of cylc/cylc-doc#11
Tentatively added to the Cylc8 milestone to facilitate suite interface changes. Feel free to bump it back.
Additional context
The global spec must be loaded before pretty much every Cylc command so it is important not to make the
SPEC
s too heavy.Having said that would a little extra text cause problems?
Question/Decision
How should we encorporate documentation?
SPEC
e.g.Pull requests welcome!
The text was updated successfully, but these errors were encountered: