Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mircealungu/77d9b8f5b90deb3a6e1c96f2cefd49e4 to your computer and use it in GitHub Desktop.
Save mircealungu/77d9b8f5b90deb3a6e1c96f2cefd49e4 to your computer and use it in GitHub Desktop.
6,7d5
< roots = sys.path[:]
<
29,31d26
< if os.path.isdir(fileName):
< fileName = fileName.rstrip('/\\') + os.path.sep
<
33c28
< # because of django took advantage of module name
---
> #because of django took advantage of module name
35d29
<
39,48d32
< else:
< path = fileName
< for p in roots:
< # Python 2.6+
< try:
< rel_path = os.path.relpath(fileName, start=p)
< if rel_path.find('..') == -1 and len(rel_path) < len(path):
< path = rel_path
< except:
< pass # relpath can raise an error in case of different drives for a path and start on Windows
50,55c34
< if path.endswith('.py'):
< path = path[0:-3]
<
< moduleName = path.replace('/', '.').replace('\\', '.')
<
< if moduleName in modules and len(sys.argv[1:-1]) == 1: # add unique number to prevent name collisions
---
> if moduleName in modules and len(sys.argv[1:-1]) == 1: # add unique number to prevent name collisions
61d39
<
63,72c41,43
<
< try:
< module = imp.load_source(moduleName, fileName)
< except SystemError: # probably failed because of the relative imports
< # first we import module with all its parents
< __import__(moduleName)
<
< # then load it by filename to be sure it is the one we need
< module = imp.load_source(moduleName, fileName)
<
---
> if os.path.isdir(fileName):
> fileName = fileName + os.path.sep
> module = imp.load_source(moduleName, fileName)
125,127d95
< if len(sys.argv) == 2: # If folder not provided, we need pretend folder is current
< sys.argv.insert(1, ".")
<
148c116
< if os.path.isdir(a[0]):
---
> if os.path.isdir(a[0]):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment