Skip to content

Commit 2e4b1df

Browse files
committed
fix: remove dependency on pandoc to improve performance
1 parent dcc7879 commit 2e4b1df

File tree

73 files changed

+10133
-8938
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+10133
-8938
lines changed

.github/workflows/tests.yaml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ jobs:
126126
- name: Install system dependencies.
127127
run: |
128128
sudo apt-get update
129-
sudo apt-get install -y curl pandoc unzip
129+
sudo apt-get install -y curl unzip
130130
- name: Install showcase
131131
run: |
132132
sudo mkdir -p /usr/src/showcase
@@ -174,7 +174,7 @@ jobs:
174174
- name: Install system dependencies.
175175
run: |
176176
sudo apt-get update
177-
sudo apt-get install -y curl pandoc unzip
177+
sudo apt-get install -y curl unzip
178178
- name: Install nox.
179179
run: python -m pip install nox
180180
- name: Install protoc.
@@ -220,7 +220,7 @@ jobs:
220220
- name: Install system dependencies.
221221
run: |
222222
sudo apt-get update
223-
sudo apt-get install -y curl pandoc unzip
223+
sudo apt-get install -y curl unzip
224224
- name: Install protoc.
225225
run: |
226226
sudo mkdir -p /usr/src/protoc/
@@ -248,7 +248,7 @@ jobs:
248248
- name: Install system dependencies.
249249
run: |
250250
sudo apt-get update
251-
sudo apt-get install -y curl pandoc unzip
251+
sudo apt-get install -y curl unzip
252252
- name: Install protoc.
253253
run: |
254254
sudo mkdir -p /usr/src/protoc/
@@ -276,7 +276,7 @@ jobs:
276276
- name: Install system dependencies.
277277
run: |
278278
sudo apt-get update
279-
sudo apt-get install -y curl pandoc unzip
279+
sudo apt-get install -y curl unzip
280280
- name: Install protoc.
281281
run: |
282282
sudo mkdir -p /usr/src/protoc/
@@ -302,7 +302,7 @@ jobs:
302302
- name: Install system dependencies.
303303
run: |
304304
sudo apt-get update
305-
sudo apt-get install -y curl pandoc unzip
305+
sudo apt-get install -y curl unzip
306306
- name: Install nox.
307307
run: python -m pip install nox
308308
- name: Check autogenerated snippets.
@@ -323,10 +323,6 @@ jobs:
323323
python-version: "${{ matrix.python }}"
324324
cache: 'pip'
325325
allow-prereleases: true
326-
- name: Install pandoc
327-
run: |
328-
sudo apt-get update
329-
sudo apt-get install -y pandoc gcc git
330326
- name: Install nox.
331327
run: |
332328
python -m pip install nox
@@ -349,10 +345,6 @@ jobs:
349345
python-version: "${{ matrix.python }}"
350346
cache: 'pip'
351347
allow-prereleases: true
352-
- name: Install pandoc
353-
run: |
354-
sudo apt-get update
355-
sudo apt-get install -y pandoc gcc git
356348
- name: Install nox.
357349
run: |
358350
python -m pip install nox

BUILD.bazel

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,6 @@
1-
load("//:gapic_generator_python.bzl", "pandoc_binary", "pandoc_toolchain")
21
load("@gapic_generator_python_pip_deps//:requirements.bzl", "requirement")
32
load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair")
43

