Skip to content

Commit cdb6f36

Browse files
authored
Merge pull request winpython#1161 from stonebig/master
fix Path(site_pypy).is_dir()
2 parents 7b22aa0 + 1926b5a commit cdb6f36

File tree

1 file changed

+1
-40
lines changed

1 file changed

+1
-40
lines changed

winpython/utils.py

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from __future__ import print_function
1414

1515
import os
16-
# import os.path as osp
1716
from pathlib import Path
1817
import subprocess
1918
import re
@@ -33,29 +32,20 @@
3332
def get_python_executable(path = None):
3433
"""return the python executable"""
3534
my_path = sys.executable if path == None else path # default = current one
36-
# my_path = my_path if osp.isdir(my_path) else osp.dirname(my_path)
3735
my_path = my_path if Path(my_path).is_dir() else str(Path(my_path).parent)
38-
#exec_py = os.path.join(my_path, 'python.exe')
3936
exec_py = str(Path(my_path) / 'python.exe')
40-
# exec_pypy = os.path.join(my_path, 'pypy3.exe') # PyPy !
4137
exec_pypy = str(Path(my_path) / 'pypy3.exe') # PyPy !
4238
# PyPy >=7.3.6 3.8 aligns to python.exe and Lib\site-packages
43-
#python_executable = exec_pypy if osp.isfile(exec_pypy) else exec_py
44-
#python_executable = exec_py if osp.isfile(exec_py) else exec_pypy
4539
python_executable = exec_py if Path(exec_py).is_file() else exec_pypy
4640
return python_executable
4741

4842
def get_site_packages_path(path = None):
4943
"""return the python site-packages"""
5044
my_path = sys.executable if path == None else path # default = current one
51-
# my_path = my_path if osp.isdir(my_path) else osp.dirname(my_path)
5245
my_path = my_path if Path(my_path).is_dir() else str(Path(my_path).parent)
53-
# site_py = os.path.join(my_path, 'Lib', 'site-packages')
5446
site_py = str(Path(my_path) / 'Lib' / 'site-packages')
55-
# site_pypy = os.path.join(my_path, 'site-packages') # PyPy !!
5647
site_pypy = str(Path(my_path) / 'site-packages') # PyPy !!
57-
# site_packages_path = site_pypy if osp.isfile(site_pypy) else site_py
58-
site_packages_path = site_pypy if Path(site_pypy).is_file() else site_py
48+
site_packages_path = site_pypy if Path(site_pypy).is_dir() else site_py
5949
return site_packages_path
6050

6151
def onerror(function, path, excinfo):
@@ -79,9 +69,7 @@ def is_program_installed(basename):
7969
"""Return program absolute path if installed in PATH
8070
Otherwise, return None"""
8171
for path in os.environ["PATH"].split(os.pathsep):
82-
# abspath = osp.join(path, basename)
8372
abspath = str(Path(path) / basename)
84-
# if osp.isfile(abspath):
8573
if Path(abspath).is_file():
8674
return abspath
8775

@@ -225,15 +213,13 @@ def get_winpython_start_menu_folder(current=True):
225213
folder = get_special_folder_path(
226214
"CSIDL_PROGRAMS"
227215
)
228-
# return osp.join(folder, 'WinPython')
229216
return str(Path(folder) / 'WinPython')
230217

231218

232219

233220
def create_winpython_start_menu_folder(current=True):
234221
"""Create WinPython Start menu folder -- remove it if it already exists"""
235222
path = get_winpython_start_menu_folder(current=current)
236-
# if osp.isdir(path):
237223
if Path(path).is_dir():
238224
try:
239225
shutil.rmtree(path, onerror=onerror)
@@ -298,9 +284,7 @@ def print_box(text):
298284
def is_python_distribution(path):
299285
"""Return True if path is a Python distribution"""
300286
# XXX: This test could be improved but it seems to be sufficient
301-
# has_exec = osp.isfile(get_python_executable(path))
302287
has_exec = Path(get_python_executable(path)).is_file()
303-
# has_site = osp.isdir(get_site_packages_path(path))
304288
has_site = Path(get_site_packages_path(path)).is_dir()
305289
return has_exec and has_site
306290

