##// END OF EJS Templates
pyoxidizer: produce working Python 3 Windows installers (issue6366)...
pyoxidizer: produce working Python 3 Windows installers (issue6366) While we've had code to produce Python 3 Windows installers with PyOxidizer, we haven't been advertising them on the web site due to a bug in making TLS connections and issues around resource handling. This commit upgrades our PyOxidizer install and configuration to use a recent Git commit of PyOxidizer. This new version of PyOxidizer contains a *ton* of changes, improvements, and bug fixes. Notably, Windows shared distributions now mostly "just work" and the TLS bug and random problems with Python extension modules in the standard library go away. And Python has been upgraded from 3.7 to 3.8.6. The price we pay for this upgrade is a ton of backwards incompatible changes to Starlark. I applied this commit (the overall series actually) on stable to produce Windows installers for Mercurial 5.5.2, which I published shortly before submitting this commit for review. In order to get the stable branch working, I decided to take a less aggressive approach to Python resource management. Previously, we were attempting to load all Python modules from memory and were performing some hacks to copy Mercurial's non-module resources into additional directories in Starlark. This commit implements a resource callback function in Starlark (a new feature since PyOxidizer 0.7) to dynamically assign standard library resources to in-memory loading and all other resources to filesystem loading. This means that Mercurial's files and all the other packages we ship in the Windows installers (e.g. certifi and pygments) are loaded from the filesystem instead of from memory. This avoids issues due to lack of __file__ and enables us to ship a working Python 3 installer on Windows. The end state of the install layout after this patch is not ideal for @: we still copy resource files like templates and help text to directories next to the hg.exe executable. There is code in @ to use importlib.resources to load these files and we could likely remove these copies once this lands on @. But for now, the install layout mimics what we've shipped for seemingly forever and is backwards compatible. It allows us to achieve the milestone of working Python 3 Windows installers and gets us a giant step closer to deleting Python 2. Differential Revision: https://phab.mercurial-scm.org/D9148

File last commit:

