linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: Linux Doc Mailing List <linux-doc@vger.kernel.org>
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	linux-kernel@vger.kernel.org, Jonathan Corbet <corbet@lwn.net>
Subject: [PATCH 4/5] scripts: sphinx-pre-install: fix a bug when using with venv
Date: Tue, 21 Apr 2020 16:31:08 +0200	[thread overview]
Message-ID: <aa622ff71bebf6960fc0262fb90e7ebc7a999a02.1587478901.git.mchehab+huawei@kernel.org> (raw)
In-Reply-To: <cover.1587478901.git.mchehab+huawei@kernel.org>

When python3 creates a venv, it adds python into it!

This causes any upgrade recommendation to look like this:

	/devel/v4l/docs/sphinx_1.7.9/bin/python3 -m venv sphinx_2.4.4
	. sphinx_2.4.4/bin/activate
	pip install -r ./Documentation/sphinx/requirements.txt

With is wrong (and it may not work). So, when recomending
an upgrade, exclude the venv dir from the search path, and
get the system's python.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 scripts/sphinx-pre-install | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/scripts/sphinx-pre-install b/scripts/sphinx-pre-install
index 938b65d40fc8..987aebf7e3a0 100755
--- a/scripts/sphinx-pre-install
+++ b/scripts/sphinx-pre-install
@@ -148,6 +148,24 @@ sub findprog($)
 	}
 }
 
+sub find_python_no_venv()
+{
+	my $prog = shift;
+
+	my $cur_dir = qx(pwd);
+	$cur_dir =~ s/\s+$//;
+
+	foreach my $dir (split(/:/, $ENV{PATH})) {
+		next if ($dir =~ m,($cur_dir)/sphinx,);
+		return "$dir/python3" if(-x "$dir/python3");
+	}
+	foreach my $dir (split(/:/, $ENV{PATH})) {
+		next if ($dir =~ m,($cur_dir)/sphinx,);
+		return "$dir/python" if(-x "$dir/python");
+	}
+	return "python";
+}
+
 sub check_program($$)
 {
 	my $prog = shift;
@@ -814,6 +832,8 @@ sub check_needs()
 
 			print "To upgrade Sphinx, use:\n\n" if ($rec_sphinx_upgrade);
 
+			$python_cmd = find_python_no_venv();
+
 			if ($need_venv) {
 				printf "\t$python_cmd -m venv $virtenv_dir\n";
 			} else {
-- 
2.25.2


  parent reply	other threads:[~2020-04-21 14:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-21 14:31 [PATCH 0/5] More changes for sphinx-pre-install script Mauro Carvalho Chehab
2020-04-21 14:31 ` [PATCH 1/5] scripts: sphinx-pre-install: only ask to activate valid venvs Mauro Carvalho Chehab
2020-04-21 14:31 ` [PATCH 2/5] scripts: sphinx-pre-install: change the warning for version < 2.4.4 Mauro Carvalho Chehab
2020-04-21 14:31 ` [PATCH 3/5] scripts: sphinx-pre-install: change recommendation text if venv exists Mauro Carvalho Chehab
2020-04-21 14:31 ` Mauro Carvalho Chehab [this message]
2020-04-21 14:31 ` [PATCH 5/5] scripts: sphinx-pre-install: change the output order Mauro Carvalho Chehab
2020-04-21 16:27   ` [PATCH v1.1 " Mauro Carvalho Chehab
2020-04-28 18:53 ` [PATCH 0/5] More changes for sphinx-pre-install script Jonathan Corbet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aa622ff71bebf6960fc0262fb90e7ebc7a999a02.1587478901.git.mchehab+huawei@kernel.org \
    --to=mchehab+huawei@kernel.org \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).