Skip to content

Commit 4736d66

Browse files
authored
Merge pull request #1549 from stonebig/master
rectify bad tweaks
2 parents 7cd17d0 + a2c3d4c commit 4736d66

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

winpython/utils.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@
2929

3030
def get_python_executable(path=None):
3131
"""Return the path to the Python executable."""
32-
python_path = sys.executable if path is None else path
33-
base_dir = Path(python_path).parent if not Path(python_path).is_dir() else Path(python_path)
32+
python_path = Path(path) if path else Path(sys.executable)
33+
base_dir = python_path if python_path.is_dir() else python_path.parent
3434
python_exe = base_dir / 'python.exe'
3535
pypy_exe = base_dir / 'pypy3.exe' # For PyPy
3636
return str(python_exe if python_exe.is_file() else pypy_exe)
3737

3838
def get_site_packages_path(path=None):
3939
"""Return the path to the Python site-packages directory."""
40-
python_path = sys.executable if path is None else path
41-
base_dir = Path(python_path).parent if not Path(python_path).is_dir() else Path(python_path)
40+
python_path = Path(path) if path else Path(sys.executable)
41+
base_dir = python_path if python_path.is_dir() else python_path.parent
4242
site_packages = base_dir / 'Lib' / 'site-packages'
4343
pypy_site_packages = base_dir / 'site-packages' # For PyPy
4444
return str(pypy_site_packages if pypy_site_packages.is_dir() else site_packages)
@@ -322,40 +322,33 @@ def buildflit_wininst(root, python_exe=None, copy_to=None, verbose=False):
322322
if verbose:
323323
subprocess.call(cmd, cwd=root)
324324
else:
325-
process = subprocess.Popen(cmd, cwd=root, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
326-
process.communicate()
327-
process.stdout.close()
328-
process.stderr.close()
329-
distdir = str(Path(root) / 'dist')
330-
if not Path(distdir).is_dir():
325+
subprocess.Popen(cmd, cwd=root, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
326+
distdir = Path(root) / 'dist'
327+
if not distdir.is_dir():
331328
raise RuntimeError(
332329
"Build failed: see package README file for further details regarding installation requirements.\n\n"
333330
"For more concrete debugging infos, please try to build the package from the command line:\n"
334331
"1. Open a WinPython command prompt\n"
335332
"2. Change working directory to the appropriate folder\n"
336-
"3. Type `python -m filt build`"
333+
"3. Type `python -m flit build`"
337334
)
338-
339335
for distname in os.listdir(distdir):
340336
if re.match(SOURCE_PATTERN, distname) or re.match(WHEELBIN_PATTERN, distname):
341337
break
342338
else:
343339
raise RuntimeError(f"Build failed: not a pure Python package? {distdir}")
344340

345-
src_fname = str(Path(distdir) / distname)
341+
src_fname = distdir / distname
346342
if copy_to:
347-
dst_fname = str(Path(copy_to) / distname)
343+
dst_fname = Path(copy_to) / distname
348344
shutil.move(src_fname, dst_fname)
349345
if verbose:
350346
print(f"Move: {src_fname} --> {dst_fname}")
351-
return dst_fname
352-
return src_fname
353347

354348
def direct_pip_install(fname, python_exe=None, verbose=False, install_options=None):
355349
"""Direct install via python -m pip !"""
356350
python_exe = python_exe or sys.executable
357-
myroot = str(Path(python_exe).parent)
358-
351+
myroot = Path(python_exe).parent
359352
cmd = [python_exe, "-m", "pip", "install"] + (install_options or []) + [fname]
360353
if not verbose:
361354
process = subprocess.Popen(cmd, cwd=myroot, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -374,15 +367,12 @@ def direct_pip_install(fname, python_exe=None, verbose=False, install_options=No
374367
def do_script(this_script, python_exe=None, copy_to=None, verbose=False, install_options=None):
375368
"""Execute a script (get-pip typically)."""
376369
python_exe = python_exe or sys.executable
377-
myroot = os.path.dirname(python_exe)
370+
myroot = Path(python_exe).parent
378371
# cmd = [python_exe, myroot + r'\Scripts\pip-script.py', 'install']
379372
cmd = [python_exe] + (install_options or []) + ([this_script] if this_script else [])
380373
print("Executing ", cmd)
381374
if not verbose:
382-
process = subprocess.Popen(cmd, cwd=myroot, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
383-
process.communicate()
384-
process.stdout.close()
385-
process.stderr.close()
375+
subprocess.Popen(cmd, cwd=myroot, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
386376
else:
387377
subprocess.call(cmd, cwd=myroot)
388378
print("Executed ", cmd)
@@ -406,9 +396,9 @@ def normalize(this):
406396

407397
def get_package_metadata(database, name):
408398
"""Extract infos (description, url) from the local database."""
409-
DATA_PATH = str(Path(sys.modules['winpython'].__file__).parent / 'data')
399+
DATA_PATH = Path(sys.modules['winpython'].__file__).parent / 'data'
410400
db = cp.ConfigParser()
411-
filepath = Path(database) if Path(database).is_absolute() else Path(DATA_PATH) / database
401+
filepath = Path(database) if Path(database).is_absolute() else DATA_PATH / database
412402
db.read_file(open(str(filepath), encoding=guess_encoding(filepath)[0]))
413403

414404
my_metadata = {

winpython/wppm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def get_installed_packages(self, update: bool = False) -> list[Package]:
8383
pip_list = self.pip.pip_list()
8484

8585
# return a list of package objects
86-
return [Package(f"{utils.normalize(i[0])}-{i[1]}-py3-none-any.whl") for i in pip_list]
86+
return [Package(f"{i[0].replace('-', '_').lower()}-{i[1]}-py3-none-any.whl") for i in pip_list]
8787

8888
def find_package(self, name: str) -> Package | None:
8989
"""Find installed package by name."""

0 commit comments

Comments
 (0)