Skip to content

Commit 893aa26

Browse files
committed
changelog now made from pip inspect by default
1 parent d9fd924 commit 893aa26

5 files changed

Lines changed: 56 additions & 43 deletions

File tree

make.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ def _create_batch_scripts_initial(self):
846846
"env.bat",
847847
r"""@echo off
848848
set WINPYDIRBASE=%~dp0..
849-
849+
rem set PYTHONUTF8=1 would create issues in "movable" patching
850850
rem get a normalize path
851851
set WINPYDIRBASETMP=%~dp0..
852852
pushd %WINPYDIRBASETMP%
@@ -997,7 +997,7 @@ def _create_batch_scripts_initial(self):
997997
###############################
998998
$0 = $myInvocation.MyCommand.Definition
999999
$dp0 = [System.IO.Path]::GetDirectoryName($0)
1000-
1000+
# $env:PYTHONUTF8 = 1 would create issues in "movable" patching
10011001
$env:WINPYDIRBASE = "$dp0\.."
10021002
# get a normalize path
10031003
# http://stackoverflow.com/questions/1645843/resolve-absolute-path-from-relative-path-and-or-file-name

winpython/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
OTHER DEALINGS IN THE SOFTWARE.
2929
"""
3030

31-
__version__ = '7.3.20240309'
31+
__version__ = '7.4.20240310'
3232
__license__ = __doc__
3333
__project_url__ = 'http://winpython.github.io/'

winpython/piptree.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
import json, sys, re, platform, os
2+
import json, sys, re, platform, os, sysconfig
33
import re
44
from winpython import utils
55
from collections import OrderedDict
@@ -17,10 +17,13 @@ class pipdata:
1717
def __init__(self, Target=None):
1818

1919
# get pip_inpsect raw data in json form
20+
#os.environ["pythonutf8"] = "1" causes issues in movable, so limit to there
2021
if Target == None:
21-
pip_inspect = utils.exec_run_cmd(["pip", "inspect"])
22+
#pip_inspect = utils.exec_run_cmd(["pip", "inspect"])
23+
pip_inspect = utils.exec_shell_cmd(f'set pythonutf8=1 & python -X utf8=1 -m pip inspect', sys.prefix)
2224
else:
23-
pip_inspect = utils.exec_run_cmd([Target , "-m", "pip", "inspect"])
25+
#pip_inspect = utils.exec_run_cmd([Target , "-X" ,"utf8=1", "-m", "pip", "inspect"])
26+
pip_inspect = utils.exec_shell_cmd(f'set pythonutf8=1 & "{Target}" -X utf8=1 -m pip inspect', sys.prefix)
2427
pip_json = json.loads(pip_inspect)
2528

2629
# create a distro{} dict of Packages
@@ -199,9 +202,14 @@ def up(self, pp, extra="", depth=99, indent=5, version_req="", verbose=False):
199202
print("\n".join(lines).replace('"', ""))
200203

201204
def description(self, pp):
202-
"return desciption of the package"
205+
"return description of the package"
203206
if pp in self.distro:
204207
return print("\n".join(self.distro[pp]["description"].split(r"\n")))
208+
209+
def summary(self, pp):
210+
"return summary of the package"
211+
if pp in self.distro:
212+
return self.distro[pp]["summary"]
205213

206214
def pip_list(self, full=False):
207215
"""do like pip list"""

winpython/utils.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def exec_shell_cmd(args, path):
323323
stdout=subprocess.PIPE,
324324
stderr=subprocess.PIPE,
325325
cwd=path,
326-
shell=True,
326+
shell=True
327327
)
328328
return decode_fs_string(process.stdout.read())
329329

@@ -333,14 +333,16 @@ def exec_run_cmd(args, path=None):
333333
# python-3.7+ allows to replace "stdout and stderr ", per "capture_output=True"
334334
if path:
335335
process = subprocess.run(args,
336-
stdout=subprocess.PIPE,
337-
stderr=subprocess.PIPE,
338-
cwd=path)
336+
capture_output=True,
337+
cwd=path, text=True)
338+
#return decode_fs_string(process.stdout)
339+
return process.stdout
339340
else:
340341
process = subprocess.run(args,
341-
stdout=subprocess.PIPE,
342-
stderr=subprocess.PIPE)
343-
return decode_fs_string(process.stdout)
342+
capture_output=True,
343+
cwd=path, text=True)
344+
#return decode_fs_string(process.stdout)
345+
return process.stdout
344346

