File tree 5 files changed +55
-0
lines changed
5 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 1
1
try :
2
2
import importlib .metadata
3
+
3
4
__version__ = importlib .metadata .version (__package__ or __name__ )
4
5
except ImportError :
5
6
import importlib_metadata
7
+
6
8
__version__ = importlib_metadata .version (__package__ or __name__ )
Original file line number Diff line number Diff line change @@ -194,6 +194,12 @@ def parse_arguments(args: Optional[List[str]]) -> Args:
194
194
action = 'store_true' ,
195
195
default = False ,
196
196
)
197
+ parser .add_argument (
198
+ '--version' ,
199
+ help = 'Shows deadcode version' ,
200
+ action = 'store_true' ,
201
+ default = False ,
202
+ )
197
203
198
204
parsed_args = parser .parse_args (args ).__dict__
199
205
Original file line number Diff line number Diff line change 1
1
from typing import List , Optional
2
2
3
+ from deadcode import __version__
3
4
from deadcode .actions .find_python_filenames import find_python_filenames
4
5
from deadcode .actions .find_unused_names import find_unused_names
5
6
from deadcode .actions .fix_or_show_unused_code import fix_or_show_unused_code
12
13
def main (
13
14
command_line_args : Optional [List [str ]] = None ,
14
15
) -> Optional [str ]:
16
+
17
+ if command_line_args and '--version' in command_line_args :
18
+ return __version__
19
+
15
20
args = parse_arguments (command_line_args )
16
21
17
22
filenames = find_python_filenames (args = args )
Original file line number Diff line number Diff line change 14
14
class Args :
15
15
fix : bool = False
16
16
verbose : bool = False
17
+ version : bool = False
17
18
dry : bool = False
18
19
only : Iterable [Pathname ] = ()
19
20
paths : Iterable [Pathname ] = ()
Original file line number Diff line number Diff line change
1
+ from deadcode import __version__
2
+ from deadcode .cli import main
3
+ from deadcode .utils .base_test_case import BaseTestCase
4
+
5
+
6
+ class TestVersionCliOption (BaseTestCase ):
7
+ def test_show_version (self ):
8
+ self .files = {
9
+ 'foo.py' : b"""
10
+ class UnusedClass:
11
+ pass
12
+
13
+ print("Dont change this file")""" ,
14
+ 'bar.py' : b"""
15
+ def unused_function():
16
+ pass
17
+
18
+ print("Dont change this file")""" ,
19
+ }
20
+
21
+ result = main ('--version' .split ())
22
+
23
+ self .assertEqual (result , __version__ )
24
+
25
+ def test_show_version_when_path_provided (self ):
26
+ self .files = {
27
+ 'foo.py' : b"""
28
+ class UnusedClass:
29
+ pass
30
+
31
+ print("Dont change this file")""" ,
32
+ 'bar.py' : b"""
33
+ def unused_function():
34
+ pass
35
+
36
+ print("Dont change this file")""" ,
37
+ }
38
+
39
+ result = main ('. --version' .split ())
40
+
41
+ self .assertEqual (result , __version__ )
You can’t perform that action at this time.
0 commit comments