Skip to content

Commit

Permalink
Merge pull request #2436 from Gavinok/migrate-to-poetry
Browse files Browse the repository at this point in the history
#2289 Migrate to Poetry
  • Loading branch information
swcurran authored Aug 30, 2023
2 parents 084f206 + 040e830 commit 981a3f0
Show file tree
Hide file tree
Showing 24 changed files with 3,173 additions and 185 deletions.
20 changes: 19 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,22 @@
ARG VARIANT="3.9"
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}

# if we need to enhance this image we can do it in this dockerfile or the post-install.sh script
ARG POETRY_VERSION="1.4"
ENV POETRY_HOME="/opt/poetry" \
POETRY_VERSION=${POETRY_VERSION}

RUN curl -sSL https://install.python-poetry.org | python3 - \
&& update-alternatives --install /usr/local/bin/poetry poetry /opt/poetry/bin/poetry 900 \
# Enable tab completion for bash
&& poetry completions bash >> /home/vscode/.bash_completion \
# Enable tab completion for Zsh
&& mkdir -p /home/vscode/.zfunc/ \
&& poetry completions zsh > /home/vscode/.zfunc/_poetry \
&& echo "fpath+=~/.zfunc\nautoload -Uz compinit && compinit" >> /home/vscode/.zshrc

