Skip to content

Commit

Permalink
Migrate to uv
Browse files Browse the repository at this point in the history
  • Loading branch information
vemel committed Sep 3, 2024
1 parent ee323b9 commit a32e978
Show file tree
Hide file tree
Showing 10 changed files with 552 additions and 77 deletions.
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: uv run ruff check --fix
- id: format
name: format
language: system
pass_filenames: false
entry: uv run ruff format
- id: pyright
name: pyright
language: system
pass_filenames: false
entry: uv run pyright
- id: pytest
name: pytest
language: system
pass_filenames: false
entry: uv run pytest
4 changes: 3 additions & 1 deletion awscliv2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ def execute(self, args: Sequence[str]) -> str:
return_code = self.run_awscli_v2(args)
if return_code:
self.output.seek(0)
raise AWSCLIError(f"Command {shlex.join(args)} failed with code {return_code}: {self.output.read()}")
raise AWSCLIError(
f"Command {shlex.join(args)} failed with code {return_code}: {self.output.read()}"
)
self.output.seek(0)
result = self.output.read()
self.output = old_output
Expand Down
7 changes: 1 addition & 6 deletions awscliv2/cli_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@

import argparse
import contextlib
import sys
from importlib import metadata
from typing import Sequence

from awscliv2.constants import ENCODING, PACKAGE_NAME, PROG_NAME

if sys.version_info >= (3, 8):
from importlib import metadata # type: ignore
else:
import importlib_metadata as metadata # type: ignore


