-
Notifications
You must be signed in to change notification settings - Fork 179
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
Repo fhs restructure #896
Repo fhs restructure #896
Conversation
In adding features to the Python scripts in order to make them compatible with packaging via PyInstaller, much of the library has been shuffled around. Most noticeable difference is that individual functions are no longer defined in their own library file; instead, some semblence of function grouping has been applied. This means that library function calls will typically have 'lib.' and a module name before the function name. For PyInstaller, differences are in scripts/lib/algorithm.py and scripts/algorithm/package.py; getting PyInstaller to pull in an appropriately read from the algorithm files in scripts/src/ is the trickiest part of the process.
Also had to rename lib.message.print to lib.message.console, since PyInstaller didn't like the former.
./build now creates executables in bin/ and stores temporaries in tmp/
and move some scripts over to bin/ to check operation
this post seems relevant for locating the python modules. On that note, I note the current strategy for importing seems pretty cumbersome: from lib.errorMessage import errorMessage
from lib.getHeaderInfo import getHeaderInfo
from lib.getUserPath import getUserPath
from lib.printMessage import printMessage
from lib.warnMessage import warnMessage
from lib.runCommand import runCommand
from lib.runFunction import runFunction Ideally, this should be enough: from mrtrix3 import errorMessage, getHeaderInfo, getUserPath, printMessage, warnMessage, runCommand, runFunction, app, cmdlineParser Any reason why we can't support that kind of setup...? |
Bear in mind that my creating these scripts / library was basically my first Python experience... Had not yet encountered the word "Pythonic". Was probably just a habit I got since (as you know) I like the readability afforded by consistent indentation. P.S. Some of the changes I made in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave it a test run with different configure
settings and it all worked like a charm. Nice work!
W.r.t. the python scripts:
Good, that certainly cleans things up a bit. Personally, I would organise things in fewer modules and use the |
Just another quick note about how python modules should be conceptualised: there's a good discussion on this thread about this. I reckon this particular quote is probably the best way to think about this:
Point being that you're kind of expected to pack a lot more into each python file (which is a module in this context) than you would in C++. |
The changes in Just to be clear:
If the user were to install MRtrix3 to |
- Python library files have been re-arranged: There is no longer one function per file, instead there is some degree of grouping of functionalities into modules. - Various conformations to the FHS restructure: - Scripts now reside in the bin/ directory. - Script libraries now reside in lib/mrtrix3/. - Additional data used by scripts now reside in share/mrtrix3/, in sub-directories according to the script using the data. - The example connectome lookup table files have been moved to share/mrtrix3/labelconvert.
I think there's a slight misunderstanding here... I'll clarify my understanding of how the FHS is supposed to work, sorry if you already know all of this - maybe I'm missing your point here. So the way I understand it, the folder structure on a linux system is organised as a kind of nested hierarchy, with known folders at each level with clear functions. These known folders include
You'll find most of these in the root The idea is that packages get installed directly into one of these trees, not within their own folders. That way, if you install something, there is no change required to your settings, it will already be in your PATH, the libraries will be where the dynamic linker can find them, the man pages (if you have them) will be indexed, etc. So the idea here is that the structure of the repo would match that expectation, so that if users/sysdamins want to install/repackage MRtrix3 that way, it will fit in as expected. What that means is that if the users were to install into |
Good point. As far as I can tell though, it already does, given this line for listing the binaries, and this line for identifying the scripts. Would definitely need amending to match the new locations, but should otherwise work as-is, as far as I can tell...? |
I agree, there's no massive requirement to do this. But there are a few arguments for. It does mean that MRtrix3 will be structured in a way to matches conventions a bit better, which will reduce some of the frustrations from sysadmins and packagers like the one that prompted this discussion. It makes it simpler to package MRtrix3 in a way that matches the way most distros manage packages, and so makes it more likely that users' install match our own. It makes dealing with different configs if anything a little bit less confusing, since the concept is now managed separately from the build itself - at the moment there's a lot of gymnastics to figure out where temporaries and binaries are to be stored, whereas with these changes it's a fixed location. Also, the user-visible changes are actually not that big: the main thing that changes is the location of the binaries, and hence how the PATH is set. And if anything, that PATH will now only need to consist of a single entry rather than the current two ( But as you say:
I also feel that if we do proceed, it's best to have a clear break, and |
Just spent my first child-free evening in months catching up with this thread and #864. If only I had cold beer and popcorn! I'm a fan of the new config selection. I used the old multi-config set up a lot. I like that I now won't have to type the full path to the debug binary when running gdb! I also think the restructure makes sense. I'm in favour of including it in tag_0.3.16. It's already huge enough, has several new commands (and lost a few), new documentation, fixel format and visualisation etc. I agree users are likely to prefer fewer large updates. We will just need to make sure we clearly separate the critical information from the fine details in the announcement. |
Just to amend @jdtournier's comment:
The namespace analogy is spot on, but a module does not have to be a single file. I also think it makes sense to pack a lot more in each module, but you can still distribute the functions and classes over a range of files if you prefer. The way to do that is to arrange the relevant files in a folder and provide a In my mind, there are ultimately only 2 logical modules: one for user-script interaction (argument parsing, error messages, progress bar, etc.) and one for script-mrtrix interaction (running commands, managing temporary files, etc.). I would call these
In addition, such structure would also allow room for possible future additions such as functions to read and write But as I said before, it is a matter of preference and I also appreciate that it may require quite a lot of effort to refactor the code. The above were just my two cents on the matter. The one thing I do feel strongly about is the naming of On a different note:
I also agree with @thijsdhollander here: if we're going to break our user's install once more, we might as well do it now. |
I think my misunderstanding was related to this:
As long as the relative path between different components of MRtrix3 is preserved during 'installation', then the techniques currently employed for locating different components relative to one another will work. I had an image in my head where MRtrix3's Given how quickly this is coming together, and how long 0.3.16 has already been pushed back, and the consensus surrounding it, I reckon we should get it in there. |
Yes, definitely agree it's better for any new future users; I'm more worried about the existing ones who'll need to do some conscious changes to their installation. But it's indeed for the better, so I'm all for the short "pain" now, rather than the stretched-out and frequent one.
It's just a happy (opportunity for) coincidence. 🙂
This will indeed be key to avoiding unneeded (and dramatic) fallout on the forum. I suppose we recommend a fresh install after this? If so, we need to make sure (to communicate clearly that) people also remove their old install and/or PATH entries to the old install. In a weird turn of events, these big changes happening together, may actually have people ending up with 2 installations; both which may come with old and new PATH entries. That would be a bit of a nightmare.
I like this idea, especially with a potential future addition of...
...there could be good scenarios for scripts that just need |
Script redesign
Script refactor and creation of |
…etion.py Also tweaked a few little things, such as removing the regex search for '__debug' and ensuring that scripts now present in bin/ don't get added.
and update the docs to match.
Just merged |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go for it; we'll sort out any residual issues once everything's into tag_0.3.16
and we're all using it.
done. |
👍 perfect, that should help sort out further issues and avoid too much chaos! |
This is a start at making the changes outlined in #864, to get some early feedback on the idea.
So far:
lib/
→core/
bin/
bin/
tmp/
./build
has a newselect
special target to swap between configsbin/
, all oftmp/
,lib/libmrtrix*
, andconfig
) gets moved as-is over to a folder namedbuild.name
.active
to it, so the system know which folder to store the current config into when swapping out.lib/mrtrix3
and sort out the module loading issues that will ensueshare/mrtrix3
and update scripts to matchStill to do:
How it works in practice:
Here's a little sample of what you can do. I recommend you start with a fresh clone on this one:
Check what config you are currently using:
Even though there is no such folder yet. It just assumes if no config is active, you're on the default config...
Do what you need to do as usual:
You run stuff, and your new command falls over (note I'm assuming you've added the
bin/
folder to your PATH here):OK, let's create an assert build and see if that catches anything:
Note that the command remains identical - the new executable is already in the PATH. You fix the bug, now you can go back to the default (release) build:
and so on.
A good thing here is that the command that's failing might be a script, but it might be failing because the executable it invokes is buggy. So with this you can trivially compile an assert build and have the script run with those executables with no further modifications.
Anyway, that's just to give you a flavour of how the idea works. Give it a shot, see what you think...