pyinvoke/invoke — pull request #92 by Ivoz (2013-10-22 05:48:23+00:00)
Title: [WIP] Simplify loader functionality

I looked into issue #91

Firstly, updating `releases` to v0.2.4 might fix the broken python 3.2 test on travis for pull #88.

From there I looked at the loader code. It seems the loader's use of sys.path may be causing the user's issue. Although I haven't worked with invoke that much, I don't see a tempting use case for needing to load a `tasks.py` that is on the sys.path somehow, that wasn't somewhere else already. Moreover, this loader modifies the sys.path.

Since the loader is a very simple class, with only three methods that really only call eacho ther sequentially, I thought this could be refactored out. You don't really need a class for this.

I added the code to the `Collections` class as a class method. I also implemented searching in parent directories, using `_parent_dirs()`. `sys.path` is no longer implicitly modified. The code thought that `name` could use being configurable, so I thought a rudimentary mechanism to allow for this could be as a class variable on Collection (`default_module_name`). Finally, the new class method `load_collection()` now closes the file returned by `find_module()` as recommended.

I haven't reimplemented tests yet as they need to be redesigned to accommodate for the api change.

I thought maybe you'd like to review the changes, and if you like the design please say so and I will add commits adding tests for this.

Cheers