Skip to content

Commit 37697b1

Browse files
author
AntoniaSzecsi
committed
Migrate the poetry for dependency management
1 parent 3f43f4d commit 37697b1

16 files changed

+1135
-211
lines changed

.github/workflows/test-on-push-and-pr.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ jobs:
1212

1313
steps:
1414
- uses: actions/checkout@v4
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: '3.12'
20+
21+
- name: Install Poetry
22+
run: |
23+
curl -sSL https://install.python-poetry.org | python3 -
24+
echo "$HOME/.local/bin" >> $GITHUB_PATH
25+
1526
- name: Run 'pr' target
1627
run: make pr
1728

@@ -45,4 +56,4 @@ jobs:
4556
steps:
4657
- uses: actions/checkout@v4
4758
- name: Run ubuntu integration tests
48-
run: DISTRO=ubuntu make test-integ
59+
run: DISTRO=ubuntu make test-integ

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,6 @@ tmp*.py
153153
deps/artifacts/
154154
deps/aws-lambda-cpp-*/
155155
deps/curl-*/
156+
157+
# local caches
158+
.DS_Store

.pre-commit-config.yaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
repos:
2-
- repo: https://github.com/python/black
3-
rev: 19.3b0
2+
- repo: local
43
hooks:
5-
- id: black
6-
language_version: python3.9
7-
exclude_types: ['markdown', 'ini', 'toml', 'rst']
4+
- id: ruff-check
5+
name: ruff
6+
entry: poetry run ruff check --fix
7+
language: system
8+
types: [python]
9+
- id: ruff-format
10+
name: ruff format
11+
entry: poetry run ruff format
12+
language: system
13+
types: [python]

Makefile

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,23 @@ target:
55

66
.PHONY: init
77
init:
8-
pip3 install -r requirements/base.txt -r requirements/dev.txt
8+
python3 scripts/dev.py init
99

1010
.PHONY: test
11-
test: check-format
12-
pytest --cov awslambdaric --cov-report term-missing --cov-fail-under 90 tests
11+
test:
12+
python3 scripts/dev.py test
13+
14+
.PHONY: lint
15+
lint:
16+
python3 scripts/dev.py lint
17+
18+
.PHONY: clean
19+
clean:
20+
python3 scripts/dev.py clean
21+
22+
.PHONY: build
23+
build: clean
24+
python3 scripts/dev.py build
1325

1426
.PHONY: setup-codebuild-agent
1527
setup-codebuild-agent:
@@ -25,48 +37,40 @@ test-integ: setup-codebuild-agent
2537

2638
.PHONY: check-security
2739
check-security:
28-
bandit -r awslambdaric
40+
poetry run bandit -r awslambdaric
2941

3042
.PHONY: format
3143
format:
32-
black setup.py awslambdaric/ tests/
44+
poetry run ruff format awslambdaric/ tests/
3345

3446
.PHONY: check-format
3547
check-format:
36-
black --check setup.py awslambdaric/ tests/
48+
poetry run ruff format --check awslambdaric/ tests/
3749

38-
# Command to run everytime you make changes to verify everything works
3950
.PHONY: dev
4051
dev: init test
4152

42-
# Verifications to run before sending a pull request
4353
.PHONY: pr
4454
pr: init check-format check-security dev
4555

56+
.PHONY: codebuild
4657
codebuild: setup-codebuild-agent
4758
CODEBUILD_IMAGE_TAG=codebuild-agent DISTRO="$(DISTRO)" tests/integration/codebuild-local/test_all.sh tests/integration/codebuild
4859

49-
.PHONY: clean
50-
clean:
51-
rm -rf dist
52-
rm -rf awslambdaric.egg-info
53-
54-
.PHONY: build
55-
build: clean
56-
BUILD=true python3 setup.py sdist
57-
5860
define HELP_MESSAGE
5961

6062
Usage: $ make [TARGETS]
6163

6264
TARGETS
6365
check-security Run bandit to find security issues.
64-
format Run black to automatically update your code to match our formatting.
65-
build Builds the package.
66-
clean Cleans the working directory by removing built artifacts.
67-
dev Run all development tests after a change.
68-
init Initialize and install the requirements and dev-requirements for this project.
66+
format Run black to automatically update your code to match formatting.
67+
build Build the package using scripts/dev.py.
68+
clean Cleans the working directory using scripts/dev.py.
69+
dev Run all development tests using scripts/dev.py.
70+
init Install dependencies via scripts/dev.py.
6971
pr Perform all checks before submitting a Pull Request.
70-
test Run the Unit tests.
71-
72-
endef
72+
test Run unit tests using scripts/dev.py.
73+
lint Run all linters via scripts/dev.py.
74+
test-smoke Run smoke tests inside Docker.
75+
test-integ Run all integration tests.
76+
endef

poetry.lock