def get_version() -> str:
"""
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("Process stdout is not available")
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("Process stdin is not available")
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("Process stdin is not available")
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)
136 changes: 82 additions & 54 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
[tool.black]
line-length = 100
include = "(awscliv2|tests)/.*\\.pyi?$"
target-version = ["py37", "py38", "py39", "py310", "py311", "py312"]

[tool.isort]
profile = "black"
line_length = 100
known_first_party = ["awscliv2", "tests"]
src_paths = []

[tool.poetry]
[project]
name = "awscliv2"
version = "2.3.0"
requires-python = ">=3.8"
description = "Wrapper for AWS CLI v2"
authors = ["Vlad Emelianov <[email protected]>"]
license = "MIT"
authors = [{ name = "Vlad Emelianov", email = "[email protected]" }]
license = { file = "LICENSE" }
readme = "README.md"
homepage = "https://youtype.github.io/awscliv2/"
repository = "https://github.com/youtype/awscliv2"
documentation = "https://youtype.github.io/awscliv2/"
keywords = ["awscli", "awscliv2", "wrapper"]
classifiers = [
"Development Status :: 5 - Production/Stable",
Expand All @@ -40,35 +27,40 @@ classifiers = [
"Typing :: Typed",
"Topic :: Software Development :: Libraries :: Python Modules",
]
packages = [{ include = "awscliv2" }]
include = ["LICENSE", "awscliv2/py.typed"]
dependencies = ["importlib-metadata"]

[tool.poetry.scripts]
awscliv2 = 'awscliv2.main:main_cli'
awsv2 = 'awscliv2.main:main_cli'
[project.optional-dependencies]
build = ["setuptools"]

[tool.poetry.urls]
"Documentation" = "https://awscliv2.readthedocs.io/en/latest/"
"Source" = "https://github.com/youtype/awscliv2"
"Bug Tracker" = "https://github.com/youtype/awscliv2/issues"
[tool.uv]
dev-dependencies = [
"ruff",
"pyright",
"pytest",
"pytest-cov",
"pre-commit",
"types-setuptools",
]

[tool.poetry.dependencies]
python = "^3.7"
pip = "*"
importlib-metadata = { version = "*", python = "<3.8" }

[tool.poetry.group.dev.dependencies]
ruff = { version = "*", python = ">=3.10" }
pyright = { version = "*", python = ">=3.10" }
rope = { version = "*", python = ">=3.10" }
handsdown = { version = "*", python = ">=3.10" }
pytest = { version = "*", python = ">=3.10" }
pytest-cov = { version = "*", python = ">=3.10" }
types-setuptools = "*"
[project.scripts]
awscliv2 = 'awscliv2.main:main_cli'
awsv2 = 'awscliv2.main:main_cli'

[project.urls]
Homepage = "https://github.com/youtype/awscliv2"
Documentation = "https://youtype.github.io/awscliv2/"
Repository = "https://github.com/youtype/awscliv2"
Changelog = "https://github.com/youtype/awscliv2/releases"
Issues = "https://github.com/youtype/awscliv2/issues"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
requires = ['setuptools']
build-backend = 'setuptools.build_meta'

[tool.setuptools.packages.find]
where = ["."]
include = ["awscliv2", "awscliv2.*"]

[tool.coverage.report]
exclude_lines = [
Expand All @@ -91,7 +83,7 @@ reportMissingTypeArgument = "error"
reportIncompatibleMethodOverride = "error"
reportIncompatibleVariableOverride = "error"
reportUnknownParameterType = "error"
pythonVersion = "3.7"
pythonVersion = "3.8"

[tool.ruff]
exclude = [
Expand All @@ -109,22 +101,58 @@ exclude = [

line-length = 100
indent-width = 4
target-version = "py37"
target-version = "py38"

[tool.ruff.lint]
select = ["E4", "E7", "E9", "F", "B", "I", "N", "D", "C4", "C90", "RUF"]
select = [
"E", # pycodestyle
"W", # pycodestyle
"F", # Pyflakes
"B", # flake8-bugbear
"I", # isort
"N", # pep8-naming
"D", # pydocstyle
"C4", # flake8-comprehensions
"C90", # mccabe
"RUF", # Ruff-specific rules
"SIM", # flake8-simplify
"PYI", # flake8-pyi
"PT", # flake8-pytest-style
"T", # flake8-raise
"LOG", # flake8-logging
"Q", # flake8-quotes
"RSE", # flake8-raise
"RET", # flake8-return
"TID", # flake8-tidy-imports
"TCH", # flake8-type-checking
"S", # flake8-bandit
"BLE", # flake8-blind-except
"ANN", # flake8-annotations
"A", # flake8-builtins
"PTH", # flake8-use-pathlib
"YTT", # flake8-2020
"UP", # pyupgrade
"TRY", # tryceratops
"PERF", # Perflint
"FURB", # refurb
]
ignore = [
"E501",
"N803",
"N818",
"D107",
"D200",
"D203",
"D212",
"D406",
"D407",
"D413",
"D417",
"D107", # undocumented-public-init
"D200", # fits-on-one-line
"D203", # one-blank-line-before-class
"D212", # multi-line-summary-first-line
"D406", # new-line-after-section-name
"D407", # dashed-underline-after-section
"D413", # blank-line-after-last-section
"D417", # undocumented-param
"S310", # suspicious-url-open-usage
"S404", # suspicious-subprocess-import
"S603", # subprocess-without-shell-equals-true
"ANN101", # missing-type-self
"ANN102", # missing-type-cls
# "ANN401", # any-type
"TRY003", # raise-vanilla-args
"PERF203", # try-except-in-loop
]
fixable = ["ALL"]
unfixable = ["B"]
Expand Down
5 changes: 1 addition & 4 deletions scripts/before_commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@ set -e
ROOT_PATH=$(dirname $(dirname $(realpath $0)))
cd $ROOT_PATH

poetry run ruff check
poetry run ruff format --check
poetry run pytest --cov-report term --cov=awscliv2
poetry run npx pyright
uv run pre-commit run --all-files
2 changes: 1 addition & 1 deletion scripts/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
instances = data["Reservations"][0]["Instances"]
instance_ids = [i["InstanceId"] for i in instances]

print("Instance IDs:", instance_ids)
print("Instance IDs:", instance_ids) # noqa: T201
Loading

0 comments on commit a32e978

Please sign in to comment.