Skip to content
Merged
Show file tree
Hide file tree
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
93 changes: 76 additions & 17 deletions make.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def __init__(
docsdirs = []
self._docsdirs = docsdirs
self.verbose = verbose
self.winpydir = None
self.winpydir = None # new WinPython BaseDirectory
self.distribution = None
self.installed_packages = []
self.simulation = simulation
Expand All @@ -331,20 +331,31 @@ def __init__(
self.install_options = install_options
self.flavor = flavor

self.python_fname = self.get_package_fname(
# python_fname = the .zip of the python interpreter PyPy !
# impot re
# re.match(r'(pypy3*-v|python-)([0-9\.rcba]*)((\.|\-)(amd64|win64)?\.zip')
try: # PyPy
self.python_fname = self.get_package_fname(
r'(pypy3|python-)([0-9]|[a-zA-Z]|.)*.zip'
)
except: # normal Python
self.python_fname = self.get_package_fname(
r'python-([0-9\.rcba]*)((\.|\-)amd64)?\.(zip|zip)'
)
)

# osp.join(self.winpydir, self.python_name) = Directory of Python exec
# self.pythondir =osp.join(self.winpydir, self.python_name)
self.python_name = osp.basename(self.python_fname)[
:-4
]
self.distname = 'win%s' % self.python_name
vlst = (
re.match(r'winpython-([0-9\.]*)', self.distname)
.groups()[0]
.split('.')
)
self.python_version = '.'.join(vlst[:2])
self.python_fullversion = '.'.join(vlst[:3])
self.distname = 'winUNKNOWN' #win%s' % self.python_name # PyPy ?
#vlst = (
# re.match(r'winpython-([0-9\.]*)', self.distname)
# .groups()[0]
# .split('.')
#)
self.python_version = 'winUNKNOWN' # '.'.join(vlst[:2])
self.python_fullversion = 'winUNKNOWN' # '.'.join(vlst[:3])

@property
def package_index_wiki(self):
Expand Down Expand Up @@ -471,7 +482,7 @@ def winpyver(self):
@property
def python_dir(self):
"""Return Python dirname (full path) of the target distribution"""
return osp.join(self.winpydir, self.python_name)
return osp.join(self.winpydir, self.python_name) # python.exe path

@property
def winpy_arch(self):
Expand Down Expand Up @@ -561,13 +572,21 @@ def get_package_fname(self, pattern):
% pattern
)

def create_batch_script(self, name, contents):
def create_batch_script(self, name, contents,
do_changes=None):
"""Create batch script %WINPYDIR%/name"""
scriptdir = osp.join(self.winpydir, 'scripts')
if not osp.isdir(scriptdir):
os.mkdir(scriptdir)
print ('dochanges for %s %', name, do_changes)
# live patch pypy3
contents_final = contents
if do_changes != None:
for i in do_changes:
contents_final = contents_final.replace(i[0], i[1])

fd = open(osp.join(scriptdir, name), 'w')
fd.write(contents)
fd.write(contents_final)
fd.close()

def create_launcher(
Expand Down Expand Up @@ -985,6 +1004,14 @@ def _create_batch_scripts_initial(self):
+ convps(self.postpath)
)

# PyPy3
shorty =self.distribution.short_exe
changes=(
(r'DIR%\python.exe' , r'DIR%' + "\\" + shorty),
(r'DIR%\PYTHON.EXE' , r'DIR%' + "\\" + shorty),
)
if shorty == 'pypy3.exe':
changes += ((r'\Lib\idlelib' , r'\lib-python\3\idlelib'),)
self.create_batch_script(
'env.bat',
r"""@echo off
Expand All @@ -1003,7 +1030,6 @@ def _create_batch_scripts_initial(self):
+ r"""
rem 2019-08-25 pyjulia needs absolutely a variable PYTHON=%WINPYDIR%python.exe
set PYTHON=%WINPYDIR%\python.exe

set WINPYVER="""
+ self.winpyver
+ r"""
Expand Down Expand Up @@ -1124,6 +1150,7 @@ def _create_batch_scripts_initial(self):
)>> "%winpython_ini%"

""",
do_changes=changes,
)

self.create_batch_script(
Expand Down Expand Up @@ -1303,6 +1330,7 @@ def _create_batch_scripts_initial(self):
$host.ui.RawUI.ForegroundColor = "White"

""",
do_changes=changes,
)

