Skip to content
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

Introduce Poetry as Dependency Manager and Update Dockerfiles #557

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pr_agent/settings/.secrets.toml
pics/
pr_agent.egg-info/
build/
__pycache__/
19 changes: 10 additions & 9 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ codiumai/pr-agent@v0.9

```
git clone https://github.com/Codium-ai/pr-agent.git
cd pr-agent
```

2. Install the requirements in your favorite virtual environment:

```
pip install -r requirements.txt
poetry install
```

3. Copy the secrets template file and fill in your OpenAI key and your GitHub user token:
Expand All @@ -96,14 +97,14 @@ chmod 600 pr_agent/settings/.secrets.toml
4. Add the pr_agent folder to your PYTHONPATH, then run the cli.py script:

```
export PYTHONPATH=[$PYTHONPATH:]<PATH to pr_agent folder>
python3 -m pr_agent.cli --pr_url <pr_url> review
python3 -m pr_agent.cli --pr_url <pr_url> ask <your question>
python3 -m pr_agent.cli --pr_url <pr_url> describe
python3 -m pr_agent.cli --pr_url <pr_url> improve
python3 -m pr_agent.cli --pr_url <pr_url> add_docs
python3 -m pr_agent.cli --pr_url <pr_url> generate_labels
python3 -m pr_agent.cli --issue_url <issue_url> similar_issue
poetry shell
python -m pr_agent.cli --pr_url <pr_url> review
python -m pr_agent.cli --pr_url <pr_url> ask <your question>
python -m pr_agent.cli --pr_url <pr_url> describe
python -m pr_agent.cli --pr_url <pr_url> improve
python -m pr_agent.cli --pr_url <pr_url> add_docs
python -m pr_agent.cli --pr_url <pr_url> generate_labels
python -m pr_agent.cli --issue_url <issue_url> similar_issue
...
```

Expand Down
59 changes: 43 additions & 16 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,64 @@
FROM python:3.10 as base
ARG PYTHON_VERSION=3.10
FROM python:$PYTHON_VERSION as builder

WORKDIR /app
ADD pyproject.toml .
ADD requirements.txt .
RUN pip install . && rm pyproject.toml requirements.txt
ENV PYTHONPATH=/app
# Configure Poetry
ARG POETRY_VERSION=1.7.1
ENV POETRY_HOME=/opt/poetry
ENV POETRY_VENV=/opt/poetry-venv
ENV POETRY_CACHE_DIR=/opt/.cache
ENV POETRY_VIRTUALENVS_IN_PROJECT=1
ENV POETRY_NO_INTERACTION=1
ENV PYTHONUNBUFFERED=1

# Install poetry separated from system interpreter
RUN python3 -m venv $POETRY_VENV \
&& $POETRY_VENV/bin/pip install -U pip setuptools \
&& $POETRY_VENV/bin/pip install poetry==$POETRY_VERSION

# Add `poetry` to PATH
ENV PATH="${PATH}:${POETRY_VENV}/bin"

WORKDIR /usr/app
COPY poetry.lock pyproject.toml ./
RUN poetry install --without dev --no-root && rm -rf $POETRY_CACHE_DIR
RUN poetry export -f requirements.txt -o requirements-dev.txt --only=dev

FROM python:$PYTHON_VERSION as base

ARG UID=1000
ARG GID=1000

ENV PYTHONPATH=/usr/app/
ENV VIRTUAL_ENV=/usr/app/.venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# Create and use non-root user
RUN groupadd -g $GID -r pr_agent && useradd -m -g $GID -u $UID pr_agent

WORKDIR /usr/app
COPY --chown=pr_agent:pr_agent --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
COPY --chown=pr_agent:pr_agent pr_agent/ $PYTHONPATH/pr_agent/
USER pr_agent

FROM base as github_app
ADD pr_agent pr_agent
CMD ["python", "pr_agent/servers/github_app.py"]

FROM base as bitbucket_app
ADD pr_agent pr_agent
CMD ["python", "pr_agent/servers/bitbucket_app.py"]

FROM base as bitbucket_server_webhook
ADD pr_agent pr_agent
CMD ["python", "pr_agent/servers/bitbucket_server_webhook.py"]

FROM base as github_polling
ADD pr_agent pr_agent
CMD ["python", "pr_agent/servers/github_polling.py"]

FROM base as gitlab_webhook
ADD pr_agent pr_agent
CMD ["python", "pr_agent/servers/gitlab_webhook.py"]

FROM base as test
ADD requirements-dev.txt .
RUN pip install -r requirements-dev.txt && rm requirements-dev.txt
ADD pr_agent pr_agent
ADD tests tests
COPY --chown=pr_agent:pr_agent --from=builder /usr/app/requirements-dev.txt /usr/app/requirements-dev.txt
RUN python -m pip install -r requirements-dev.txt
COPY tests/ ./tests/

