Skip to content

Commit d1ac25b

Browse files
committed
[SPARK-28752][BUILD][DOCS] Documentation build to support Python 3
### What changes were proposed in this pull request? This PR proposes to switch `pygments.rb`, which only support Python 2 and seems inactive for the last few years (https://github.com/tmm1/pygments.rb), to Rouge which is pure Ruby code highlighter that is compatible with Pygments. I thought it would be pretty difficult to change but thankfully Rouge does a great job as the alternative. ### Why are the changes needed? We're moving to Python 3 and drop Python 2 completely. ### Does this PR introduce any user-facing change? Maybe a little bit of different syntax style but should not have a notable change. ### How was this patch tested? Manually tested the build and checked the documentation. Closes apache#26521 from HyukjinKwon/SPARK-28752. Authored-by: HyukjinKwon <[email protected]> Signed-off-by: HyukjinKwon <[email protected]>
1 parent 65a189c commit d1ac25b

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

dev/create-release/spark-rm/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ENV DEBCONF_NONINTERACTIVE_SEEN true
3434
ARG APT_INSTALL="apt-get install --no-install-recommends -y"
3535

3636
ARG BASE_PIP_PKGS="setuptools wheel virtualenv"
37-
ARG PIP_PKGS="pyopenssl pypandoc numpy pygments sphinx"
37+
ARG PIP_PKGS="pyopenssl pypandoc numpy sphinx"
3838

3939
# Install extra needed repos and refresh.
4040
# - CRAN repo
@@ -80,7 +80,7 @@ RUN apt-get clean && apt-get update && $APT_INSTALL gnupg ca-certificates && \
8080
$APT_INSTALL ruby2.3 ruby2.3-dev mkdocs && \
8181
gem install jekyll --no-rdoc --no-ri -v 3.8.6 && \
8282
gem install jekyll-redirect-from && \
83-
gem install pygments.rb
83+
gem install rogue
8484

8585
WORKDIR /opt/spark-rm/output
8686

docs/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ You need to have [Ruby](https://www.ruby-lang.org/en/documentation/installation/
3636
installed. Also install the following libraries:
3737

3838
```sh
39-
$ sudo gem install jekyll jekyll-redirect-from pygments.rb
40-
$ sudo pip install Pygments
39+
$ sudo gem install jekyll jekyll-redirect-from rouge
4140
# Following is needed only for generating API docs
4241
$ sudo pip install sphinx pypandoc mkdocs
4342
$ sudo Rscript -e 'install.packages(c("knitr", "devtools", "rmarkdown"), repos="https://cloud.r-project.org/")'

docs/_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
highlighter: pygments
1+
highlighter: rouge
22
markdown: kramdown
33
gems:
44
- jekyll-redirect-from

docs/_plugins/include_example.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#
1717

1818
require 'liquid'
19-
require 'pygments'
19+
require 'rouge'
2020

2121
module Jekyll
2222
class IncludeExampleTag < Liquid::Tag
@@ -56,7 +56,9 @@ def render(context)
5656
end
5757
code = select_lines(code)
5858

59-
rendered_code = Pygments.highlight(code, :lexer => @lang)
59+
formatter = Rouge::Formatters::HTML.new
60+
lexer = Rouge::Lexer.find(@lang)
61+
rendered_code = formatter.format(lexer.lex(code))
6062

6163
hint = "<div><small>Find full example code at " \
6264
"\"examples/src/main/#{snippet_file}\" in the Spark repo.</small></div>"

docs/css/pygments-default.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Also, I was thrown off for a while at first when I was using markdown
1111
code block inside my {% highlight scala %} ... {% endhighlight %} tags
1212
(I was using 4 spaces for this), when it turns out that pygments will
1313
insert the code (or pre?) tags for you.
14+
15+
Note that due to Python 3 compatibility in the project, now we use
16+
Rouge which claims Pygments compatibility, instead of pygments.rb which
17+
does not support Python 3. See SPARK-28752.
1418
*/
1519

1620
.hll { background-color: #ffffcc }
@@ -73,4 +77,4 @@ insert the code (or pre?) tags for you.
7377
.vc { color: #bb60d5 } /* Name.Variable.Class */
7478
.vg { color: #bb60d5 } /* Name.Variable.Global */
7579
.vi { color: #bb60d5 } /* Name.Variable.Instance */
76-
.il { color: #40a070 } /* Literal.Number.Integer.Long */
80+
.il { color: #40a070 } /* Literal.Number.Integer.Long */

0 commit comments

Comments
 (0)