argparse-from-file 1.3__tar.gz → 1.4__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,5 +1,6 @@
1
1
  NAME = $(shell basename $(CURDIR))
2
- PYFILES = $(subst -,_,$(NAME)).py
2
+ PYNAME = $(subst -,_,$(NAME))
3
+ PYFILES = $(wildcard $(PYNAME)/[^_]*.py)
3
4
 
4
5
  check:
5
6
  ruff check $(PYFILES)
@@ -19,4 +20,4 @@ format::
19
20
  ruff check --select I --fix $(PYFILES) && ruff format $(PYFILES)
20
21
 
21
22
  clean::
22
- @rm -vrf *.egg-info build/ dist/ __pycache__/
23
+ @rm -vrf *.egg-info build/ dist/ __pycache__/ */__pycache__
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: argparse-from-file
3
- Version: 1.3
3
+ Version: 1.4
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
@@ -57,11 +57,11 @@ which is the only addition to the standard
57
57
  [`ArgumentParser()`][argparser] API:
58
58
 
59
59
  ```python
60
- # Use a specific file path
61
- parser = argparse.ArgumentParser(from_file='/path/to/my/config', ..)
60
+ # Use a specific () file path
61
+ parser = argparse.ArgumentParser(from_file='/path/to/myprog.conf', ..)
62
62
 
63
63
  # Use a file relative to the user's config directory
64
- parser = argparse.ArgumentParser(from_file='my-app.conf', ..)
64
+ parser = argparse.ArgumentParser(from_file='myprog.conf', ..)
65
65
  ```
66
66
 
67
67
  The `from_file` argument accepts a string or a [`pathlib.Path`][pathlib].
@@ -76,10 +76,11 @@ clarity.
76
76
 
77
77
  Example `~/.config/myprog-flags.conf`:
78
78
  ```
79
- --verbose
80
-
81
79
  # Always run with foo set to 123
82
80
  --foo 123
81
+
82
+ # Default to verbose output
83
+ --verbose
83
84
  ```
84
85
 
85
86
  ## Customizing the Help Message
@@ -44,11 +44,11 @@ which is the only addition to the standard
44
44
  [`ArgumentParser()`][argparser] API:
45
45
 
46
46
  ```python
47
- # Use a specific file path
48
- parser = argparse.ArgumentParser(from_file='/path/to/my/config', ..)
47
+ # Use a specific () file path
48
+ parser = argparse.ArgumentParser(from_file='/path/to/myprog.conf', ..)
49
49
 
50
50
  # Use a file relative to the user's config directory
51
- parser = argparse.ArgumentParser(from_file='my-app.conf', ..)
51
+ parser = argparse.ArgumentParser(from_file='myprog.conf', ..)
52
52
  ```
53
53
 
54
54
  The `from_file` argument accepts a string or a [`pathlib.Path`][pathlib].
@@ -63,10 +63,11 @@ clarity.
63
63
 
64
64
  Example `~/.config/myprog-flags.conf`:
65
65
  ```
66
- --verbose
67
-
68
66
  # Always run with foo set to 123
69
67
  --foo 123
68
+
69
+ # Default to verbose output
70
+ --verbose
70
71
  ```
71
72
 
72
73
  ## Customizing the Help Message
@@ -0,0 +1,2 @@
1
+ from argparse import * # type: ignore
2
+ from .argparse import ArgumentParser # type: ignore
@@ -15,7 +15,7 @@ PLACEHOLDER = '#FROM_FILE_PATH#'
15
15
 
16
16
 
17
17
  # Get program name. This function is copied (but very modified) from argparse 3.14.0
18
- def _prog_name():
18
+ def _prog_name() -> str:
19
19
  try:
20
20
  modspec = sys.modules['__main__'].__spec__
21
21
  except (KeyError, AttributeError):
@@ -28,15 +28,16 @@ def _prog_name():
28
28
 
29
29
  return name[:-9] if name.endswith('.__main__') else name
30
30
 
31
+
31
32
  class ArgumentParser(argparse.ArgumentParser):
32
33
  _top = True
33
34
 
34
35
  def __init__(self, *args, **kwargs):
35
36
  self._argv = []
36
37
 
37
- # Only set up "from file" stuff once, for the top-level
38
- if ArgumentParser._top:
39
- ArgumentParser._top = False
38
+ # Only set up "from file" stuff once, for the top-level/main ArgumentParser()
39
+ if __class__._top:
40
+ __class__._top = False
40
41
 
41
42
  # from_file = 'path-to/file': Use this as "from file" name/path. If
42
43
  # relative then wrt platform specific user config dir.
@@ -78,7 +79,7 @@ class ArgumentParser(argparse.ArgumentParser):
78
79
 
79
80
  self.from_file_path = from_file_path
80
81
 
81
- return super().__init__(*args, **kwargs)
82
+ super().__init__(*args, **kwargs)
82
83
 
83
84
  def parse_args(self, args=None, namespace=None): # type: ignore[override]
84
85
  if args is None and self._argv:
@@ -88,8 +89,3 @@ class ArgumentParser(argparse.ArgumentParser):
88
89
  self._argv.clear()
89
90
 
90
91
  return super().parse_args(args, namespace)
91
-
92
-
93
- def __getattr__(name: str):
94
- "Proxy all other attributes from argparse module."
95
- return getattr(argparse, name)
File without changes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: argparse-from-file
3
- Version: 1.3
3
+ Version: 1.4
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
@@ -57,11 +57,11 @@ which is the only addition to the standard
57
57
  [`ArgumentParser()`][argparser] API:
58
58
 
59
59
  ```python
60
- # Use a specific file path
61
- parser = argparse.ArgumentParser(from_file='/path/to/my/config', ..)
60
+ # Use a specific () file path
61
+ parser = argparse.ArgumentParser(from_file='/path/to/myprog.conf', ..)
62
62
 
63
63
  # Use a file relative to the user's config directory
64
- parser = argparse.ArgumentParser(from_file='my-app.conf', ..)
64
+ parser = argparse.ArgumentParser(from_file='myprog.conf', ..)
65
65
  ```
66
66
 
67
67
  The `from_file` argument accepts a string or a [`pathlib.Path`][pathlib].
@@ -76,10 +76,11 @@ clarity.
76
76
 
77
77
  Example `~/.config/myprog-flags.conf`:
78
78
  ```
79
- --verbose
80
-
81
79
  # Always run with foo set to 123
82
80
  --foo 123
81
+
82
+ # Default to verbose output
83
+ --verbose
83
84
  ```
84
85
 
85
86
  ## Customizing the Help Message
@@ -1,8 +1,11 @@
1
1
  .gitignore
2
2
  Makefile
3
3
  README.md
4
- argparse_from_file.py
5
4
  pyproject.toml
5
+ test.py
6
+ argparse_from_file/__init__.py
7
+ argparse_from_file/argparse.py
8
+ argparse_from_file/py.typed
6
9
  argparse_from_file.egg-info/PKG-INFO
7
10
  argparse_from_file.egg-info/SOURCES.txt
8
11
  argparse_from_file.egg-info/dependency_links.txt
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/python
2
+ import argparse_from_file as argparse
3
+
4
+ opt = argparse.ArgumentParser()
5
+ opt.add_argument('-b', '--bool', action='store_true', help='sample bool option')
6
+ opt.add_argument('-s', '--str', help='sample str option')
7
+ print(opt.parse_args())
8
+
9
+ # Ensure external argparse constants are accessible
10
+ print(argparse.SUPPRESS)