argparse-from-file 1.1__tar.gz → 1.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: argparse-from-file
3
- Version: 1.1
3
+ Version: 1.2
4
4
  Summary: Wrapper for Python's argparse to also read arguments from a file
5
5
  Author-email: Mark Blakeney <mark.blakeney@bullet-systems.net>
6
6
  License-Expression: GPL-3.0-or-later
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: argparse-from-file
3
- Version: 1.1
3
+ Version: 1.2
4
4
  Summary: Wrapper for Python's argparse to also read arguments from a file
5
5
  Author-email: Mark Blakeney <mark.blakeney@bullet-systems.net>
6
6
  License-Expression: GPL-3.0-or-later
@@ -5,15 +5,30 @@ file.
5
5
  """
6
6
 
7
7
  import argparse
8
+ import os
8
9
  import shlex
9
10
  import sys
10
- from pathlib import Path
11
11
 
12
12
  import platformdirs
13
13
 
14
14
  PLACEHOLDER = '#FROM_FILE_PATH#'
15
15
 
16
16
 
17
+ # Get program name. This function is copied (but very modified) from argparse 3.14.0
18
+ def _prog_name():
19
+ try:
20
+ modspec = sys.modules['__main__'].__spec__
21
+ except (KeyError, AttributeError):
22
+ # possibly PYTHONSTARTUP or -X presite or other weird edge case
23
+ # no good answer here, so fall back to the default
24
+ modspec = None
25
+
26
+ if not modspec or modspec.name == '__main__':
27
+ return os.path.basename(sys.argv[0])
28
+
29
+ return modspec.name.removesuffix('.__main__')
30
+
31
+
17
32
  class ArgumentParser(argparse.ArgumentParser):
18
33
  _top = True
19
34
 
@@ -29,7 +44,7 @@ class ArgumentParser(argparse.ArgumentParser):
29
44
  # from_file = '': Do not use a "from file".
30
45
  # from_file = None: Create default "from file" path.
31
46
  if (from_file := kwargs.pop('from_file', None)) is None:
32
- from_file = Path(sys.argv[0]).stem + '-flags.conf'
47
+ from_file = _prog_name() + '-flags.conf'
33
48
 
34
49
  if from_file:
35
50
  from_file_path = platformdirs.user_config_path(from_file)