| Conditions | 6 |
| Total Lines | 63 |
| Code Lines | 45 |
| 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 | """ |
||
| 13 | def parse_arguments(): |
||
| 14 | """ |
||
| 15 | Parse and handle CLI arguments |
||
| 16 | """ |
||
| 17 | debris_default_topics = ['build', 'cache', 'coverage', 'pytest'] |
||
| 18 | debris_optional_topics = ['tox'] |
||
| 19 | ignore_default_items = ['.git', '.tox', '.venv'] |
||
| 20 | |||
| 21 | parser = argparse.ArgumentParser( |
||
| 22 | description='Remove byte-compiled files for a package or project.', |
||
| 23 | ) |
||
| 24 | |||
| 25 | if sys.version_info < (3, 8): |
||
| 26 | parser.register('action', 'extend', compat.ExtendAction) |
||
| 27 | |||
| 28 | parser.add_argument('--version', action='version', version=__version__) |
||
| 29 | parser.add_argument('-V', metavar='VERSION', dest='version', |
||
| 30 | help='specify Python version to clean') |
||
| 31 | parser.add_argument('-p', '--package', metavar='PACKAGE', |
||
| 32 | action='append', default=[], |
||
| 33 | help='Debian package to byte-compile ' |
||
| 34 | '(may be specified multiple times)') |
||
| 35 | parser.add_argument('directory', nargs='*', |
||
| 36 | help='directory tree to traverse for byte-code') |
||
| 37 | parser.add_argument('-i', '--ignore', metavar='DIRECTORY', action='extend', |
||
| 38 | nargs='+', default=ignore_default_items, |
||
| 39 | help='directory that should be ignored ' |
||
| 40 | '(may be specified multiple times; ' |
||
| 41 | 'default: %s)' % ' '.join(ignore_default_items)) |
||
| 42 | parser.add_argument('-d', '--debris', metavar='TOPIC', action='extend', |
||
| 43 | nargs='*', default=argparse.SUPPRESS, |
||
| 44 | choices=debris_default_topics + debris_optional_topics, |
||
| 45 | help='remove leftovers from popular Python development ' |
||
| 46 | 'tools (may be specified multiple times; ' |
||
| 47 | 'default: %s)' % ' '.join(debris_default_topics)) |
||
| 48 | parser.add_argument('--legacy', action='store_true', |
||
| 49 | help='use legacy Debian implementation (autodetect)') |
||
| 50 | parser.add_argument('-n', '--dry-run', action='store_true', |
||
| 51 | help='show what would be done') |
||
| 52 | |||
| 53 | verbosity = parser.add_mutually_exclusive_group() |
||
| 54 | verbosity.add_argument('-q', '--quiet', action='store_true', |
||
| 55 | help='be quiet') |
||
| 56 | verbosity.add_argument('-v', '--verbose', action='store_true', |
||
| 57 | help='be more verbose') |
||
| 58 | |||
| 59 | args = parser.parse_args() |
||
| 60 | init_logging(args) |
||
| 61 | |||
| 62 | if not (args.package or args.directory): |
||
| 63 | parser.error('A directory (or files) or a list of packages ' |
||
| 64 | 'must be specified.') |
||
| 65 | |||
| 66 | if 'debris' in args: |
||
| 67 | if args.debris == []: |
||
| 68 | args.debris = debris_default_topics |
||
| 69 | log.debug("Debris requested to clean up for: %s", ' '.join(args.debris)) |
||
| 70 | else: |
||
| 71 | args.debris = [] |
||
| 72 | |||
| 73 | log.debug("Ignored directories: %s", ' '.join(args.ignore)) |
||
| 74 | |||
| 75 | return args |
||
| 76 | |||
| 120 |