FROM base as cli
ADD pr_agent pr_agent
ENTRYPOINT ["python", "pr_agent/cli.py"]
6 changes: 4 additions & 2 deletions docker/Dockerfile.lambda
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
FROM public.ecr.aws/lambda/python:3.10
ARG PYTHON_VERSION=3.10
FROM public.ecr.aws/lambda/python:$PYTHON_VERSION

RUN yum update -y && \
yum install -y gcc python3-devel && \
yum clean all
RUN pip install poetry

ADD pyproject.toml .
RUN pip install . && rm pyproject.toml
RUN poetry install && rm pyproject.toml
RUN pip install mangum==0.17.0
COPY pr_agent/ ${LAMBDA_TASK_ROOT}/pr_agent/

Expand Down
3,133 changes: 3,133 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

121 changes: 52 additions & 69 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,80 +1,63 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "pr_agent"
version = "0.0.1"

authors = [
{name = "Itamar Friedman", email = "itamar.f@codium.ai"},
]
[tool.poetry]
name = "pr-agent"
version = "0.11"
description = "CodiumAI PR-Agent is an open-source tool to automatically analyze a pull request and provide several types of feedback"
homepage = "https://github.com/Codium-ai/pr-agent"
repository = "https://github.com/Codium-ai/pr-agent"
authors = ["Itamar Friedman <itamar.f@codium.ai>"]
maintainers = [
{name = "Ori Kotek", email = "ori.k@codium.ai"},
{name = "Tal Ridnik", email = "tal.r@codium.ai"},
{name = "Hussam Lawen", email = "hussam.l@codium.ai"},
{name = "Sagi Medina", email = "sagi.m@codium.ai"}
"Ori Kotek <ori.k@codium.ai>",
"Tal Ridnik <tal.r@codium.ai>",
"Hussam Lawen <hussam.l@codium.ai>",
"Sagi Medina <sagi.m@codium.ai>",
]
description = "CodiumAI PR-Agent is an open-source tool to automatically analyze a pull request and provide several types of feedback"
readme = "README.md"
requires-python = ">=3.9"
keywords = ["ai", "tool", "developer", "review", "agent"]
license = {file = "LICENSE", name = "Apache 2.0 License"}
license = "Apache 2.0 License"
readme = "README.md"
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Operating System :: Independent",
"Programming Language :: Python :: 3",
]
dynamic = ["dependencies"]

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}

[project.urls]
"Homepage" = "https://github.com/Codium-ai/pr-agent"

[tool.setuptools]
include-package-data = false
license-files = ["LICENSE"]

[tool.setuptools.packages.find]
where = ["."]
include = ["pr_agent"]

[project.scripts]
pr-agent = "pr_agent.cli:run"


[tool.ruff]

line-length = 120

select = [
"E", # Pyflakes
"F", # Pyflakes
"B", # flake8-bugbear
"I001", # isort basic checks
"I002", # isort missing-required-import
]

# First commit - only fixing isort
fixable = [
"I001", # isort basic checks
]

unfixable = [
"B", # Avoid trying to fix flake8-bugbear (`B`) violations.
]

exclude = [
"api/code_completions",
]
include = ["CHANGELOG.md"]

[tool.poetry.dependencies]
python = "^3.10"
aiohttp = "3.9.1"
atlassian-python-api = "3.39.0"
azure-devops = "7.1.0b3"
boto3 = "1.33.6"
dynaconf = "3.2.4"
fastapi = "0.99.0"
gitpython = "3.1.32"
google-cloud-aiplatform = "1.35.0"
google-cloud-storage = "2.10.0"
jinja2 = "3.1.2"
litellm = "0.12.5"
loguru = "0.7.2"
msrest = "0.7.1"
openai = "0.27.8"
pygithub = "==1.59.*"
pyyaml = "6.0.1"
python-gitlab = "3.15.0"
retry = "0.9.2"
starlette-context = "0.3.6"
tiktoken = "0.5.2"
ujson = "5.8.0"
uvicorn = "0.22.0"
pinecone-client = "^2.2.4"
pinecone-datasets = {git = "https://github.com/mrT23/pinecone-datasets.git", rev = "main"}


[tool.poetry.group.dev.dependencies]
pytest = "^7.4.3"
httpx = "^0.26.0"
ruff = "^0.1.9"

ignore = [
"E999", "B008"
]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.ruff.per-file-ignores]
"__init__.py" = ["E402"] # Ignore `E402` (import violations) in all `__init__.py` files, and in `path/to/file.py`.
# TODO: should decide if maybe not to ignore these.
[tool.poetry.scripts]
pr-agent = "python pr_agent.cli:run"
1 change: 0 additions & 1 deletion requirements-dev.txt

This file was deleted.

26 changes: 0 additions & 26 deletions requirements.txt

This file was deleted.