self.create_batch_script(
Expand All @@ -1313,6 +1341,7 @@ def _create_batch_scripts_initial(self):
Powershell.exe -Command "& {Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy RemoteSigned -noexit -File ""%~dp0WinPython_PS_Prompt.ps1""'}"
exit
""",
do_changes=changes,
)

self.create_batch_script(
Expand All @@ -1322,6 +1351,7 @@ def _create_batch_scripts_initial(self):
Powershell.exe -Command "& {Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy RemoteSigned -noexit -File ""%~dp0WinPython_PS_Prompt.ps1""'}"
exit
""",
do_changes=changes,
)

self.create_batch_script(
Expand Down Expand Up @@ -1369,6 +1399,7 @@ def _create_batch_scripts_initial(self):
if not exist "%HOME%\pydistutils.cfg" xcopy "%WINPYDIRBASE%\settings\pydistutils.cfg" "%HOME%"
:no_cython
""",
do_changes=changes,
)

self.create_batch_script(
Expand Down Expand Up @@ -1440,6 +1471,17 @@ def _create_batch_scripts_initial(self):
def _create_batch_scripts(self):
"""Create batch scripts"""
self._print("Creating batch scripts")

# PyPy3
shorty =self.distribution.short_exe
changes=(
(r'DIR%\python.exe' , r'DIR%' + "\\" + shorty),
(r'DIR%\PYTHON.EXE' , r'DIR%' + "\\" + shorty),
)
if shorty == 'pypy3.exe':
changes += ((r'\Lib\idlelib' , r'\lib-python\3\idlelib'),)


self.create_batch_script(
'readme.txt',
r"""These batch files are required to run WinPython icons.
Expand Down Expand Up @@ -1498,6 +1540,7 @@ def _create_batch_scripts(self):
"%WINPYDIR%\python.exe" -c "from winpython import wppm;dist=wppm.Distribution(r'%WINPYDIR%');dist.patch_standard_packages('pip', to_movable=True)"
pause
""",
do_changes=changes,
)

self.create_batch_script(
Expand All @@ -1509,6 +1552,7 @@ def _create_batch_scripts(self):
"%WINPYDIR%\python.exe" -c "from winpython import wppm;dist=wppm.Distribution(r'%WINPYDIR%');dist.patch_standard_packages('pip', to_movable=False)"
pause
""",
do_changes=changes,
)

self.create_batch_script(
Expand Down Expand Up @@ -1588,6 +1632,7 @@ def _create_batch_scripts(self):
if not "%WINPYWORKDIR%"=="%WINPYWORKDIR1%" cd %WINPYWORKDIR1%
"%WINPYDIR%\python.exe" %*
""",
do_changes=changes,
)

self.create_batch_script(
Expand All @@ -1602,6 +1647,7 @@ def _create_batch_scripts(self):
"%WINPYDIR%\python.exe" %*
)
""",
do_changes=changes,
)

self.create_batch_script(
Expand All @@ -1615,6 +1661,7 @@ def _create_batch_scripts(self):
"%WINPYDIR%\python.exe" "%WINPYDIR%\Lib\idlelib\idle.pyw" %*
)
""",
do_changes=changes,
)

self.create_batch_script(
Expand All @@ -1624,6 +1671,7 @@ def _create_batch_scripts(self):
"%WINPYDIR%\python.exe" "%WINPYDIR%\Lib\idlelib\idle.pyw" %*

""",
do_changes=changes,
)
self.create_batch_script(
'winidlex.bat',
Expand All @@ -1638,6 +1686,7 @@ def _create_batch_scripts(self):
"%WINPYDIR%\python.exe" "%WINPYDIR%\Lib\idlelib\idle.pyw" %*
)
""",
do_changes=changes,
)
self.create_batch_script(
'winidle.bat',
Expand All @@ -1646,6 +1695,7 @@ def _create_batch_scripts(self):
cd/D "%WINPYWORKDIR1%"
"%WINPYDIR%\python.exe" "%WINPYDIR%\Lib\idlelib\idle.pyw" %*
""",
do_changes=changes,
)

