Skip to content

Commit 5ebfb29

Browse files
sdpythonxadupre
andauthored
add simple command line to convert images to pdf (#33)
* add simple command line to convert images to pdf * black * changelogs * code * clean --------- Co-authored-by: Xavier Dupre <xadupre@microsoft.com>
1 parent 9412326 commit 5ebfb29

File tree

11 files changed

+129
-2
lines changed

11 files changed

+129
-2
lines changed

CHANGELOGS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Change Logs
44
0.3.0
55
+++++
66

7+
* :pr:`33`: add simple command line to convert images to pdf
78
* :pr:`28`: add syntax to check the readme syntax
89
* :pr:`27`: fix missing __text_signature__ in docassert
910

CODE_OF_CONDUCT.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Code of Conduct
2+
3+
We are a community based on openness, as well as friendly and didactic discussions.
4+
5+
We aspire to treat everybody equally, and value their contributions.
6+
7+
Decisions are made based on technical merit and consensus.
8+
9+
Code is not the only way to help the project. Reviewing pull requests,
10+
answering questions to help others on mailing lists or issues, organizing and
11+
teaching tutorials, working on the website, improving the documentation, are
12+
all priceless contributions.
13+
14+
We abide by the principles of openness, respect, and consideration of others of
15+
the Python Software Foundation: https://www.python.org/psf/codeofconduct/

_unittests/ut_tools/data/image.png

2.14 KB
Loading

_unittests/ut_tools/data/img4.png

5.28 KB
Loading
347 KB
Loading
231 KB
Loading
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
import unittest
3+
from sphinx_runpython.ext_test_case import ExtTestCase
4+
from sphinx_runpython.tools.img_export import images2pdf
5+
6+
7+
class TestImgExport(ExtTestCase):
8+
9+
def test_export1(self):
10+
dest = "test_export1.pdf"
11+
data = os.path.join(os.path.dirname(__file__), "data", "mazures1.jpg")
12+
datap = os.path.join(os.path.dirname(__file__), "data", "*.jpg")
13+
res = images2pdf([data, datap], dest)
14+
self.assertExists(dest)
15+
self.assertEqual(len(res), 3)
16+
17+
def test_export2(self):
18+
dest = "test_export2.pdf"
19+
data = os.path.join(os.path.dirname(__file__), "data", "mazures1.jpg")
20+
datap = os.path.join(os.path.dirname(__file__), "data", "*.jpg")
21+
res = images2pdf(",".join([data, datap]), dest)
22+
self.assertExists(dest)
23+
self.assertEqual(len(res), 3)
24+
25+
26+
if __name__ == "__main__":
27+
unittest.main(verbosity=2)

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ black
22
coverage
33
flake8
44
furo
5+
img2pdf
56
isort
67
matplotlib
78
numpydoc

sphinx_runpython/_cmd_helper.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import os
33
from argparse import ArgumentParser
44
from tempfile import TemporaryDirectory
5-
from .convert import convert_ipynb_to_gallery
65

76

87
def get_parser():
@@ -12,7 +11,8 @@ def get_parser():
1211
epilog="",
1312
)
1413
parser.add_argument(
15-
"command", help="Command to run, only 'nb2py' or 'readme' are available"
14+
"command",
15+
help="Command to run, only 'nb2py', 'readme', 'img2pdf' are available",
1616
)
1717
parser.add_argument(
1818
"-p", "--path", help="Folder or file which contains the files to process"
@@ -23,11 +23,18 @@ def get_parser():
2323
help="Recursive search.",
2424
action="store_true",
2525
)
26+
parser.add_argument(
27+
"-o",
28+
"--output",
29+
help="output",
30+
)
2631
parser.add_argument("-v", "--verbose", help="verbosity", default=1, type=int)
2732
return parser
2833

2934

3035
def nb2py(infolder: str, recursive: bool = False, verbose: int = 0):
36+
from .convert import convert_ipynb_to_gallery
37+
3138
if not os.path.exists(infolder):
3239
raise FileNotFoundError(f"Unable to find {infolder!r}.")
3340
patterns = [infolder + "/*.ipynb", infolder + "/**/*.ipynb"]
@@ -47,6 +54,11 @@ def process_args(args):
4754
if cmd == "nb2py":
4855
nb2py(args.path, recursive=args.recursive, verbose=args.verbose)
4956
return
57+
if cmd == "img2pdf":
58+
from .tools.img_export import images2pdf
59+
60+
images2pdf(args.path, args.output, verbose=args.verbose)
61+
return
5062
if cmd == "readme":
5163
from .readme import check_readme_syntax
5264

sphinx_runpython/tools/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)