Skip to content

Commit

Permalink
Merge branch 'prod'
Browse files Browse the repository at this point in the history
  • Loading branch information
metaist committed Jul 25, 2023
2 parents d1838e1 + f687119 commit b1f0800
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"pypdf",
"pyproject",
"rangify",
"unrotated"
"unrotated",
"venv"
]
}
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ These are changes that are on `main` that are not yet in `prod`.

---

[#28]: https://github.com/metaist/pdfmerge/issues/28
[1.0.1]: https://github.com/metaist/pdfmerge/compare/1.0.0...1.0.1

## [1.0.1] - 2023-07-24T19:59:45Z

As a consequence of fixing [#28], the output file can now be one of the input files because we build up the result in a temporary file first.

**Fixed**

- [#28]: reading and writing to a network drive

---

[#13]: https://github.com/metaist/pdfmerge/issues/13
[#15]: https://github.com/metaist/pdfmerge/pull/15
[#19]: https://github.com/metaist/pdfmerge/pull/19
Expand Down
30 changes: 30 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Setting up a dev environment

```bash
git clone <url>
cd pdfmerge
python -m .venv --prompt pdfmerge
source .venv/bin/activate
pip install -e ".[dev]"

pnpm install -g cspell
```

## Making a release

```bash
git checkout prod
git merge --no-ff --no-edit main
# update __init__.py version
# update changelog.md
pdm all

git commit -m "release: $VER"
git tag "$VER"
git push
git push --tags

git checkout main
git merge --no-ff --no-edit prod
git push
```
2 changes: 0 additions & 2 deletions docs/__main__.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ <h1 class="title">Module <code>pdfmerge.__main__</code></h1>
&lt;path&gt; paths to PDFs to merge
-p PASS, --password PASS password to decrypt PDFs
-o FILE, --output FILE output file [default: output.pdf]
NOTE: this may not be any of the input files
</code></pre>
<p>After each <code>&lt;path&gt;</code>, there are some optional rules you apply. These are written
in brackets after the file name. Remember to put quotes around the file name so
Expand Down Expand Up @@ -93,7 +92,6 @@ <h2 id="rotate-individual-pages-or-page-ranges">Rotate individual pages or page
&lt;path&gt; paths to PDFs to merge
-p PASS, --password PASS password to decrypt PDFs
-o FILE, --output FILE output file [default: output.pdf]
NOTE: this may not be any of the input files
```

After each `&lt;path&gt;`, there are some optional rules you apply. These are written
Expand Down
31 changes: 19 additions & 12 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ <h2 id="usage">Usage</h2>
<pre><code>$ pdfmerge [-h] [--version] [-o FILE|--output FILE] [-p PASSWORD|--password PASSWORD] PATH[RULE[, RULE ...]] [PATH[RULE, ...]] ...]
</code></pre>
<ul>
<li><code>-o</code>, <code>--output</code> output file (default: <code>output.pdf</code>).
<strong>Must not be any of the input files.</strong></li>
<li><code>-o</code>, <code>--output</code> output file (default: <code>output.pdf</code>).</li>
<li><code>-p</code>, '&ndash;password` password for encrypted files (default: empty string).</li>
<li><code>PATH</code> a file, directory, or wildcard string (e.g., <code>file*.pdf</code>) of files
to merge.</li>
Expand Down Expand Up @@ -96,13 +95,15 @@ <h2 id="license">License</h2>
from typing import Union
import re
import sys
import tempfile
import shutil

# lib
from pypdf import PdfReader
from pypdf import PdfWriter

__all__ = (&#34;__version__&#34;, &#34;pdfmerge&#34;)
__version__ = &#34;1.0.0&#34;
__version__ = &#34;1.0.1&#34;

ERR_PATH = &#34;ERROR: path not found: {0}&#34;
&#34;&#34;&#34;Error when a path is not found.&#34;&#34;&#34;
Expand Down Expand Up @@ -260,7 +261,7 @@ <h2 id="license">License</h2>
Returns:
PdfFileWriter: the writer object
&#34;&#34;&#34;
reader = PdfReader(item.path.open(&#34;rb&#34;))
reader = PdfReader(item.path.open(&#34;rb&#34;), strict=True)
if reader.is_encrypted:
if password is None:
print(f&#34;Reading encrypted PDF &lt;{item.path}&gt;&#34;)
Expand Down Expand Up @@ -354,10 +355,13 @@ <h2 id="license">License</h2>
print(err, file=sys.stderr)
return

with Path(output).open(&#34;wb&#34;) as stream:
with PdfWriter(stream) as writer:
for item in parsed.done:
add_path(writer, item, password)
with tempfile.NamedTemporaryFile(delete=False) as temp:
writer = PdfWriter(temp)
for item in parsed.done:
add_path(writer, item, password)
writer.write_stream(temp)
temp.flush()
shutil.move(temp.name, Path(output).expanduser().resolve())


__pdoc__ = {&#34;pdfmerge.__main__&#34;: True}</code></pre>
Expand Down Expand Up @@ -409,10 +413,13 @@ <h2 id="args">Args</h2>
print(err, file=sys.stderr)
return

with Path(output).open(&#34;wb&#34;) as stream:
with PdfWriter(stream) as writer:
for item in parsed.done:
add_path(writer, item, password)</code></pre>
with tempfile.NamedTemporaryFile(delete=False) as temp:
writer = PdfWriter(temp)
for item in parsed.done:
add_path(writer, item, password)
writer.write_stream(temp)
temp.flush()
shutil.move(temp.name, Path(output).expanduser().resolve())</code></pre>
</details>
</dd>
</dl>
Expand Down
2 changes: 1 addition & 1 deletion src/pdfmerge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from pypdf import PdfWriter

__all__ = ("__version__", "pdfmerge")
__version__ = "1.0.0-post"
__version__ = "1.0.1"

ERR_PATH = "ERROR: path not found: {0}"
"""Error when a path is not found."""
Expand Down

0 comments on commit b1f0800

Please sign in to comment.