-
Notifications
You must be signed in to change notification settings - Fork 80
Migrate to poetry for better dependency management #194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
37697b1
3ec0f50
8bc1b08
32fb527
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,3 +153,6 @@ tmp*.py | |
| deps/artifacts/ | ||
| deps/aws-lambda-cpp-*/ | ||
| deps/curl-*/ | ||
|
|
||
| # local caches | ||
| .DS_Store | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,13 @@ | ||
| repos: | ||
| - repo: https://github.com/python/black | ||
| rev: 19.3b0 | ||
| - repo: local | ||
| hooks: | ||
| - id: black | ||
| language_version: python3.9 | ||
| exclude_types: ['markdown', 'ini', 'toml', 'rst'] | ||
| - id: ruff-check | ||
| name: ruff | ||
| entry: poetry run ruff check --fix | ||
| language: system | ||
| types: [python] | ||
| - id: ruff-format | ||
| name: ruff format | ||
| entry: poetry run ruff format | ||
| language: system | ||
| types: [python] |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| [tool.poetry] | ||
| name = "awslambdaric" | ||
| version = "3.0.2" | ||
| description = "AWS Lambda Runtime Interface Client for Python" | ||
| authors = ["Amazon Web Services"] | ||
| license = "Apache-2.0" | ||
| readme = "README.md" | ||
| packages = [{ include = "awslambdaric" }] | ||
|
|
||
| [tool.poetry.dependencies] | ||
| python = ">=3.9" | ||
| simplejson = ">=3.20.1" | ||
| snapshot-restore-py = ">=1.0.0" | ||
|
|
||
| [tool.poetry.group.dev.dependencies] | ||
| coverage = ">=4.4.0" | ||
| pytest = ">=3.0.7" | ||
| mock = ">=2.0.0" | ||
| parameterized = ">=0.9.0" | ||
| ruff = "^0.1.0" | ||
| bandit = "^1.7.5" | ||
| pre-commit = "^3.0.0" | ||
|
|
||
| # Development scripts | ||
| [tool.poetry.scripts] | ||
| init = "scripts.dev:init" | ||
| test = "scripts.dev:test" | ||
| lint = "scripts.dev:lint" | ||
| format = "scripts.dev:format_code" | ||
| clean = "scripts.dev:clean" | ||
| build = "scripts.dev:build" | ||
| local-test = "scripts.dev:local_test" | ||
|
|
||
| [build-system] | ||
| requires = ["poetry-core>=2.0.0,<3.0.0", "setuptools>=68", "wheel"] | ||
| build-backend = "poetry.core.masonry.api" | ||
|
|
||
| # Ruff configuration | ||
| [tool.ruff] | ||
| target-version = "py39" | ||
| line-length = 88 | ||
|
|
||
| [tool.ruff.lint] | ||
| select = [ | ||
| "E", # pycodestyle errors | ||
| "W", # pycodestyle warnings | ||
| "F", # pyflakes | ||
| "I", # isort | ||
| "UP", # pyupgrade | ||
| "C90", # mccabe complexity | ||
| ] | ||
|
|
||
| # Ignore rules that are too strict for existing codebases | ||
| ignore = [ | ||
| "E501", # Line too long (handled by formatter) | ||
| "PLR0913", # Too many arguments | ||
| "E722", # Bare except | ||
| "PLW0603", # Global statement | ||
| "UP031", # % formatting vs f-strings | ||
| "E402", # Module import not at top | ||
| ] | ||
|
|
||
| [tool.ruff.format] | ||
| quote-style = "double" | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #!/usr/bin/env python3 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's what's happening: Makefile (a build tool) calls this script (a build tool) which calls poetry (another build tool). This layering feels a bit complex. Do you think there's an opportunity to simplify the flow? Or could you help me understand why we have this?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, true, the workflow is a little complex, but the purpose was to make the MakeFile as minimal and simple looking as possible. But surely, we can directly call the poetry from the MakeFile and get rid completely of the dev.py |
||
| import argparse | ||
| import subprocess | ||
| import shutil | ||
| import sys | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
| ROOT = Path(__file__).resolve().parent.parent | ||
|
|
||
| def run(cmd, check=True, env=None): | ||
| print("\n$ {}".format(' '.join(cmd) if isinstance(cmd, list) else cmd)) | ||
| result = subprocess.run(cmd, shell=isinstance(cmd, str), check=check, env=env) | ||
| if result.returncode != 0 and check: | ||
| sys.exit(result.returncode) | ||
|
|
||
|
|
||
| def init(): | ||
| print("Initializing environment") | ||
| run(["poetry", "install"]) | ||
|
|
||
|
|
||
| def test(): | ||
| print("Running tests") | ||
| run(["poetry", "run", "pytest", "tests"]) | ||
|
|
||
|
|
||
| def lint(): | ||
| print("Running linters") | ||
| run(["poetry", "run", "ruff", "check", "awslambdaric/", "tests/"]) | ||
|
|
||
|
|
||
| def format_code(): | ||
| print("Formatting code") | ||
| run(["poetry", "run", "ruff", "format", "awslambdaric/", "tests/"]) | ||
|
|
||
|
|
||
| def clean(): | ||
| print("Cleaning build artifacts") | ||
| dirs_to_remove = ["build", "dist", "*.egg-info"] | ||
| for pattern in dirs_to_remove: | ||
| for path in ROOT.glob(pattern): | ||
| if path.is_dir(): | ||
| shutil.rmtree(path) | ||
| print("Removed directory: {}".format(path)) | ||
| elif path.is_file(): | ||
| path.unlink() | ||
| print("Removed file: {}".format(path)) | ||
|
|
||
|
|
||
| def build(): | ||
| print("Building package") | ||
| env = os.environ.copy() | ||
|
|
||
| # Set BUILD=true on Linux for native compilation | ||
| import platform | ||
| if platform.system() == "Linux": | ||
| env["BUILD"] = "true" | ||
| elif os.getenv("BUILD") == "true": | ||
| env["BUILD"] = "true" | ||
|
|
||
| run([sys.executable, "setup.py", "sdist", "bdist_wheel"], env=env) | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description="Development scripts") | ||
| parser.add_argument("command", choices=[ | ||
| "init", "test", "lint", "format", "clean", "build" | ||
| ]) | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| command_map = { | ||
| "init": init, | ||
| "test": test, | ||
| "lint": lint, | ||
| "format": format_code, | ||
| "clean": clean, | ||
| "build": build, | ||
|
|
||
| } | ||
|
|
||
| command_map[args.command]() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you help me understand the reasoning behind ignoring these rules? I'm curious if there's a specific use case or limitation that made this necessary