Lines changed: 785 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
[tool.poetry]
2+
name = "awslambdaric"
3+
version = "3.0.2"
4+
description = "AWS Lambda Runtime Interface Client for Python"
5+
authors = ["Amazon Web Services"]
6+
license = "Apache-2.0"
7+
readme = "README.md"
8+
packages = [{ include = "awslambdaric" }]
9+
10+
[tool.poetry.dependencies]
11+
python = ">=3.9"
12+
simplejson = ">=3.20.1"
13+
snapshot-restore-py = ">=1.0.0"
14+
15+
[tool.poetry.group.dev.dependencies]
16+
coverage = ">=4.4.0"
17+
pytest = ">=3.0.7"
18+
mock = ">=2.0.0"
19+
parameterized = ">=0.9.0"
20+
ruff = "^0.1.0"
21+
bandit = "^1.7.5"
22+
pre-commit = "^3.0.0"
23+
24+
# Development scripts
25+
[tool.poetry.scripts]
26+
init = "scripts.dev:init"
27+
test = "scripts.dev:test"
28+
lint = "scripts.dev:lint"
29+
format = "scripts.dev:format_code"
30+
clean = "scripts.dev:clean"
31+
build = "scripts.dev:build"
32+
local-test = "scripts.dev:local_test"
33+
34+
[build-system]
35+
requires = ["poetry-core>=2.0.0,<3.0.0", "setuptools>=68", "wheel"]
36+
build-backend = "poetry.core.masonry.api"
37+
38+
# Ruff configuration
39+
[tool.ruff]
40+
target-version = "py39"
41+
line-length = 88
42+
43+
[tool.ruff.lint]
44+
select = [
45+
"E", # pycodestyle errors
46+
"W", # pycodestyle warnings
47+
"F", # pyflakes
48+
"I", # isort
49+
"UP", # pyupgrade
50+
"C90", # mccabe complexity
51+
]
52+
53+
# Ignore rules that are too strict for existing codebases
54+
ignore = [
55+
"E501", # Line too long (handled by formatter)
56+
"PLR0913", # Too many arguments
57+
"E722", # Bare except
58+
"PLW0603", # Global statement
59+
"UP031", # % formatting vs f-strings
60+
"E402", # Module import not at top
61+
]
62+
63+
[tool.ruff.format]
64+
quote-style = "double"

requirements/base.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

requirements/dev.txt

Lines changed: 0 additions & 12 deletions
This file was deleted.

scripts/dev.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
import subprocess
4+
import shutil
5+
import sys
6+
import os
7+
from pathlib import Path
8+
9+
ROOT = Path(__file__).resolve().parent.parent
10+
11+
def run(cmd, check=True, env=None):
12+
print("\n$ {}".format(' '.join(cmd) if isinstance(cmd, list) else cmd))
13+
result = subprocess.run(cmd, shell=isinstance(cmd, str), check=check, env=env)
14+
if result.returncode != 0 and check:
15+
sys.exit(result.returncode)
16+
17+
18+
def init():
19+
print("Initializing environment")
20+
run(["poetry", "install"])
21+
22+
23+
def test():
24+
print("Running tests")
25+
run(["poetry", "run", "pytest", "tests"])
26+
27+
28+
def lint():
29+
print("Running linters")
30+
run(["poetry", "run", "ruff", "check", "awslambdaric/", "tests/"])
31+
32+
33+
def format_code():
34+
print("Formatting code")
35+
run(["poetry", "run", "ruff", "format", "awslambdaric/", "tests/"])
36+
37+
38+
def clean():
39+
print("Cleaning build artifacts")
40+
dirs_to_remove = ["build", "dist", "*.egg-info"]
41+
for pattern in dirs_to_remove:
42+
for path in ROOT.glob(pattern):
43+
if path.is_dir():
44+
shutil.rmtree(path)
45+
print("Removed directory: {}".format(path))
46+
elif path.is_file():
47+
path.unlink()
48+
print("Removed file: {}".format(path))
49+
50+
51+
def build():
52+
print("Building package")
53+
env = os.environ.copy()
54+
55+
# Set BUILD=true on Linux for native compilation
56+
import platform
57+
if platform.system() == "Linux":
58+
env["BUILD"] = "true"
59+
elif os.getenv("BUILD") == "true":
60+
env["BUILD"] = "true"
61+
62+
run([sys.executable, "setup.py", "sdist", "bdist_wheel"], env=env)
63+
64+
65+
def main():
66+
parser = argparse.ArgumentParser(description="Development scripts")
67+
parser.add_argument("command", choices=[
68+
"init", "test", "lint", "format", "clean", "build"
69+
])
70+
71+
args = parser.parse_args()
72+
73+
command_map = {
74+
"init": init,
75+
"test": test,
76+
"lint": lint,
77+
"format": format_code,
78+
"clean": clean,
79+
"build": build,
80+
81+
}
82+
83+
command_map[args.command]()
84+
85+
86+
if __name__ == "__main__":
87+
main()
88+

0 commit comments

Comments
 (0)