r44780:0e8b28fb default
r46277:57b5452a default
Show More
httpconnection.py
135 lines | 4.2 KiB | text/x-python | PythonLexer
Augie Fackler
url: use new http support if requested by the user...
r14244 # httpconnection.py - urllib2 handler for new http support
#
# Copyright 2005, 2006, 2007, 2008 Matt Mackall <mpm@selenic.com>
# Copyright 2006, 2007 Alexis S. L. Carvalho <alexis@cecm.usp.br>
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
# Copyright 2011 Google, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
Gregory Szorc
httpconnection: use absolute_import
r27521
from __future__ import absolute_import
import os
Augie Fackler
url: use new http support if requested by the user...
r14244
Gregory Szorc
httpconnection: use absolute_import
r27521 from .i18n import _
Gregory Szorc
py3: manually import pycompat.open into files that need it...
r43355 from .pycompat import open
Gregory Szorc
httpconnection: use absolute_import
r27521 from . import (
Augie Fackler
httpconnection: convert url to bytes in readauthforuri...
r36669 pycompat,
Gregory Szorc
httpconnection: use absolute_import
r27521 util,
)
Augie Fackler
url: use new http support if requested by the user...
r14244
timeless
pycompat: switch to util.urlreq/util.urlerr for py3 compat
r28883 urlerr = util.urlerr
urlreq = util.urlreq
Augie Fackler
url: use new http support if requested by the user...
r14244 # moved here from url.py to avoid a cycle
class httpsendfile(object):
"""This is a wrapper around the objects returned by python's "open".
Mads Kiilerich
http: handle push of bundles > 2 GB again (issue3017)...
r15152 Its purpose is to send file-like objects via HTTP.
It do however not define a __len__ attribute because the length
might be more than Py_ssize_t can handle.
Augie Fackler
url: use new http support if requested by the user...
r14244 """
def __init__(self, ui, *args, **kwargs):
self.ui = ui
self._data = open(*args, **kwargs)
self.seek = self._data.seek
self.close = self._data.close
self.write = self._data.write
Mads Kiilerich
http: handle push of bundles > 2 GB again (issue3017)...
r15152 self.length = os.fstat(self._data.fileno()).st_size
Augie Fackler
url: use new http support if requested by the user...
r14244 self._pos = 0
Matt Harbison
httpconnection: allow `httpsendfile` subclasses to suppress the progressbar...
r44780 self._progress = self._makeprogress()
def _makeprogress(self):
Augie Fackler
url: use new http support if requested by the user...
r14244 # We pass double the max for total because we currently have
# to send the bundle twice in the case of a server that
# requires authentication. Since we can't know until we try
# once whether authentication will be required, just lie to
# the user and maybe the push succeeds suddenly at 50%.
Matt Harbison
httpconnection: allow `httpsendfile` subclasses to suppress the progressbar...
r44780 return self.ui.makeprogress(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'sending'), unit=_(b'kb'), total=(self.length // 1024 * 2)
Augie Fackler
style: run a patched black on a subset of mercurial...
r43345 )
Martin von Zweigbergk
httpconnection: use progress helper...
r38412
def read(self, *args, **kwargs):
ret = self._data.read(*args, **kwargs)
if not ret:
self._progress.complete()
return ret
self._pos += len(ret)
self._progress.update(self._pos // 1024)
Augie Fackler
url: use new http support if requested by the user...
r14244 return ret
Mads Kiilerich
largefiles: use context for file closing...
r30142 def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.close()
Augie Fackler
style: run a patched black on a subset of mercurial...
r43345
Augie Fackler
url: use new http support if requested by the user...
r14244 # moved here from url.py to avoid a cycle
Patrick Mezard
http: pass user to readauthforuri() (fix 4a43e23b8c55)...
r15025 def readauthforuri(ui, uri, user):
Augie Fackler
httpconnection: convert url to bytes in readauthforuri...
r36669 uri = pycompat.bytesurl(uri)
Augie Fackler
url: use new http support if requested by the user...
r14244 # Read configuration
Gregory Szorc
httpconnection: rename config to groups...
r31300 groups = {}
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 for key, val in ui.configitems(b'auth'):
if key in (b'cookiefile',):
Gregory Szorc
httpconnection: allow a global auth.cookiefile config entry...
r31935 continue
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'.' not in key:
ui.warn(_(b"ignoring invalid [auth] key '%s'\n") % key)
Augie Fackler
url: use new http support if requested by the user...
r14244 continue
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 group, setting = key.rsplit(b'.', 1)
Gregory Szorc
httpconnection: rename config to groups...
r31300 gdict = groups.setdefault(group, {})
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if setting in (b'username', b'cert', b'key'):
Augie Fackler
url: use new http support if requested by the user...
r14244 val = util.expandpath(val)
gdict[setting] = val
# Find the best match
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 scheme, hostpath = uri.split(b'://', 1)
Patrick Mezard
hgweb: do not ignore [auth] if url has a username (issue2822)...
r15005 bestuser = None
Augie Fackler
url: use new http support if requested by the user...
r14244 bestlen = 0
bestauth = None
Gregory Szorc
py3: finish porting iteritems() to pycompat and remove source transformer...
r43376 for group, auth in pycompat.iteritems(groups):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if user and user != auth.get(b'username', user):
Patrick Mezard
hgweb: do not ignore [auth] if url has a username (issue2822)...
r15005 # If a username was set in the URI, the entry username
# must either match it or be unset
continue
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 prefix = auth.get(b'prefix')
Augie Fackler
url: use new http support if requested by the user...
r14244 if not prefix:
continue
Matt Harbison
http: allow 'auth.prefix' to have a username consistent with the URI...
r40699
prefixurl = util.url(prefix)
if prefixurl.user and prefixurl.user != user:
# If a username was set in the prefix, it must match the username in
# the URI.
continue
# The URI passed in has been stripped of credentials, so erase the user
# here to allow simpler matching.
prefixurl.user = None
prefix = bytes(prefixurl)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 p = prefix.split(b'://', 1)
Augie Fackler
url: use new http support if requested by the user...
r14244 if len(p) > 1:
schemes, prefix = [p[0]], p[1]
else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 schemes = (auth.get(b'schemes') or b'https').split()
Augie Fackler
style: run a patched black on a subset of mercurial...
r43345 if (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (prefix == b'*' or hostpath.startswith(prefix))
Augie Fackler
style: run a patched black on a subset of mercurial...
r43345 and (
len(prefix) > bestlen
or (
len(prefix) == bestlen
and not bestuser
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 and b'username' in auth
Augie Fackler
style: run a patched black on a subset of mercurial...
r43345 )
)
and scheme in schemes
):
Augie Fackler
url: use new http support if requested by the user...
r14244 bestlen = len(prefix)
bestauth = group, auth
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 bestuser = auth.get(b'username')
Patrick Mezard
hgweb: do not ignore [auth] if url has a username (issue2822)...
r15005 if user and not bestuser:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 auth[b'username'] = user
Augie Fackler
url: use new http support if requested by the user...
r14244 return bestauth