33import os
44import platform
55import sys
6- import posixpath
7- import ntpath
86import re
97import shutil
108
@@ -21,28 +19,30 @@ def possibly_convert_to_windows_style_path(path):
2119 if not isinstance (path , str ):
2220 path = str (path )
2321 # Check if the path is in Unix-style (Git Bash)
24- if os .name == 'nt' :
25- if path .startswith ('/' ):
26- drive , tail = re .match (r"^/([a-zA-Z])/(.*)" , path ).groups ()
27- revised_path = drive .upper () + ":\\ " + tail .replace ('/' , '\\ ' )
28- return revised_path
29- elif path .startswith ('\\ ' ):
30- drive , tail = re .match (r"^\\([a-zA-Z])\\(.*)" , path ).groups ()
31- revised_path = drive .upper () + ":\\ " + tail .replace ('\\ ' , '\\ ' )
32- return revised_path
33-
22+ if os .name != 'nt' :
23+ return path
24+ if os .path .exists (path ):
25+ return path
26+ match = re .match (r"[/\\]([a-zA-Z])[/\\](.*)" , path )
27+ if match is None :
28+ return path
29+ drive , rest_of_path = match .groups ()
30+ rest_of_path = rest_of_path .replace ("/" , "\\ " )
31+ revised_path = f"{ drive .upper ()} :\\ { rest_of_path } "
32+ if os .path .exists (revised_path ):
33+ return revised_path
3434 return path
3535
3636
3737PYENV_ROOT = os .path .expanduser (
3838 os .path .expandvars (os .environ .get ("PYENV_ROOT" , "~/.pyenv" ))
3939)
4040PYENV_ROOT = possibly_convert_to_windows_style_path (PYENV_ROOT )
41- PYENV_INSTALLED = shutil .which ("pyenv" ) != None
41+ PYENV_INSTALLED = shutil .which ("pyenv" ) is not None
4242ASDF_DATA_DIR = os .path .expanduser (
4343 os .path .expandvars (os .environ .get ("ASDF_DATA_DIR" , "~/.asdf" ))
4444)
45- ASDF_INSTALLED = shutil .which ("asdf" ) != None
45+ ASDF_INSTALLED = shutil .which ("asdf" ) is not None
4646IS_64BIT_OS = None
4747SYSTEM_ARCH = platform .architecture ()[0 ]
4848
@@ -61,20 +61,9 @@ def possibly_convert_to_windows_style_path(path):
6161"""
6262
6363
64- def join_path_for_platform (path , path_parts ):
65- # If we're on Unix or Unix-like system
66- if os .name == 'posix' or sys .platform == 'linux' :
67- return posixpath .join (path , * path_parts )
68- # If we're on Windows
69- elif os .name == 'nt' or sys .platform == 'win32' :
70- return ntpath .join (path , * path_parts )
71- else :
72- raise Exception ("Unknown environment" )
73-
74-
7564def set_asdf_paths ():
7665 if ASDF_INSTALLED :
77- python_versions = join_path_for_platform (ASDF_DATA_DIR , [ "installs" , "python" ] )
66+ python_versions = os . path . join (ASDF_DATA_DIR , "installs" , "python" )
7867 try :
7968 # Get a list of all files and directories in the given path
8069 all_files_and_dirs = os .listdir (python_versions )
@@ -92,10 +81,10 @@ def set_pyenv_paths():
9281 if PYENV_INSTALLED :
9382 is_windows = False
9483 if os .name == "nt" :
95- python_versions = join_path_for_platform (PYENV_ROOT , [ "pyenv-win" , "versions" ] )
84+ python_versions = os . path . join (PYENV_ROOT , "pyenv-win" , "versions" )
9685 is_windows = True
9786 else :
98- python_versions = join_path_for_platform (PYENV_ROOT , [ "versions" ] )
87+ python_versions = os . path . join (PYENV_ROOT , "versions" )
9988 try :
10089 # Get a list of all files and directories in the given path
10190 all_files_and_dirs = os .listdir (python_versions )
0 commit comments