COPY pyproject.toml poetry.lock ./
# we do not want the packages defined for this install, comment out the line.
RUN sed -i 's/^[^#]*packages/#&/' pyproject.toml
RUN poetry config virtualenvs.create false \
&& poetry install --no-interaction --all-extras \
&& rm -rf /root/.cache/pypoetry
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"dockerfile": "Dockerfile",
"context": "..",
"args": {
"VARIANT": "3.9-bullseye"
"VARIANT": "3.9-bullseye",
"POETRY_VERSION": "1.4.2"
}
},
"customizations": {
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/post-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WORKSPACE_DIR=$(pwd)

# install all ACA-Py requirements
python -m pip install --upgrade pip
pip3 install -r requirements.txt -r requirements.askar.txt -r requirements.bbs.txt -r requirements.dev.txt -r requirements.indy.txt
pip3 install -r demo/requirements.txt -r demo/requirements.behave.txt

# install black for formatting
pip3 install black
4 changes: 2 additions & 2 deletions .github/workflows/pythonpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install setuptools wheel twine poetry
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
poetry build
twine upload dist/*
13 changes: 4 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@ jobs:
python-version: ${{ inputs.python-version }}
cache: 'pip'
cache-dependency-path: 'requirements*.txt'
- name: Install dependencies
- name: Install the project dependencies
run: |
python -m pip install --upgrade pip
pip3 install --no-cache-dir \
-r requirements.txt \
-r requirements.askar.txt \
-r requirements.bbs.txt \
-r requirements.dev.txt
pip install poetry
poetry install -E "askar bbs"
- name: Tests
run: |
pytest
run: poetry run pytest
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,4 @@ _build/
**/*.iml

# Open API build
open-api/.build

# poetry
poetry.lock
pyproject.toml
open-api/.build
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ You can extend Aca-Py using plug-ins, which can be loaded at runtime. Plug-ins

An ["install and go" page for developers](https://github.com/hyperledger/aries-cloudagent-python/blob/main/DevReadMe.md) is available if you are comfortable with Trust over IP and Aries concepts. ACA-Py can be run with Docker without installation (highly recommended), or can be installed [from PyPi](https://pypi.org/project/aries-cloudagent/). In the [/demo directory](/demo) there is a full set of demos for developers to use in getting started, and the [demo read me](/demo/README.md) is a great starting point for developers to use an "in-browser" approach to run a zero-install example. The [Read the Docs](https://aries-cloud-agent-python.readthedocs.io/en/latest/) overview is also a way to reference the modules and APIs that make up an ACA-Py instance.

If you would like to develop on ACA-Py locally note that we use Poetry for dependency management and packaging, if you are unfamiliar with poetry please see our [cheat sheet](/docs/Poetry.md)

## About the ACA-Py Admin API

The [overview of ACA-Py’s API](https://github.com/hyperledger/aries-cloudagent-python/blob/main/AdminAPI.md) is a great starting place for learning about the ACA-Py API when you are starting to build your own controller.
Expand Down
13 changes: 9 additions & 4 deletions aries_cloudagent/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,16 @@ def run(args):
run_command(command, args)


def script_main():
"""Run the main function as a script for poetry."""
main(sys.argv)


def main(args):
"""Execute default entry point."""
if __name__ == "__main__":
init_debug(args)
run(args)
init_debug(args)
run(args)


main(sys.argv)
if __name__ == "__main__":
script_main()
10 changes: 0 additions & 10 deletions bin/aca-py

This file was deleted.

5 changes: 4 additions & 1 deletion devcontainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ The primary use case for this `devcontainer` is for developing, debugging and un
There are limitations running this devcontainer, such as all networking is within this container. This container has [docker-in-docker](https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/docker-in-docker.md) which allows running demos, building docker images, running `docker compose` all within this container.

### Files
The `.devcontainer` folder contains the `devcontainer.json` file which defines this container. We are using a `Dockerfile` and `post-install.sh` to build and configure the container run image. The `Dockerfile` is simple but in place for simplifying image enhancements (ex. adding `poetry` to the image). The `post-install.sh` will install all the ACA-Py requirements and any additional steps (ex. adding additional development libraries).
The `.devcontainer` folder contains the `devcontainer.json` file which defines this container. We are using a `Dockerfile` and `post-install.sh` to build and configure the container run image. The `Dockerfile` is simple but in place for simplifying image enhancements (ex. adding `poetry` to the image). The `post-install.sh` will install some additional development libraries (including for BDD support).

### Poetry
The Python libraries / dependencies are installed using [`poetry`](https://python-poetry.org). For the devcontainer, we *DO NOT* use virtual environments. This means you will not see or need venv prompts in the terminals and you will not need to run tasks through poetry (ie. `poetry run black .`). If you need to add new dependencies, you will need to add the dependency via poetry *AND* you should rebuild your devcontainer.

### Running docker-in-docker demos
The following is an example of running the demos in this container using a local [von-network](https://github.com/bcgov/von-network/tree/main). You will have to connect to the local von-network using `host.docker.internal` not `localhost`.
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ WORKDIR /src

ADD . .

RUN pip install setuptools wheel
RUN python setup.py sdist bdist_wheel
RUN pip install --no-cache-dir poetry
RUN poetry build

FROM python:${python_version}-slim-bullseye AS main

Expand Down
15 changes: 5 additions & 10 deletions docker/Dockerfile.demo
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,15 @@ RUN mkdir -p bin && curl -L -o bin/jq \
https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 && \
chmod ug+x bin/jq

# Add and install Indy Agent code
ADD requirements*.txt ./
# Add and install Aries Agent code
RUN pip install --no-cache-dir poetry

RUN pip3 install --no-cache-dir \
-r requirements.txt \
-r requirements.askar.txt \
-r requirements.bbs.txt \
-r requirements.dev.txt
ADD README.md pyproject.toml poetry.lock ./

RUN poetry install --no-root --no-directory -E "askar bbs"

ADD aries_cloudagent ./aries_cloudagent
ADD bin ./bin
ADD README.md ./
ADD scripts ./scripts
ADD setup.py ./

RUN pip3 install --no-cache-dir -e .

Expand Down
15 changes: 6 additions & 9 deletions docker/Dockerfile.indy
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,16 @@ WORKDIR /home/indy/src

RUN mkdir -p test-reports && chown -R indy:indy test-reports && chmod -R ug+rw test-reports

ADD requirements*.txt ./
ADD ./README.md pyproject.toml ./poetry.lock ./

USER root
RUN pip3 install --no-cache-dir \
-r requirements.txt \
-r requirements.askar.txt \
-r requirements.bbs.txt \
-r requirements.dev.txt
RUN pip install --no-cache-dir poetry
RUN poetry install --no-root --no-directory -E "askar bbs indy"

ADD --chown=indy:root . .
USER indy

ENTRYPOINT ["/bin/bash", "-c", "pytest \"$@\"", "--"]
ENTRYPOINT ["/bin/bash", "-c", "poetry run pytest \"$@\"", "--"]

# ACA-Py Builder
# Build ACA-Py wheel using setuptools
Expand All @@ -210,8 +207,8 @@ WORKDIR /src

ADD . .

RUN pip install setuptools wheel
RUN python setup.py sdist bdist_wheel
RUN pip install --no-cache-dir poetry
RUN poetry build


# ACA-Py Indy
Expand Down
22 changes: 8 additions & 14 deletions docker/Dockerfile.run
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,17 @@ ENV ENABLE_PTVSD 0

# For consistency with base images, include curl for healthchecks
RUN apt-get update && apt-get install -y curl && apt-get clean
ADD requirements*.txt ./

RUN pip3 install --no-cache-dir \
-r requirements.txt \
-r requirements.askar.txt \
-r requirements.bbs.txt \
-r requirements.dev.txt
RUN pip install --no-cache-dir poetry

RUN mkdir aries_cloudagent && touch aries_cloudagent/__init__.py
ADD aries_cloudagent/version.py aries_cloudagent/version.py
ADD bin ./bin
ADD README.md ./
ADD setup.py ./
ADD . .

RUN poetry install -E "askar bbs"

RUN pip3 install --no-cache-dir -e .
RUN mkdir -p aries_cloudagent && touch aries_cloudagent/__init__.py
ADD aries_cloudagent/version.py aries_cloudagent/version.py

RUN mkdir logs && chmod -R ug+rw logs
RUN mkdir -p logs && chmod -R ug+rw logs
ADD aries_cloudagent ./aries_cloudagent

ENTRYPOINT ["/bin/bash", "-c", "aca-py \"$@\"", "--"]
ENTRYPOINT ["/bin/bash", "-c", "poetry run aca-py \"$@\"", "--"]
12 changes: 5 additions & 7 deletions docker/Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ RUN apt-get update -y && \

WORKDIR /usr/src/app

ADD requirements*.txt ./
RUN pip install --no-cache-dir poetry

RUN pip3 install --no-cache-dir \
-r requirements.txt \
-r requirements.askar.txt \
-r requirements.bbs.txt \
-r requirements.dev.txt
ADD ./README.md pyproject.toml ./poetry.lock ./

RUN poetry install --no-root --no-directory -E "askar bbs"

ADD . .

ENTRYPOINT ["/bin/bash", "-c", "pytest \"$@\"", "--"]
ENTRYPOINT ["/bin/bash", "-c", "poetry run pytest \"$@\"", "--"]
Loading

0 comments on commit 981a3f0

Please sign in to comment.