Conditions | 7 |
Total Lines | 110 |
Code Lines | 82 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | # SPDX-FileCopyrightText: 2019 Peter Bittner <[email protected]> |
||
18 | def parse_arguments(): |
||
19 | """ |
||
20 | Parse and handle CLI arguments. |
||
21 | """ |
||
22 | debris_default_topics = ['cache', 'coverage', 'package', 'pytest', 'ruff'] |
||
23 | debris_optional_topics = ['jupyter', 'mypy', 'tox'] |
||
24 | debris_choices = ['all', *debris_default_topics, *debris_optional_topics] |
||
25 | ignore_default_items = [ |
||
26 | '.git', |
||
27 | '.hg', |
||
28 | '.svn', |
||
29 | '.tox', |
||
30 | '.venv', |
||
31 | 'node_modules', |
||
32 | 'venv', |
||
33 | ] |
||
34 | |||
35 | parser = argparse.ArgumentParser( |
||
36 | description=( |
||
37 | 'Remove bytecode files, cache directories, build and test artifacts ' |
||
38 | 'and other debris in your Python project or elsewhere.' |
||
39 | ), |
||
40 | epilog='Made with ♥ by Painless Software, 🄯 Peter Bittner.', |
||
41 | ) |
||
42 | |||
43 | if sys.version_info < (3, 8): # pragma: no-cover-gt-py37 |
||
44 | parser.register('action', 'extend', compat.ExtendAction) |
||
45 | |||
46 | parser.add_argument('--version', action='version', version=__version__) |
||
47 | parser.add_argument( |
||
48 | 'directory', |
||
49 | nargs='+', |
||
50 | help='directory tree to traverse for bytecode and debris', |
||
51 | ) |
||
52 | parser.add_argument( |
||
53 | '-i', |
||
54 | '--ignore', |
||
55 | metavar='DIRECTORY', |
||
56 | action='extend', |
||
57 | nargs='+', |
||
58 | default=ignore_default_items, |
||
59 | help='directory that should be ignored (may be specified multiple times;' |
||
60 | ' default: %s)' % ' '.join(ignore_default_items), |
||
61 | ) |
||
62 | parser.add_argument( |
||
63 | '-d', |
||
64 | '--debris', |
||
65 | metavar='TOPIC', |
||
66 | action='extend', |
||
67 | nargs='*', |
||
68 | default=argparse.SUPPRESS, |
||
69 | choices=debris_choices, |
||
70 | help='remove leftovers from popular Python development tools' |
||
71 | ' (may be specified multiple times; optional: all %s; default: %s)' |
||
72 | % ( |
||
73 | ' '.join(debris_optional_topics), |
||
74 | ' '.join(debris_default_topics), |
||
75 | ), |
||
76 | ) |
||
77 | parser.add_argument( |
||
78 | '-e', |
||
79 | '--erase', |
||
80 | metavar='PATTERN', |
||
81 | action='extend', |
||
82 | nargs='+', |
||
83 | default=[], |
||
84 | help='delete files or folders matching a globbing pattern (may be specified' |
||
85 | ' multiple times); this will be interactive unless --yes is used.', |
||
86 | ) |
||
87 | parser.add_argument( |
||
88 | '-n', |
||
89 | '--dry-run', |
||
90 | action='store_true', |
||
91 | help='show what would be done', |
||
92 | ) |
||
93 | |||
94 | verbosity = parser.add_mutually_exclusive_group() |
||
95 | verbosity.add_argument('-q', '--quiet', action='store_true', help='be quiet') |
||
96 | verbosity.add_argument( |
||
97 | '-v', |
||
98 | '--verbose', |
||
99 | action='store_true', |
||
100 | help='be more verbose', |
||
101 | ) |
||
102 | |||
103 | parser.add_argument( |
||
104 | '-y', |
||
105 | '--yes', |
||
106 | action='store_true', |
||
107 | help='assume yes as answer for interactive questions', |
||
108 | ) |
||
109 | |||
110 | args = parser.parse_args() |
||
111 | init_logging(args) |
||
112 | |||
113 | if args.yes and not args.erase: |
||
114 | parser.error('Specifying --yes only makes sense with --erase.') |
||
115 | |||
116 | if 'debris' in args: |
||
117 | if 'all' in args.debris: |
||
118 | args.debris = debris_default_topics + debris_optional_topics |
||
119 | elif not args.debris: |
||
120 | args.debris = debris_default_topics |
||
121 | log.debug('Debris topics to scan for: %s', ' '.join(args.debris)) |
||
122 | else: |
||
123 | args.debris = [] |
||
124 | |||
125 | log.debug('Ignored directories: %s', ' '.join(args.ignore)) |
||
126 | |||
127 | return args |
||
128 | |||
151 |