Patchwork completion: install completers to conventional locations

login
register
mail settings
Submitter Matthew Martin
Date March 25, 2022, 3:37 a.m.
Message ID <Yj05AnVI3zFAit50@CptOrmolo.darkstar>
Download mbox | patch
Permalink /patch/50757/
State New
Headers show

Comments

Matthew Martin - March 25, 2022, 3:37 a.m.
I've tested the patch on OpenBSD, but don't have other systems handy.

# HG changeset patch
# User Matthew Martin <phy1729@gmail.com>
# Date 1648175205 18000
#      Thu Mar 24 21:26:45 2022 -0500
# Node ID 106bcb6cfb02c00b7e240bb041f6fbab00891a85
# Parent  0590c6c96852a8d05065dde5a757e2a025db2567
completion: install completers to conventional locations

Installs the bash and zsh completers to the convential locations so they will
automatically be picked up without user intervention.  The zsh completer
on Debian is still installed to vendor-completions to match their policy.

bash: https://github.com/scop/bash-completion#faq
zsh: https://github.com/zsh-users/zsh/blob/57305cf245853b8b30895b41a90142dffab97e38/INSTALL#L254
Debian zsh: https://salsa.debian.org/debian/zsh/-/blob/5086b5356abcef8849dc8a09902b7c55f01db3c0/debian/README.Debian#L73
Raphaël Gomès - April 5, 2022, 3:05 p.m.
It appears that this was queued some days ago.

Thanks for the patch!

