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

Respect --cache-dir and other flags when auditing project directories #300

Merged
merged 7 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ jobs:
with:
python-version: "3.7"

- name: setup
run: make
- run: python -m pip install .

- name: check-readme
run: |
Expand All @@ -54,5 +53,5 @@ jobs:
< README.md | sed '1d;$d' \
) \
<( \
make run ARGS="--help" \
python -m pip_audit --help \
)
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ All versions prior to 0.0.9 are untracked.
can fully verify hashes
([#298](https://github.com/trailofbits/pip-audit/pull/298))

### Fixed

* CLI/Dependency sources: `--cache-dir=...` and other flags that affect
dependency resolver behavior now work correctly when auditing a
`pyproject.toml` dependency source
([#300](https://github.com/trailofbits/pip-audit/pull/300))

## [2.3.2] - 2022-05-14

### Changed
Expand Down
21 changes: 8 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,18 @@ else
COV_ARGS := --fail-under 100
endif

env/pyvenv.cfg: pyproject.toml
# Create our Python 3 virtual environment
[[ -d env ]] || python3 -m venv env
./env/bin/python -m pip install --upgrade pip
./env/bin/python -m pip install -e .[dev]


.PHONY: dev
dev: env/pyvenv.cfg

.PHONY: all
all:
@echo "Run my targets individually!"

.PHONY: run
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's happening here? I see make run is getting removed.

run: env/pyvenv.cfg
@. env/bin/activate && pip-audit $(ARGS)
.PHONY: dev
dev: env/pyvenv.cfg

env/pyvenv.cfg: pyproject.toml
# Create our Python 3 virtual environment
python3 -m venv env
./env/bin/python -m pip install --upgrade pip
./env/bin/python -m pip install -e .[dev]

.PHONY: lint
lint: env/pyvenv.cfg
Expand Down
14 changes: 11 additions & 3 deletions pip_audit/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,13 @@ def _parse_args(parser: argparse.ArgumentParser) -> argparse.Namespace:
return parser.parse_args()


def _dep_source_from_project_path(project_path: Path, state: AuditState) -> DependencySource:
def _dep_source_from_project_path(
project_path: Path, resolver: ResolveLibResolver, state: AuditState
) -> DependencySource:
# Check for a `pyproject.toml`
pyproject_path = project_path / "pyproject.toml"
if pyproject_path.is_file():
return PyProjectSource(pyproject_path, ResolveLibResolver(), state)
return PyProjectSource(pyproject_path, resolver, state)

# TODO: Checks for setup.py and other project files will go here.

Expand Down Expand Up @@ -390,7 +392,13 @@ def audit() -> None:
# once PEP 660 is more widely supported: https://www.python.org/dev/peps/pep-0660/

# Determine which kind of project file exists in the project path
source = _dep_source_from_project_path(args.project_path, state)
source = _dep_source_from_project_path(
args.project_path,
ResolveLibResolver(
index_urls, args.timeout, args.cache_dir, args.skip_editable, state
),
state,
)
else:
source = PipSource(
local=args.local, paths=args.paths, skip_editable=args.skip_editable, state=state
Expand Down