conver 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
conver-0.1.0/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+ © 2024 Timur Ulyahin, https://github.com/ucomru
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
@@ -0,0 +1,6 @@
1
+ # Include essential documentation files
2
+ include README.md
3
+ include LICENSE
4
+
5
+ # Recursively include all files in the scripts folder within src/conver
6
+ recursive-include src/conver/scripts *
conver-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,353 @@
1
+ Metadata-Version: 2.4
2
+ Name: conver
3
+ Version: 0.1.0
4
+ Summary: A cross-platform document converter.
5
+ Author-email: Timur Ulyahin <ucomru@pm.me>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/ucomru/python-conver
8
+ Project-URL: Repository, https://github.com/ucomru/python-conver
9
+ Project-URL: Documentation, https://github.com/ucomru/python-conver
10
+ Project-URL: Issues, https://github.com/ucomru/python-conver/issues
11
+ Keywords: conversion,documents,office,tools,cli
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Operating System :: MacOS
14
+ Classifier: Operating System :: Microsoft :: Windows
15
+ Requires-Python: >=3.9
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: click
19
+ Dynamic: license-file
20
+
21
+ # conver — Cross-platform Word Document Converter
22
+
23
+ `conver` is a cross-platform Python package that converts Microsoft Word documents
24
+ using native system automation:
25
+
26
+ - macOS: JXA (JavaScript for Automation)
27
+ - Windows: PowerShell + Word COM automation
28
+
29
+ The package provides:
30
+
31
+ 1. A high-level Python API: `conver.conver()`
32
+ 2. A command-line interface: `conver`
33
+ 3. A low-level IPC layer calling platform scripts
34
+ (`convert.jxa` for macOS, `convert.ps1` for Windows)
35
+
36
+ Conversion is performed via Microsoft Word itself, ensuring maximum compatibility
37
+ with `.docx`, `.doc`, `.rtf`, `.txt`, `.html`, `.odt`.
38
+
39
+ ---
40
+
41
+ ## Features
42
+
43
+ - Cross-platform: macOS and Windows
44
+ - Uses the actual Microsoft Word engine
45
+ - Clean, minimal Python API
46
+ - CLI with direct input/output or format-selection flags
47
+ - Structured error handling via custom exceptions
48
+ - Filename-only outputs automatically placed next to the input file
49
+ - Safe low-level IPC layer between Python and native automation scripts
50
+
51
+ ## Installation
52
+
53
+ ### Using pip
54
+
55
+ ```bash
56
+ pip install conver
57
+ ```
58
+
59
+ ### Recommended for CLI use: pipx
60
+
61
+ If you primarily use `conver` as a command-line tool, it is best installed with **pipx**.
62
+ This isolates the package in its own virtual environment and avoids polluting your system Python:
63
+
64
+ ```bash
65
+ pipx install conver
66
+ ```
67
+
68
+ After installation:
69
+
70
+ ```bash
71
+ conver --help
72
+ ```
73
+
74
+ will be available globally.
75
+
76
+ ---
77
+
78
+ ### Requirements
79
+
80
+ - Python **3.9+**
81
+ - Microsoft Word must be installed on the system
82
+ - macOS (JXA) or Windows (PowerShell + Word COM automation)
83
+
84
+ ---
85
+
86
+ ## Python Usage
87
+
88
+ ### Basic example
89
+
90
+ ```python
91
+ from conver import conver
92
+
93
+ conver("document.docx", "document.pdf")
94
+ ```
95
+
96
+ Returns:
97
+
98
+ ```python
99
+ Path("/absolute/path/document.pdf")
100
+ ```
101
+
102
+ ### Filename-only output
103
+
104
+ ```python
105
+ conver("/Users/me/docs/a.docx", "a.pdf")
106
+ ```
107
+
108
+ Automatically produces:
109
+
110
+ ```bash
111
+ /Users/me/docs/a.pdf
112
+ ```
113
+
114
+ ### Error handling example
115
+
116
+ ```python
117
+ from conver import conver, UnsupportedFormat
118
+
119
+ try:
120
+ conver("a.doc", "a.xyz")
121
+ except UnsupportedFormat:
122
+ print("This output format is not supported.")
123
+ ```
124
+
125
+ ---
126
+
127
+ ## Python API Reference
128
+
129
+ ### `conver(input_path, output_path, keep_open=False) -> pathlib.Path`
130
+
131
+ High-level document conversion function.
132
+
133
+ #### Parameters
134
+
135
+ - `input_path` — `str` or `pathlib.Path`
136
+ Path to the source document.
137
+ - `output_path` — `str` or `pathlib.Path`
138
+ Target output filename or full path.
139
+ - `keep_open` — `bool`
140
+ Whether to keep Microsoft Word open after conversion.
141
+
142
+ #### Returns
143
+ - `pathlib.Path` — absolute path of the output file.
144
+
145
+ #### Raises
146
+
147
+ - `InputFileNotFound`
148
+ - `UnsupportedFormat`
149
+ - `WordStartError`
150
+ - `SaveError`
151
+ - `IPCError`
152
+ - `PlatformNotSupported`
153
+
154
+ ---
155
+
156
+ ## CLI Usage
157
+
158
+ The CLI supports two modes: direct output path, or format flags.
159
+
160
+ ### 1. Explicit input/output
161
+
162
+ ```bash
163
+ conver input.docx output.pdf
164
+ ```
165
+
166
+ ### 2. Format flags (output placed next to input)
167
+
168
+ ```bash
169
+ conver input.docx --pdf
170
+ conver input.docx --rtf
171
+ conver input.docx --txt
172
+ conver input.docx --html
173
+ conver input.docx --docx
174
+ ```
175
+
176
+ If only one input file and no explicit output is given,
177
+ the selected format determines the extension:
178
+
179
+ ```
180
+ input.docx --pdf -> input.pdf
181
+ input.docx --rtf -> input.rtf
182
+ ```
183
+
184
+ ### Output Behavior
185
+
186
+ When OUTPUT is omitted, the resulting file is written next to the INPUT file.
187
+ Examples:
188
+
189
+ ```
190
+ conver a.docx --pdf -> a.pdf
191
+ conver /path/x.docx -> /path/x.pdf
192
+ ```
193
+
194
+ When multiple inputs are provided, --output must be a directory.
195
+ If the directory does not exist, it will be created automatically.
196
+
197
+ ### Default Format
198
+
199
+ If no format flag is provided and no explicit output path is given,
200
+ the default output format is **PDF**:
201
+
202
+ ```bash
203
+ conver input.docx # -> input.pdf
204
+ ```
205
+
206
+ ### CLI Syntax
207
+
208
+ ```
209
+ Usage:
210
+ conver <input> <output>
211
+ conver <input> [--pdf | --docx | --rtf | --txt | --html] [--keep-open]
212
+
213
+ Examples:
214
+ conver a.docx a.pdf
215
+ conver a.docx --pdf
216
+ conver /path/to/file.doc --html
217
+ ```
218
+
219
+ ### CLI Arguments
220
+
221
+ `input`
222
+ One or more input files. Patterns like `*.docx` are expanded by the shell.
223
+
224
+ `output`
225
+ Optional.
226
+ For single input: output filename.
227
+ For multiple inputs: must be a directory.
228
+
229
+ ---
230
+
231
+ ### Multiple Inputs (Batch Mode)
232
+
233
+ The CLI can process multiple input files at once:
234
+
235
+ ```bash
236
+ conver *.docx -o outdir
237
+ conver file1.docx file2.docx file3.docx -o converted/
238
+ ```
239
+
240
+ Rules:
241
+
242
+ - When multiple inputs are provided, `--output` **must** point to a directory.
243
+ - If the directory does not exist, it will be created automatically.
244
+ - If no format flag is provided, the default output format is **PDF**.
245
+ - Format flags (`--pdf`, `--rtf`, etc.) **cannot be used together with** `--output FILE`.
246
+ - Globbing (`*.docx`) is expanded by your shell before reaching the CLI.
247
+
248
+ Output filenames follow the pattern:
249
+
250
+ ```
251
+ input.docx -> outdir/input.pdf
252
+ ```
253
+
254
+ ### Shell Globbing
255
+
256
+ Patterns like `*.docx` are expanded by your shell before the `conver` command is executed.
257
+
258
+ Examples:
259
+ `conver *.docx -o outdir`
260
+ `conver path/*.rtf --pdf`
261
+
262
+ This means the CLI receives the expanded list of files as separate arguments.
263
+
264
+ ### Format-Flag Restrictions
265
+
266
+ Format-selection flags:
267
+
268
+ ```
269
+ --pdf --docx --rtf --txt --html
270
+ ```
271
+
272
+ work **only when OUTPUT is omitted**, i.e.:
273
+
274
+ *Allowed*:
275
+ ```bash
276
+ conver input.docx --pdf
277
+ conver input.docx output.pdf
278
+ ```
279
+
280
+ *Invalid:
281
+ ```bash
282
+ conver input.docx output.pdf --pdf
283
+ ```
284
+
285
+ ---
286
+
287
+ ## Supported Formats
288
+
289
+ Conversion capabilities depend on Microsoft Word.
290
+
291
+ Input formats: `.docx`, `.doc`, `.pdf`, `.rtf`, `.odt`, `.txt`, `.html`
292
+
293
+ Output formats: `.pdf`, `.docx`, `.doc`, `.pdf`, `.rtf`, `.odt`, `.txt`, `.html`
294
+
295
+ ---
296
+
297
+ ## Platform Notes
298
+
299
+ ### macOS (JXA)
300
+
301
+ The script `convert.jxa` runs through:
302
+
303
+ ```
304
+ osascript -l JavaScript
305
+ ```
306
+
307
+ macOS may require granting Microsoft Word file-access permissions.
308
+
309
+ ### Windows (PowerShell)
310
+
311
+ The script `convert.ps1` uses:
312
+
313
+ ```
314
+ Word.Application COM automation
315
+ ```
316
+
317
+ If Word prompts the user, automation must be allowed.
318
+
319
+ ---
320
+
321
+ ## Low-Level Error Codes (Reference)
322
+
323
+ These codes come from platform scripts and are mapped to exceptions by `conver()`:
324
+
325
+ | Code | Meaning |
326
+ |------|--------------------------------------|
327
+ | 0 | Success |
328
+ | 1 | Invalid JSON from stdin |
329
+ | 2 | Unsupported input format |
330
+ | 3 | Unsupported output format |
331
+ | 11 | Input file not found |
332
+ | 21 | Word startup timeout |
333
+ | 31 | Word could not save the file |
334
+ | 98 | Script produced invalid JSON |
335
+ | 99 | Unsupported platform |
336
+
337
+ ---
338
+
339
+ ## License
340
+
341
+ MIT License
342
+ (c) 2024 Timur Ulyahin
343
+ https://github.com/ucomru
344
+
345
+ ---
346
+
347
+ ## Project Homepage
348
+
349
+ GitHub:
350
+ https://github.com/ucomru/python-conver
351
+
352
+ PyPI:
353
+ https://pypi.org/project/conver/
conver-0.1.0/README.md ADDED
@@ -0,0 +1,333 @@
1
+ # conver — Cross-platform Word Document Converter
2
+
3
+ `conver` is a cross-platform Python package that converts Microsoft Word documents
4
+ using native system automation:
5
+
6
+ - macOS: JXA (JavaScript for Automation)
7
+ - Windows: PowerShell + Word COM automation
8
+
9
+ The package provides:
10
+
11
+ 1. A high-level Python API: `conver.conver()`
12
+ 2. A command-line interface: `conver`
13
+ 3. A low-level IPC layer calling platform scripts
14
+ (`convert.jxa` for macOS, `convert.ps1` for Windows)
15
+
16
+ Conversion is performed via Microsoft Word itself, ensuring maximum compatibility
17
+ with `.docx`, `.doc`, `.rtf`, `.txt`, `.html`, `.odt`.
18
+
19
+ ---
20
+
21
+ ## Features
22
+
23
+ - Cross-platform: macOS and Windows
24
+ - Uses the actual Microsoft Word engine
25
+ - Clean, minimal Python API
26
+ - CLI with direct input/output or format-selection flags
27
+ - Structured error handling via custom exceptions
28
+ - Filename-only outputs automatically placed next to the input file
29
+ - Safe low-level IPC layer between Python and native automation scripts
30
+
31
+ ## Installation
32
+
33
+ ### Using pip
34
+
35
+ ```bash
36
+ pip install conver
37
+ ```
38
+
39
+ ### Recommended for CLI use: pipx
40
+
41
+ If you primarily use `conver` as a command-line tool, it is best installed with **pipx**.
42
+ This isolates the package in its own virtual environment and avoids polluting your system Python:
43
+
44
+ ```bash
45
+ pipx install conver
46
+ ```
47
+
48
+ After installation:
49
+
50
+ ```bash
51
+ conver --help
52
+ ```
53
+
54
+ will be available globally.
55
+
56
+ ---
57
+
58
+ ### Requirements
59
+
60
+ - Python **3.9+**
61
+ - Microsoft Word must be installed on the system
62
+ - macOS (JXA) or Windows (PowerShell + Word COM automation)
63
+
64
+ ---
65
+
66
+ ## Python Usage
67
+
68
+ ### Basic example
69
+
70
+ ```python
71
+ from conver import conver
72
+
73
+ conver("document.docx", "document.pdf")
74
+ ```
75
+
76
+ Returns:
77
+
78
+ ```python
79
+ Path("/absolute/path/document.pdf")
80
+ ```
81
+
82
+ ### Filename-only output
83
+
84
+ ```python
85
+ conver("/Users/me/docs/a.docx", "a.pdf")
86
+ ```
87
+
88
+ Automatically produces:
89
+
90
+ ```bash
91
+ /Users/me/docs/a.pdf
92
+ ```
93
+
94
+ ### Error handling example
95
+
96
+ ```python
97
+ from conver import conver, UnsupportedFormat
98
+
99
+ try:
100
+ conver("a.doc", "a.xyz")
101
+ except UnsupportedFormat:
102
+ print("This output format is not supported.")
103
+ ```
104
+
105
+ ---
106
+
107
+ ## Python API Reference
108
+
109
+ ### `conver(input_path, output_path, keep_open=False) -> pathlib.Path`
110
+
111
+ High-level document conversion function.
112
+
113
+ #### Parameters
114
+
115
+ - `input_path` — `str` or `pathlib.Path`
116
+ Path to the source document.
117
+ - `output_path` — `str` or `pathlib.Path`
118
+ Target output filename or full path.
119
+ - `keep_open` — `bool`
120
+ Whether to keep Microsoft Word open after conversion.
121
+
122
+ #### Returns
123
+ - `pathlib.Path` — absolute path of the output file.
124
+
125
+ #### Raises
126
+
127
+ - `InputFileNotFound`
128
+ - `UnsupportedFormat`
129
+ - `WordStartError`
130
+ - `SaveError`
131
+ - `IPCError`
132
+ - `PlatformNotSupported`
133
+
134
+ ---
135
+
136
+ ## CLI Usage
137
+
138
+ The CLI supports two modes: direct output path, or format flags.
139
+
140
+ ### 1. Explicit input/output
141
+
142
+ ```bash
143
+ conver input.docx output.pdf
144
+ ```
145
+
146
+ ### 2. Format flags (output placed next to input)
147
+
148
+ ```bash
149
+ conver input.docx --pdf
150
+ conver input.docx --rtf
151
+ conver input.docx --txt
152
+ conver input.docx --html
153
+ conver input.docx --docx
154
+ ```
155
+
156
+ If only one input file and no explicit output is given,
157
+ the selected format determines the extension:
158
+
159
+ ```
160
+ input.docx --pdf -> input.pdf
161
+ input.docx --rtf -> input.rtf
162
+ ```
163
+
164
+ ### Output Behavior
165
+
166
+ When OUTPUT is omitted, the resulting file is written next to the INPUT file.
167
+ Examples:
168
+
169
+ ```
170
+ conver a.docx --pdf -> a.pdf
171
+ conver /path/x.docx -> /path/x.pdf
172
+ ```
173
+
174
+ When multiple inputs are provided, --output must be a directory.
175
+ If the directory does not exist, it will be created automatically.
176
+
177
+ ### Default Format
178
+
179
+ If no format flag is provided and no explicit output path is given,
180
+ the default output format is **PDF**:
181
+
182
+ ```bash
183
+ conver input.docx # -> input.pdf
184
+ ```
185
+
186
+ ### CLI Syntax
187
+
188
+ ```
189
+ Usage:
190
+ conver <input> <output>
191
+ conver <input> [--pdf | --docx | --rtf | --txt | --html] [--keep-open]
192
+
193
+ Examples:
194
+ conver a.docx a.pdf
195
+ conver a.docx --pdf
196
+ conver /path/to/file.doc --html
197
+ ```
198
+
199
+ ### CLI Arguments
200
+
201
+ `input`
202
+ One or more input files. Patterns like `*.docx` are expanded by the shell.
203
+
204
+ `output`
205
+ Optional.
206
+ For single input: output filename.
207
+ For multiple inputs: must be a directory.
208
+
209
+ ---
210
+
211
+ ### Multiple Inputs (Batch Mode)
212
+
213
+ The CLI can process multiple input files at once:
214
+
215
+ ```bash
216
+ conver *.docx -o outdir
217
+ conver file1.docx file2.docx file3.docx -o converted/
218
+ ```
219
+
220
+ Rules:
221
+
222
+ - When multiple inputs are provided, `--output` **must** point to a directory.
223
+ - If the directory does not exist, it will be created automatically.
224
+ - If no format flag is provided, the default output format is **PDF**.
225
+ - Format flags (`--pdf`, `--rtf`, etc.) **cannot be used together with** `--output FILE`.
226
+ - Globbing (`*.docx`) is expanded by your shell before reaching the CLI.
227
+
228
+ Output filenames follow the pattern:
229
+
230
+ ```
231
+ input.docx -> outdir/input.pdf
232
+ ```
233
+
234
+ ### Shell Globbing
235
+
236
+ Patterns like `*.docx` are expanded by your shell before the `conver` command is executed.
237
+
238
+ Examples:
239
+ `conver *.docx -o outdir`
240
+ `conver path/*.rtf --pdf`
241
+
242
+ This means the CLI receives the expanded list of files as separate arguments.
243
+
244
+ ### Format-Flag Restrictions
245
+
246
+ Format-selection flags:
247
+
248
+ ```
249
+ --pdf --docx --rtf --txt --html
250
+ ```
251
+
252
+ work **only when OUTPUT is omitted**, i.e.:
253
+
254
+ *Allowed*:
255
+ ```bash
256
+ conver input.docx --pdf
257
+ conver input.docx output.pdf
258
+ ```
259
+
260
+ *Invalid:
261
+ ```bash
262
+ conver input.docx output.pdf --pdf
263
+ ```
264
+
265
+ ---
266
+
267
+ ## Supported Formats
268
+
269
+ Conversion capabilities depend on Microsoft Word.
270
+
271
+ Input formats: `.docx`, `.doc`, `.pdf`, `.rtf`, `.odt`, `.txt`, `.html`
272
+
273
+ Output formats: `.pdf`, `.docx`, `.doc`, `.pdf`, `.rtf`, `.odt`, `.txt`, `.html`
274
+
275
+ ---
276
+
277
+ ## Platform Notes
278
+
279
+ ### macOS (JXA)
280
+
281
+ The script `convert.jxa` runs through:
282
+
283
+ ```
284
+ osascript -l JavaScript
285
+ ```
286
+
287
+ macOS may require granting Microsoft Word file-access permissions.
288
+
289
+ ### Windows (PowerShell)
290
+
291
+ The script `convert.ps1` uses:
292
+
293
+ ```
294
+ Word.Application COM automation
295
+ ```
296
+
297
+ If Word prompts the user, automation must be allowed.
298
+
299
+ ---
300
+
301
+ ## Low-Level Error Codes (Reference)
302
+
303
+ These codes come from platform scripts and are mapped to exceptions by `conver()`:
304
+
305
+ | Code | Meaning |
306
+ |------|--------------------------------------|
307
+ | 0 | Success |
308
+ | 1 | Invalid JSON from stdin |
309
+ | 2 | Unsupported input format |
310
+ | 3 | Unsupported output format |
311
+ | 11 | Input file not found |
312
+ | 21 | Word startup timeout |
313
+ | 31 | Word could not save the file |
314
+ | 98 | Script produced invalid JSON |
315
+ | 99 | Unsupported platform |
316
+
317
+ ---
318
+
319
+ ## License
320
+
321
+ MIT License
322
+ (c) 2024 Timur Ulyahin
323
+ https://github.com/ucomru
324
+
325
+ ---
326
+
327
+ ## Project Homepage
328
+
329
+ GitHub:
330
+ https://github.com/ucomru/python-conver
331
+
332
+ PyPI:
333
+ https://pypi.org/project/conver/