345347

346348
def get_r_version(path):

winpython/wppm.py

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,22 @@ def is_compatible_with(self, distribution):
155155
iscomp = iscomp and self.pyversion == distribution.version
156156
return iscomp
157157

158-
def extract_optional_infos(self, update=False):
158+
def extract_optional_infos(self, update=False, suggested_summary=None):
159159
"""Extract package optional infos (description, url)
160160
from the package database"""
161161
metadata = get_package_metadata("packages.ini", self.name, True, update=update)
162162
for key, value in list(metadata.items()):
163163
setattr(self, key, value)
164+
if suggested_summary and suggested_summary!="":
165+
setattr(self, 'description',suggested_summary)
164166

165167

166168
class Package(BasePackage):
167-
def __init__(self, fname, update=False):
169+
def __init__(self, fname, update=False, suggested_summary=None):
168170
BasePackage.__init__(self, fname)
169171
self.files = []
170172
self.extract_infos()
171-
self.extract_optional_infos(update=update)
173+
self.extract_optional_infos(update=update,suggested_summary=suggested_summary)
172174

173175
def extract_infos(self):
174176
"""Extract package infos (name, version, architecture)
@@ -245,6 +247,7 @@ def __init__(self, target=None, verbose=False, indent=False):
245247
self.target = target
246248
self.verbose = verbose
247249
self.indent = indent
250+
self.pip = None
248251

249252
# if no target path given, take the current python interpreter one
250253
if self.target is None:
@@ -340,33 +343,33 @@ def get_installed_packages(self, update=False):
340343

341344
# Include package installed via pip (not via WPPM)
342345
wppm = []
343-
try:
346+
try: # we try to use also 'pip inspect' via piptree (work for pip>= 22.2)
344347
if str(Path(sys.executable).parent) == self.target:
345-
# win pip 22.2, we can use pip inspect API
346-
pip = piptree.pipdata()
347-
pip_list = pip.pip_list()
348+
self.pip = piptree.pipdata()
348349
else:
349-
# indirect way: we use pip list (for now)
350-
cmdx = [
351-
utils.get_python_executable(self.target), # PyPy !
352-
"-m",
353-
"pip",
354-
"list",
355-
]
356-
pip_list_raw = utils.exec_run_cmd(cmdx).splitlines()
357-
# pip list gives 2 lines of titles to ignore
358-
pip_list = [l.split() for l in pip_list_raw[2:]]
359-
# there are only Packages installed with pip now
360-
# create pip package list
361-
wppm = [
362-
Package(
363-
f"{i[0].replace('-', '_').lower()}-{i[1]}-py2.py3-none-any.whl",
364-
update=update,
365-
)
366-
for i in pip_list
367-
]
350+
self.pip = piptree.pipdata(Target=utils.get_python_executable(self.target))
351+
pip_list = self.pip.pip_list()
368352
except:
369-
pass
353+
# if failure back to pip list (will use packages.ini for names)
354+
cmdx = [
355+
utils.get_python_executable(self.target), # PyPy !
356+
"-m",
357+
"pip",
358+
"list",
359+
]
360+
pip_list_raw = utils.exec_run_cmd(cmdx).splitlines()
361+
# pip list gives 2 lines of titles to ignore
362+
pip_list = [l.split() for l in pip_list_raw[2:]]
363+
364+
# create pip package list
365+
wppm = [
366+
Package(
367+
f"{i[0].replace('-', '_').lower()}-{i[1]}-py3-none-any.whl",
368+
update=update,
369+
suggested_summary=self.pip.summary(i[0]) if self.pip else None
370+
)
371+
for i in pip_list
372+
]
370373
return sorted(wppm, key=lambda tup: tup.name.lower())
371374

372375
def find_package(self, name):
@@ -842,8 +845,8 @@ def main(test=False):
842845
args = parser.parse_args()
843846
targetpython = None
844847
if args.target and not args.target==sys.prefix:
845-
targetpython = args.target if args.target[-4:] == '.exe' else args.target+r'\python.exe'
846-
# print(targetpython)
848+
targetpython = args.target if args.target[-4:] == '.exe' else str(Path(args.target) / 'python.exe')
849+
# print(targetpython.resolve() to check)
847850
if args.install and args.uninstall:
848851
raise RuntimeError("Incompatible arguments: --install and --uninstall")
849852
if args.registerWinPython and args.unregisterWinPython:

0 commit comments

Comments
 (0)