When specifying a requisite and you only need to list a single item you
can specify it without being wraped in a list and we will handle it
automatically. This was being handled when we built our attrs to output
the final data, but this failed when you extended a require requisite
inside of a context manager.
From the Python docs on the exec statement:
> Remember that at module level, globals and locals are the same dictionary.
> If two separate objects are given as globals and locals, the code will be
> executed as if it were embedded in a class definition.
We were providing a specific object for locals and in the specific case
reported in #21796 this caused a very strange name error when used in a
specific way. By removing the explicit locals dictionary and just having the
globals dictionary be shared fixes the issue, and we weren't using the
specific locals anyway.
The problem with using the loaded states (see commit cc8539f) is that
you can end up in situations where a particular state doesn't exist for
whatever reason. This prevents you from building states freely (see
ticket #10918).
The refactor focuses on breaking out the `gen_functions` function into a
number of smaller reusable functions so that pyobjects can load all of
the states and still process `__virtual__()` and `__virtualname__` in a
way that makes sense for building states. After all pyobjects is just
compiling a high state data structure, if a state is available or not
during application time is up to the minion.
As part of this refactor I have also updated all of the inline comments
in the loader to be more consistent with the way things are actually
working now (such as `__virtual__()` returning a string being
deprecated).
There are also some pep8 fixes to the loader file.
Fix#10918
----
This also adds a new feature to pyobjects named `Map`, which allows for
definition of grain dependent data in a pythonic way -- using inner
classes.
----
Lastly this ditches the instance based registry and instead uses a class
based approach like a singleton.
As it stands the following will fail as we didn't allow duplicate IDs
under any circumstances:
with Pkg.installed("nginx"):
Service.running("nginx")
This commit changes the way the StateRegistry stores states to allow the
above example to work properly.
Now it behaves much more closely to the YAML + Jinja renderer.
This is another suggestion from @mgwilliams. It adds an object to the
sls file scope named Salt, which dispatches its attributes to the
__salt__ dictionary.
For example, the following two lines are functionally the same:
ret = Salt.cmd.run(bar)
ret = salt['cmd.run'](bar)