contrib/Makefile.python
author Kyle Lippincott <spectral@google.com>
Wed, 02 Dec 2020 12:33:51 -0800
changeset 46018 8b0a3ff5ed12
parent 42191 ae68418cc3a1
permissions -rw-r--r--
statprof: separate functions and "line", assume 4 digit line numbers Previously, the profile output looked like this (I've removed many lines that are mostly inconsequential): ``` | 100.0% 0.02s hg: <module> line 43: dispatch.run() | 100.0% 0.02s dispatch.py: run line 115: status = dispatch(req) | 100.0% 0.02s dispatch.py: _runcatchfunc line 432: return _dispatch(req) \ 50.0% 0.01s dispatch.py: _dispatch line 1228: return runcommand( | 50.0% 0.01s dispatch.py: runcommand line 883: ret = _runcommand(ui, optio... | 50.0% 0.01s dispatch.py: _runcommand line 1240: return cmdfunc() | 50.0% 0.01s localrepo.py: __getitem__ line 1670: quick_access = self._quick_... | 50.0% 0.01s localrepo.py: _quick_access_changeidline 1650: return self._quick_access_c... | 50.0% 0.01s localrepo.py: __get__ line 179: return getattr(unfi, self.n... | 50.0% 0.01s util.py: __get__ line 1747: result = self.func(obj) | 50.0% 0.01s localrepo.py: _quick_access_changeid_wcline 1611: cl = self.unfiltered().chan... | 50.0% 0.01s localrepo.py: __get__ line 110: return super(_basefilecache... | 50.0% 0.01s util.py: __getattribute__line 245: self.__spec__.loader.exec_m... | 50.0% 0.01s <frozen importlib._bootstrap_external>: exec_moduleline 783: | 50.0% 0.01s <frozen importlib._bootstrap>: _call_with_frames_removedline 219: | 50.0% 0.01s changelog.py: <module> line 376: class changelog(revlog.revl... | 50.0% 0.01s util.py: __getattribute__line 245: self.__spec__.loader.exec_m... | 50.0% 0.01s <frozen importlib._bootstrap_external>: exec_moduleline 779: | 50.0% 0.01s <frozen importlib._bootstrap_external>: get_codeline 868: | 50.0% 0.01s <frozen importlib._bootstrap_external>: path_statsline 1012: | 50.0% 0.01s <frozen importlib._bootstrap_external>: _path_statline 87: ``` This has a few problems, though I'm only addressing some of them. 1. If the stuff before "line ###" is long, there's no separation between the function name and the "line" string. 2. If the stuff before "line ###" is really long, there's excessive separation between the "line" string and the line number. 3. We frequently have 4-digit line numbers, the code on the right wasn't dynamically indented and ended up quite messy looking. To solve these problems, I've added a ", " prefix before "line" iff it would otherwise not have any separation such as spaces. I've added a 'max' so that we never use a negative width (which is the cause of problem #2 above), and I've added a default assumption of 4 digit line numbers (but again using a 'max' so this shouldn't cause problems if we go beyond that. With these changes, it now looks like this: ``` | 100.0% 0.02s hg: <module> line 43: dispatch.run() | 100.0% 0.02s dispatch.py: run line 115: status = dispatch(req) | 100.0% 0.02s dispatch.py: _runcatchfunc line 432: return _dispatch(req) \ 50.0% 0.01s dispatch.py: _dispatch line 1228: return runcommand( | 50.0% 0.01s dispatch.py: runcommand line 883: ret = _runcommand(ui, optio... | 50.0% 0.01s dispatch.py: _runcommand line 1240: return cmdfunc() | 50.0% 0.01s localrepo.py: __getitem__ line 1670: quick_access = self._quick_... | 50.0% 0.01s localrepo.py: _quick_access_changeid, line 1650: return self._quick_access_c... | 50.0% 0.01s localrepo.py: __get__ line 179: return getattr(unfi, self.n... | 50.0% 0.01s util.py: __get__ line 1747: result = self.func(obj) | 50.0% 0.01s localrepo.py: _quick_access_changeid_wc, line 1611: cl = self.unfiltered().chan... | 50.0% 0.01s localrepo.py: __get__ line 110: return super(_basefilecache... | 50.0% 0.01s util.py: __getattribute__, line 245: self.__spec__.loader.exec_m... | 50.0% 0.01s <frozen importlib._bootstrap_external>: exec_module, line 783: | 50.0% 0.01s <frozen importlib._bootstrap>: _call_with_frames_removed, line 219: | 50.0% 0.01s changelog.py: <module> line 376: class changelog(revlog.revl... | 50.0% 0.01s util.py: __getattribute__, line 245: self.__spec__.loader.exec_m... | 50.0% 0.01s <frozen importlib._bootstrap_external>: exec_module, line 779: | 50.0% 0.01s <frozen importlib._bootstrap_external>: get_code, line 868: | 50.0% 0.01s <frozen importlib._bootstrap_external>: path_stats, line 1012: | 50.0% 0.01s <frozen importlib._bootstrap_external>: _path_stat, line 87: ``` Differential Revision: https://phab.mercurial-scm.org/D9511
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42191
ae68418cc3a1 buildrpm: bump bundled Python version to 2.7.16 when building for centos{5,6}
Antonio Muci <a.mux@inwind.it>
parents: 36143
diff changeset
     1
PYTHONVER=2.7.16
20388
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
     2
PYTHONNAME=python-
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
     3
PREFIX=$(HOME)/bin/prefix-$(PYTHONNAME)$(PYTHONVER)
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
     4
SYMLINKDIR=$(HOME)/bin
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
     5
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
     6
help:
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
     7
	@echo
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
     8
	@echo 'Make a custom installation of a Python version'
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
     9
	@echo
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    10
	@echo 'Common make parameters:'
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    11
	@echo '  PYTHONVER=...    [$(PYTHONVER)]'
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    12
	@echo '  PREFIX=...       [$(PREFIX)]'
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    13
	@echo '  SYMLINKDIR=...   [$(SYMLINKDIR) creating $(PYTHONNAME)$(PYTHONVER)]'
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    14
	@echo
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    15
	@echo 'Common make targets:'
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    16
	@echo '  python    - install Python $$PYTHONVER in $$PREFIX'
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    17
	@echo '  symlink   - create a $$SYMLINKDIR/$(PYTHONNAME)$$PYTHONVER symlink'
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    18
	@echo
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    19
	@echo 'Example: create a temporary Python installation:'
26735
ec74ea542201 contrib: offer Python 2.7.10
Mads Kiilerich <madski@unity3d.com>
parents: 26734
diff changeset
    20
	@echo '  $$ make -f Makefile.python python PYTHONVER=${PYTHONVER} PREFIX=/tmp/p27'
ec74ea542201 contrib: offer Python 2.7.10
Mads Kiilerich <madski@unity3d.com>
parents: 26734
diff changeset
    21
	@echo '  $$ /tmp/p27/bin/python -V'
ec74ea542201 contrib: offer Python 2.7.10
Mads Kiilerich <madski@unity3d.com>
parents: 26734
diff changeset
    22
	@echo '  Python 2.7'
20388
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    23
	@echo
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    24
	@echo 'Some external libraries are required for building Python: zlib bzip2 openssl.'
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    25
	@echo 'Make sure their development packages are installed systemwide.'
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    26
# fedora: yum install zlib-devel bzip2-devel openssl-devel
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    27
# debian: apt-get install zlib1g-dev libbz2-dev libssl-dev
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    28
	@echo
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    29
	@echo 'To build a nice collection of interesting Python versions:'
26735
ec74ea542201 contrib: offer Python 2.7.10
Mads Kiilerich <madski@unity3d.com>
parents: 26734
diff changeset
    30
	@echo '  $$ for v in 2.{6{,.1,.2,.9},7{,.8,.10}}; do'
20388
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    31
	@echo '    make -f Makefile.python symlink PYTHONVER=$$v || break; done'
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    32
	@echo 'To run a Mercurial test on all these Python versions:'
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    33
	@echo '  $$ for py in `cd ~/bin && ls $(PYTHONNAME)2.*`; do'
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    34
	@echo '    echo $$py; $$py run-tests.py test-http.t; echo; done'
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    35
	@echo
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    36
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    37
export LANGUAGE=C
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    38
export LC_ALL=C
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    39
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    40
python: $(PREFIX)/bin/python docutils
26734
b000d34f863f contrib: drop Python < 2.6 from Makefile.python
Mads Kiilerich <madski@unity3d.com>
parents: 23880
diff changeset
    41
	printf 'import sys, zlib, bz2, docutils, ssl' | $(PREFIX)/bin/python
20388
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    42
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    43
PYTHON_SRCDIR=Python-$(PYTHONVER)
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    44
PYTHON_SRCFILE=$(PYTHON_SRCDIR).tgz
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    45
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    46
$(PREFIX)/bin/python:
23824
e278fc8bb0c3 Makefile.python: try curl if wget fails
Augie Fackler <augie@google.com>
parents: 23140
diff changeset
    47
	[ -f $(PYTHON_SRCFILE) ] || wget http://www.python.org/ftp/python/$(PYTHONVER)/$(PYTHON_SRCFILE) || curl -OL http://www.python.org/ftp/python/$(PYTHONVER)/$(PYTHON_SRCFILE) || [ -f $(PYTHON_SRCFILE) ]
20388
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    48
	rm -rf $(PYTHON_SRCDIR)
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    49
	tar xf $(PYTHON_SRCFILE)
27230
9f8b8c4e5076 contrib: disable SSLv3_method() to build old Python with recent libssl
Yuya Nishihara <yuya@tcha.org>
parents: 26735
diff changeset
    50
	# Debian/Ubuntu disables SSLv2,3 the hard way, disable it on old Pythons too
9f8b8c4e5076 contrib: disable SSLv3_method() to build old Python with recent libssl
Yuya Nishihara <yuya@tcha.org>
parents: 26735
diff changeset
    51
	-sed -i 's,self.*SSLv[23]_method(),0;//\0,g' $(PYTHON_SRCDIR)/Modules/_ssl.c
20388
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    52
	# Find multiarch system libraries on Ubuntu and disable fortify error when setting argv
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    53
	LDFLAGS="-L/usr/lib/`dpkg-architecture -qDEB_HOST_MULTIARCH`"; \
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    54
	BASECFLAGS=-U_FORTIFY_SOURCE; \
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    55
	export LDFLAGS BASECFLAGS; \
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    56
	cd $(PYTHON_SRCDIR) && ./configure --prefix=$(PREFIX) && make all SVNVERSION=pwd && make install
26734
b000d34f863f contrib: drop Python < 2.6 from Makefile.python
Mads Kiilerich <madski@unity3d.com>
parents: 23880
diff changeset
    57
	printf 'import sys, zlib, bz2, ssl' | $(PREFIX)/bin/python
20388
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    58
	rm -rf $(PYTHON_SRCDIR)
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    59
23140
fbd79c2552a6 contrib: update build defaults to latest Python and docutils versions
Mads Kiilerich <madski@unity3d.com>
parents: 20388
diff changeset
    60
DOCUTILSVER=0.12
20388
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    61
DOCUTILS_SRCDIR=docutils-$(DOCUTILSVER)
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    62
DOCUTILS_SRCFILE=$(DOCUTILS_SRCDIR).tar.gz
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    63
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    64
docutils: $(PREFIX)/bin/python
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    65
	@$(PREFIX)/bin/python -c 'import docutils' || ( set -ex; \
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    66
	[ -f $(DOCUTILS_SRCFILE) ] || wget http://downloads.sourceforge.net/project/docutils/docutils/$(DOCUTILSVER)/$(DOCUTILS_SRCFILE) || [ -f $(DOCUTILS_SRCFILE) ]; \
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    67
	rm -rf $(DOCUTILS_SRCDIR); \
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    68
	tar xf $(DOCUTILS_SRCFILE); \
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    69
	cd $(DOCUTILS_SRCDIR) && $(PREFIX)/bin/python setup.py install --prefix=$(PREFIX); \
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    70
	$(PREFIX)/bin/python -c 'import docutils'; \
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    71
	rm -rf $(DOCUTILS_SRCDIR); )
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    72
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    73
symlink: python $(SYMLINKDIR)
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    74
	ln -sf $(PREFIX)/bin/python $(SYMLINKDIR)/$(PYTHONNAME)$(PYTHONVER)
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    75
9fe578297b5c contrib/Makefile.python: build local Python from source
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    76
.PHONY: help python docutils symlink