On 3/25/22 04:37, Matthew Martin wrote:
> I've tested the patch on OpenBSD, but don't have other systems handy.
>
> # HG changeset patch
> # User Matthew Martin <phy1729@gmail.com>
> # Date 1648175205 18000
> #      Thu Mar 24 21:26:45 2022 -0500
> # Node ID 106bcb6cfb02c00b7e240bb041f6fbab00891a85
> # Parent  0590c6c96852a8d05065dde5a757e2a025db2567
> completion: install completers to conventional locations
>
> Installs the bash and zsh completers to the convential locations so they will
> automatically be picked up without user intervention.  The zsh completer
> on Debian is still installed to vendor-completions to match their policy.
>
> bash: https://github.com/scop/bash-completion#faq
> zsh: https://github.com/zsh-users/zsh/blob/57305cf245853b8b30895b41a90142dffab97e38/INSTALL#L254
> Debian zsh: https://salsa.debian.org/debian/zsh/-/blob/5086b5356abcef8849dc8a09902b7c55f01db3c0/debian/README.Debian#L73
>
> diff -r 0590c6c96852 -r 106bcb6cfb02 Makefile
> --- a/Makefile	Fri Dec 10 17:55:22 2021 -0800
> +++ b/Makefile	Thu Mar 24 21:26:45 2022 -0500
> @@ -238,16 +238,6 @@
>           # Place a bogon .DS_Store file in the target dir so we can be
>           # sure it doesn't get included in the final package.
>   	touch build/mercurial/.DS_Store
> -        # install zsh completions - this location appears to be
> -        # searched by default as of macOS Sierra.
> -	install -d build/mercurial/usr/local/share/zsh/site-functions/
> -	install -m 0644 contrib/zsh_completion build/mercurial/usr/local/share/zsh/site-functions/_hg
> -        # install bash completions - there doesn't appear to be a
> -        # place that's searched by default for bash, so we'll follow
> -        # the lead of Apple's git install and just put it in a
> -        # location of our own.
> -	install -d build/mercurial/usr/local/hg/contrib/
> -	install -m 0644 contrib/bash_completion build/mercurial/usr/local/hg/contrib/hg-completion.bash
>   	make -C contrib/chg \
>   	  HGPATH=/usr/local/bin/hg \
>   	  PYTHON=/usr/bin/python2.7 \
> diff -r 0590c6c96852 -r 106bcb6cfb02 contrib/packaging/debian/rules
> --- a/contrib/packaging/debian/rules	Fri Dec 10 17:55:22 2021 -0800
> +++ b/contrib/packaging/debian/rules	Thu Mar 24 21:26:45 2022 -0500
> @@ -92,10 +92,8 @@
>   	mkdir -p "$(CURDIR)"/debian/mercurial/etc/mercurial/hgrc.d/
>   	cp contrib/packaging/debian/*.rc "$(CURDIR)"/debian/mercurial/etc/mercurial/hgrc.d/
>   	# completions
> -	mkdir -p "$(CURDIR)"/debian/mercurial/usr/share/bash-completion/completions
> -	cp contrib/bash_completion "$(CURDIR)"/debian/mercurial/usr/share/bash-completion/completions/hg
>   	mkdir -p "$(CURDIR)"/debian/mercurial/usr/share/zsh/vendor-completions
> -	cp contrib/zsh_completion "$(CURDIR)"/debian/mercurial/usr/share/zsh/vendor-completions/_hg
> +	mv "$(CURDIR)"/debian/mercurial/usr/share/zsh/site-functions/_hg "$(CURDIR)"/debian/mercurial/usr/share/zsh/vendor-completions/_hg
>   	if [ "$(DEB_HG_CHG_BY_DEFAULT)" -eq 1 ]; then \
>   		mkdir -p "$(CURDIR)"/debian/mercurial/usr/lib/mercurial; \
>   		mv "$(CURDIR)"/debian/mercurial/usr/bin/hg "$(CURDIR)"/debian/mercurial/usr/lib/mercurial/hg; \
> diff -r 0590c6c96852 -r 106bcb6cfb02 contrib/packaging/hgpackaging/py2exe.py
> --- a/contrib/packaging/hgpackaging/py2exe.py	Fri Dec 10 17:55:22 2021 -0800
> +++ b/contrib/packaging/hgpackaging/py2exe.py	Thu Mar 24 21:26:45 2022 -0500
> @@ -21,7 +21,6 @@
>   
>   
>   STAGING_RULES = [
> -    ('contrib/bash_completion', 'contrib/'),
>       ('contrib/hgk', 'contrib/hgk.tcl'),
>       ('contrib/hgweb.fcgi', 'contrib/'),
>       ('contrib/hgweb.wsgi', 'contrib/'),
> @@ -34,7 +33,6 @@
>       ('contrib/win32/postinstall.txt', 'ReleaseNotes.txt'),
>       ('contrib/win32/ReadMe.html', 'ReadMe.html'),
>       ('contrib/xml.rnc', 'contrib/'),
> -    ('contrib/zsh_completion', 'contrib/'),
>       ('dist/hg.exe', './'),
>       ('dist/lib/*.dll', 'lib/'),
>       ('dist/lib/*.pyd', 'lib/'),
> diff -r 0590c6c96852 -r 106bcb6cfb02 contrib/packaging/hgpackaging/pyoxidizer.py
> --- a/contrib/packaging/hgpackaging/pyoxidizer.py	Fri Dec 10 17:55:22 2021 -0800
> +++ b/contrib/packaging/hgpackaging/pyoxidizer.py	Thu Mar 24 21:26:45 2022 -0500
> @@ -23,7 +23,6 @@
>   
>   
>   STAGING_RULES_WINDOWS = [
> -    ('contrib/bash_completion', 'contrib/'),
>       ('contrib/hgk', 'contrib/hgk.tcl'),
>       ('contrib/hgweb.fcgi', 'contrib/'),
>       ('contrib/hgweb.wsgi', 'contrib/'),
> @@ -36,7 +35,6 @@
>       ('contrib/win32/postinstall.txt', 'ReleaseNotes.txt'),
>       ('contrib/win32/ReadMe.html', 'ReadMe.html'),
>       ('contrib/xml.rnc', 'contrib/'),
> -    ('contrib/zsh_completion', 'contrib/'),
>       ('doc/*.html', 'doc/'),
>       ('doc/style.css', 'doc/'),
>       ('COPYING', 'Copying.txt'),
> diff -r 0590c6c96852 -r 106bcb6cfb02 contrib/packaging/mercurial.spec
> --- a/contrib/packaging/mercurial.spec	Fri Dec 10 17:55:22 2021 -0800
> +++ b/contrib/packaging/mercurial.spec	Thu Mar 24 21:26:45 2022 -0500
> @@ -126,14 +126,6 @@
>   install -m 755 contrib/hgk $RPM_BUILD_ROOT%{_bindir}/
>   install -m 755 contrib/hg-ssh $RPM_BUILD_ROOT%{_bindir}/
>   
> -bash_completion_dir=$RPM_BUILD_ROOT%{_sysconfdir}/bash_completion.d
> -mkdir -p $bash_completion_dir
> -install -m 644 contrib/bash_completion $bash_completion_dir/mercurial.sh
> -
> -zsh_completion_dir=$RPM_BUILD_ROOT%{_datadir}/zsh/site-functions
> -mkdir -p $zsh_completion_dir
> -install -m 644 contrib/zsh_completion $zsh_completion_dir/_mercurial
> -
>   mkdir -p $RPM_BUILD_ROOT%{emacs_lispdir}
>   install -m 644 contrib/mercurial.el $RPM_BUILD_ROOT%{emacs_lispdir}/
>   install -m 644 contrib/mq.el $RPM_BUILD_ROOT%{emacs_lispdir}/
> @@ -148,9 +140,12 @@
>   %doc CONTRIBUTORS COPYING doc/README doc/hg*.txt doc/hg*.html *.cgi contrib/*.fcgi contrib/*.wsgi
>   %doc %attr(644,root,root) %{_mandir}/man?/hg*
>   %doc %attr(644,root,root) contrib/*.svg
> +%dir %{_datadir}/bash-completion/
> +%dir %{_datadir}/bash-completion/completions
> +%{_datadir}/bash-completion/completions/hg
>   %dir %{_datadir}/zsh/
>   %dir %{_datadir}/zsh/site-functions/
> -%{_datadir}/zsh/site-functions/_mercurial
> +%{_datadir}/zsh/site-functions/_hg
>   %dir %{_datadir}/emacs/site-lisp/
>   %{_datadir}/emacs/site-lisp/mercurial.el
>   %{_datadir}/emacs/site-lisp/mq.el
> @@ -158,8 +153,6 @@
>   %{_bindir}/chg
>   %{_bindir}/hgk
>   %{_bindir}/hg-ssh
> -%dir %{_sysconfdir}/bash_completion.d/
> -%config(noreplace) %{_sysconfdir}/bash_completion.d/mercurial.sh
>   %dir %{_sysconfdir}/mercurial
>   %dir %{_sysconfdir}/mercurial/hgrc.d
>   %if "%{?withpython}"
> diff -r 0590c6c96852 -r 106bcb6cfb02 setup.py
> --- a/setup.py	Fri Dec 10 17:55:22 2021 -0800
> +++ b/setup.py	Thu Mar 24 21:26:45 2022 -0500
> @@ -1069,6 +1069,10 @@
>           ),
>       ]
>   
> +    sub_commands = install.sub_commands + [
> +        ('install_completion', lambda self: True)
> +    ]
> +
>       # Also helps setuptools not be sad while we refuse to create eggs.
>       single_version_externally_managed = True
>   
> @@ -1188,6 +1192,33 @@
>                   fp.write(data)
>   
>   
> +class hginstallcompletion(Command):
> +    description = 'Install shell completion'
> +
> +    def initialize_options(self):
> +        self.install_dir = None
> +
> +    def finalize_options(self):
> +        self.set_undefined_options(
> +            'install_data', ('install_dir', 'install_dir')
> +        )
> +
> +    def run(self):
> +        for src, dir_path, dest in (
> +            (
> +                'bash_completion',
> +                ('share', 'bash-completion', 'completions'),
> +                'hg',
> +            ),
> +            ('zsh_completion', ('share', 'zsh', 'site-functions'), '_hg'),
> +        ):
> +            dir = os.path.join(self.install_dir, *dir_path)
> +            self.mkpath(dir)
> +            self.copy_file(
> +                os.path.join('contrib', src), os.path.join(dir, dest)
> +            )
> +
> +
>   # virtualenv installs custom distutils/__init__.py and
>   # distutils/distutils.cfg files which essentially proxy back to the
>   # "real" distutils in the main Python install. The presence of this
> @@ -1278,6 +1309,7 @@
>       'build_scripts': hgbuildscripts,
>       'build_hgextindex': buildhgextindex,
>       'install': hginstall,
> +    'install_completion': hginstallcompletion,
>       'install_lib': hginstalllib,
>       'install_scripts': hginstallscripts,
>       'build_hgexe': buildhgexe,
> diff -r 0590c6c96852 -r 106bcb6cfb02 tests/test-mac-packages.t
> --- a/tests/test-mac-packages.t	Fri Dec 10 17:55:22 2021 -0800
> +++ b/tests/test-mac-packages.t	Thu Mar 24 21:26:45 2022 -0500
> @@ -39,8 +39,8 @@
>     ./Library/Python/2.7/site-packages/mercurial/pure/bdiff.pyo	100644	0/0
>     $ grep zsh/site-functions/_hg boms.txt | cut -d '	' -f 1,2,3
>     ./usr/local/share/zsh/site-functions/_hg	100644	0/0
> -  $ grep hg-completion.bash boms.txt | cut -d '	' -f 1,2,3
> -  ./usr/local/hg/contrib/hg-completion.bash	100644	0/0
> +  $ grep bash-completion/completions/hg boms.txt | cut -d '	' -f 1,2,3
> +  ./usr/local/share/bash-completion-completions/hg	100644	0/0
>     $ egrep 'man[15]' boms.txt | cut -d '	' -f 1,2,3
>     ./usr/local/share/man/man1	40755	0/0
>     ./usr/local/share/man/man1/chg.1	100644	0/0
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff -r 0590c6c96852 -r 106bcb6cfb02 Makefile
--- a/Makefile	Fri Dec 10 17:55:22 2021 -0800
+++ b/Makefile	Thu Mar 24 21:26:45 2022 -0500
@@ -238,16 +238,6 @@ 
         # Place a bogon .DS_Store file in the target dir so we can be
         # sure it doesn't get included in the final package.
 	touch build/mercurial/.DS_Store
-        # install zsh completions - this location appears to be
-        # searched by default as of macOS Sierra.
-	install -d build/mercurial/usr/local/share/zsh/site-functions/
-	install -m 0644 contrib/zsh_completion build/mercurial/usr/local/share/zsh/site-functions/_hg
-        # install bash completions - there doesn't appear to be a
-        # place that's searched by default for bash, so we'll follow
-        # the lead of Apple's git install and just put it in a
-        # location of our own.
-	install -d build/mercurial/usr/local/hg/contrib/
-	install -m 0644 contrib/bash_completion build/mercurial/usr/local/hg/contrib/hg-completion.bash
 	make -C contrib/chg \
 	  HGPATH=/usr/local/bin/hg \
 	  PYTHON=/usr/bin/python2.7 \
diff -r 0590c6c96852 -r 106bcb6cfb02 contrib/packaging/debian/rules
--- a/contrib/packaging/debian/rules	Fri Dec 10 17:55:22 2021 -0800
+++ b/contrib/packaging/debian/rules	Thu Mar 24 21:26:45 2022 -0500
@@ -92,10 +92,8 @@ 
 	mkdir -p "$(CURDIR)"/debian/mercurial/etc/mercurial/hgrc.d/
 	cp contrib/packaging/debian/*.rc "$(CURDIR)"/debian/mercurial/etc/mercurial/hgrc.d/
 	# completions
-	mkdir -p "$(CURDIR)"/debian/mercurial/usr/share/bash-completion/completions
-	cp contrib/bash_completion "$(CURDIR)"/debian/mercurial/usr/share/bash-completion/completions/hg
 	mkdir -p "$(CURDIR)"/debian/mercurial/usr/share/zsh/vendor-completions
-	cp contrib/zsh_completion "$(CURDIR)"/debian/mercurial/usr/share/zsh/vendor-completions/_hg
+	mv "$(CURDIR)"/debian/mercurial/usr/share/zsh/site-functions/_hg "$(CURDIR)"/debian/mercurial/usr/share/zsh/vendor-completions/_hg
 	if [ "$(DEB_HG_CHG_BY_DEFAULT)" -eq 1 ]; then \
 		mkdir -p "$(CURDIR)"/debian/mercurial/usr/lib/mercurial; \
 		mv "$(CURDIR)"/debian/mercurial/usr/bin/hg "$(CURDIR)"/debian/mercurial/usr/lib/mercurial/hg; \
diff -r 0590c6c96852 -r 106bcb6cfb02 contrib/packaging/hgpackaging/py2exe.py
--- a/contrib/packaging/hgpackaging/py2exe.py	Fri Dec 10 17:55:22 2021 -0800
+++ b/contrib/packaging/hgpackaging/py2exe.py	Thu Mar 24 21:26:45 2022 -0500
@@ -21,7 +21,6 @@ 
 
 
 STAGING_RULES = [
-    ('contrib/bash_completion', 'contrib/'),
     ('contrib/hgk', 'contrib/hgk.tcl'),
     ('contrib/hgweb.fcgi', 'contrib/'),
     ('contrib/hgweb.wsgi', 'contrib/'),
@@ -34,7 +33,6 @@ 
     ('contrib/win32/postinstall.txt', 'ReleaseNotes.txt'),
     ('contrib/win32/ReadMe.html', 'ReadMe.html'),
     ('contrib/xml.rnc', 'contrib/'),
-    ('contrib/zsh_completion', 'contrib/'),
     ('dist/hg.exe', './'),
     ('dist/lib/*.dll', 'lib/'),
     ('dist/lib/*.pyd', 'lib/'),
diff -r 0590c6c96852 -r 106bcb6cfb02 contrib/packaging/hgpackaging/pyoxidizer.py
--- a/contrib/packaging/hgpackaging/pyoxidizer.py	Fri Dec 10 17:55:22 2021 -0800
+++ b/contrib/packaging/hgpackaging/pyoxidizer.py	Thu Mar 24 21:26:45 2022 -0500
@@ -23,7 +23,6 @@ 
 
 
 STAGING_RULES_WINDOWS = [
-    ('contrib/bash_completion', 'contrib/'),
     ('contrib/hgk', 'contrib/hgk.tcl'),
     ('contrib/hgweb.fcgi', 'contrib/'),
     ('contrib/hgweb.wsgi', 'contrib/'),
@@ -36,7 +35,6 @@ 
     ('contrib/win32/postinstall.txt', 'ReleaseNotes.txt'),
     ('contrib/win32/ReadMe.html', 'ReadMe.html'),
     ('contrib/xml.rnc', 'contrib/'),
-    ('contrib/zsh_completion', 'contrib/'),
     ('doc/*.html', 'doc/'),
     ('doc/style.css', 'doc/'),
     ('COPYING', 'Copying.txt'),
diff -r 0590c6c96852 -r 106bcb6cfb02 contrib/packaging/mercurial.spec
--- a/contrib/packaging/mercurial.spec	Fri Dec 10 17:55:22 2021 -0800
+++ b/contrib/packaging/mercurial.spec	Thu Mar 24 21:26:45 2022 -0500
@@ -126,14 +126,6 @@ 
 install -m 755 contrib/hgk $RPM_BUILD_ROOT%{_bindir}/
 install -m 755 contrib/hg-ssh $RPM_BUILD_ROOT%{_bindir}/
 
-bash_completion_dir=$RPM_BUILD_ROOT%{_sysconfdir}/bash_completion.d
-mkdir -p $bash_completion_dir
-install -m 644 contrib/bash_completion $bash_completion_dir/mercurial.sh
-
-zsh_completion_dir=$RPM_BUILD_ROOT%{_datadir}/zsh/site-functions
-mkdir -p $zsh_completion_dir
-install -m 644 contrib/zsh_completion $zsh_completion_dir/_mercurial
-
 mkdir -p $RPM_BUILD_ROOT%{emacs_lispdir}
 install -m 644 contrib/mercurial.el $RPM_BUILD_ROOT%{emacs_lispdir}/
 install -m 644 contrib/mq.el $RPM_BUILD_ROOT%{emacs_lispdir}/
@@ -148,9 +140,12 @@ 
 %doc CONTRIBUTORS COPYING doc/README doc/hg*.txt doc/hg*.html *.cgi contrib/*.fcgi contrib/*.wsgi
 %doc %attr(644,root,root) %{_mandir}/man?/hg*
 %doc %attr(644,root,root) contrib/*.svg
+%dir %{_datadir}/bash-completion/
+%dir %{_datadir}/bash-completion/completions
+%{_datadir}/bash-completion/completions/hg
 %dir %{_datadir}/zsh/
 %dir %{_datadir}/zsh/site-functions/
-%{_datadir}/zsh/site-functions/_mercurial
+%{_datadir}/zsh/site-functions/_hg
 %dir %{_datadir}/emacs/site-lisp/
 %{_datadir}/emacs/site-lisp/mercurial.el
 %{_datadir}/emacs/site-lisp/mq.el
@@ -158,8 +153,6 @@ 
 %{_bindir}/chg
 %{_bindir}/hgk
 %{_bindir}/hg-ssh
-%dir %{_sysconfdir}/bash_completion.d/
-%config(noreplace) %{_sysconfdir}/bash_completion.d/mercurial.sh
 %dir %{_sysconfdir}/mercurial
 %dir %{_sysconfdir}/mercurial/hgrc.d
 %if "%{?withpython}"
diff -r 0590c6c96852 -r 106bcb6cfb02 setup.py
--- a/setup.py	Fri Dec 10 17:55:22 2021 -0800
+++ b/setup.py	Thu Mar 24 21:26:45 2022 -0500
@@ -1069,6 +1069,10 @@ 
         ),
     ]
 
+    sub_commands = install.sub_commands + [
+        ('install_completion', lambda self: True)
+    ]
+
     # Also helps setuptools not be sad while we refuse to create eggs.
     single_version_externally_managed = True
 
@@ -1188,6 +1192,33 @@ 
                 fp.write(data)
 
 
+class hginstallcompletion(Command):
+    description = 'Install shell completion'
+
+    def initialize_options(self):
+        self.install_dir = None
+
+    def finalize_options(self):
+        self.set_undefined_options(
+            'install_data', ('install_dir', 'install_dir')
+        )
+
+    def run(self):
+        for src, dir_path, dest in (
+            (
+                'bash_completion',
+                ('share', 'bash-completion', 'completions'),
+                'hg',
+            ),
+            ('zsh_completion', ('share', 'zsh', 'site-functions'), '_hg'),
+        ):
+            dir = os.path.join(self.install_dir, *dir_path)
+            self.mkpath(dir)
+            self.copy_file(
+                os.path.join('contrib', src), os.path.join(dir, dest)
+            )
+
+
 # virtualenv installs custom distutils/__init__.py and
 # distutils/distutils.cfg files which essentially proxy back to the
 # "real" distutils in the main Python install. The presence of this
@@ -1278,6 +1309,7 @@ 
     'build_scripts': hgbuildscripts,
     'build_hgextindex': buildhgextindex,
     'install': hginstall,
+    'install_completion': hginstallcompletion,
     'install_lib': hginstalllib,
     'install_scripts': hginstallscripts,
     'build_hgexe': buildhgexe,
diff -r 0590c6c96852 -r 106bcb6cfb02 tests/test-mac-packages.t
--- a/tests/test-mac-packages.t	Fri Dec 10 17:55:22 2021 -0800
+++ b/tests/test-mac-packages.t	Thu Mar 24 21:26:45 2022 -0500
@@ -39,8 +39,8 @@ 
   ./Library/Python/2.7/site-packages/mercurial/pure/bdiff.pyo	100644	0/0
   $ grep zsh/site-functions/_hg boms.txt | cut -d '	' -f 1,2,3
   ./usr/local/share/zsh/site-functions/_hg	100644	0/0
-  $ grep hg-completion.bash boms.txt | cut -d '	' -f 1,2,3
-  ./usr/local/hg/contrib/hg-completion.bash	100644	0/0
+  $ grep bash-completion/completions/hg boms.txt | cut -d '	' -f 1,2,3
+  ./usr/local/share/bash-completion-completions/hg	100644	0/0
   $ egrep 'man[15]' boms.txt | cut -d '	' -f 1,2,3
   ./usr/local/share/man/man1	40755	0/0
   ./usr/local/share/man/man1/chg.1	100644	0/0