Skip to content

Commit

Permalink
Add opt '--outputs'
Browse files Browse the repository at this point in the history
  • Loading branch information
si-23 committed Oct 29, 2024
1 parent 3ad379f commit edf2d29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
8 changes: 7 additions & 1 deletion py_import_cycles/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ def _parse_arguments() -> argparse.Namespace:
action="store_true",
help="show cycles if some are found",
)
parser.add_argument(
"--outputs",
help=(
"path to outputs folder." " If no set $HOME/.local/py-import-cycles/outputs/ is used"
),
)
parser.add_argument(
"--graph",
action="store_true",
Expand Down Expand Up @@ -85,7 +91,7 @@ def main() -> int:

packages = [Path(p) for p in args.packages]

outputs_filepaths = get_outputs_filepaths(project_path)
outputs_filepaths = get_outputs_filepaths(Path(args.outputs) if args.outputs else None)

setup_logging(outputs_filepaths.log, args.debug)

Expand Down
16 changes: 7 additions & 9 deletions py_import_cycles/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ class OutputsFilepaths(NamedTuple):
graph: Path


def get_outputs_filepaths(project_path: Path) -> OutputsFilepaths:
target_dir = Path.home() / Path(".local", "py_import_cycles", "outputs")
target_dir.mkdir(parents=True, exist_ok=True)

filename_parts = list(project_path.parts[1:]) + [str(int(time.time()))]
filename = Path("-".join(filename_parts).replace(".", "-"))

def get_outputs_filepaths(outputs_folder: Path | None) -> OutputsFilepaths:
if not outputs_folder:
outputs_folder = Path.home() / Path(".local", "py-import-cycles", "outputs")
outputs_folder.mkdir(parents=True, exist_ok=True)
file_name = str(int(time.time()))
return OutputsFilepaths(
log=target_dir / filename.with_suffix(".log"),
graph=target_dir / filename.with_suffix(".gv"),
log=(outputs_folder / file_name).with_suffix(".log"),
graph=(outputs_folder / file_name).with_suffix(".gv"),
)

0 comments on commit edf2d29

Please sign in to comment.