Skip to content

tweaks picked from MistralAI free #1548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 14 additions & 29 deletions winpython/wppm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
# (see winpython/__init__.py for details)

import os
from pathlib import Path
import shutil
import re
import sys
import shutil
import subprocess
import json
from pathlib import Path
from argparse import ArgumentParser, RawTextHelpFormatter

# Local imports
from winpython import utils, piptree

# Workaround for installing PyVISA on Windows from source:
Expand Down Expand Up @@ -66,34 +64,26 @@ def remove_directory(self, path: str):

def create_file(self, package, name, dstdir, contents):
"""Generate data file -- path is relative to distribution root dir"""
dst = str(Path(dstdir) / name)
dst = Path(dstdir) / name
if self.verbose:
print(f"create: {dst}")
full_dst = str(Path(self.target) / dst)
full_dst = Path(self.target) / dst
with open(full_dst, "w") as fd:
fd.write(contents)
package.files.append(dst)
package.files.append(str(dst))

def get_installed_packages(self, update: bool = False) -> list[Package]:
"""Return installed packages."""

# Include package installed via pip (not via WPPM)
wppm = []
if str(Path(sys.executable).parent) == self.target:
self.pip = piptree.PipData()
else:
self.pip = piptree.PipData(utils.get_python_executable(self.target))
pip_list = self.pip.pip_list()

# create pip package list
wppm = [
Package(
f"{i[0].replace('-', '_').lower()}-{i[1]}-py3-none-any.whl", #faking wheel
suggested_summary=self.pip.summary(i[0]) if self.pip else None
)
for i in pip_list
]
return sorted(wppm, key=lambda tup: tup.name.lower())
# return a list of package objects
return [Package(f"{utils.normalize(i[0])}-{i[1]}-py3-none-any.whl") for i in pip_list]

def find_package(self, name: str) -> Package | None:
"""Find installed package by name."""
Expand All @@ -103,16 +93,13 @@ def find_package(self, name: str) -> Package | None:

def patch_all_shebang(self, to_movable: bool = True, max_exe_size: int = 999999, targetdir: str = ""):
"""Make all python launchers relative."""
import glob

for ffname in glob.glob(r"%s\Scripts\*.exe" % self.target):
size = os.path.getsize(ffname)
if size <= max_exe_size:
for ffname in Path(self.target).glob("Scripts/*.exe"):
if ffname.stat().st_size <= max_exe_size:
utils.patch_shebang_line(ffname, to_movable=to_movable, targetdir=targetdir)
for ffname in glob.glob(r"%s\Scripts\*.py" % self.target):
for ffname in Path(self.target).glob("Scripts/*.py"):
utils.patch_shebang_line_py(ffname, to_movable=to_movable, targetdir=targetdir)

def install(self, package: Package, install_options: list[str] = None): # Type hint install_options
def install(self, package: Package, install_options: list[str] = None):
"""Install package in distribution."""
if package.fname.endswith((".whl", ".tar.gz", ".zip")): # Check extension with tuple
self.install_bdist_direct(package, install_options=install_options)
Expand Down Expand Up @@ -158,12 +145,10 @@ def patch_standard_packages(self, package_name="", to_movable=True):
# ensure pip will create movable launchers
# sheb_mov1 = classic way up to WinPython 2016-01
# sheb_mov2 = tried way, but doesn't work for pip (at least)
the_place = Path(self.target) / "lib" / "site-packages" / "pip" / "_vendor" / "distlib" / "scripts.py"
sheb_fix = " executable = get_executable()"
sheb_mov1 = " executable = os.path.join(os.path.basename(get_executable()))"
sheb_mov2 = " executable = os.path.join('..',os.path.basename(get_executable()))"

the_place = Path(self.target) / "lib" / "site-packages" / "pip" / "_vendor" / "distlib" / "scripts.py"
print(the_place)
if to_movable:
utils.patch_sourcefile(the_place, sheb_fix, sheb_mov1)
utils.patch_sourcefile(the_place, sheb_mov2, sheb_mov1)
Expand All @@ -176,7 +161,7 @@ def patch_standard_packages(self, package_name="", to_movable=True):
if package_name.lower() in ("", "spyder"):
# spyder don't goes on internet without I ask
utils.patch_sourcefile(
Path(self.target) / "lib" / "site-packages" / "spyder" / "config" /"main.py",
Path(self.target) / "lib" / "site-packages" / "spyder" / "config" / "main.py",
"'check_updates_on_startup': True,",
"'check_updates_on_startup': False,",
)
Expand Down Expand Up @@ -250,7 +235,7 @@ def install_bdist_direct(self, package, install_options=None):

def main(test=False):
if test:
sbdir = Path(__file__).parents[0].parent.parent.parent / "sandbox"
sbdir = Path(__file__).parents[3] / "sandbox"
tmpdir = sbdir / "tobedeleted"
fname = sbdir / "VTK-5.10.0-Qt-4.7.4.win32-py2.7.exe"
print(Package(str(fname)))
Expand Down