Skip to content

Commit

Permalink
chore: migrate from pipenv to poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
jdobes authored and psegedy committed Jan 9, 2024
1 parent 8404869 commit 6b0fd00
Show file tree
Hide file tree
Showing 15 changed files with 2,081 additions and 1,692 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/safety.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Safety

on:
push:
branches:
- "master"
- "stable"
pull_request:
branches:
- "master"
- "stable"

jobs:
safety:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
poetry-version: [1.5]
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Set up Poetry
run: pip install poetry~=1.5
- name: Set up Safety
run: pip install safety
- name: Export requirements.txt
run: poetry export --with dev -f requirements.txt --output requirements.txt
- name: Run safety
run: safety check -r requirements.txt
1 change: 0 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
matrix:
python-version: [3.9]
env:
PIPENV_CHECK: "1"
PGPORT: "5433"
steps:
- name: Checkout
Expand Down
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ RUN microdnf module enable postgresql:12 && \

WORKDIR /vmaas

ADD /Pipfile* /vmaas/
ADD pyproject.toml /vmaas/
ADD poetry.lock /vmaas/

ENV LC_ALL=C.utf8
ENV LANG=C.utf8
ARG PIPENV_CHECK=1
ARG PIPENV_PYUP_API_KEY=""
ARG VAR_PIPENV_INSTALL_OPT=""
RUN pip3 install --upgrade pip pipenv==2022.12.19 && \
pipenv install --ignore-pipfile --deploy --system $VAR_PIPENV_INSTALL_OPT && \
if [ "${PIPENV_CHECK}" == 1 ] ; then pipenv check --system -i 62142; fi
ARG VAR_POETRY_INSTALL_OPT="--only main"
RUN pip3 install --upgrade pip && \
pip3 install --upgrade poetry~=1.5
RUN poetry export $VAR_POETRY_INSTALL_OPT -f requirements.txt --output requirements.txt && \
pip3 install -r requirements.txt

RUN install -m 1777 -d /data && \
adduser --gid 0 -d /vmaas --no-create-home vmaas
Expand Down
42 changes: 0 additions & 42 deletions Pipfile

This file was deleted.

1,581 changes: 0 additions & 1,581 deletions Pipfile.lock

This file was deleted.

5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ docker-compose down -v # Stop and remove containers and database data volume (bu
docker-compose build
~~~

### Building parameters
~~~bash
PIPENV_CHECK=0 docker-compose build # Builds images without performing "pipenv check" command
~~~

#### Managing containers
All at once
~~~bash
Expand Down
3 changes: 1 addition & 2 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ services:
dockerfile: Dockerfile
args:
VAR_RPMS: "findutils"
VAR_PIPENV_INSTALL_OPT: "--dev"
PIPENV_CHECK: "${PIPENV_CHECK:-1}"
VAR_POETRY_INSTALL_OPT: "--with dev"
image: vmaas/app:latest
environment:
CI: "${CI:-false}"
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ services:
build:
context: .
dockerfile: ./Dockerfile
args:
PIPENV_CHECK: "${PIPENV_CHECK:-1}"
image: vmaas/app:latest
restart: unless-stopped
env_file:
Expand Down
1,938 changes: 1,938 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
[tool.semantic_release]
version_variables = ["vmaas/common/constants.py:VMAAS_VERSION"]
version_toml = ["pyproject.toml:tool.poetry.version"]
commit_author = "vmaas-bot <[email protected]>"

[tool.poetry]
name = "vmaas"
version = "2.50.3"
description = ""
authors = [""]
readme = "README.md"
packages = []

[tool.poetry.dependencies]
python = "~3.9"
aiohttp = ">=3.8.0"
aiohttp-jinja2 = ">=1.5"
app-common-python = ">=0.2.5"
boto3 = ">=1.16.13"
botocore = ">=1.19.13"
click = ">=0.7"
connexion = {extras = ["swagger-ui"],version = "2.14.1"}
flask = "2.2.5"
gitpython = ">=3.1.30"
iso8601 = ">=0.1.12"
jsonschema = ">=3.2.0"
natsort = ">=7.0.1"
psycopg2-binary = ">=2.8.6"
prometheus-client = ">=0.8.0"
pyopenssl = ">=19.1.0"
python-dateutil = ">=2.8.1"
pytz = ">=2020.4"
pyyaml = ">=5.4.1"
requests = ">=2.31.0"
schema = ">=0.7.3"
tornado = ">=6.0.3"
watchtower = ">=1.0.0"
werkzeug = ">=1.0.1"
yarl = ">=1.6.2"

