Skip to content

Commit

Permalink
port to uv
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <[email protected]>
  • Loading branch information
wagoodman committed Feb 14, 2025
1 parent ef988c7 commit 761a9c7
Show file tree
Hide file tree
Showing 10 changed files with 1,419 additions and 1,736 deletions.
24 changes: 5 additions & 19 deletions .github/actions/bootstrap/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,16 @@ runs:
with:
go-version: ${{ inputs.go-version }}

- uses: actions/setup-python@v5
- name: Install uv
if: inputs.python == 'true'
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ inputs.python-version }}

- name: Install Poetry
if: inputs.python == 'true'
shell: bash
run: |
pipx install poetry==${{ inputs.poetry-version }}
enable-cache: true

- name: Cache Poetry cache
uses: actions/cache@v4
if: inputs.python == 'true'
with:
path: ~/.cache/pypoetry
key: poetry-cache-${{ runner.os }}-${{ inputs.python-version }}-${{ inputs.poetry-version }}

- name: Cache Packages
uses: actions/cache@v4
- uses: actions/setup-python@v5
if: inputs.python == 'true'
with:
path: ~/.local
key: poetry-local-${{ runner.os }}-${{ inputs.python-version }}-${{ hashFiles('**/poetry.lock') }}-${{ hashFiles('.github/workflows/*.yml') }}
python-version: ${{ inputs.python-version }}

- name: Bootstrap python dependencies
if: inputs.python == 'true'
Expand Down
26 changes: 5 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ all: static-analysis test ## Run all checks (linting, license checks, unit, and

.PHONY: static-analysis ## Run all static analysis checks (linting and license checks)
static-analysis: check-go-mod-tidy lint check-licenses
cd manager && poetry run make static-analysis
cd manager && uv run make static-analysis

.PHONY: test
test: unit cli ## Run all tests
cd manager && poetry run make test
cd manager && uv run make test


## Bootstrapping targets #################################
Expand Down Expand Up @@ -172,19 +172,19 @@ unit: $(TEMP_DIR) ## Run Go unit tests (with coverage)
.PHONY: unit-python
unit-python: ## Run Python unit tests (with coverage)
$(call title,Running Python unit tests)
cd manager && poetry run make unit
cd manager && make unit

.PHONY: db-acceptance
db-acceptance: ## Run acceptance tests
$(call title,"Running DB acceptance tests (schema=$(schema))")
poetry run ./test/db/acceptance.sh $(schema)
uv run ./test/db/acceptance.sh $(schema)

.PHONY: cli
cli: cli-go cli-python ## Run all CLI tests

.PHONY: cli-python
cli-python: ## Run python CLI tests
cd manager && poetry run make cli
cd manager && uv run make cli

.PHONY: cli-go
cli-go: $(SNAPSHOT_DIR) ## Run go CLI tests
Expand All @@ -194,22 +194,6 @@ cli-go: $(SNAPSHOT_DIR) ## Run go CLI tests
go test -count=1 -timeout=15m -v ./test/cli


## Test-fixture-related targets #################################

.PHONY: update-test-fixtures
update-test-fixtures:
docker run \
--pull always \
--rm \
-it \
anchore/grype:latest \
-q \
-o json \
centos:8.2.2004 > publish/test-fixtures/centos-8.2.2004.json
dos2unix publish/test-fixtures/centos-8.2.2004.json
cd test/acceptance && poetry install --with dev && poetry run python grype-ingest.py capture-test-fixtures


## Data management targets #################################

.PHONY: show-providers
Expand Down
30 changes: 12 additions & 18 deletions manager/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,49 @@ static-analysis: lint ## Run all static analyses
.PHONY: test
test: unit ## Run all tests

virtual-env-check:
@ if [ "${VIRTUAL_ENV}" = "" ]; then \
echo "$(ERROR)Not in a virtual environment. Try running with 'poetry run' or enter a 'poetry shell' session.$(RESET)"; \
exit 1; \
fi


## Bootstrapping targets #################################

.PHONY: bootstrap
bootstrap: ## Install all dependencies
$(call title,Bootstrapping dependencies)
poetry install --with dev
uv sync --all-extras --dev


## Static analysis targets #################################

