Skip to content

cleanup of source_to_wininst part #129

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
Jul 16, 2015
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
cleanup of source_to_wininst part
  • Loading branch information
stonebig committed Jul 16, 2015
commit 154cdaad5d99dcaee974d9d8f6b94faeb608a401
109 changes: 21 additions & 88 deletions winpython/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,31 +363,32 @@ def patch_sourcelines(fname, in_line_start, out_line, endline='\n', silent_mode=
print("impossible to patch", fname, "from", content,
"to", new_content)


def patch_julia03():
"""Ugly patch of Julia/ZMQ and Julia/Nettle to make them movable"""
import io
import os.path as osp
out_line ='"'+ os.path.dirname(os.environ["WINPYDIR"]).replace("\\" ,"\\\\")
out_line = '"' + os.path.dirname(os.environ["WINPYDIR"]).replace("\\", "\\\\")
end_line = r"\\settings\\.julia"
from winpython.utils import patch_sourcelines
from winpython.utils import patch_sourcelines

in_line_start = '@checked_lib zmq ';
in_line_start = '@checked_lib zmq '

fname= os.path.dirname(os.environ["WINPYDIR"]) + r"\settings\.julia\v0.3\ZMQ\deps\deps.jl";
patch_sourcelines (fname, in_line_start, out_line, end_line);
fname= os.path.dirname(os.environ["WINPYDIR"]) + r"\settings\.julia\v0.4\ZMQ\deps\deps.jl";
patch_sourcelines (fname, in_line_start, out_line, end_line);
fname= os.path.dirname(os.environ["WINPYDIR"]) + r"\settings\.julia\v0.5\ZMQ\deps\deps.jl";
patch_sourcelines (fname, in_line_start, out_line, end_line);
fname = os.path.dirname(os.environ["WINPYDIR"]) + r"\settings\.julia\v0.3\ZMQ\deps\deps.jl";
patch_sourcelines(fname, in_line_start, out_line, end_line)
fname = os.path.dirname(os.environ["WINPYDIR"]) + r"\settings\.julia\v0.4\ZMQ\deps\deps.jl";
patch_sourcelines(fname, in_line_start, out_line, end_line)
fname = os.path.dirname(os.environ["WINPYDIR"]) + r"\settings\.julia\v0.5\ZMQ\deps\deps.jl";
patch_sourcelines(fname, in_line_start, out_line, end_line)

in_line_start = '@checked_lib nettle ';

fname= os.path.dirname(os.environ["WINPYDIR"]) + r"\settings\.julia\v0.3\Nettle\deps\deps.jl";
patch_sourcelines (fname, in_line_start, out_line, end_line);
fname= os.path.dirname(os.environ["WINPYDIR"]) + r"\settings\.julia\v0.4\Nettle\deps\deps.jl";
patch_sourcelines (fname, in_line_start, out_line, end_line);
fname= os.path.dirname(os.environ["WINPYDIR"]) + r"\settings\.julia\v0.5\Nettle\deps\deps.jl";
patch_sourcelines (fname, in_line_start, out_line, end_line);
fname = os.path.dirname(os.environ["WINPYDIR"]) + r"\settings\.julia\v0.3\Nettle\deps\deps.jl";
patch_sourcelines(fname, in_line_start, out_line, end_line)
fname = os.path.dirname(os.environ["WINPYDIR"]) + r"\settings\.julia\v0.4\Nettle\deps\deps.jl";
patch_sourcelines(fname, in_line_start, out_line, end_line)
fname = os.path.dirname(os.environ["WINPYDIR"]) + r"\settings\.julia\v0.5\Nettle\deps\deps.jl";
patch_sourcelines(fname, in_line_start, out_line, end_line)


# =============================================================================
Expand Down Expand Up @@ -484,85 +485,16 @@ def extract_archive(fname, targetdir=None, verbose=False):
# "win32|win\_amd64" to replace per "win\_amd64" for 64bit
WHEELBIN_PATTERN = r'([a-zA-Z0-9\-\_\.]*)-([0-9\.\_]*[a-z0-9\+]*[0-9]?)-cp([0-9]*)\-none\-(win32|win\_amd64)\.whl'


def get_source_package_infos(fname):
"""Return a tuple (name, version) of the Python source package"""
match = re.match(SOURCE_PATTERN, osp.basename(fname))
if match is not None:
return match.groups()[:2]


def build_wininst(root, python_exe=None, copy_to=None,
architecture=None, verbose=False, installer='bdist_wininst'):
"""Build wininst installer from Python package located in *root*
and eventually copy it to *copy_to* folder.
Return wininst installer full path."""
if python_exe is None:
python_exe = sys.executable
assert osp.isfile(python_exe)
cmd = [python_exe, 'setup.py', 'build']
if architecture is not None:
archstr = 'win32' if architecture == 32 else 'win-amd64'
cmd += ['--plat-name=%s' % archstr]
cmd += [installer]
# root = a tmp dir in windows\tmp,
if verbose:
subprocess.call(cmd, cwd=root)
else:
p = subprocess.Popen(cmd, cwd=root, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
p.communicate()
p.stdout.close()
p.stderr.close()
distdir = osp.join(root, 'dist')
if not osp.isdir(distdir):
raise RuntimeError("Build failed: see package README file for further"
" details regarding installation requirements.\n\n"
"For more concrete debugging infos, please try to build "
"the package from the command line:\n"
"1. Open a WinPython command prompt\n"
"2. Change working directory to the appropriate folder\n"
"3. Type `python setup.py build install`")
pattern = WININST_PATTERN.replace(r'(win32|win\-amd64)', archstr)
for distname in os.listdir(distdir):
match = re.match(pattern, distname)
if match is not None:
break
# for wheels (winpython here)
match = re.match(SOURCE_PATTERN, distname)
if match is not None:
break
match = re.match(WHEELBIN_PATTERN, distname)
if match is not None:
break
else:
raise RuntimeError("Build failed: not a pure Python package? %s" %
distdir)
src_fname = osp.join(distdir, distname)
if copy_to is None:
return src_fname
else:
dst_fname = osp.join(copy_to, distname)
shutil.move(src_fname, dst_fname)
if verbose:
print(("Move: %s --> %s" % (src_fname, (dst_fname))))
# remove tempo dir 'root' no more needed
shutil.rmtree(root, onerror=onerror)
return dst_fname


def source_to_wininst(fname, python_exe=None,
architecture=None, verbose=False):
"""Extract source archive, build it and create a distutils installer"""
tmpdir = extract_archive(fname)
root = osp.join(tmpdir, '%s-%s' % get_source_package_infos(fname))
assert osp.isdir(root)
return build_wininst(root, python_exe=python_exe,
copy_to=osp.dirname(fname),
architecture=architecture, verbose=verbose)


def direct_pip_install(fname, python_exe=None,
architecture=None, verbose=False, install_options=None):
def direct_pip_install(fname, python_exe=None, architecture=None,
verbose=False, install_options=None):
"""Direct install via pip !"""
copy_to = osp.dirname(fname)

Expand Down Expand Up @@ -599,8 +531,9 @@ def direct_pip_install(fname, python_exe=None,
print("Installed %s" % src_fname)
return src_fname


def do_script(this_script, python_exe=None, copy_to=None,
architecture=None, verbose=False, install_options=None):
architecture=None, verbose=False, install_options=None):
"""Execute a script (get-pip typically)"""
if python_exe is None:
python_exe = sys.executable
Expand Down
15 changes: 1 addition & 14 deletions winpython/wppm.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,20 +370,7 @@ def install(self, package, install_options=None):
"""Install package in distribution"""
assert package.is_compatible_with(self)
tmp_fname = None
# (tragic if pip) self.uninstall_existing(package)
if package.fname.endswith(('.NOtar.gz', '.NOzip')):
self._print(package, "Building")
try:
fname = utils.source_to_wininst(package.fname,
python_exe=osp.join(self.target, 'python.exe'),
architecture=self.architecture, verbose=self.verbose)
except RuntimeError:
if not self.verbose:
print("Failed!")
raise
tmp_fname = fname
package = Package(fname)
self._print_done()

# wheel addition
if package.fname.endswith(('.whl', '.tar.gz', '.zip')):
self.install_bdist_direct(package, install_options=install_options)
Expand Down