#5 Mercurial for Python2 and Python3
Merged a month ago by pstodulk. Opened 2 months ago by pstodulk.
rpms/ pstodulk/mercurial master  into  master

file added
+37

@@ -0,0 +1,37 @@ 

+ From 313f85a013b487149bff441411d4b643d0cea6c2 Mon Sep 17 00:00:00 2001

+ From: Petr Stodulka <pstodulk@redhat.com>

+ Date: Thu, 15 Aug 2019 01:20:11 +0200

+ Subject: [PATCH] create hg3 bin/script to keep Py2 & Py3 mercurial

+  installable..

+ 

+ This can be removed completely once the mercurial for Python2 is

+ removed

+ ---

+  setup.py | 4 ++++

+  1 file changed, 4 insertions(+)

+ 

+ diff --git a/setup.py b/setup.py

+ index 99556ce..5e30421 100644

+ --- a/setup.py

+ +++ b/setup.py

+ @@ -207,6 +207,8 @@ def write_if_changed(path, content):

+              fh.write(content)

+  

+  scripts = ['hg']

+ +if 'HGPYTHON3' in os.environ:

+ +    scripts = ['hg3']

+  if os.name == 'nt':

+      # We remove hg.bat if we are able to build hg.exe.

+      scripts.append('contrib/win32/hg.bat')

+ @@ -311,6 +313,8 @@ def findhg():

+      hgenv['HGPLAIN'] = '1'

+      hgenv['LANGUAGE'] = 'C'

+      hgcmd = ['hg']

+ +    if 'HGPYTHON3' in os.environ:

+ +        hgcmd = ['hg3']

+      # Run a simple "hg log" command just to see if using hg from the user's

+      # path works and can successfully interact with this repository.  Windows

+      # gives precedence to hg.exe in the current directory, so fall back to the

+ -- 

+ 2.21.0

+ 

file modified
+2 -2

@@ -3,8 +3,8 @@ 

  +++ b/contrib/hg-ssh	Tue Mar 05 07:26:54 2019 -0500

  @@ -1,4 +1,4 @@

  -#!/usr/bin/env python

- +#!/usr/bin/env python2

+ +#!/usr/bin/env python3

   #

   # Copyright 2005-2007 by Intevation GmbH <intevation@intevation.de>

   #

-   

\ No newline at end of file

+  

file added
+13

@@ -0,0 +1,13 @@ 

+ diff --git a/hgext/hgk.py b/hgext/hgk.py

+ index 3da626e..61239e8 100644

+ --- a/hgext/hgk.py

+ +++ b/hgext/hgk.py

+ @@ -335,7 +335,7 @@ def revtree(ui, args, repo, full="tree", maxnr=0, parents=False):

+      ('[OPTION]... REV...'))

+  def revlist(ui, repo, *revs, **opts):

+      """print revisions"""

+ -    if opts['header']:

+ +    if opts[u'header']:

why is this needed?

+          full = "commit"

+      else:

+          full = None

file modified
+68 -13

@@ -1,5 +1,3 @@ 

- %{!?python2_sitearch: %define python2_sitearch %(%{__python2} -c "from distutils.sysconfig import get_python2_lib; print get_python2_lib(1)")}

- 

  Summary: Mercurial -- a distributed SCM

  Name: mercurial

  Version: 5.1.2

@@ -16,10 +14,13 @@ 

  Source0: http://www.selenic.com/mercurial/release/%{name}-%{upstreamversion}.tar.gz

  Source1: mercurial-site-start.el

  Patch0: contrib-hg-ssh.patch

+ Patch1: hgk_python3.patch

+ Patch2: 0001-setup-hg3.patch

  BuildRequires: python2 python2-devel bash-completion

  BuildRequires: emacs-nox emacs-el pkgconfig gettext python2-docutils

  BuildRequires: gcc

  Requires: python2 emacs-filesystem

+ Requires: %{name}-lang = %{version}-%{release}

  Provides: hg = %{version}-%{release}

  Obsoletes: emacs-mercurial <= 3.4.1, emacs-mercurial-el <= 3.4.1

  Provides: emacs-mercurial <= 3.4.1, emacs-mercurial-el <= 3.4.1

@@ -36,11 +37,22 @@ 

  

  # If the emacs-el package has installed a pkgconfig file, use that to determine

  

+ %package py3

+ Summary: Mercurial -- a distributed SCM for Python3

+ Provides: hg3 = %{version}-%{release}

+ Requires: python3 emacs-filesystem

+ BuildRequires: python3 python3-devel bash-completion