self.create_batch_script(
Expand Down Expand Up @@ -1753,6 +1803,7 @@ def _create_batch_scripts(self):
"%WINPYDIR%\python.exe" "%WINPYDIR%\Lib\site-packages\PySide2\examples\datavisualization\bars3d.py"
)
""",
do_changes=changes,
)

self.create_batch_script(
Expand Down Expand Up @@ -1854,6 +1905,7 @@ def _create_batch_scripts(self):
cd/D "%WINPYWORKDIR1%"
"%WINPYDIR%\python.exe" -m winpython.controlpanel %*
""",
do_changes=changes,
)

# self.create_python_batch('wpcp.bat', '-m winpython.controlpanel',
Expand All @@ -1869,6 +1921,7 @@ def _create_batch_scripts(self):
"%WINPYDIR%\python.exe" -c "from winpython import wppm;dist=wppm.Distribution(r'%WINPYDIR%');dist.patch_standard_packages('pip', to_movable=True)
pause
""",
do_changes=changes,
)

self.create_batch_script(
Expand Down Expand Up @@ -2018,7 +2071,7 @@ def make(
self._print_done()

if remove_existing and not self.simulation:
self._extract_python()
self._extract_python() # unzip Python interpreter
self.distribution = wppm.Distribution(
self.python_dir,
verbose=self.verbose,
Expand All @@ -2033,6 +2086,11 @@ def make(
# always create all launchers (as long as it is NSIS-based)
self._create_launchers()
# pre-patch current pip (until default python has pip 8.0.3)

# PyPY must ensure pip
# "pypy3.exe -m ensurepip"
utils.python_execmodule('ensurepip', self.distribution.target)

self.distribution.patch_standard_packages('pip')
# not forced update of pip (FIRST) and setuptools here
for req in ('pip', 'setuptools', 'wheel', 'winpython'):
Expand Down Expand Up @@ -2180,7 +2238,8 @@ def make_all(
), "The *basedir* directory must be specified"
assert architecture in (32, 64)
utils.print_box(
"Making WinPython %dbits" % architecture
"Making WinPython %dbits at %s" % (architecture,
osp.join(basedir, 'bu' + flavor))
)

# Create Build director, where Winpython will be constructed
Expand Down
6 changes: 6 additions & 0 deletions winpython/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ def python_query(cmd, path):
the_exe = get_python_executable(path)
return exec_shell_cmd('%s -c "%s"' % (the_exe, cmd), path).splitlines()[0]

def python_execmodule(cmd, path):
"""Execute Python command using the Python interpreter located in *path*"""
the_exe = get_python_executable(path)
exec_shell_cmd('%s -m %s' % (the_exe, cmd), path)


def get_python_infos(path):
"""Return (version, architecture) for the Python distribution located in
Expand All @@ -385,6 +390,7 @@ def get_python_infos(path):
)
if re.match(r'([0-9]*)\.([0-9]*)', ver) is None:
ver = None

return ver, arch


Expand Down
7 changes: 7 additions & 0 deletions winpython/wppm.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ def __init__(
self.version, self.architecture = utils.get_python_infos(
target
)
# name of the exe (python.exe or pypy3;exe)
self.short_exe = osp.basename(utils.get_python_executable(self.target))

def clean_up(self):
"""Remove directories which couldn't be removed when building"""
Expand Down Expand Up @@ -634,6 +636,11 @@ def create_pybat(
scriptpy = osp.join(
self.target, 'Scripts'
) # std Scripts of python

# PyPy has no initial Scipts directory
if not osp.isdir(scriptpy):
os.mkdir(scriptpy)

if not list(names) == names:
my_list = [
f
Expand Down