Improve script and test output. Build using pyproject.tml with setuptools_scm#92
Improve script and test output. Build using pyproject.tml with setuptools_scm#92MichaelClerx merged 24 commits intomainfrom
Conversation
|
Missing nice docstrings on the new functions |
|
Not tested on Mac. But I think the subprocess git call should work. I suppose this means that command-line git is a requirement. |
MichaelClerx
left a comment
There was a problem hiding this comment.
I would have thought a version number should do?
E.g. some variables somewhere version_str and release=False or similar. Don't need to mix git hashes in, do we? I'd want people using it seriously to use a released version, not the github one?
|
Yeah, it should do if people are using the actual releases. But it might be useful for us if we're using it constantly between releases. The only downside I can see is possible portability issues if people don't have git. So maybe we just need to handle that case. Another thing we could do is check for uncommitted changes with git diff-index and add "clean" or "dirty" to the commit hash |
|
I really don't think we should be sending people data processed by software that has uncommitted changes! |
|
Yes, you're right. I'm mostly thinking of the files I have on my own computer. If I have a fully processed dataset sat somewhere for a while, it's nice to know exactly what code was used to produce it - even if I only want pull up a graph or two for my own purposes. I feel like we should include all of this information in the file in case it's useful. I don't see what we'd gain by leaving it out. If we don't want to anyone to receive data from uncommitted changes, then it's probably a good thing to be able to see if a clean/dirty worktree was used. I see this as a sort of safe guard to someone messing up and using the wrong branch or something. The original issue asked for a git hash, but we can leave it out if everyone thinks it's unnecessary. |
|
We'd gain easier to maintain code that doesn't rely on subprocess calls to I realise it asks for a commit hash in the original issue, but I don't think that was a good idea. I think we could quite easily get what we need by having it output either the version number (for released versions), or an all-bets-are-off warning message if the |
|
We can handle the cases where git's missing. Thinking about this again, the biggest problem is probably that the git history isn't necessarily available when it's installed through PyPI/pip. Also, this code will won't return the right git hash when pcpostprocess is imported into a different module. |
|
OK This is looking better and I like having a dev dependency rather than a user dependency! But what's the rationale for the directory builder stuff? Why make the test output go somewhere else with every commit? |
It's supposed to go to the same place. It's just the content of the pcpostprocess_info.txt that changes. The rational is to ensure that any generated output has version information and other relevant details (commands, data/time, etc..). Each script also has a unique subdirectory name so they won't overwrite each other if the user runs two scripts pointing at the same output directory |
|
But why are you doing that in test_herg_qc, test_leak_correct, and test_subtraction_plots? |
|
I don't want them to generate any output, to be honest |
|
It's a convenient way to generate some example plots and to manually check that nothing is broken with them. I think it's important to run fig.savefig() because some matplotlib errors only come up when you try to actually save the plot. If we don't want to save it permanently, we can use tempfile to not create any output (depending on a flag maybe). @mirams and @frankiepe were looking at these test-generated plots the other day, so might be worth keeping them. |
|
It is nice to have a test to generate plots, I used it recently because I wanted to edit the style of everyone's plots a bit. I don't mind too much if that is uncommenting a |
|
OK two points here:
|
Could do. But I think it might be simpler to pass in an environment variable or command line argument to turn on output generation. Seems like the command-line arg approach is possible with pytest but is a bit more involved with unittest.
I think the current code doesn't output to a new location. I had some UUID things in where I had copied it over from a previous project, but I took them out (I hope I did anyway!). |
|
You don't actually need to go through the unittest or pytest modules at all! See e.g. this example we use this in Myokit and PINTS all the time. Usually the code is just but as shown in this example you can do all sorts of things like enabling plotting/debugging, messing with logging etc. |
|
|
||
| plot_dir = "test_output" | ||
| os.makedirs(plot_dir, exist_ok=True) | ||
| plot_dir = directory_builder.setup_output_directory("test_output", |
There was a problem hiding this comment.
These lines, @joeyshuttleworth ! If the above works just as well, then let's stick with that! No need to make the tests use a function only the scripts use. The less stuff to untangle the better
|
|
||
| if not os.path.exists(self.output_dir): | ||
| os.makedirs(self.output_dir) | ||
| self.output_dir = directory_builder.setup_output_directory("test_output", |
|
Yeah, we could run the tests like that. But you would lose the convenience of running everything using pytest or unittest. Removing the directory_builder code from the tests is good practice because it uncouples them, so we should do that. |
Nonono, for individual tests you don't go through unittest |
|
So if you want to run all tests locally, or in actions, you do e.g. But if you want to run a single test, you don't have to do or whatever the syntax is, you can just do which also uses unittest, internally, but lets you just add any command line args or anything you want without having to do a deep dive into the unittest framework |
|
Yeah, that's nice but if you use pytest you can get it to output everything at once which is convenient. Otherwise you have to run every test manually |
MichaelClerx
left a comment
There was a problem hiding this comment.
Thanks @joeyshuttleworth , looks good
Description
Move build system over to a pyproject.toml file. https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#writing-pyproject-toml
Adds a new submodule for generating output directories,
directory_builder. This function also creates a "pcpostprocess_info.txt" file which lists the date/time run, pcpostprocess version info and the relevant git commit. This is now used in all scripts and tests (addresses issue #63.). This is handled through setuptools-scm using the new pyproject.toml.Also tidy up some of the output from run_herg_qc:
Types of changes
Testing
Documentation checklist