Skip to content

Commit

Permalink
Use uv
Browse files Browse the repository at this point in the history
  • Loading branch information
vemel committed Sep 18, 2024
1 parent 5a48660 commit 4f5312c
Show file tree
Hide file tree
Showing 16 changed files with 218 additions and 766 deletions.
34 changes: 5 additions & 29 deletions .github/workflows/on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,15 @@ jobs:
- "3.10"
- "3.11"
- "3.12"
include:
- version: "3.12"
check-formatting: "true"
check-typing: "true"
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "${{ matrix.version }}"
- name: Install poetry
run: pip install poetry
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "${{ matrix.version }}"
cache: "poetry"
- name: Set up uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Install dependencies
run: |
poetry install -n
- name: Code style
if: ${{ matrix.check-formatting }}
run: |
poetry run ruff format --check
- name: Lint
if: ${{ matrix.check-formatting }}
run: |
poetry run ruff check
- name: Typing
if: ${{ matrix.check-typing }}
run: |
poetry run pyright awscliv2
- name: Test
run: |
pip install pytest
poetry run pytest
run: uv sync --dev
- name: Run pre-commit
run: uvx pre-commit run --all-files
10 changes: 4 additions & 6 deletions .github/workflows/on_push_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "poetry"
- name: Set up uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Install dependencies
run: |
poetry install -n
run: uv sync --dev
- name: Build coverage report
run: |
poetry run pytest --cov awscliv2 --cov-report=xml --junitxml=junit.xml
uvx --with pytest-cov pytest --cov awscliv2 --cov-report=xml --junitxml=junit.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
Expand Down
17 changes: 7 additions & 10 deletions .github/workflows/on_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
- uses: actions/checkout@v4
with:
ref: main
- name: Install poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Set up uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Get version
id: version
uses: actions/github-script@v7
Expand All @@ -33,17 +33,14 @@ jobs:
}
return context.ref.split('/').pop()
- name: Install dependencies
run: |
poetry install -n
poetry run pip install -U twine wheel
run: uv sync --extra check --dev
- name: Bump version
env:
VERSION: ${{ steps.version.outputs.result }}
run: |
echo "Bumping version to ${VERSION}"
poetry version ${VERSION}
rm -rf *.egg-info || true
poetry install -n
sed -i 's/^version = ".*"$/version = "'$VERSION'"/' pyproject.toml
uv pip install .
- name: Setup git
run: |
git config --global user.email "[email protected]"
Expand All @@ -60,5 +57,5 @@ jobs:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
poetry build
poetry run twine upload --non-interactive dist/*
uvx --from build pyproject-build --installer uv
uvx twine upload --non-interactive dist/*
14 changes: 7 additions & 7 deletions .github/workflows/update_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ jobs:
- uses: actions/checkout@v4
with:
ref: docs
- name: Install poetry
run: pipx install poetry
- name: Set up Python
id: python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "poetry"
- name: Set up uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Setup git
run: |
git config --global user.email "[email protected]"
Expand All @@ -33,16 +32,17 @@ jobs:
git rebase main
- name: Install dependencies
run: |
poetry install -n
poetry run pip install -r requirements.mkdocs.txt
uv sync --dev
uv run pip install -r requirements.mkdocs.txt
- name: Build docs
run: |
poetry run handsdown --external `git config --get remote.origin.url` -o docsmd --cleanup --theme material --branch main
uv run pip install handsdown
uv run handsdown --external `git config --get remote.origin.url` -o docsmd --cleanup --theme material --branch main
- name: Build html docs
run: |
rm -rf docs
echo `ls -lh`
poetry run mkdocs build
uv run mkdocs build
- name: Commit docs
run: |
git add docs docsmd
Expand Down
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
repos:
- repo: local
hooks:
- id: lint
name: lint
language: system
pass_filenames: false
entry: uvx ruff check --fix
- id: format
name: format
language: system
pass_filenames: false
entry: uvx ruff format
- id: pyright
name: pyright
language: system
pass_filenames: false
entry: uvx pyright
- id: pytest
name: pytest
language: system
pass_filenames: false
entry: uvx pytest
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include awscliv2/py.typed
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ aws_api.assume_role(

## Development

- Install [poetry](https://python-poetry.org/)
- Run `poetry install`
- Use `black` formatter in your IDE
- Install [uv](https://docs.astral.sh/uv/): `curl -LsSf https://astral.sh/uv/install.sh | sh`
- Install dependencies: `uv sync --all-extras --dev`
- Run manual pre-commit: `./scripts/before_commit.sh`

## How to help

Expand Down
5 changes: 2 additions & 3 deletions awscliv2/installers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
AWS CLI v2 installers.
"""

import os
import platform
import shutil
from io import StringIO
Expand Down Expand Up @@ -92,8 +91,8 @@ def install_linux(url: str) -> None:
zip_obj.extractall(temp_dir_path.as_posix())

installer_path = temp_dir_path / "aws" / "install"
os.chmod(installer_path, 0o744)
os.chmod(temp_dir_path / "aws" / "dist" / "aws", 0o744)
installer_path.chmod(0o744)
(temp_dir_path / "aws" / "dist" / "aws").chmod(0o744)
logger.info(f"Installing {installer_path.as_posix()} to {install_path.as_posix()}")
output = StringIO()
process = InteractiveProcess(
Expand Down
9 changes: 6 additions & 3 deletions awscliv2/interactive_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def writeall(self, process: Popen, stdout: TextIO) -> None: # type: ignore
process -- Popen process
stdout -- Stream to write
"""
assert process.stdout
if not process.stdout:
raise SubprocessError("No stdout stream")
output = ""
while True:
if self.finished:
Expand All @@ -67,7 +68,8 @@ def writeall(self, process: Popen, stdout: TextIO) -> None: # type: ignore

def _propagate_streams(self, process: Popen, inputs: Sequence[TInput]) -> bool: # type: ignore
has_input = False
assert process.stdin
if not process.stdin:
raise SubprocessError("No stdin stream")
for stream_input in inputs:
if isinstance(stream_input, socket.socket):
try:
Expand Down Expand Up @@ -100,7 +102,8 @@ def readall(self, process: Popen, inputs: Sequence[TInput]) -> None: # type: ig
process -- Popen process
inputs -- Streams to read
"""
assert process.stdin
if not process.stdin:
raise SubprocessError("No stdin stream")
while True:
if self.finished:
break
Expand Down
9 changes: 4 additions & 5 deletions awscliv2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def main(args: Sequence[str]) -> int:

if namespace.version:
version = get_version()
print(version)
sys.stdout.write(f"{version}\n")
cmd = " ".join(runner.get_awscli_v2_cmd())
print(f"AWS CLI v2 command: {cmd}")
sys.stdout.write(f"AWS CLI v2 command: {cmd}\n")
runner.print_version()
return 0

Expand All @@ -52,8 +52,7 @@ def main(args: Sequence[str]) -> int:
if not namespace.other:
raise AWSCLIError("No command provided")

exit_code = runner.run_awscli_v2_detached(namespace.other)
return exit_code
return runner.run_awscli_v2_detached(namespace.other)


def main_cli() -> None:
Expand All @@ -66,5 +65,5 @@ def main_cli() -> None:
message = str(e)
if message:
logger = get_logger()
logger.error(message)
logger.exception(message)
sys.exit(e.returncode)
Loading

0 comments on commit 4f5312c

Please sign in to comment.