Skip to content
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

put easyblocks in easybuild.easyblocks namespace #87

Merged
merged 5 commits into from
Aug 24, 2012

Conversation

JensTimmerman
Copy link
Contributor

Currently easyblocks are in the easybuild.easyblocks.a-z namespace, let's move this all up.
We can keep the directory structure, just define them in the correct namespace.

@ghost ghost assigned JensTimmerman Aug 17, 2012
@boegel
Copy link
Member

boegel commented Aug 17, 2012

Just as a side-note: we're considering this change because then others are free to use a different scheme for organizing their easyblocks, just as long as they also use the easybuild.easyblocks namespace we're aiming at.

@JensTimmerman
Copy link
Contributor Author

I'm trying to come up with a straightforward solution here, but there doesn't seem to be a quick answer:
http://stackoverflow.com/questions/12040689/add-a-subdirectory-to-a-python-namespace/12051794

@JensTimmerman
Copy link
Contributor Author

Ok, it is simpler then thought:
adding this in __init__.py does the trick:

__path__.extend([os.path.join(__path__[0],chr(y)) for y in range(ord('a'),ord('z')+1) + [ord('0')]  ])

but learnt me some great python hacks on the way.

@fgeorgatos
Copy link
Collaborator

good point; now for generality I suggest the following:

__path__.extend([os.path.join(__path__[0],chr(y)) for y in range(ord('a'),ord('z')+1) + range(ord('0'),ord('9')+1) + [ord('_')] ])

ie. the funny underscore directory will hold the more funny things in it, and all dirs are mapping nicely to directory:
encode_string(name).lower()[0]

enjoy,
Fotis

@boegel
Copy link
Member

boegel commented Aug 21, 2012

@fgeorgatos: We use the 0 subdirectory as a catch all, it also implemented in EasyBuild that way (everything that doesn't start with a letter in being looked for in the 0 subdir).

@JensTimmerman: Nice solution after all the screwing around we did this afternoon. :D

@fgeorgatos
Copy link
Collaborator

Hi there,

indeed this is better practice: "use the 0 subdirectory as a catch all" and I didn't realize that the python oneliner I supplied isn't up to the task: only Jens solution gets both the elegance and the result ;-)

@JensTimmerman
Copy link
Contributor Author

Please review pull request.

@@ -22,3 +22,8 @@
# You should have received a copy of the GNU General Public License
# along with EasyBuild. If not, see <http://www.gnu.org/licenses/>.
##
import os
from pkgutil import extend_path

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You really need to add documentation here, describing what this does, and how it works.

Maybe also information on how to change this if you're using a different directory structure to organize the easyblocks in.

Is there a way to make this more generic, so that it works no matter what the easyblocks subdirs are? E.g. use os.listdir, and extend _path_ with that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.listdir might add a big overhead.
There is no need to be generic here, since we know what we are doing, other people using a different scheme will also know what it is.

I suspect people will want to either use one directory, or adopt our a-z + 0 scheme.
I'll add a short description of why we do this + an explenation to the FAQ about this.

@JensTimmerman
Copy link
Contributor Author

updated application.py + processed remarks.

# Extend path so python finds our easyblocks in the subdirectories where they are located
__path__.extend([os.path.join(__path__[0],chr(y)) for y in range(ord('a'),ord('z')+1) + [ord('0')] ])
# And let python know this is not the only place to look for them,
# so we can have 2 easybuild/easyblock paths in your pythonpath, one for public, one for private easyblocks.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change '2' to 'multiple', I don't think this limits it to just too, you can have dozens if you want to.

 We will just try to import the easyblock when none is defined, if this fails, fall back to application.
 Since we can't know where the easyblock is actually located, it could be anywhere in __path__
 So let python figure this out.
@JensTimmerman
Copy link
Contributor Author

Building trilinos works.

boegel added a commit that referenced this pull request Aug 24, 2012
put easyblocks in easybuild.easyblocks namespace
@boegel boegel merged commit 8be1ec0 into easybuilders:develop Aug 24, 2012
This was referenced Aug 25, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants