|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | from typing import Iterable |
| 4 | +import argparse |
| 5 | +from pathlib import Path |
4 | 6 |
|
5 | 7 | import nox |
6 | 8 | from nox import Session |
@@ -62,11 +64,34 @@ def type_check(session: Session) -> None: |
62 | 64 |
|
63 | 65 |
|
64 | 66 | @nox.session(name="import-lint", python=False) |
65 | | -@nox.parametrize('own_config_file', ['no', 'yes']) |
66 | | -def import_lint(session: Session, own_config_file: str) -> None: |
| 67 | +def import_lint(session: Session) -> None: |
67 | 68 | """Runs the import linter on the project""" |
68 | | - if own_config_file == 'yes': |
69 | | - path = input("Config file: ") |
| 69 | + |
| 70 | + usage = "nox -s import-lint -- [options]" |
| 71 | + description = "Runs the import linter on the project" |
| 72 | + parser = argparse.ArgumentParser( |
| 73 | + description=description, |
| 74 | + usage=usage |
| 75 | + ) |
| 76 | + parser.add_argument( |
| 77 | + "-c", |
| 78 | + "--config", |
| 79 | + type=str, |
| 80 | + help="path to the configuration file for the importlinter", |
| 81 | + metavar="TEXT" |
| 82 | + ) |
| 83 | + |
| 84 | + args: argparse.Namespace = parser.parse_args(args=session.posargs) |
| 85 | + file: str = args.config |
| 86 | + print(f"-{file}-") |
| 87 | + if file is None: |
| 88 | + path: path = getattr(PROJECT_CONFIG, "importlinter", Path(".importlinter")) |
| 89 | + else: |
| 90 | + path: path = Path(file) |
| 91 | + if path.exists(): |
| 92 | + _import_lint(session=session, path=path) |
70 | 93 | else: |
71 | | - path = str(PROJECT_CONFIG.importlinter) |
72 | | - _import_lint(session, path) |
| 94 | + session.error( |
| 95 | + "Please make sure you have a configuration file for the importlinter" |
| 96 | + ) |
| 97 | + |
0 commit comments