Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pyproject.toml #246

Merged
merged 16 commits into from
Mar 4, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions pip_audit/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,7 @@ def _parser() -> argparse.ArgumentParser:
help="audit the given requirements file; this option can be used multiple times",
)
dep_source_args.add_argument(
"-p",
"--pyproject",
type=argparse.FileType("r"),
help="audit the given `pyproject.toml` file",
"project_path", type=Path, nargs="?", help="audit a local Python project at the given path"
)
parser.add_argument(
"-f",
Expand Down Expand Up @@ -276,6 +273,15 @@ def _parse_args(parser: argparse.ArgumentParser) -> argparse.Namespace:
return parser.parse_args()


def _create_project_source(project_path: Path, state: AuditState) -> Optional[DependencySource]:
# Check for a `pyproject.toml`
pyproject_path = project_path.joinpath("pyproject.toml")
if pyproject_path.is_file():
return PyProjectSource(pyproject_path, ResolveLibResolver(), state)
else:
return None


def audit() -> None:
"""
The primary entrypoint for `pip-audit`.
Expand Down Expand Up @@ -317,13 +323,12 @@ def audit() -> None:
args.require_hashes,
state,
)
elif args.pyproject is not None:
pyproject_file = Path(args.pyproject.name)
source = PyProjectSource(
pyproject_file,
ResolveLibResolver(index_urls, args.timeout, args.cache_dir, state),
state,
)
elif args.project_path is not None:
# Determine which kind of project file exists in the project path
_source = _create_project_source(args.project_path, state)
if _source is None:
parser.error(f"couldn't find project file at path: {args.project_path}")
source = _source
woodruffw marked this conversation as resolved.
Show resolved Hide resolved
else:
source = PipSource(local=args.local, paths=args.paths, state=state)

Expand Down