+ BuildRequires: emacs-nox emacs-el pkgconfig gettext python3-docutils

+ Requires: %{name}-lang = %{version}-%{release}

+ 

+ %description py3

+ Subpackage with mercurial for Python3. This is beta version with own problems.

+ 

+ 

  %package hgk

  Summary:    Hgk interface for mercurial

  Requires:   hg = %{version}-%{release}, tk

  

- 

  %description hgk

  A Mercurial extension for displaying the change history graphically

  using Tcl/Tk.  Displays branches and merges in an easily

@@ -51,6 +63,7 @@ 

  http://www.selenic.com/mercurial/wiki/index.cgi/UsingHgk for more

  documentation.

  

+ 

  %package chg

  Summary:    A fast client for Mercurial command server running on Unix. It saves time of slow Python startup.

  Requires:   hg = %{version}-%{release}

@@ -65,25 +78,44 @@ 

  and executes Mercurial commands.

  

  

+ %package lang

+ Summary:    Locales for mercurial

+ 

+ %description lang

+ Locales for mercurial.

+ 

  %prep

  %setup -q -n %{name}-%{upstreamversion}

- # Patch files to use python2 instead of (since lately) non existent python binary.

- sed -ri 's|python\b|python2|' %{_builddir}/%{name}-%{version}/Makefile %{_builddir}/%{name}-%{version}/doc/Makefile

+ # NOTE: Use PYTHON envar instead of pathing Makefiles

+ # sed -ri 's|python\b|python2|' %{_builddir}/%{name}-%{version}/Makefile %{_builddir}/%{name}-%{version}/doc/Makefile

  %patch0 -p1 -b .contrib-hg-ssh

+ # NOTE: The patch1 cannot be applied here as it has to be kept as it is for py2 version..

+ # %%patch1 -p1 -b .hgk_python3

+ %patch2 -p1 -b .create_hg3

  

  %build

- make all

+ # copy hg to hg3 to be able to create /usr/bin/hg3 script

+ cp -a hg hg3

+ PYTHON=%{__python3} HGPYTHON3=1 make all

+ PYTHON=%{__python2} make all

  

+ #TODO: Now just for Py2, version for Py3 will need probably more fixes

+ # in installer - and possibly some renames..

  pushd contrib/chg

  make

  popd

  

  %install

+ # NOTE: this is nasty, but if we want to have parallel Py2/Py3 mercurial..

+ # ignoring now stuff related to *_completion, extensions

  rm -rf $RPM_BUILD_ROOT

+ HGPYTHON3=1 %{__python3} setup.py install -O1 --root $RPM_BUILD_ROOT --prefix %{_prefix} --record=%{name}3.files

  %{__python2} setup.py install -O1 --root $RPM_BUILD_ROOT --prefix %{_prefix} --record=%{name}.files

  make install-doc DESTDIR=$RPM_BUILD_ROOT MANDIR=%{_mandir}

  

+ grep -v -e 'hgk.py*' -e %{python3_sitearch}/mercurial/ -e %{python3_sitearch}/hgext/ < %{name}3.files > %{name}3-base.files

  grep -v -e 'hgk.py*' -e %{python2_sitearch}/mercurial/ -e %{python2_sitearch}/hgext/ < %{name}.files > %{name}-base.files

+ grep 'hgk.py*' < %{name}3.files > %{name}3-hgk.files

  grep 'hgk.py*' < %{name}.files > %{name}-hgk.files

  

  install -D -m 755 contrib/hgk       $RPM_BUILD_ROOT%{_libexecdir}/mercurial/hgk

@@ -134,25 +166,28 @@ 

  EOF

  install -m 644 certs.rc $RPM_BUILD_ROOT/%{_sysconfdir}/mercurial/hgrc.d

  

+ # Despite the original path, locales can be used for Python3 as well

  mv $RPM_BUILD_ROOT%{python2_sitearch}/mercurial/locale $RPM_BUILD_ROOT%{_datadir}/locale

+ rm -rf $RPM_BUILD_ROOT%{python3_sitearch}/mercurial/locale

  rm -rf $RPM_BUILD_ROOT%{python2_sitearch}/mercurial/locale

  

  

  %find_lang hg

  

  grep -v locale %{name}-base.files > %{name}-base-filtered.files

+ grep -v locale %{name}3-base.files > %{name}3-base-filtered.files

  

- %files -f %{name}-base-filtered.files -f hg.lang

