Skip to content

Commit

Permalink
feat: Add uv as package manager (#1)
Browse files Browse the repository at this point in the history
* style: Reformat README

* refactor: Remove unused import

* refactor: Fix linter warnings

* feat: Add uv as package manager

* ci: Change workflow trigger to avoid duplicate runs
  • Loading branch information
LarsV123 authored Oct 18, 2024
1 parent 2178afa commit 6cd8e83
Show file tree
Hide file tree
Showing 7 changed files with 315 additions and 24 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build

on:
push:
branches: [main]
pull_request:
types: [opened, reopened, synchronize]

jobs:
python:
name: Build & check Python
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "0.4.20"
enable-cache: true

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: ".python-version"

- name: Install the project
run: uv sync --all-extras --dev

- name: Run Ruff
run: uv run ruff check --output-format=github .
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
45 changes: 36 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,57 @@
# nva-aws-cli-tools
Python scripts using aws-cli

# Prerequisites
Python scripts using aws-cli

## Prerequisites

* python 3.2 or newer
* pip3 install boto3
* aws credentials available

# Log in to get AWS credentials
## Setup with uv (experimental)

Follow manual here:
https://gitlab.sikt.no/platon/aws-cli-tools/-/tree/master/samlauth
This section describes how to use `uv`, a new package manager for Python.
Following this guide will set up an isolated virtual environment with the Python version specified in `.python-version`.
Ignore the section if you prefer to manage dependencies in some other way.

To use `uv`, follow the installation guide at [astral.sh/uv](https://docs.astral.sh/uv/getting-started/installation/).

```bash
# Install Python
uv python install

# Scripts
# Install dependencies
uv sync

## list_old_function_versions.py
# Example: Add or remove dependencies from the project
uv add boto3 click rich
uv remove rich click

# Run a script using the managed virtual environment
uv run roles.py help
```

### Log in to get AWS credentials

Follow manual here:
<https://gitlab.sikt.no/platon/aws-cli-tools/-/tree/master/samlauth>

## Scripts

### list_old_function_versions.py

```bash
> python3 list_old_function_versions.py -h
> usage: list_old_function_versions.py [-h] [-d]

options:
-h, --help show this help message and exit
-d, --delete delete old versions
```
## roles.py
```

### roles.py

```bash
python3 roles.py help

Please, specify one of the following actions:
Expand Down
3 changes: 2 additions & 1 deletion list_old_function_versions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import boto3, argparse
import boto3
import argparse

def clean_old_lambda_versions(client, delete):
functions_paginator = client.get_paginator('list_functions')
Expand Down
18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[project]
name = "nva-aws-cli-tools"
version = "0.1.0"
description = "Python scripts using aws-cli"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
"boto3>=1.35.36",
"click>=8.1.7",
"rich>=13.9.2",
"tabulate>=0.9.0",
"tqdm>=4.66.5",
]

[tool.uv]
dev-dependencies = [
"ruff>=0.6.9",
]
20 changes: 6 additions & 14 deletions roles.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import boto3
from boto3.dynamodb.conditions import Attr
from boto3.dynamodb.types import TypeDeserializer, TypeSerializer
import sys
import json
Expand Down Expand Up @@ -116,19 +115,12 @@ def write_roles_to_db(roles, key):
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table(table_name)

response = table.update_item(
Key={
'PrimaryKeyHashKey': key,
'PrimaryKeyRangeKey': key
},
table.update_item(
Key={"PrimaryKeyHashKey": key, "PrimaryKeyRangeKey": key},
UpdateExpression="set #rl = :r",
ExpressionAttributeNames={
"#rl": "roles"
},
ExpressionAttributeValues={
':r': roles
},
ReturnValues="UPDATED_NEW"
ExpressionAttributeNames={"#rl": "roles"},
ExpressionAttributeValues={":r": roles},
ReturnValues="UPDATED_NEW",
)

def lookup(value):
Expand Down Expand Up @@ -249,4 +241,4 @@ def help():
help()

else:
print("Invalid action. Please specify either 'read', 'write', 'lookup', or 'help'.")
print("Invalid action. Please specify either 'read', 'write', 'lookup', or 'help'.")
220 changes: 220 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6cd8e83

Please sign in to comment.