diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2015-01-20 20:33:29 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2015-01-20 20:33:29 -0500 |
commit | ad794c2809cc2ad0a48a14129dca82996f14af28 (patch) | |
tree | 7ae598eb9d2e3620259e7c9b71af7e22f78d0c10 /setuptools/command/easy_install.py | |
parent | c279903336c73f74c9c8df7aac1e43fb6046c34e (diff) | |
download | external_python_setuptools-ad794c2809cc2ad0a48a14129dca82996f14af28.tar.gz external_python_setuptools-ad794c2809cc2ad0a48a14129dca82996f14af28.tar.bz2 external_python_setuptools-ad794c2809cc2ad0a48a14129dca82996f14af28.zip |
Use a .best classmethod to resolve JythonCommandSpec when relevant.
Diffstat (limited to 'setuptools/command/easy_install.py')
-rwxr-xr-x | setuptools/command/easy_install.py | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index dda183c8..9978c132 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -1876,6 +1876,13 @@ class CommandSpec(list): split_args = dict() @classmethod + def best(cls): + """ + Choose the best CommandSpec class based on environmental conditions. + """ + return cls if not JythonCommandSpec.relevant() else JythonCommandSpec + + @classmethod def _sys_executable(cls): _default = os.path.normpath(sys.executable) return os.environ.get('__PYVENV_LAUNCHER__', _default) @@ -1897,9 +1904,7 @@ class CommandSpec(list): @classmethod def from_environment(cls): - string = '"' + cls._sys_executable() + '"' - jython_spec = JythonCommandSpec.from_string(string) - return jython_spec or cls([cls._sys_executable()]) + return cls([cls._sys_executable()]) @classmethod def from_string(cls, string): @@ -1908,7 +1913,7 @@ class CommandSpec(list): line parseable by shlex.split. """ items = shlex.split(string, **cls.split_args) - return JythonCommandSpec.from_string(string) or cls(items) + return cls(items) def install_options(self, script_text): self.options = shlex.split(self._extract_options(script_text)) @@ -1944,17 +1949,21 @@ class WindowsCommandSpec(CommandSpec): class JythonCommandSpec(CommandSpec): @classmethod - def from_string(cls, string): - """ - On Jython, construct an instance of this class. - On platforms other than Jython, return None. - """ - needs_jython_spec = ( + def relevant(cls): + return ( sys.platform.startswith('java') and __import__('java').lang.System.getProperty('os.name') != 'Linux' ) - return cls([string]) if needs_jython_spec else None + + @classmethod + def from_environment(cls): + string = '"' + cls._sys_executable() + '"' + return cls.from_string(string) + + @classmethod + def from_string(cls, string): + return cls([string]) def as_header(self): """ @@ -2011,7 +2020,7 @@ class ScriptWriter(object): warnings.warn("Use get_header", DeprecationWarning) if wininst: executable = "python.exe" - cmd = cls.command_spec_class.from_param(executable) + cmd = cls.command_spec_class.best().from_param(executable) cmd.install_options(script_text) return cmd.as_header() @@ -2052,7 +2061,7 @@ class ScriptWriter(object): @classmethod def get_header(cls, script_text="", executable=None): """Create a #! line, getting options (if any) from script_text""" - cmd = cls.command_spec_class.from_param(executable) + cmd = cls.command_spec_class.best().from_param(executable) cmd.install_options(script_text) return cmd.as_header() |