| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,6 +28,6 @@ | |||
| 28 | 28 | OTHER DEALINGS IN THE SOFTWARE. | |
| 29 | 29 | """ | |
| 30 | 30 | ||
| 31 | - __version__ = '5.2.20221113' | ||
| 31 | + __version__ = '5.2.20221120' | ||
| 32 | 32 | __license__ = __doc__ | |
| 33 | 33 | __project_url__ = 'http://winpython.github.io/' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,7 @@ | |||
| 13 | 13 | from __future__ import print_function | |
| 14 | 14 | ||
| 15 | 15 | import os | |
| 16 | - import os.path as osp | ||
| 16 | + # import os.path as osp | ||
| 17 | 17 | from pathlib import Path | |
| 18 | 18 | import subprocess | |
| 19 | 19 | import re | |
@@ -33,21 +33,29 @@ | |||
| 33 | 33 | def get_python_executable(path = None): | |
| 34 | 34 | """return the python executable""" | |
| 35 | 35 | 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) | ||
| 37 | - exec_py = os.path.join(my_path, 'python.exe') | ||
| 38 | - exec_pypy = os.path.join(my_path, 'pypy3.exe') # PyPy ! | ||
| 36 | + # my_path = my_path if osp.isdir(my_path) else osp.dirname(my_path) | ||
| 37 | + 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') | ||
| 39 | + exec_py = str(Path(my_path) / 'python.exe') | ||
| 40 | + # exec_pypy = os.path.join(my_path, 'pypy3.exe') # PyPy ! | ||
| 41 | + exec_pypy = str(Path(my_path) / 'pypy3.exe') # PyPy ! | ||
| 39 | 42 | # PyPy >=7.3.6 3.8 aligns to python.exe and Lib\site-packages | |
| 40 | 43 | #python_executable = exec_pypy if osp.isfile(exec_pypy) else exec_py | |
| 41 | - python_executable = exec_py if osp.isfile(exec_py) else exec_pypy | ||
| 44 | + #python_executable = exec_py if osp.isfile(exec_py) else exec_pypy | ||
| 45 | + python_executable = exec_py if Path(exec_py).is_file() else exec_pypy | ||
| 42 | 46 | return python_executable | |
| 43 | 47 | ||
| 44 | 48 | def get_site_packages_path(path = None): | |
| 45 | 49 | """return the python site-packages""" | |
| 46 | 50 | my_path = sys.executable if path == None else path # default = current one | |
| 47 | - my_path = my_path if osp.isdir(my_path) else osp.dirname(my_path) | ||
| 48 | - site_py = os.path.join(my_path, 'Lib', 'site-packages') | ||
| 49 | - site_pypy = os.path.join(my_path, 'site-packages') # PyPy !! | ||
| 50 | - site_packages_path = site_pypy if osp.isfile(site_pypy) else site_py | ||
| 51 | + # my_path = my_path if osp.isdir(my_path) else osp.dirname(my_path) | ||
| 52 | + 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') | ||
| 54 | + site_py = str(Path(my_path) / 'Lib' / 'site-packages') | ||
| 55 | + # site_pypy = os.path.join(my_path, 'site-packages') # PyPy !! | ||
| 56 | + 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 | ||
| 51 | 59 | return site_packages_path | |
| 52 | 60 | ||
| 53 | 61 | def onerror(function, path, excinfo): | |
@@ -73,7 +81,8 @@ def is_program_installed(basename): | |||
| 73 | 81 | for path in os.environ["PATH"].split(os.pathsep): | |
| 74 | 82 | # abspath = osp.join(path, basename) | |
| 75 | 83 | abspath = str(Path(path) / basename) | |
| 76 | - if osp.isfile(abspath): | ||
| 84 | + # if osp.isfile(abspath): | ||
| 85 | + if Path(abspath).is_file(): | ||
| 77 | 86 | return abspath | |
| 78 | 87 | ||
| 79 | 88 | ||
@@ -224,7 +233,8 @@ def get_winpython_start_menu_folder(current=True): | |||
| 224 | 233 | def create_winpython_start_menu_folder(current=True): | |
| 225 | 234 | """Create WinPython Start menu folder -- remove it if it already exists""" | |
| 226 | 235 | path = get_winpython_start_menu_folder(current=current) | |
| 227 | - if osp.isdir(path): | ||
| 236 | + # if osp.isdir(path): | ||
| 237 | + if Path(path).is_dir(): | ||
| 228 | 238 | try: | |
| 229 | 239 | shutil.rmtree(path, onerror=onerror) | |
| 230 | 240 | except WindowsError: | |
@@ -288,8 +298,10 @@ def print_box(text): | |||
| 288 | 298 | def is_python_distribution(path): | |
| 289 | 299 | """Return True if path is a Python distribution""" | |
| 290 | 300 | # XXX: This test could be improved but it seems to be sufficient | |
| 291 | - has_exec = osp.isfile(get_python_executable(path)) | ||
| 292 | - has_site = osp.isdir(get_site_packages_path(path)) | ||
| 301 | + # has_exec = osp.isfile(get_python_executable(path)) | ||
| 302 | + has_exec = Path(get_python_executable(path)).is_file() | ||
| 303 | + # has_site = osp.isdir(get_site_packages_path(path)) | ||
| 304 | + has_site = Path(get_site_packages_path(path)).is_dir() | ||
| 293 | 305 | return has_exec and has_site | |
| 294 | 306 | ||
| 295 | 307 | ||
@@ -538,7 +550,8 @@ def patch_sourcefile( | |||
| 538 | 550 | """Replace a string in a source file""" | |
| 539 | 551 | import io | |
| 540 | 552 | ||
| 541 | - if osp.isfile(fname) and not in_text == out_text: | ||
| 553 | + # if osp.isfile(fname) and not in_text == out_text: | ||
| 554 | + if Path(fname).is_file() and not in_text == out_text: | ||
| 542 | 555 | the_encoding = guess_encoding(fname)[0] | |
| 543 | 556 | with io.open(fname, 'r', encoding=the_encoding) as fh: | |
| 544 | 557 | content = fh.read() | |
@@ -569,9 +582,10 @@ def patch_sourcelines( | |||
| 569 | 582 | ): | |
| 570 | 583 | """Replace the middle of lines between in_line_start and endline """ | |
| 571 | 584 | import io | |
| 572 | - import os.path as osp | ||
| 585 | + # import os.path as osp | ||
| 573 | 586 | ||
| 574 | - if osp.isfile(fname): | ||
| 587 | + # if osp.isfile(fname): | ||
| 588 | + if Path(fname).is_file(): | ||
| 575 | 589 | the_encoding = guess_encoding(fname)[0] | |
| 576 | 590 | with io.open(fname, 'r', encoding=the_encoding) as fh: | |
| 577 | 591 | contents = fh.readlines() | |
@@ -641,16 +655,19 @@ def extract_exe(fname, targetdir=None, verbose=False): | |||
| 641 | 655 | assert is_program_installed(extract), ( | |
| 642 | 656 | "Required program '%s' was not found" % extract | |
| 643 | 657 | ) | |
| 644 | - bname = osp.basename(fname) | ||
| 658 | + #bname = osp.basename(fname) | ||
| 659 | + bname = Path(fname).name | ||
| 645 | 660 | args = ['x', '-o%s' % targetdir, '-aos', bname] | |
| 646 | 661 | if verbose: | |
| 647 | 662 | retcode = subprocess.call( | |
| 648 | - [extract] + args, cwd=osp.dirname(fname) | ||
| 663 | + # [extract] + args, cwd=osp.dirname(fname) | ||
| 664 | + [extract] + args, cwd=str(Path(fname).parent) | ||
| 649 | 665 | ) | |
| 650 | 666 | else: | |
| 651 | 667 | p = subprocess.Popen( | |
| 652 | 668 | [extract] + args, | |
| 653 | - cwd=osp.dirname(fname), | ||
| 669 | + #cwd=osp.dirname(fname), | ||
| 670 | + cwd=str(Path(fname).parent), | ||
| 654 | 671 | stdout=subprocess.PIPE, | |
| 655 | 672 | ) | |
| 656 | 673 | p.communicate() | |
@@ -675,7 +692,8 @@ def extract_archive(fname, targetdir=None, verbose=False): | |||
| 675 | 692 | os.mkdir(targetdir) | |
| 676 | 693 | except: | |
| 677 | 694 | pass | |
| 678 | - if osp.splitext(fname)[1] in ('.zip', '.exe'): | ||
| 695 | + #if osp.splitext(fname)[1] in ('.zip', '.exe'): | ||
| 696 | + if Path(fname).suffix in ('.zip', '.exe'): | ||
| 679 | 697 | obj = zipfile.ZipFile(fname, mode="r") | |
| 680 | 698 | elif fname.endswith('.tar.gz'): | |
| 681 | 699 | obj = tarfile.open(fname, mode='r:gz') | |
@@ -707,8 +725,10 @@ def extract_archive(fname, targetdir=None, verbose=False): | |||
| 707 | 725 | def get_source_package_infos(fname): | |
| 708 | 726 | """Return a tuple (name, version) of the Python source package""" | |
| 709 | 727 | if fname[-4:] == '.whl': | |
| 710 | - return osp.basename(fname).split("-")[:2] | ||
| 711 | - match = re.match(SOURCE_PATTERN, osp.basename(fname)) | ||
| 728 | + #return osp.basename(fname).split("-")[:2] | ||
| 729 | + return Path(fname).name.split("-")[:2] | ||
| 730 | + # match = re.match(SOURCE_PATTERN, osp.basename(fname)) | ||
| 731 | + match = re.match(SOURCE_PATTERN, Path(fname).name) | ||
| 712 | 732 | if match is not None: | |
| 713 | 733 | return match.groups()[:2] | |
| 714 | 734 | ||
@@ -726,7 +746,8 @@ def build_wininst( | |||
| 726 | 746 | Return wininst installer full path.""" | |
| 727 | 747 | if python_exe is None: | |
| 728 | 748 | python_exe = sys.executable | |
| 729 | - assert osp.isfile(python_exe) | ||
| 749 | + #assert osp.isfile(python_exe) | ||
| 750 | + assert Path(python_exe).is_file() | ||
| 730 | 751 | cmd = [python_exe, 'setup.py', 'build'] | |
| 731 | 752 | if architecture is not None: | |
| 732 | 753 | archstr = ( | |
@@ -749,7 +770,8 @@ def build_wininst( | |||
| 749 | 770 | p.stderr.close() | |
| 750 | 771 | # distdir = osp.join(root, 'dist') | |
| 751 | 772 | distdir = str(Path(root) / 'dist') | |
| 752 | - if not osp.isdir(distdir): | ||
| 773 | + # if not osp.isdir(distdir): | ||
| 774 | + if not Path(distdir).is_dir(): | ||
| 753 | 775 | raise RuntimeError( | |
| 754 | 776 | "Build failed: see package README file for further" | |
| 755 | 777 | " details regarding installation requirements.\n\n" | |
@@ -806,12 +828,15 @@ def direct_pip_install( | |||
| 806 | 828 | install_options=None, | |
| 807 | 829 | ): | |
| 808 | 830 | """Direct install via pip !""" | |
| 809 | - copy_to = osp.dirname(fname) | ||
| 831 | + # copy_to = osp.dirname(fname) | ||
| 832 | + copy_to = str(Path(fname).parent) | ||
| 810 | 833 | ||
| 811 | 834 | if python_exe is None: | |
| 812 | 835 | python_exe = sys.executable | |
| 813 | - assert osp.isfile(python_exe) | ||
| 814 | - myroot = os.path.dirname(python_exe) | ||
| 836 | + # assert osp.isfile(python_exe) | ||
| 837 | + assert Path(python_exe).is_file() | ||
| 838 | + # myroot = os.path.dirname(python_exe) | ||
| 839 | + myroot = str(Path(python_exe).parent) | ||
| 815 | 840 | ||
| 816 | 841 | cmd = [python_exe, '-m', 'pip', 'install'] | |
| 817 | 842 | if install_options: | |
@@ -898,7 +923,8 @@ def do_script( | |||
| 898 | 923 | # print dname+':', '\n', get_python_infos(dname) | |
| 899 | 924 | ||
| 900 | 925 | tmpdir = r'D:\Tests\winpython_tests' | |
| 901 | - if not osp.isdir(tmpdir): | ||
| 926 | + # if not osp.isdir(tmpdir): | ||
| 927 | + if not Path(tmpdir).is_dir(): | ||
| 902 | 928 | os.mkdir(tmpdir) | |
| 903 | 929 | print( | |
| 904 | 930 | ( | |
| Back | FazBrowse Home | New Git URL |
0 commit comments