Skip to content

Commit c2d7b9d

Browse files
committed
Documentation and formatting updates. No functional changes.
helper.py TUPLE_STR_BYTES, while functionally the same, should be str, bytes constants.py, put DEFAULT_EXECUTABLE into a one-liner so that it's properly documented by AutoAPI
1 parent a9f8af8 commit c2d7b9d

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

docs/source/examples.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Setting Tags
190190
params=["-P", "-overwrite_original"]
191191
)
192192
193-
(No output is returned if successful)
193+
(*No output is returned if successful*)
194194

195195
* Setting keywords for a file.
196196

@@ -203,7 +203,7 @@ Setting Tags
203203
tags={"Keywords": ["sunny", "nice day", "cool", "awesome"]}
204204
)
205205
206-
(No output is returned if successful)
206+
(*No output is returned if successful*)
207207

208208

209209

@@ -218,7 +218,7 @@ By default, ExifToolHelper has some **built-in error checking**, making the meth
218218

219219
* Example using get_tags() on a list which includes a non-existent file
220220

221-
* Using ExifToolHelper.get_tags()
221+
* ExifToolHelper with error-checking, using :py:meth:`exiftool.ExifToolHelper.get_tags`
222222

223223
.. code-block::
224224
@@ -245,7 +245,7 @@ By default, ExifToolHelper has some **built-in error checking**, making the meth
245245
exiftool.exceptions.ExifToolExecuteError: execute returned a non-zero exit status: 1
246246
247247
248-
* Using ExifTool.execute_json() (Note how the missing file is silently ignored and doesn't show up in returned list.)
248+
* ExifTool only, without error checking, using :py:meth:`exiftool.ExifTool.execute_json` (**Note how the missing file is silently ignored and doesn't show up in returned list.**)
249249

250250
.. code-block::
251251
@@ -263,9 +263,9 @@ By default, ExifToolHelper has some **built-in error checking**, making the meth
263263
[{'SourceFile': 'rose.jpg', 'File:FileSize': 4949}, {'SourceFile': 'skyblue.png', 'File:FileSize': 206}]
264264
265265
266-
* Example using get_tags() with a typo. Let's say you wanted to get_tags, but accidentally copy/pasted something and left a ``=`` character behind...
266+
* Example using :py:meth:`exiftool.ExifToolHelper.get_tags` with a typo. Let's say you wanted to ``get_tags()``, but accidentally copy/pasted something and left a ``=`` character behind (deletes tag rather than getting!)...
267267

268-
* Using ExifToolHelper.get_tags()
268+
* Using :py:meth:`exiftool.ExifToolHelper.get_tags`
269269

270270
.. code-block::
271271
@@ -286,7 +286,7 @@ By default, ExifToolHelper has some **built-in error checking**, making the meth
286286
raise ExifToolTagNameError(t)
287287
exiftool.exceptions.ExifToolTagNameError: Invalid Tag Name found: "XMP:Subject=hi"
288288
289-
* Using ExifTool.execute_json(). It still errors out, but more cryptic
289+
* Using :py:meth:`exiftool.ExifTool.execute_json`. It still raises an exception, but more cryptic and difficult to debug
290290

291291
.. code-block::
292292
@@ -305,7 +305,7 @@ By default, ExifToolHelper has some **built-in error checking**, making the meth
305305
raise ExifToolOutputEmptyError(self._last_status, self._last_stdout, self._last_stderr, params)
306306
exiftool.exceptions.ExifToolOutputEmptyError: execute_json expected output on stdout but got none
307307
308-
* Using ExifTool.execute(). **No errors, but you have now written to the file instead of reading from it!**
308+
* Using :py:meth:`exiftool.ExifTool.execute`. **No errors, but you have now written to the file instead of reading from it!**
309309

310310
.. code-block::
311311

docs/source/intro.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ What PyExifTool Is NOT
3838
Nomenclature
3939
============
4040

41-
PyExifTool's namespace is *exiftool*. While naming the library the same name of the tool it's meant to interface with, it can cause some ambiguity when describing it in docs.
41+
PyExifTool's namespace is *exiftool*. Since library name the same name of the tool it's meant to interface with, it can cause some ambiguity when describing it in docs.
4242
Hence, here's some common nomenclature used.
4343

4444
Because the term `exiftool` is overloaded (lowercase, CapWords case, ...) and can mean several things:

exiftool/constants.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,23 @@
5151

5252

5353
# specify the extension so exiftool doesn't default to running "exiftool.py" on windows (which could happen)
54-
DEFAULT_EXECUTABLE: str
54+
DEFAULT_EXECUTABLE: str = "exiftool.exe" if PLATFORM_WINDOWS else "exiftool"
5555
"""The name of the default executable to run.
5656
57-
``exiftool`` (Linux) or ``exiftool.exe`` (Windows)
57+
``exiftool.exe`` (Windows) or ``exiftool`` (Linux/Mac/non-Windows platforms)
5858
5959
By default, the executable is searched for on one of the paths listed in the
60-
``PATH`` environment variable. If it's not on the ``PATH``, a full path should be given to the ExifTool constructor.
60+
``PATH`` environment variable. If it's not on the ``PATH``, a full path should be specified in the
61+
``executable`` argument of the ExifTool constructor (:py:meth:`exiftool.ExifTool.__init__`).
6162
"""
6263

63-
if PLATFORM_WINDOWS:
64-
DEFAULT_EXECUTABLE = "exiftool.exe"
65-
else: # pytest-cov:windows: no cover
64+
"""
65+
# flipped the if/else so that the sphinx documentation shows "exiftool" rather than "exiftool.exe"
66+
if not PLATFORM_WINDOWS: # pytest-cov:windows: no cover
6667
DEFAULT_EXECUTABLE = "exiftool"
67-
68+
else:
69+
DEFAULT_EXECUTABLE = "exiftool.exe"
70+
"""
6871

6972

7073
##################################
@@ -96,7 +99,7 @@
9699
should be fine, though other values might give better performance in
97100
some cases."""
98101

99-
EXIFTOOL_MINIMUM_VERSION = "12.15"
102+
EXIFTOOL_MINIMUM_VERSION: str = "12.15"
100103
"""this is the minimum *exiftool* version required for current version of PyExifTool
101104
102105
* 8.40 / 8.60 (production): implemented the -stay_open flag

exiftool/helper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from .exceptions import ExifToolOutputEmptyError, ExifToolJSONInvalidError, ExifToolExecuteError, ExifToolTagNameError
3636

3737
# basestring makes no sense in Python 3, so renamed tuple to this const
38-
TUPLE_STR_BYTES = (bytes, str)
38+
TUPLE_STR_BYTES: tuple = (str, bytes,)
3939

4040
from typing import Any, Union, Optional, List, Dict
4141

@@ -124,7 +124,7 @@ def execute(self, *params: Any, **kwargs) -> Union[str, bytes]:
124124
# this was originally to support Path() but it's now generic enough to support any object that str() to something useful
125125
#
126126
# Thanks @jangop for the single line contribution!
127-
str_bytes_params = [x if isinstance(x, TUPLE_STR_BYTES) else str(x) for x in params]
127+
str_bytes_params: Union[str, bytes] = [x if isinstance(x, TUPLE_STR_BYTES) else str(x) for x in params]
128128
# TODO: this list copy could be expensive if the input is a very huge list. Perhaps in the future have a flag that takes the lists in verbatim without any processing?
129129

130130

@@ -549,7 +549,7 @@ def _check_tag_list(tags: List) -> None:
549549
# we can check self.version ... then this method will no longer
550550
# be static and requires the underlying exiftool process to be running to get the self.version
551551
#
552-
# This is not done right now because the odds of the tag name format changing is very low, and requirin
552+
# This is not done right now because the odds of the tag name format changing is very low, and requiring
553553
# exiftool to be running during this tag check could introduce unneccesary overhead at this time
554554

555555

@@ -560,7 +560,7 @@ def _check_tag_list(tags: List) -> None:
560560
# \w in Perl => https://perldoc.perl.org/perlrecharclass#Backslash-sequences
561561
# \w in Python => https://docs.python.org/3/library/re.html#regular-expression-syntax
562562
#
563-
# Perl vs Python's "\w" seem to mean slightly different things, so we write our own regex / matching algo
563+
# Perl vs Python's "\w" seem to mean slightly different things, so we write our own regex / matching algorithm
564564

565565

566566
# * make sure the first character is not a special one

0 commit comments

Comments
 (0)