[Jython-checkins] jython: Use relative path in launcher only if shorter than absolute path

jeff.allen jython-checkins at python.org
Sat Apr 14 04:50:12 EDT 2018


https://hg.python.org/jython/rev/4af36339826e
changeset:   8152:4af36339826e
user:        Jeff Allen <ja.py at farowl.co.uk>
date:        Wed Mar 28 17:25:06 2018 +0100
summary:
  Use relative path in launcher only if shorter than absolute path

We opted for relative paths to make paths and command-lines more
readable, and avoid some non-ascii encoding risks, when Jython is
installed locally to a user. The choice was counter-productive when
Jython was installed in a shared location.

files:
  src/shell/jython.py |  6 +++---
  1 files changed, 3 insertions(+), 3 deletions(-)


diff --git a/src/shell/jython.py b/src/shell/jython.py
--- a/src/shell/jython.py
+++ b/src/shell/jython.py
@@ -202,9 +202,9 @@
         # Python 2 thinks in bytes. Carefully normalise in Unicode.
         path = os.path.realpath(bytes_path.decode(ENCODING))
         try:
-            # If possible, make this relative to the CWD.
-            # This helps manage multi-byte names in installation location.
-            path = os.path.relpath(path, os.getcwdu())
+            # If shorter, make this relative to the CWD.
+            relpath = os.path.relpath(path, os.getcwdu())
+            if len(relpath) < len(path): path = relpath
         except ValueError:
             # Many reasons why this might be impossible: use an absolute path.
             path = os.path.abspath(path)

-- 
Repository URL: https://hg.python.org/jython


More information about the Jython-checkins mailing list