-
Notifications
You must be signed in to change notification settings - Fork 2
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
Make default plot directory customizable #5
Comments
I would propose a combination of 1 and 2. We have a configuration option for the directory. This can just be a simple string (this is option 1 above). However, we could also let this be some sort of template string, where you could for example put Overall, I think this balances simplicity and customizability fairly well. Do people agree with this general approach? Of course, we can have discussions about the actual syntax for specifying template values in the string (perhaps we want something more jinja-like with double curly braces The other option (that could either be used with the above, or as an alternative), is to allow users to provide a python function that returns the directory name. This would allow it to be even more customizable (for example, having directories based on fixture, which we used in nengo to group things both by simulator and by neuron type). This option didn't seem to have too much traction in our brief discussion this morning, though. An alternative would be to extend the templating approach to allow arbitrary python code in the template, so you could do something like ``plots.{{request.getfixturevalue('nl').name}}` to put the nonlinearity in the directory name, for example. However, if we really want this kind of power, I think we'd be better served by just allowing arbitrary python functions; it'd be easier to implement and use, and more powerful. |
I like the idea of having some way to template it, though I think it should be pretty restricted as I think this will be one of those things that 0.01% of users will use. So, the Python function for example seems like a difficult thing to implement correctly and maintain, and isn't worth it gives how few users I suspect will want it. Some restricted templating in pytest config options sort of has precedent with log format messages; unfortunately, that's caused a few issues and resulted in pytest kind of giving up on using |
Thinking about this a bit more, it's not clear how to do templating in a way that would actually be useful. My inspiration was what we do in nengo: https://github.com/nengo/nengo/blob/36070176f05da29ee896f27917a470d83e7d87c5/nengo/conftest.py#L101 To achieve something like that, though, we'd need a lot of control over how to format each template value. In that example, we use each fixture's Personally, I think a Python function is a lot easier to support than a complex templating system, since for that we don't have to build anything (users just have to be familiar with pytest's API to get what they need and return the appropriate string). So I would vote either to either allow Python functions only (instead of the templating system), or to only allow strings in the .ini file (in which case, you'd be setting a fixed default that would be used if no other directory name is specified by the |
Of those two options, I would vote for only allowing strings, as I think that'll cover 99% of the use cases anyway. Partly I lean that way because I'm not sure how the Python function approach would work. Are you exposing a new pytest hook that people can override? If not, how do people know what function to write, what it takes in and what it returns? |
There's two ways I would do it. One is just basically monkeypatching. So in def dirname(request):
return "ourdefaultdirname"
def set_dirname_function(fn):
Plotter.dirname_function = fn
class Plotter:
dirname_function = dirname then in their The other option would be to have a def make_plt_fixture(dirname_fn):
@pytest.fixture
def plt(request):
# do some stuff to return a Plotter using the dirname_fn then in their |
The monkeypatching could work, it relies a lot on documentation but since very few will want to do it anyway seems like no harm to make it possible to patch if people want to (we can even expose a function that does the monkeypatch so people don't need to know about the I don't think the |
Done in #13; the monkeypatching approach was also attempted in the directory-formatter branch if we decide to revisit that idea. |
Currently, if you do not pass a string to
--plots
, the default directory that plots will be placed in is calledplots
. In Nengo core we had some automated ways of setting this directory (using theSimulator
fixture), but since this needs to work for any repository, we can't expect aSimulator
fixture to exist.A few ways we could think about automating the name of this directory:
setup.cfg
/pytest.ini
file that sets the default plot directory name for a given project.--target loihi
you get a different default plot directory name than if you pass in--target sim
).The text was updated successfully, but these errors were encountered: