Compare commits
3 commits
fd6c7de526
...
fd0986908c
Author | SHA1 | Date | |
---|---|---|---|
fd0986908c | |||
093e629c70 | |||
e850eb4960 |
7 changed files with 129 additions and 118 deletions
2
AUTHORS
2
AUTHORS
|
@ -1,3 +1,5 @@
|
|||
(in chronological order)
|
||||
|
||||
* Kujiu
|
||||
* PtitGNU
|
||||
* Anonymous contributor
|
||||
|
|
100
pyproject.toml
Normal file
100
pyproject.toml
Normal file
|
@ -0,0 +1,100 @@
|
|||
[build-system]
|
||||
requires = ["flit_core>=3.2"]
|
||||
build-backend = "flit_core.buildapi"
|
||||
|
||||
[project]
|
||||
name = "sphinx_pyppeteer_builder"
|
||||
version = "1.0.0"
|
||||
requires-python = ">=3.8"
|
||||
dependencies = [
|
||||
"Sphinx>=7.0.0",
|
||||
"pyppeteer"
|
||||
]
|
||||
license = {text = "EUPL-1.2"}
|
||||
authors = [
|
||||
{name = "Nerv Project ASBL", email = "contact@nerv-project.eu"},
|
||||
{name = "kujiu"},
|
||||
{name = "ptitgnu"}
|
||||
]
|
||||
maintainers = [
|
||||
{name = "Nerv Project ASBL", email = "contact@nerv-project.eu"},
|
||||
{name = "kujiu"},
|
||||
{name = "ptitgnu"}
|
||||
]
|
||||
description = "A Sphinx PDF builder using pyppeteer"
|
||||
readme = {file = "README.rst", content-type = "text/x-rst"}
|
||||
keywords=["sphinx", "doc", "pdf", "pyppeteer"]
|
||||
classifiers=[
|
||||
"Framework :: Sphinx",
|
||||
"Framework :: Sphinx :: Extension",
|
||||
"Development Status :: 5 - Production/Stable",
|
||||
"License :: OSI Approved :: European Union Public Licence 1.2 (EUPL 1.2)",
|
||||
"Environment :: Console",
|
||||
"Environment :: Web Environment",
|
||||
"Intended Audience :: Developers",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Operating System :: OS Independent",
|
||||
"Topic :: Documentation",
|
||||
"Topic :: Software Development :: Documentation",
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
homepage = "https://www.nerv-project.eu"
|
||||
repository = "https://procrastinator.nerv-project.eu/nerv-project/sphinx_pyppeteer_builder"
|
||||
issues = "https://procrastinator.nerv-project.eu/nerv-project/sphinx_pyppeteer_builder/issues"
|
||||
editor = "https://www.nerv-project.eu"
|
||||
changelog = "https://procrastinator.nerv-project.eu/nerv-project/sphinx_pyppeteer_builder/raw/branch/main/CHANGES.rst"
|
||||
|
||||
[project.entry-points."sphinx.builders"]
|
||||
pyppeteer = "sphinx_pyppeteer_builder"
|
||||
|
||||
[project.optional-dependencies]
|
||||
tests = [
|
||||
"pytest",
|
||||
"flake8",
|
||||
"pylint",
|
||||
"pytest-cov"
|
||||
]
|
||||
setup = [
|
||||
"Sphinx",
|
||||
"pytest-runner",
|
||||
"flake8",
|
||||
"pylint",
|
||||
"babel",
|
||||
"flit",
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
minversion = "6.0"
|
||||
addopts = "-ra -q"
|
||||
testpaths = [
|
||||
"tests",
|
||||
]
|
||||
|
||||
[tool.babel.extract_messages]
|
||||
mapping_file = "babel.cfg"
|
||||
output_file = "locale/sphinx.pot"
|
||||
keywords = ["_", "__", "l_", "lazy_gettext", "gettext", "ngettext"]
|
||||
add_comments = "Translators:"
|
||||
|
||||
[tool.babel.init_catalog]
|
||||
domain = "sphinx"
|
||||
input_file = "locale/sphinx.pot"
|
||||
output_dir = "locale/"
|
||||
|
||||
[tool.babel.update_catalog]
|
||||
domain = "sphinx"
|
||||
input_file = "locale/sphinx.pot"
|
||||
output_dir = "locale/"
|
||||
|
||||
[tool.babel.compile_catalog]
|
||||
domain = "sphinx"
|
||||
directory = "locale/"
|
||||
|
||||
[tool.flit.sdist]
|
||||
include = [
|
||||
"*.py",
|
||||
]
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
Sphinx>=3.0.0
|
||||
pyppeteer
|
28
setup.cfg
28
setup.cfg
|
@ -1,28 +0,0 @@
|
|||
[metadata]
|
||||
description-file = README.rst
|
||||
license-files =
|
||||
LICENSE
|
||||
LICENSE-de
|
||||
LICENSE-fr
|
||||
LICENSE-nl
|
||||
|
||||
|
||||
[extract_messages]
|
||||
mapping_file = babel.cfg
|
||||
output_file = sphinx_pyppeteer_builder/locale/sphinx.pot
|
||||
keywords = _ l_ lazy_gettext gettext ngettext
|
||||
add_comments = Translators:
|
||||
|
||||
[init_catalog]
|
||||
domain = sphinx
|
||||
input_file = sphinx_pyppeteer_builder/locale/sphinx.pot
|
||||
output_dir = sphinx_pyppeteer_builder/locale/
|
||||
|
||||
[update_catalog]
|
||||
domain = sphinx
|
||||
input_file = sphinx_pyppeteer_builder/locale/sphinx.pot
|
||||
output_dir = sphinx_pyppeteer_builder/locale/
|
||||
|
||||
[compile_catalog]
|
||||
domain = sphinx
|
||||
directory = sphinx_pyppeteer_builder/locale/
|
76
setup.py
76
setup.py
|
@ -1,76 +0,0 @@
|
|||
from setuptools import setup
|
||||
import distutils
|
||||
|
||||
|
||||
class TranslateCommand(distutils.cmd.Command):
|
||||
description = "Translation"
|
||||
|
||||
user_options = []
|
||||
sub_commands = [
|
||||
('extract_messages', None),
|
||||
('update_catalog', None),
|
||||
('compile_catalog', None),
|
||||
]
|
||||
|
||||
def initialize_options(self):
|
||||
pass
|
||||
|
||||
def finalize_options(self):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
for cmd_name in self.get_sub_commands():
|
||||
self.run_command(cmd_name)
|
||||
|
||||
|
||||
with open("README.rst", "r") as fh:
|
||||
long_description = fh.read()
|
||||
|
||||
setup(
|
||||
name="sphinx_pyppeteer_builder",
|
||||
version="0.1.1",
|
||||
url="https://procrastinator.nerv-project.eu/nerv-project/sphinx_pyppeteer_builder",
|
||||
license="EUPL 1.2",
|
||||
author="Kujiu",
|
||||
author_email="kujiu-pypi@kujiu.org",
|
||||
description="A Sphinx PDF builder using pyppeteer",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/x-rst",
|
||||
packages=["sphinx_pyppeteer_builder"],
|
||||
cmdclass={
|
||||
'translate': TranslateCommand,
|
||||
},
|
||||
package_data={
|
||||
"sphinx_pyppeteer_builder": [
|
||||
"locale/*/LC_MESSAGES/*.mo",
|
||||
"locale/*/LC_MESSAGES/*.po",
|
||||
]
|
||||
},
|
||||
entry_points={"sphinx.builders": ["pyppeteer = sphinx_pyppeteer_builder"]},
|
||||
install_requires=[
|
||||
"sphinx>=3.0.0",
|
||||
"pyppeteer",
|
||||
],
|
||||
classifiers=[
|
||||
"Framework :: Sphinx",
|
||||
"Framework :: Sphinx :: Extension",
|
||||
"Development Status :: 4 - Beta",
|
||||
"License :: OSI Approved :: European Union Public Licence 1.2 (EUPL 1.2)",
|
||||
"Environment :: Console",
|
||||
"Environment :: Web Environment",
|
||||
"Intended Audience :: Developers",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.6",
|
||||
"Programming Language :: Python :: 3.7",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
"Programming Language :: Python :: 3.9",
|
||||
"Operating System :: OS Independent",
|
||||
"Topic :: Documentation",
|
||||
"Topic :: Software Development :: Documentation",
|
||||
],
|
||||
keywords="sphinx doc pdf pyppeteer",
|
||||
project_urls={
|
||||
"Source": "https://procrastinator.nerv-project.eu/nerv-project/sphinx_pyppeteer_builder",
|
||||
"Issues": "https://procrastinator.nerv-project.eu/nerv-project/sphinx_pyppeteer_builder/issues",
|
||||
},
|
||||
)
|
|
@ -5,11 +5,12 @@ from copy import deepcopy
|
|||
from .pyppeteer_builder import PyppeteerPDFBuilder
|
||||
from typing import Dict, Any
|
||||
from sphinx.application import Sphinx
|
||||
from sphinx.config import Config
|
||||
from sphinx.util.osutil import make_filename
|
||||
|
||||
|
||||
version = (0, 1, 1)
|
||||
|
||||
import pkg_resources
|
||||
__version__ = pkg_resources.get_distribution(__package__).version
|
||||
__version_info__ = tuple(int(v) for v in __version__.split('.'))
|
||||
|
||||
DEFAULT_PDF_OPTIONS = {
|
||||
'printBackground': True,
|
||||
|
@ -22,12 +23,19 @@ DEFAULT_PDF_OPTIONS = {
|
|||
}
|
||||
}
|
||||
|
||||
DEFAULT_PYPPETEER_ARGS = [
|
||||
'--allow-file-access-from-file',
|
||||
'--disable-web-security',
|
||||
'--no-sandbox',
|
||||
]
|
||||
|
||||
def on_config_inited(app, config):
|
||||
|
||||
def on_config_inited(app, config: Config):
|
||||
""" Change config on the fly """
|
||||
pdf_options = deepcopy(DEFAULT_PDF_OPTIONS)
|
||||
pdf_options.update(app.config.pyppeteer_pdf_options)
|
||||
app.config.pyppeteer_pdf_options = pdf_options
|
||||
app.set_html_assets_policy("always")
|
||||
|
||||
|
||||
def setup(app: Sphinx) -> Dict[str, Any]:
|
||||
|
@ -46,6 +54,11 @@ def setup(app: Sphinx) -> Dict[str, Any]:
|
|||
DEFAULT_PDF_OPTIONS,
|
||||
'pyppeteer'
|
||||
)
|
||||
app.add_config_value(
|
||||
'pyppeteer_args',
|
||||
DEFAULT_PYPPETEER_ARGS,
|
||||
'pyppeteer'
|
||||
)
|
||||
app.add_config_value(
|
||||
'pyppeteer_basename',
|
||||
lambda self: make_filename(self.project),
|
||||
|
@ -107,9 +120,14 @@ def setup(app: Sphinx) -> Dict[str, Any]:
|
|||
'',
|
||||
'pyppeteer'
|
||||
)
|
||||
app.add_config_value(
|
||||
'pyppeteer_baseurl',
|
||||
'#',
|
||||
'pyppeteer'
|
||||
)
|
||||
|
||||
return {
|
||||
'version': version,
|
||||
'version': __version__,
|
||||
'parallel_read_safe': True,
|
||||
'parallel_write_safe': True,
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import asyncio
|
|||
from typing import Dict, Set, Tuple
|
||||
|
||||
from sphinx.builders.singlehtml import SingleFileHTMLBuilder
|
||||
from sphinx.util import progress_message, logging
|
||||
from sphinx.util.display import progress_message, logging
|
||||
from sphinx.util.osutil import os_path
|
||||
from sphinx.locale import __
|
||||
|
||||
|
@ -23,7 +23,7 @@ class PyppeteerPDFBuilder(SingleFileHTMLBuilder):
|
|||
search = False
|
||||
|
||||
def _get_translations_js(self) -> str:
|
||||
return
|
||||
return ""
|
||||
|
||||
def copy_translation_js(self) -> None:
|
||||
return
|
||||
|
@ -101,14 +101,11 @@ class PyppeteerPDFBuilder(SingleFileHTMLBuilder):
|
|||
"""
|
||||
# Disable security to allow SVG use.
|
||||
browser = await pyppeteer.launch({
|
||||
'args': [
|
||||
'--allow-file-access-from-file',
|
||||
'--disable-web-security',
|
||||
]
|
||||
'args': self.config.pyppeteer_args,
|
||||
})
|
||||
try:
|
||||
page = await browser.newPage()
|
||||
await page.goto(url)
|
||||
await page.goto(url, {"waitUntil": ["networkidle2"]})
|
||||
await page.pdf(pdf_options)
|
||||
await browser.close()
|
||||
finally:
|
||||
|
|
Loading…
Reference in a new issue