summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPJ Eby <distutils-sig@python.org>2005-07-07 01:53:57 +0000
committerPJ Eby <distutils-sig@python.org>2005-07-07 01:53:57 +0000
commit6a241540966aab371e48413a7f8ace8d2257aa6f (patch)
tree77897079baf231bb10faff7544abd1987e7ee2e7
parent2b9b1a6c4914dc5a49253cb4250bcdea6916e629 (diff)
downloadpython-setuptools-git-6a241540966aab371e48413a7f8ace8d2257aa6f.tar.gz
Fix for .py scripts that might be imported (e.g. the "py" library's hideous
'_findpy.py' hack.) --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041084
-rw-r--r--pkg_resources.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/pkg_resources.py b/pkg_resources.py
index 7b047c19..2ba7ba41 100644
--- a/pkg_resources.py
+++ b/pkg_resources.py
@@ -22,7 +22,7 @@ __all__ = [
'InvalidOption', 'Distribution', 'Requirement', 'yield_lines',
'get_importer', 'find_distributions', 'find_on_path', 'register_finder',
'split_sections', 'declare_namespace', 'register_namespace_handler',
- 'safe_name', 'safe_version', 'run_main', 'BINARY_DIST',
+ 'safe_name', 'safe_version', 'run_main', 'BINARY_DIST', 'run_script',
]
import sys, os, zipimport, time, re, imp
@@ -102,15 +102,15 @@ def compatible_platforms(provided,required):
# XXX all the tricky cases go here
return False
-def run_main(dist_spec, script_name):
+def run_script(dist_spec, script_name):
"""Locate distribution `dist_spec` and run its `script_name` script"""
- import __main__
- __main__.__dict__.clear()
- __main__.__dict__.update({'__name__':'__main__'})
- require(dist_spec)[0].metadata.run_script(script_name, __main__.__dict__)
-
-
+ ns = sys._getframe(1).f_globals
+ name = ns['__name__']
+ ns.clear()
+ ns['__name__'] = name
+ require(dist_spec)[0].metadata.run_script(script_name, ns)
+run_main = run_script # backward compatibility