[tool.poetry.group.dev.dependencies]
coverage = ">=4.5.3"
pur = ">=5.4.1"
pytest = ">=5.0.1"
pylint = ">=2.3.1"
pytest-cov = ">=2.7.1"
pytest-flask = ">=1.1.0"
testing-postgresql = ">=1.3.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
4 changes: 2 additions & 2 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ for test_dir in $test_dirs; do
done

# Find and run tests
pipenv run pytest -vvv --cov-report=xml --cov=. --color=yes --durations=1
pytest -vvv --cov-report=xml --cov=. --color=yes --durations=1

rc=$(($rc+$?))

# Run pylint
find . -iname '*.py' | xargs pipenv run pylint --rcfile=../../pylintrc --output-format=colorized
find . -iname '*.py' | xargs pylint --rcfile=../../pylintrc --output-format=colorized
rc=$(($rc+$?))

exit $rc
Expand Down
8 changes: 4 additions & 4 deletions scripts/check_deps_versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ CYAN='\033[0;36m'
NO_COLOR='\033[0m'
echo -e "${CYAN}Dependency updates checking...${NO_COLOR}"

# Check for python deps updates (all dirs containing Pipfile).
for APP_DIR in $(find -name Pipfile -printf '%h ')
# Check for python deps updates (all dirs containing poetry.lock).
for APP_DIR in $(find -name poetry.lock -printf '%h ')
do
echo "Analyzing deps in '$APP_DIR'"
cd $APP_DIR
pipenv run pip freeze > /tmp/req.txt
pipenv run pur -r /tmp/req.txt -o /dev/null | grep "Updated" | sed -e "s/Updated/You can update:/g"
pip freeze > /tmp/req.txt
pur -r /tmp/req.txt -o /dev/null | grep "Updated" | sed -e "s/Updated/You can update:/g"
cd -
done
echo -e "${CYAN}------------------------------${NO_COLOR}"
2 changes: 0 additions & 2 deletions scripts/devel-compose
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/sh

export PIPENV_CHECK=${PIPENV_CHECK:-0}

if [ ! -e /usr/bin/docker-compose ] ; then
podman-compose ${PODMAN_PATH:+--podman-path=$PODMAN_PATH} \
-f docker-compose.yml \
Expand Down
44 changes: 0 additions & 44 deletions scripts/pipenv-lock.sh

This file was deleted.

44 changes: 44 additions & 0 deletions scripts/poetry-lock.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

# Script to lock Poetry dependencies in container and copy generated lock file back

workdir="/tmp/"
dockerfile="Dockerfile-poetry"

for runtime in podman docker; do
cmd=$(command -v $runtime)
if [[ "$cmd" != "" ]] && $cmd ps &> /dev/null; then
break
else
echo "Unable to use $runtime"
cmd=""
fi
done

if [[ "$cmd" != "" ]]; then
echo "Using: $cmd"
else
echo "No container runtime found!"
exit 1
fi

cat <<EOF > $workdir$dockerfile
FROM registry.access.redhat.com/ubi8/ubi-minimal
RUN microdnf install --setopt=install_weak_deps=0 --setopt=tsflags=nodocs \
python39 python39-pip python39-devel libpq-devel gcc git && \
microdnf clean all
RUN pip3 install --upgrade pip && pip3 install --upgrade poetry~=1.5
EOF

current_dir=$(pwd)
cd $workdir
$cmd build -t poetry-locker -f $dockerfile .
cd $current_dir
$cmd run --rm -d --name poetry-locker-container poetry-locker sleep infinity

$cmd exec poetry-locker-container bash -c "mkdir -p /tmp"
$cmd cp "pyproject.toml" poetry-locker-container:"/tmp/"
$cmd exec poetry-locker-container bash -c "cd /tmp && poetry lock"
$cmd cp poetry-locker-container:"/tmp/poetry.lock" "."

$cmd kill poetry-locker-container

0 comments on commit 6b0fd00

Please sign in to comment.