5-
toolchain_type(
6-
name = "pandoc_toolchain_type",
7-
visibility = ["//visibility:public"],
8-
)
9-
10-
pandoc_toolchain(
11-
exec_compatible_with = [
12-
"@platforms//os:linux",
13-
"@platforms//cpu:arm64",
14-
],
15-
platform = "linux_arm_64",
16-
)
17-
18-
pandoc_toolchain(
19-
exec_compatible_with = [
20-
"@platforms//os:linux",
21-
"@platforms//cpu:x86_64",
22-
],
23-
platform = "linux_x86_64",
24-
)
25-
26-
pandoc_toolchain(
27-
exec_compatible_with = [
28-
"@platforms//os:osx",
29-
"@platforms//cpu:arm64",
30-
],
31-
platform = "macOS_arm_64",
32-
)
33-
34-
pandoc_toolchain(
35-
exec_compatible_with = [
36-
"@platforms//os:osx",
37-
"@platforms//cpu:x86_64",
38-
],
39-
platform = "macOS_x86_64",
40-
)
41-
42-
pandoc_toolchain(
43-
exec_compatible_with = [
44-
"@platforms//os:windows",
45-
"@platforms//cpu:x86_64",
46-
],
47-
platform = "windows_x86_64",
48-
)
49-
50-
pandoc_binary(
51-
name = "pandoc_binary",
52-
)
53-
544
py_runtime(
555
name = "pyenv3_runtime",
566
interpreter = ":pyenv3wrapper.sh",
@@ -71,11 +21,11 @@ toolchain(
7121
py_binary(
7222
name = "gapic_plugin",
7323
srcs = glob(["gapic/**/*.py"]),
74-
data = [":pandoc_binary"] + glob([
24+
data = glob([
7525
"gapic/**/*.j2",
7626
"gapic/**/.*.j2",
7727
]),
78-
main = "gapic/cli/generate_with_pandoc.py",
28+
main = "gapic/cli/generate_gapic.py",
7929
python_version = "PY3",
8030
visibility = ["//visibility:public"],
8131
deps = [
@@ -86,7 +36,6 @@ py_binary(
8636
requirement("googleapis-common-protos"),
8737
requirement("jinja2"),
8838
requirement("MarkupSafe"),
89-
requirement("pypandoc"),
9039
requirement("PyYAML"),
9140
requirement("grpc-google-iam-v1"),
9241
],

WORKSPACE

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,10 @@ install_deps()
5353
load(
5454
"//:repositories.bzl",
5555
"gapic_generator_python",
56-
"gapic_generator_register_toolchains",
5756
)
5857

5958
gapic_generator_python()
6059

61-
gapic_generator_register_toolchains()
6260

6361
_grpc_version = "1.71.0"
6462

@@ -123,3 +121,9 @@ switched_rules_by_language(
123121
gapic = True,
124122
grpc = True,
125123
)
124+
load("@rules_python//python:repositories.bzl", "python_register_toolchains")
125+
python_register_toolchains(
126+
name = "python311",
127+
python_version = "3.11",
128+
)
129+

docs/getting-started/local.rst

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,6 @@ To ensure it is installed propertly:
4848
libprotoc 3.6.0
4949
5050
51-
pandoc
52-
~~~~~~
53-
54-
This generator relies on `pandoc`_ to convert from Markdown (the *lingua
55-
franca* for documentation in protocol buffers) into ReStructured Text (the
56-
*lingua franca* for documentation in Python).
57-
58-
Install this using an appropriate mechanism for your operating system.
59-
Multiple installation paths are documented on the `pandoc installation page`_.
60-
61-
.. _pandoc: https://pandoc.org/
62-
.. _pandoc installation page: https://pandoc.org/installing.html
63-
6451
6552
API Generator for Python
6653
~~~~~~~~~~~~~~~~~~~~~~~~

gapic/cli/generate_with_pandoc.py renamed to gapic/cli/generate_gapic.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
import sys
33

44
if __name__ == "__main__":
5-
os.environ["PYPANDOC_PANDOC"] = os.path.join(
6-
os.path.abspath(__file__).rsplit("gapic", 1)[0], "pandoc"
7-
)
85
os.environ["LC_ALL"] = "C.UTF-8"
96
os.environ["PYTHONNOUSERSITE"] = "True"
107

gapic/utils/rst.py

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import re
1616
from typing import Optional
1717

18-
import pypandoc # type: ignore
19-
2018
from gapic.utils.lines import wrap
2119

2220

@@ -43,29 +41,12 @@ def rst(
4341
Returns:
4442
str: The same text, in RST format.
4543
"""
46-
# Quick check: If the text block does not appear to have any formatting,
47-
# do not convert it.
48-
# (This makes code generation significantly faster; calling out to pandoc
49-
# is by far the most expensive thing we do.)
50-
if not re.search(r"[|*`_[\]]", text):
51-
answer = wrap(
52-
text,
53-
indent=indent,
54-
offset=indent + 3,
55-
width=width - indent,
56-
)
57-
else:
58-
# Convert from CommonMark to ReStructured Text.
59-
answer = (
60-
pypandoc.convert_text(
61-
text,
62-
"rst",
63-
format=source_format,
64-
extra_args=["--columns=%d" % (width - indent)],
65-
)
66-
.strip()
67-
.replace("\n", f"\n{' ' * indent}")
68-
)
44+
answer = wrap(
45+
text,
46+
indent=indent,
47+
offset=indent + 3,
48+
width=width - indent,
49+
)
6950

7051
# Add a newline to the end of the document if any line breaks are
7152
# already present.

gapic_generator_python.bzl

Lines changed: 0 additions & 62 deletions
This file was deleted.

repositories.bzl

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
22

3-
_PANDOC_BUILD_FILE = """
4-
filegroup(
5-
name = "pandoc",
6-
srcs = ["bin/pandoc"],
7-
visibility = ["//visibility:public"],
8-
)"""
9-
103
def gapic_generator_python():
114

125
_maybe(
@@ -25,47 +18,6 @@ def gapic_generator_python():
2518
strip_prefix = "grpc-{}".format(_grpc_version),
2619
url = "https://github.com/grpc/grpc/archive/v{}.zip".format(_grpc_version),
2720
)
28-
29-
_maybe(
30-
http_archive,
31-
name = "pandoc_linux_arm_64",
32-
build_file_content = _PANDOC_BUILD_FILE,
33-
strip_prefix = "pandoc-3.7.0.2",
34-
url = "https://github.com/jgm/pandoc/releases/download/3.7.0.2/pandoc-3.7.0.2-linux-arm64.tar.gz",
35-
)
36-
37-
_maybe(
38-
http_archive,
39-
name = "pandoc_linux_x86_64",
40-
build_file_content = _PANDOC_BUILD_FILE,
41-
strip_prefix = "pandoc-3.7.0.2",
42-
url = "https://github.com/jgm/pandoc/releases/download/3.7.0.2/pandoc-3.7.0.2-linux-amd64.tar.gz",
43-
)
44-
45-
_maybe(
46-
http_archive,
47-
name = "pandoc_macOS_arm_64",
48-
build_file_content = _PANDOC_BUILD_FILE,
49-
strip_prefix = "pandoc-3.7.0.2",
50-
url = "https://github.com/jgm/pandoc/releases/download/3.7.0.2/pandoc-3.7.0.2-arm64-macOS.zip",
51-
)
52-
53-
_maybe(
54-
http_archive,
55-
name = "pandoc_macOS_x86_64",
56-
build_file_content = _PANDOC_BUILD_FILE,
57-
strip_prefix = "pandoc-3.7.0.2",
58-
url = "https://github.com/jgm/pandoc/releases/download/3.7.0.2/pandoc-3.7.0.2-x86_64-macOS.zip",
59-
)
60-
61-
_maybe(
62-
http_archive,
63-
name = "pandoc_windows_x86_64",
64-
build_file_content = _PANDOC_BUILD_FILE,
65-
strip_prefix = "pandoc-3.7.0.2",
66-
url = "https://github.com/jgm/pandoc/releases/download/3.7.0.2/pandoc-3.7.0.2-windows-x86_64.zip",
67-
)
68-
6921
_rules_gapic_version = "0.5.4"
7022
_maybe(
7123
http_archive,
@@ -81,14 +33,6 @@ def gapic_generator_python():
8133
urls = ["https://github.com/googleapis/googleapis/archive/{}.zip".format(_commit_sha)],
8234
)
8335

84-
def gapic_generator_register_toolchains():
85-
native.register_toolchains(
86-
"@gapic_generator_python//:pandoc_toolchain_linux_arm_64",
87-
"@gapic_generator_python//:pandoc_toolchain_linux_x86_64",
88-
"@gapic_generator_python//:pandoc_toolchain_macOS_arm_64",
89-
"@gapic_generator_python//:pandoc_toolchain_macOS_x86_64",
90-
"@gapic_generator_python//:pandoc_toolchain_windows_x86_64",
91-
)
9236

9337
def _maybe(repo_rule, name, strip_repo_prefix = "", **kwargs):
9438
if not name.startswith(strip_repo_prefix):

requirements.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ googleapis-common-protos
44
jinja2
55
MarkupSafe
66
protobuf
7-
pypandoc
87
PyYAML
98
grpc-google-iam-v1
109
proto-plus

0 commit comments

Comments
 (0)