hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/scripts/sphinx-pre-install
....@@ -1,20 +1,16 @@
1
-#!/usr/bin/perl
1
+#!/usr/bin/env perl
2
+# SPDX-License-Identifier: GPL-2.0-or-later
23 use strict;
34
4
-# Copyright (c) 2017 Mauro Carvalho Chehab <mchehab@kernel.org>
5
+# Copyright (c) 2017-2020 Mauro Carvalho Chehab <mchehab@kernel.org>
56 #
6
-# This program is free software; you can redistribute it and/or
7
-# modify it under the terms of the GNU General Public License
8
-# as published by the Free Software Foundation; either version 2
9
-# of the License, or (at your option) any later version.
10
-#
11
-# This program is distributed in the hope that it will be useful,
12
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
-# GNU General Public License for more details.
157
16
-my $virtenv_dir = "sphinx_1.4";
17
-my $requirement_file = "Documentation/sphinx/requirements.txt";
8
+my $prefix = "./";
9
+$prefix = "$ENV{'srctree'}/" if ($ENV{'srctree'});
10
+
11
+my $conf = $prefix . "Documentation/conf.py";
12
+my $requirement_file = $prefix . "Documentation/sphinx/requirements.txt";
13
+my $virtenv_prefix = "sphinx_";
1814
1915 #
2016 # Static vars
....@@ -26,7 +22,16 @@
2622 my $optional = 0;
2723 my $need_symlink = 0;
2824 my $need_sphinx = 0;
25
+my $need_venv = 0;
26
+my $need_virtualenv = 0;
27
+my $rec_sphinx_upgrade = 0;
2928 my $install = "";
29
+my $virtenv_dir = "";
30
+my $python_cmd = "";
31
+my $min_version;
32
+my $cur_version;
33
+my $rec_version = "1.7.9"; # PDF won't build here
34
+my $min_pdf_version = "2.4.4"; # Min version where pdf builds
3035
3136 #
3237 # Command line arguments
....@@ -34,6 +39,7 @@
3439
3540 my $pdf = 1;
3641 my $virtualenv = 1;
42
+my $version_check = 0;
3743
3844 #
3945 # List of required texlive packages on Fedora and OpenSuse
....@@ -70,6 +76,7 @@
7076 'ucs.sty' => 'texlive-ucs',
7177 'upquote.sty' => 'texlive-upquote',
7278 'wrapfig.sty' => 'texlive-wrapfig',
79
+ 'ctexhook.sty' => 'texlive-ctex',
7380 );
7481
7582 #
....@@ -82,6 +89,17 @@
8289
8390 foreach my $prog (sort keys %missing) {
8491 my $is_optional = $missing{$prog};
92
+
93
+ # At least on some LTS distros like CentOS 7, texlive doesn't
94
+ # provide all packages we need. When such distros are
95
+ # detected, we have to disable PDF output.
96
+ #
97
+ # So, we need to ignore the packages that distros would
98
+ # need for LaTeX to work
99
+ if ($is_optional == 2 && !$pdf) {
100
+ $optional--;
101
+ next;
102
+ }
85103
86104 if ($is_optional) {
87105 print "Warning: better to also install \"$prog\".\n";
....@@ -113,11 +131,13 @@
113131
114132 sub check_missing_file($$$)
115133 {
116
- my $file = shift;
134
+ my $files = shift;
117135 my $package = shift;
118136 my $is_optional = shift;
119137
120
- return if(-e $file);
138
+ for (@$files) {
139
+ return if(-e $_);
140
+ }
121141
122142 add_package($package, $is_optional);
123143 }
....@@ -129,12 +149,30 @@
129149 }
130150 }
131151
152
+sub find_python_no_venv()
153
+{
154
+ my $prog = shift;
155
+
156
+ my $cur_dir = qx(pwd);
157
+ $cur_dir =~ s/\s+$//;
158
+
159
+ foreach my $dir (split(/:/, $ENV{PATH})) {
160
+ next if ($dir =~ m,($cur_dir)/sphinx,);
161
+ return "$dir/python3" if(-x "$dir/python3");
162
+ }
163
+ foreach my $dir (split(/:/, $ENV{PATH})) {
164
+ next if ($dir =~ m,($cur_dir)/sphinx,);
165
+ return "$dir/python" if(-x "$dir/python");
166
+ }
167
+ return "python";
168
+}
169
+
132170 sub check_program($$)
133171 {
134172 my $prog = shift;
135173 my $is_optional = shift;
136174
137
- return if findprog($prog);
175
+ return $prog if findprog($prog);
138176
139177 add_package($prog, $is_optional);
140178 }
....@@ -155,9 +193,9 @@
155193 my $prog = shift;
156194 my $is_optional = shift;
157195
158
- my $err = system("python3 -c 'import $prog' 2>/dev/null /dev/null");
159
- return if ($err == 0);
160
- my $err = system("python -c 'import $prog' 2>/dev/null /dev/null");
196
+ return if (!$python_cmd);
197
+
198
+ my $err = system("$python_cmd -c 'import $prog' 2>/dev/null /dev/null");
161199 return if ($err == 0);
162200
163201 add_package($prog, $is_optional);
....@@ -201,24 +239,94 @@
201239 }
202240 }
203241
242
+sub get_sphinx_fname()
243
+{
244
+ my $fname = "sphinx-build";
245
+ return $fname if findprog($fname);
246
+
247
+ $fname = "sphinx-build-3";
248
+ if (findprog($fname)) {
249
+ $need_symlink = 1;
250
+ return $fname;
251
+ }
252
+
253
+ return "";
254
+}
255
+
256
+sub get_sphinx_version($)
257
+{
258
+ my $cmd = shift;
259
+ my $ver;
260
+
261
+ open IN, "$cmd --version 2>&1 |";
262
+ while (<IN>) {
263
+ if (m/^\s*sphinx-build\s+([\d\.]+)(\+\/[\da-f]+)?$/) {
264
+ $ver=$1;
265
+ last;
266
+ }
267
+ # Sphinx 1.2.x uses a different format
268
+ if (m/^\s*Sphinx.*\s+([\d\.]+)$/) {
269
+ $ver=$1;
270
+ last;
271
+ }
272
+ }
273
+ close IN;
274
+ return $ver;
275
+}
276
+
204277 sub check_sphinx()
205278 {
206
- return if findprog("sphinx-build");
279
+ my $default_version;
207280
208
- if (findprog("sphinx-build-3")) {
209
- $need_symlink = 1;
281
+ open IN, $conf or die "Can't open $conf";
282
+ while (<IN>) {
283
+ if (m/^\s*needs_sphinx\s*=\s*[\'\"]([\d\.]+)[\'\"]/) {
284
+ $min_version=$1;
285
+ last;
286
+ }
287
+ }
288
+ close IN;
289
+
290
+ die "Can't get needs_sphinx version from $conf" if (!$min_version);
291
+
292
+ open IN, $requirement_file or die "Can't open $requirement_file";
293
+ while (<IN>) {
294
+ if (m/^\s*Sphinx\s*==\s*([\d\.]+)$/) {
295
+ $default_version=$1;
296
+ last;
297
+ }
298
+ }
299
+ close IN;
300
+
301
+ die "Can't get default sphinx version from $requirement_file" if (!$default_version);
302
+
303
+ $virtenv_dir = $virtenv_prefix . $default_version;
304
+
305
+ my $sphinx = get_sphinx_fname();
306
+ if ($sphinx eq "") {
307
+ $need_sphinx = 1;
210308 return;
211309 }
212310
213
- if ($virtualenv) {
214
- my $prog = findprog("virtualenv-3");
215
- $prog = findprog("virtualenv-3.5") if (!$prog);
311
+ $cur_version = get_sphinx_version($sphinx);
312
+ die ("$sphinx returned an error") if (!$cur_version);
216313
217
- check_program("virtualenv", 0) if (!$prog);
314
+ die "$sphinx didn't return its version" if (!$cur_version);
315
+
316
+ if ($cur_version lt $min_version) {
317
+ printf "ERROR: Sphinx version is %s. It should be >= %s (recommended >= %s)\n",
318
+ $cur_version, $min_version, $default_version;
218319 $need_sphinx = 1;
219
- } else {
220
- add_package("python-sphinx", 0);
320
+ return;
221321 }
322
+
323
+ if ($cur_version lt $rec_version) {
324
+ $rec_sphinx_upgrade = 1;
325
+ return;
326
+ }
327
+
328
+ # On version check mode, just assume Sphinx has all mandatory deps
329
+ exit (0) if ($version_check);
222330 }
223331
224332 #
....@@ -253,6 +361,7 @@
253361 my %map = (
254362 "python-sphinx" => "python3-sphinx",
255363 "sphinx_rtd_theme" => "python3-sphinx-rtd-theme",
364
+ "ensurepip" => "python3-venv",
256365 "virtualenv" => "virtualenv",
257366 "dot" => "graphviz",
258367 "convert" => "imagemagick",
....@@ -262,11 +371,19 @@
262371 );
263372
264373 if ($pdf) {
265
- check_missing_file("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
266
- "fonts-dejavu", 1);
374
+ check_missing_file(["/usr/share/texlive/texmf-dist/tex/latex/ctex/ctexhook.sty"],
375
+ "texlive-lang-chinese", 2);
376
+
377
+ check_missing_file(["/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"],
378
+ "fonts-dejavu", 2);
379
+
380
+ check_missing_file(["/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc",
381
+ "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc",
382
+ "/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc"],
383
+ "fonts-noto-cjk", 2);
267384 }
268385
269
- check_program("dvipng", 1) if ($pdf);
386
+ check_program("dvipng", 2) if ($pdf);
270387 check_missing(\%map);
271388
272389 return if (!$need && !$optional);
....@@ -293,6 +410,7 @@
293410 my @fedora_tex_pkgs = (
294411 "texlive-collection-fontsrecommended",
295412 "texlive-collection-latex",
413
+ "texlive-xecjk",
296414 "dejavu-sans-fonts",
297415 "dejavu-serif-fonts",
298416 "dejavu-sans-mono-fonts",
....@@ -301,22 +419,45 @@
301419 #
302420 # Checks valid for RHEL/CentOS version 7.x.
303421 #
422
+ my $old = 0;
423
+ my $rel;
424
+ $rel = $1 if ($system_release =~ /release\s+(\d+)/);
425
+
304426 if (!($system_release =~ /Fedora/)) {
305427 $map{"virtualenv"} = "python-virtualenv";
428
+
429
+ if ($rel && $rel < 8) {
430
+ $old = 1;
431
+ $pdf = 0;
432
+
433
+ printf("Note: texlive packages on RHEL/CENTOS <= 7 are incomplete. Can't support PDF output\n");
434
+ printf("If you want to build PDF, please read:\n");
435
+ printf("\thttps://www.systutorials.com/241660/how-to-install-tex-live-on-centos-7-linux/\n");
436
+ }
437
+ } else {
438
+ if ($rel && $rel < 26) {
439
+ $old = 1;
440
+ }
441
+ }
442
+ if (!$rel) {
443
+ printf("Couldn't identify release number\n");
444
+ $old = 1;
445
+ $pdf = 0;
306446 }
307447
308
- my $release;
448
+ if ($pdf) {
449
+ check_missing_file(["/usr/share/fonts/google-noto-cjk/NotoSansCJK-Regular.ttc"],
450
+ "google-noto-sans-cjk-ttc-fonts", 2);
451
+ }
309452
310
- $release = $1 if ($system_release =~ /Fedora\s+release\s+(\d+)/);
311
-
312
- check_rpm_missing(\@fedora26_opt_pkgs, 1) if ($pdf && $release >= 26);
313
- check_rpm_missing(\@fedora_tex_pkgs, 1) if ($pdf);
314
- check_missing_tex(1) if ($pdf);
453
+ check_rpm_missing(\@fedora26_opt_pkgs, 2) if ($pdf && !$old);
454
+ check_rpm_missing(\@fedora_tex_pkgs, 2) if ($pdf);
455
+ check_missing_tex(2) if ($pdf);
315456 check_missing(\%map);
316457
317458 return if (!$need && !$optional);
318459
319
- if ($release >= 18) {
460
+ if (!$old) {
320461 # dnf, for Fedora 18+
321462 printf("You should run:\n\n\tsudo dnf install -y $install\n");
322463 } else {
....@@ -335,8 +476,10 @@
335476 "convert" => "ImageMagick",
336477 "Pod::Usage" => "perl-Pod-Usage",
337478 "xelatex" => "texlive-xetex-bin",
338
- "rsvg-convert" => "rsvg-view",
339479 );
480
+
481
+ # On Tumbleweed, this package is also named rsvg-convert
482
+ $map{"rsvg-convert"} = "rsvg-view" if (!($system_release =~ /Tumbleweed/));
340483
341484 my @suse_tex_pkgs = (
342485 "texlive-babel-english",
....@@ -355,8 +498,15 @@
355498 "texlive-zapfding",
356499 );
357500
358
- check_rpm_missing(\@suse_tex_pkgs, 1) if ($pdf);
359
- check_missing_tex(1) if ($pdf);
501
+ $map{"latexmk"} = "texlive-latexmk-bin";
502
+
503
+ # FIXME: add support for installing CJK fonts
504
+ #
505
+ # I tried hard, but was unable to find a way to install
506
+ # "Noto Sans CJK SC" on openSUSE
507
+
508
+ check_rpm_missing(\@suse_tex_pkgs, 2) if ($pdf);
509
+ check_missing_tex(2) if ($pdf);
360510 check_missing(\%map);
361511
362512 return if (!$need && !$optional);
....@@ -373,18 +523,38 @@
373523 "convert" => "ImageMagick",
374524 "Pod::Usage" => "perl-Pod-Usage",
375525 "xelatex" => "texlive",
376
- "rsvg-convert" => "librsvg2-tools",
526
+ "rsvg-convert" => "librsvg2",
377527 );
378528
379529 my @tex_pkgs = (
380530 "texlive-fontsextra",
381531 );
382532
383
- check_rpm_missing(\@tex_pkgs, 1) if ($pdf);
533
+ $map{"latexmk"} = "texlive-collection-basic";
534
+
535
+ my $packager_cmd;
536
+ my $noto_sans;
537
+ if ($system_release =~ /OpenMandriva/) {
538
+ $packager_cmd = "dnf install";
539
+ $noto_sans = "noto-sans-cjk-fonts";
540
+ @tex_pkgs = ( "texlive-collection-fontsextra" );
541
+ } else {
542
+ $packager_cmd = "urpmi";
543
+ $noto_sans = "google-noto-sans-cjk-ttc-fonts";
544
+ }
545
+
546
+
547
+ if ($pdf) {
548
+ check_missing_file(["/usr/share/fonts/google-noto-cjk/NotoSansCJK-Regular.ttc",
549
+ "/usr/share/fonts/TTF/NotoSans-Regular.ttf"],
550
+ $noto_sans, 2);
551
+ }
552
+
553
+ check_rpm_missing(\@tex_pkgs, 2) if ($pdf);
384554 check_missing(\%map);
385555
386556 return if (!$need && !$optional);
387
- printf("You should run:\n\n\tsudo urpmi $install\n");
557
+ printf("You should run:\n\n\tsudo $packager_cmd $install\n");
388558 }
389559
390560 sub give_arch_linux_hints()
....@@ -395,6 +565,7 @@
395565 "dot" => "graphviz",
396566 "convert" => "imagemagick",
397567 "xelatex" => "texlive-bin",
568
+ "latexmk" => "texlive-core",
398569 "rsvg-convert" => "extra/librsvg",
399570 );
400571
....@@ -403,7 +574,13 @@
403574 "texlive-latexextra",
404575 "ttf-dejavu",
405576 );
406
- check_pacman_missing(\@archlinux_tex_pkgs, 1) if ($pdf);
577
+ check_pacman_missing(\@archlinux_tex_pkgs, 2) if ($pdf);
578
+
579
+ if ($pdf) {
580
+ check_missing_file(["/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc"],
581
+ "noto-fonts-cjk", 2);
582
+ }
583
+
407584 check_missing(\%map);
408585
409586 return if (!$need && !$optional);
....@@ -421,16 +598,33 @@
421598 "rsvg-convert" => "gnome-base/librsvg",
422599 );
423600
424
- check_missing_file("/usr/share/fonts/dejavu/DejaVuSans.ttf",
425
- "media-fonts/dejavu", 1) if ($pdf);
601
+ check_missing_file(["/usr/share/fonts/dejavu/DejaVuSans.ttf"],
602
+ "media-fonts/dejavu", 2) if ($pdf);
603
+
604
+ if ($pdf) {
605
+ check_missing_file(["/usr/share/fonts/noto-cjk/NotoSansCJKsc-Regular.otf",
606
+ "/usr/share/fonts/noto-cjk/NotoSerifCJK-Regular.ttc"],
607
+ "media-fonts/noto-cjk", 2);
608
+ }
426609
427610 check_missing(\%map);
428611
429612 return if (!$need && !$optional);
430613
431614 printf("You should run:\n\n");
432
- printf("\tsudo su -c 'echo \"media-gfx/imagemagick svg png\" > /etc/portage/package.use/imagemagick'\n");
433
- printf("\tsudo su -c 'echo \"media-gfx/graphviz cairo pdf\" > /etc/portage/package.use/graphviz'\n");
615
+
616
+ my $imagemagick = "media-gfx/imagemagick svg png";
617
+ my $cairo = "media-gfx/graphviz cairo pdf";
618
+ my $portage_imagemagick = "/etc/portage/package.use/imagemagick";
619
+ my $portage_cairo = "/etc/portage/package.use/graphviz";
620
+
621
+ if (qx(grep imagemagick $portage_imagemagick 2>/dev/null) eq "") {
622
+ printf("\tsudo su -c 'echo \"$imagemagick\" > $portage_imagemagick'\n")
623
+ }
624
+ if (qx(grep graphviz $portage_cairo 2>/dev/null) eq "") {
625
+ printf("\tsudo su -c 'echo \"$cairo\" > $portage_cairo'\n");
626
+ }
627
+
434628 printf("\tsudo emerge --ask $install\n");
435629
436630 }
....@@ -474,6 +668,10 @@
474668 give_mageia_hints;
475669 return;
476670 }
671
+ if ($system_release =~ /OpenMandriva/) {
672
+ give_mageia_hints;
673
+ return;
674
+ }
477675 if ($system_release =~ /Arch Linux/) {
478676 give_arch_linux_hints;
479677 return;
....@@ -490,7 +688,7 @@
490688 my %map = (
491689 "sphinx-build" => "sphinx"
492690 );
493
- check_missing_tex(1) if ($pdf);
691
+ check_missing_tex(2) if ($pdf);
494692 check_missing(\%map);
495693 print "I don't know distro $system_release.\n";
496694 print "So, I can't provide you a hint with the install procedure.\n";
....@@ -501,64 +699,159 @@
501699 # Common dependencies
502700 #
503701
702
+sub deactivate_help()
703
+{
704
+ printf "\nIf you want to exit the virtualenv, you can use:\n";
705
+ printf "\tdeactivate\n";
706
+}
707
+
504708 sub check_needs()
505709 {
710
+ # Check if Sphinx is already accessible from current environment
711
+ check_sphinx();
712
+
506713 if ($system_release) {
507714 print "Detected OS: $system_release.\n";
508715 } else {
509716 print "Unknown OS\n";
510717 }
718
+ printf "Sphinx version: %s\n\n", $cur_version if ($cur_version);
511719
512
- # RHEL 7.x and clones have Sphinx version 1.1.x and incomplete texlive
513
- if (($system_release =~ /Red Hat Enterprise Linux/) ||
514
- ($system_release =~ /CentOS/) ||
515
- ($system_release =~ /Scientific Linux/) ||
516
- ($system_release =~ /Oracle Linux Server/)) {
517
- $virtualenv = 1;
518
- $pdf = 0;
720
+ # Check python command line, trying first python3
721
+ $python_cmd = findprog("python3");
722
+ $python_cmd = check_program("python", 0) if (!$python_cmd);
519723
520
- printf("NOTE: On this distro, Sphinx and TexLive shipped versions are incompatible\n");
521
- printf("with doc build. So, use Sphinx via a Python virtual environment.\n\n");
522
- printf("This script can't install a TexLive version that would provide PDF.\n");
724
+ # Check the type of virtual env, depending on Python version
725
+ if ($python_cmd) {
726
+ if ($virtualenv) {
727
+ my $tmp = qx($python_cmd --version 2>&1);
728
+ if ($tmp =~ m/(\d+\.)(\d+\.)/) {
729
+ if ($1 >= 3 && $2 >= 3) {
730
+ $need_venv = 1; # python 3.3 or upper
731
+ } else {
732
+ $need_virtualenv = 1;
733
+ }
734
+ if ($1 < 3) {
735
+ # Complain if it finds python2 (or worse)
736
+ printf "Warning: python$1 support is deprecated. Use it with caution!\n";
737
+ }
738
+ } else {
739
+ die "Warning: couldn't identify $python_cmd version!";
740
+ }
741
+ } else {
742
+ add_package("python-sphinx", 0);
743
+ }
744
+ }
745
+
746
+ # Set virtualenv command line, if python < 3.3
747
+ my $virtualenv_cmd;
748
+ if ($need_virtualenv) {
749
+ $virtualenv_cmd = findprog("virtualenv-3");
750
+ $virtualenv_cmd = findprog("virtualenv-3.5") if (!$virtualenv_cmd);
751
+ if (!$virtualenv_cmd) {
752
+ check_program("virtualenv", 0);
753
+ $virtualenv_cmd = "virtualenv";
754
+ }
523755 }
524756
525757 # Check for needed programs/tools
526
- check_sphinx();
527758 check_perl_module("Pod::Usage", 0);
528759 check_program("make", 0);
529760 check_program("gcc", 0);
530761 check_python_module("sphinx_rtd_theme", 1) if (!$virtualenv);
531
- check_program("xelatex", 1) if ($pdf);
532762 check_program("dot", 1);
533763 check_program("convert", 1);
534
- check_program("rsvg-convert", 1) if ($pdf);
535764
765
+ # Extra PDF files - should use 2 for is_optional
766
+ check_program("xelatex", 2) if ($pdf);
767
+ check_program("rsvg-convert", 2) if ($pdf);
768
+ check_program("latexmk", 2) if ($pdf);
769
+
770
+ if ($need_sphinx || $rec_sphinx_upgrade) {
771
+ check_python_module("ensurepip", 0) if ($need_venv);
772
+ }
773
+
774
+ # Do distro-specific checks and output distro-install commands
536775 check_distros();
537776
777
+ if (!$python_cmd) {
778
+ if ($need == 1) {
779
+ die "Can't build as $need mandatory dependency is missing";
780
+ } elsif ($need) {
781
+ die "Can't build as $need mandatory dependencies are missing";
782
+ }
783
+ }
784
+
785
+ # Check if sphinx-build is called sphinx-build-3
538786 if ($need_symlink) {
539787 printf "\tsudo ln -sf %s /usr/bin/sphinx-build\n\n",
540788 which("sphinx-build-3");
541789 }
542
- if ($need_sphinx) {
543
- my $activate = "$virtenv_dir/bin/activate";
544
- if (-e "$ENV{'PWD'}/$activate") {
545
- printf "\nNeed to activate virtualenv with:\n";
546
- printf "\t. $activate\n";
547
- } else {
548
- my $virtualenv = findprog("virtualenv-3");
549
- $virtualenv = findprog("virtualenv-3.5") if (!$virtualenv);
550
- $virtualenv = findprog("virtualenv") if (!$virtualenv);
551
- $virtualenv = "virtualenv" if (!$virtualenv);
552790
553
- printf "\t$virtualenv $virtenv_dir\n";
554
- printf "\t. $activate\n";
791
+ # NOTE: if the system has a too old Sphinx version installed,
792
+ # it will recommend installing a newer version using virtualenv
793
+
794
+ if ($need_sphinx || $rec_sphinx_upgrade) {
795
+ my $min_activate = "$ENV{'PWD'}/${virtenv_prefix}${min_version}/bin/activate";
796
+ my @activates = glob "$ENV{'PWD'}/${virtenv_prefix}*/bin/activate";
797
+
798
+ if ($cur_version lt $rec_version) {
799
+ print "Warning: It is recommended at least Sphinx version $rec_version.\n";
800
+ print " If you want pdf, you need at least $min_pdf_version.\n";
801
+ }
802
+ if ($cur_version lt $min_pdf_version) {
803
+ print "Note: It is recommended at least Sphinx version $min_pdf_version if you need PDF support.\n";
804
+ }
805
+ @activates = sort {$b cmp $a} @activates;
806
+ my ($activate, $ver);
807
+ foreach my $f (@activates) {
808
+ next if ($f lt $min_activate);
809
+
810
+ my $sphinx_cmd = $f;
811
+ $sphinx_cmd =~ s/activate/sphinx-build/;
812
+ next if (! -f $sphinx_cmd);
813
+
814
+ $ver = get_sphinx_version($sphinx_cmd);
815
+ if ($need_sphinx && ($ver ge $min_version)) {
816
+ $activate = $f;
817
+ last;
818
+ } elsif ($ver gt $cur_version) {
819
+ $activate = $f;
820
+ last;
821
+ }
822
+ }
823
+ if ($activate ne "") {
824
+ if ($need_sphinx) {
825
+ printf "\nNeed to activate Sphinx (version $ver) on virtualenv with:\n";
826
+ printf "\t. $activate\n";
827
+ deactivate_help();
828
+ exit (1);
829
+ } else {
830
+ printf "\nYou may also use a newer Sphinx (version $ver) with:\n";
831
+ printf "\tdeactivate && . $activate\n";
832
+ }
833
+ } else {
834
+ my $rec_activate = "$virtenv_dir/bin/activate";
835
+
836
+ print "To upgrade Sphinx, use:\n\n" if ($rec_sphinx_upgrade);
837
+
838
+ $python_cmd = find_python_no_venv();
839
+
840
+ if ($need_venv) {
841
+ printf "\t$python_cmd -m venv $virtenv_dir\n";
842
+ } else {
843
+ printf "\t$virtualenv_cmd $virtenv_dir\n";
844
+ }
845
+ printf "\t. $rec_activate\n";
555846 printf "\tpip install -r $requirement_file\n";
556
- $need++;
847
+ deactivate_help();
848
+
849
+ $need++ if (!$rec_sphinx_upgrade);
557850 }
558851 }
559852 printf "\n";
560853
561
- print "All optional dependenties are met.\n" if (!$optional);
854
+ print "All optional dependencies are met.\n" if (!$optional);
562855
563856 if ($need == 1) {
564857 die "Can't build as $need mandatory dependency is missing";
....@@ -580,8 +873,14 @@
580873 $virtualenv = 0;
581874 } elsif ($arg eq "--no-pdf"){
582875 $pdf = 0;
876
+ } elsif ($arg eq "--version-check"){
877
+ $version_check = 1;
583878 } else {
584
- print "Usage:\n\t$0 <--no-virtualenv> <--no-pdf>\n\n";
879
+ print "Usage:\n\t$0 <--no-virtualenv> <--no-pdf> <--version-check>\n\n";
880
+ print "Where:\n";
881
+ print "\t--no-virtualenv\t- Recommend installing Sphinx instead of using a virtualenv\n";
882
+ print "\t--version-check\t- if version is compatible, don't check for missing dependencies\n";
883
+ print "\t--no-pdf\t- don't check for dependencies required to build PDF docs\n\n";
585884 exit -1;
586885 }
587886 }
....@@ -602,6 +901,24 @@
602901 $system_release = catcheck("/etc/redhat-release") if !$system_release;
603902 $system_release = catcheck("/etc/lsb-release") if !$system_release;
604903 $system_release = catcheck("/etc/gentoo-release") if !$system_release;
904
+
905
+# This seems more common than LSB these days
906
+if (!$system_release) {
907
+ my %os_var;
908
+ if (open IN, "cat /etc/os-release|") {
909
+ while (<IN>) {
910
+ if (m/^([\w\d\_]+)=\"?([^\"]*)\"?\n/) {
911
+ $os_var{$1}=$2;
912
+ }
913
+ }
914
+ $system_release = $os_var{"NAME"};
915
+ if (defined($os_var{"VERSION_ID"})) {
916
+ $system_release .= " " . $os_var{"VERSION_ID"} if (defined($os_var{"VERSION_ID"}));
917
+ } else {
918
+ $system_release .= " " . $os_var{"VERSION"};
919
+ }
920
+ }
921
+}
605922 $system_release = catcheck("/etc/issue") if !$system_release;
606923 $system_release =~ s/\s+$//;
607924