+ %files -f %{name}-base-filtered.files

  %doc CONTRIBUTORS COPYING doc/README doc/hg*.txt doc/hg*.html *.cgi contrib/*.fcgi contrib/*.wsgi

  %doc %attr(644,root,root) %{_mandir}/man?/hg*.gz

  %doc %attr(644,root,root) contrib/*.svg

- %{_datadir}/zsh/site-functions/_mercurial

- %{_bindir}/hg-ssh

- %{_datadir}/bash-completion/

  %dir %{_datadir}/zsh/

- %{_datadir}/zsh/site-functions/

+ %dir %{_datadir}/zsh/site-functions/

  %dir %{_sysconfdir}/mercurial

  %dir %{_sysconfdir}/mercurial/hgrc.d

+ %{_bindir}/hg-ssh

+ %{_datadir}/bash-completion/

+ %{_datadir}/zsh/site-functions/_mercurial

  %{python2_sitearch}/mercurial

  %{python2_sitearch}/hgext

  %{_emacs_sitelispdir}/mercurial

@@ -160,6 +195,10 @@ 

  

  %config(noreplace) %{_sysconfdir}/mercurial/hgrc.d/certs.rc

  

+ %files py3 -f %{name}3-base-filtered.files

+ %{python3_sitearch}/mercurial

+ %{python3_sitearch}/hgext

+ 

  %files hgk -f %{name}-hgk.files

  %{_libexecdir}/mercurial/

  %{_sysconfdir}/mercurial/hgrc.d/hgk.rc

@@ -168,11 +207,27 @@ 

  %{_bindir}/chg

  %doc %attr(644,root,root) %{_mandir}/man?/chg.*.gz

  

+ %files lang -f hg.lang

+ 

+ 

+ #%%check

+ #cd tests && %%{__python2} run-tests.py

+ # This will now fail everytime. Mercurial is not ported properly for Python3

+ # and current split of mercurial for Py2 and Py3 brings additional problems

+ # for extensions then pure Python3 packaging.

+ #cd tests && HGPYTHON3=1 %%{__python3} run-tests.py

  

- ##%%check

- ##cd tests && %%{__python} run-tests.py

  

  %changelog

+ * Sat Oct 19 2019 Petr Stodulka <pstodulk@redhat.com> - 5.1.2-2

+ - first attempt to create builds for py2 & py3 version

+ - separate lang into the own subpackage as files are shared between

+   mercurial for both pythons

+ - extensions are now prepared and working only under Python2

+ - the core mercurial is prepared in mercurial-python3 subpackage providing

+   the hg3 executable

+ - Relates: #1737931

+ 

  * Sat Oct 19 2019 Petr Stodulka <pstodulk@redhat.com> - 5.1.2-1

  - Update to 5.1.2

  - fix patching of Makefiles

Introducing new subpackage mercurial-python3 with mercurial built for Python3. Original packages have been modified as well to omit dependency on the main mercurial package (which is still just for python2). Extensions are currently not handled correctly, as in the current shape, they need to be modified as well and cannot be probably built compatible with both mercurials. Mercurial for Python3 can be executed using /usr/bin/hg3.

Mercurial should work as before under Python2.
Maybe another good step could be adding of alternatives.

Relates to bug #1737931: https://bugzilla.redhat.com/show_bug.cgi?id=1737931

rebased onto 85b8344

2 months ago

This typo should be dropped from this diff.

You are right. I fixed that in previous commit and by mistake put it back. Fixed.

rebased onto 5389909

2 months ago

this is always defined when buildrequiring python3-devel. the same applies for the python2 version and python2-devel.

this note seem to be outdated

why is this needed?

Ah. Ok, I should maybe not use the patch as maybe mercurial for Python2 could be broken. I will test it. For Python3 it's needed otherwise the extension crashes constantly regarding the "code rewrite" during the import: one of actions it does, it's putting "b" before every string literal without explicit specification it's unicode or byte literal.

one of actions it does, it's putting "b" before every string literal without explicit specification it's unicode or byte literal.

:scream:

1 new commit added

  • Remove redefine of python2_sitearch & python3_sitearch
2 months ago

I had same reaction when I realized that.

Guys, anything else what I should do?

@nbecker Neal, could you check it and write some feedback or merge that?

I wonder whether to go with /usr/bin/hg alternatives, but that can be done later. Release early, release often, :rocket: it.

@churchyard Yes, that was exactly the point. I think that alternatives would be better offer, but I have no time to look at it closer now, so I prefer to do this first (people will be able to play around at least) and alternatives can be another step.

I checked that pstodulk's patches would build, and appear to install the components in the correct places.

It seems that nobody has anything against and nobody is merging that. So I am merging it and create new build.

Pull-Request has been merged by pstodulk

a month ago