Skip to content

Commit

Permalink
subscope lists + dry run + exit code #minor (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
nmichlo authored Jul 4, 2024
1 parent f137ea3 commit 8f98fe6
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 32 deletions.
1 change: 0 additions & 1 deletion .github/workflows/python-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pip'

- id: cache-pre-commit-envs
uses: actions/cache@v3
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repos:

# this repo
- repo: https://github.com/nmichlo/pydependence
rev: v0.4.1
rev: 77707323e574534761ca66122b00d67c330061f9
hooks:
- id: pydependence
args: ["pyproject.toml"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Add a pre-commit entry pointing to your pyproject.toml file or configuration fil

```yaml
- repo: https://github.com/nmichlo/pydependence
rev: v0.4.2
rev: v0.5.0
hooks:
- id: pydependence
args: ["pyproject.toml"]
Expand Down
39 changes: 36 additions & 3 deletions pydependence/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@

class PyDepsCliArgsProto(typing.Protocol):
config: str
dry_run: bool
exit_zero: bool


def _parse_args() -> "PyDepsCliArgsProto":
"""
Make argument parser, that has a `--file` argument which is required, then
returns the parsed arguments.
Make argument parser for:
`config`, required
`--dry-run`, optional
`--exit-zero`, optional # always return success exit code even if files changed
Then parse the arguments and return them.
"""
parser = argparse.ArgumentParser(
description="PyDependence: A tool for scanning and resolving python dependencies across files."
Expand All @@ -56,6 +62,16 @@ def _parse_args() -> "PyDepsCliArgsProto":
type=str,
help="The python file to analyse for dependencies.",
)
parser.add_argument(
"--dry-run",
action="store_true",
help="Run the script without making any changes.",
)
parser.add_argument(
"--exit-zero",
action="store_true",
help="Always return a success exit code, even if files changed.",
)
return parser.parse_args()


Expand All @@ -65,13 +81,30 @@ def _cli():

# run
try:
pydeps(config_path=args.config)
changed = pydeps(
config_path=args.config,
dry_run=args.dry_run,
)
except NoConfiguredRequirementMappingError as e:
LOGGER.critical(
f"[pydependence] no configured requirement mapping found, either specify all missing version mappings or disable strict mode:\n{e}"
)
exit(1)

# check if files changed
if changed:
LOGGER.info("[pydependence] files changed.")
if args.exit_zero:
LOGGER.info(
"[pydependence] exit-zero enabled, returning success exit code."
)
exit(0)
else:
exit(1)
else:
LOGGER.info("[pydependence] files unchanged.")
exit(0)


if __name__ == "__main__":
# set default log level to info
Expand Down
Loading

0 comments on commit 8f98fe6

Please sign in to comment.