@@ -550,7 +534,6 @@ def patch_sourcefile(
550534
"""Replace a string in a source file"""
551535
import io
552536

553-
# if osp.isfile(fname) and not in_text == out_text:
554537
if Path(fname).is_file() and not in_text == out_text:
555538
the_encoding = guess_encoding(fname)[0]
556539
with io.open(fname, 'r', encoding=the_encoding) as fh:
@@ -582,9 +565,7 @@ def patch_sourcelines(
582565
):
583566
"""Replace the middle of lines between in_line_start and endline """
584567
import io
585-
# import os.path as osp
586568

587-
# if osp.isfile(fname):
588569
if Path(fname).is_file():
589570
the_encoding = guess_encoding(fname)[0]
590571
with io.open(fname, 'r', encoding=the_encoding) as fh:
@@ -655,18 +636,15 @@ def extract_exe(fname, targetdir=None, verbose=False):
655636
assert is_program_installed(extract), (
656637
"Required program '%s' was not found" % extract
657638
)
658-
#bname = osp.basename(fname)
659639
bname = Path(fname).name
660640
args = ['x', '-o%s' % targetdir, '-aos', bname]
661641
if verbose:
662642
retcode = subprocess.call(
663-
# [extract] + args, cwd=osp.dirname(fname)
664643
[extract] + args, cwd=str(Path(fname).parent)
665644
)
666645
else:
667646
p = subprocess.Popen(
668647
[extract] + args,
669-
#cwd=osp.dirname(fname),
670648
cwd=str(Path(fname).parent),
671649
stdout=subprocess.PIPE,
672650
)
@@ -692,7 +670,6 @@ def extract_archive(fname, targetdir=None, verbose=False):
692670
os.mkdir(targetdir)
693671
except:
694672
pass
695-
#if osp.splitext(fname)[1] in ('.zip', '.exe'):
696673
if Path(fname).suffix in ('.zip', '.exe'):
697674
obj = zipfile.ZipFile(fname, mode="r")
698675
elif fname.endswith('.tar.gz'):
@@ -725,9 +702,7 @@ def extract_archive(fname, targetdir=None, verbose=False):
725702
def get_source_package_infos(fname):
726703
"""Return a tuple (name, version) of the Python source package"""
727704
if fname[-4:] == '.whl':
728-
#return osp.basename(fname).split("-")[:2]
729705
return Path(fname).name.split("-")[:2]
730-
# match = re.match(SOURCE_PATTERN, osp.basename(fname))
731706
match = re.match(SOURCE_PATTERN, Path(fname).name)
732707
if match is not None:
733708
return match.groups()[:2]
@@ -746,7 +721,6 @@ def build_wininst(
746721
Return wininst installer full path."""
747722
if python_exe is None:
748723
python_exe = sys.executable
749-
#assert osp.isfile(python_exe)
750724
assert Path(python_exe).is_file()
751725
cmd = [python_exe, 'setup.py', 'build']
752726
if architecture is not None:
@@ -768,9 +742,7 @@ def build_wininst(
768742
p.communicate()
769743
p.stdout.close()
770744
p.stderr.close()
771-
# distdir = osp.join(root, 'dist')
772745
distdir = str(Path(root) / 'dist')
773-
# if not osp.isdir(distdir):
774746
if not Path(distdir).is_dir():
775747
raise RuntimeError(
776748
"Build failed: see package README file for further"
@@ -800,12 +772,10 @@ def build_wininst(
800772
"Build failed: not a pure Python package? %s"
801773
% distdir
802774
)
803-
# src_fname = osp.join(distdir, distname)
804775
src_fname = str(Path(distdir) / distname)
805776
if copy_to is None:
806777
return src_fname
807778
else:
808-
# dst_fname = osp.join(copy_to, distname)
809779
dst_fname = str(Path(copy_to) / distname)
810780
shutil.move(src_fname, dst_fname)
811781
if verbose:
@@ -828,14 +798,11 @@ def direct_pip_install(
828798
install_options=None,
829799
):
830800
"""Direct install via pip !"""
831-
# copy_to = osp.dirname(fname)
832801
copy_to = str(Path(fname).parent)
833802

834803
if python_exe is None:
835804
python_exe = sys.executable
836-
# assert osp.isfile(python_exe)
837805
assert Path(python_exe).is_file()
838-
# myroot = os.path.dirname(python_exe)
839806
myroot = str(Path(python_exe).parent)
840807

841808
cmd = [python_exe, '-m', 'pip', 'install']
@@ -923,17 +890,11 @@ def do_script(
923890
# print dname+':', '\n', get_python_infos(dname)
924891

925892
tmpdir = r'D:\Tests\winpython_tests'
926-
# if not osp.isdir(tmpdir):
927893
if not Path(tmpdir).is_dir():
928894
os.mkdir(tmpdir)
929895
print(
930896
(
931897
extract_archive(
932-
#osp.join(
933-
# r'D:\WinP\bd37',
934-
# 'packages.win-amd64',
935-
# 'python-3.7.3.amd64.zip',
936-
#),
937898
str(Path(r'D:\WinP\bd37') / 'packages.win-amd64' /
938899
'python-3.7.3.amd64.zip'),
939900
tmpdir,

0 commit comments

Comments
 (0)