.PHONY: lint
lint: virtual-env-check ## Show linting issues (ruff)
ruff check .
lint: ## Show linting issues (ruff)
uv run ruff check .

.PHONY: lint-fix
lint-fix: virtual-env-check ## Fix linting issues (ruff)
ruff check . --fix
lint-fix: ## Fix linting issues (ruff)
uv run ruff check . --fix


## Testing targets #################################

.PHONY: unit
unit: virtual-env-check ## Run unit tests
pytest --cov=grype_db_manager --cov-report=html -vv tests/unit/
unit: ## Run unit tests
uv run pytest --cov=grype_db_manager --cov-report=html -vv tests/unit/

.PHONY: cli
cli: virtual-env-check ## Run cli tests
cd tests/cli && make
cli: ## Run cli tests
cd tests/cli && uv run make


## DB Testing targets #################################

.PHONY: db-acceptance
db-acceptance: virtual-env-check ## Run DB acceptance tests
db-acceptance: ## Run DB acceptance tests
@ echo "Building and testing DB schema=$(schema_version)"
if [ -z "$(schema_version)" ]; then \
echo "schema_version is not set"; \
exit 1; \
fi

export DB_ID=$(shell grype-db-manager db build --schema-version $(schema_version))
grype-db-manager db validaate $(DB_ID)
export DB_ID=$(shell uv run grype-db-manager db build --schema-version $(schema_version))
uv run grype-db-manager db validaate $(DB_ID)


## Halp! #################################
Expand Down
2 changes: 1 addition & 1 deletion manager/src/grype_db_manager/db/listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def basename(self) -> str:

def age_in_days(self, now: datetime.datetime | None = None) -> int:
if not now:
now = datetime.datetime.now(tz=datetime.timezone.utc)
now = datetime.datetime.now(tz=datetime.UTC)
return (now - iso8601.parse_date(self.built)).days


Expand Down
2 changes: 1 addition & 1 deletion manager/src/grype_db_manager/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def age_from_basename(basename: str) -> int | None:


def _now() -> datetime.datetime:
return datetime.datetime.now(tz=datetime.timezone.utc)
return datetime.datetime.now(tz=datetime.UTC)


def hash_file(path: str) -> str:
Expand Down
4 changes: 2 additions & 2 deletions manager/src/grype_db_manager/grypedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def new_session(self) -> str:

session_dir = os.path.join(self.db_dir, db_uuid)
with open(os.path.join(session_dir, "timestamp"), "w") as f:
now = datetime.datetime.now(tz=datetime.timezone.utc)
now = datetime.datetime.now(tz=datetime.UTC)
f.write(now.isoformat())

return db_uuid
Expand Down Expand Up @@ -468,7 +468,7 @@ def db_metadata(build_dir: str) -> dict:


def parse_datetime(s: str) -> datetime.datetime:
return datetime.datetime.strptime(s, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=datetime.timezone.utc)
return datetime.datetime.strptime(s, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=datetime.UTC)


class GrypeDB:
Expand Down
10 changes: 2 additions & 8 deletions manager/tests/cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ BOLD := $(shell tput -T linux bold))
CYAN := $(shell tput -T linux setaf 6)
RESET := $(shell tput -T linux sgr0)

test: virtual-env-check ## Run CLI tests
pytest . -vv -o log_cli=true
test: ## Run CLI tests
uv run pytest . -vv -o log_cli=true

.PHONY: vunnel-oracle-data
vunnel-oracle-data: cli-test-data/vunnel/oracle
Expand All @@ -20,12 +20,6 @@ install-oracle-labels:
mkdir -p cli-test-data/yardstick/labels
cp -a ../../../data/vulnerability-match-labels/labels/docker.io+oraclelinux* ./cli-test-data/yardstick/labels/

virtual-env-check:
@ if [ "${VIRTUAL_ENV}" = "" ]; then \
echo "$(ERROR)Not in a virtual environment. Try running with 'poetry run' or enter a 'poetry shell' session.$(RESET)"; \
exit 1; \
fi

.PHONY: clean
clean: clean-data ## Clear all existing yardstick results and delete python environment

Expand Down
Loading

0 comments on commit 761a9c7

Please sign in to comment.