Skip to content

Refactoring to Use Poetry #305

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

Merged
merged 12 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .github/build/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ LABEL summary="Toolchain for running pre-commit hooks." \
io.k8s.display-name="Pre-Commit Toolchain"

USER root
RUN dnf install nodejs
RUN dnf install nodejs -y && \
dnf clean all && \
rm -rf /var/cache/dnf
ADD https://mirror.openshift.com/pub/openshift-v4/clients/oc/latest/linux/oc.tar.gz $TMPDIR/
RUN tar -C /usr/local/bin -xvf $TMPDIR/oc.tar.gz && \
chmod +x /usr/local/bin/oc && \
rm $TMPDIR/oc.tar.gz
USER $USERID

COPY requirements-dev.txt /tmp/requirements-dev.txt
RUN python -m pip install -r /tmp/requirements-dev.txt
RUN pip3 install poetry && \
poetry config virtualenvs.create false
COPY pyproject.toml ./
RUN poetry install

CMD bash
4 changes: 3 additions & 1 deletion .github/build/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Pre-Commit Build Artifacts

This directory contains the artifacts required to build the codeflare-sdk pre-commit image. As of right now, we will need to manually update `requirements-dev.txt` in this directory as well.
This directory contains the artifacts required to build the codeflare-sdk pre-commit image.

To build the image run `podman build -f .github/build/Containerfile .` from the root directory.
6 changes: 0 additions & 6 deletions .github/build/requirements-dev.txt

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/coverage-badge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest==6.2.4
pip install pytest-mock==3.6.1
pip install coverage
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install poetry
poetry config virtualenvs.create false
poetry lock --no-update
poetry install --with test
- name: Generate coverage report
run: |
coverage run -m --source=src pytest -v tests/unit_test.py
Expand Down
File renamed without changes.
38 changes: 0 additions & 38 deletions .github/workflows/python-app.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Python Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
unit-tests:

runs-on: ubuntu-latest
container:
image: quay.io/project-codeflare/codeflare-sdk-precommit:v0.0.3
steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pip install poetry
- uses: actions/setup-python@v4
with:
python-version: '3.8'
- name: Install dependencies
run: |
poetry config virtualenvs.create false
poetry lock --no-update
poetry install --with test
- name: Test with pytest and check coverage
run: |
coverage run -m --source=src pytest -v tests/unit_test.py
coverage=$(coverage report -m | tail -1 | tail -c 4 | head -c 2)
if (( $coverage < 90 )); then exit 1; else echo "Coverage passed, ${coverage}%"; fi
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ __pycache__/
.coverage
Pipfile
Pipfile.lock
poetry.lock
.venv*
build/
tls-cluster-namespace
Expand Down
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,33 @@ Can be installed via `pip`: `pip install codeflare-sdk`

### Prerequisites

We recommend using Python 3.9 for development.
Install development specific dependencies:
`$ pip install -r requirements-dev.txt`
We recommend using Python 3.9 for development, along with Poetry.
Create a Poetry virtual environment with the required Python version 3.9, and run all commands within this environment.

Additional dependencies can be found in `requirements.txt`: `$ pip install -r requirements.txt`
- run: `poetry shell`

#### Install dependencies:

- run: `poetry install`

This will install standard requirements as specified in the poetry.lock file. Test and docs dependencies are optional.

- To include test dependencies run: `poetry install --with test`

- To include docs dependencies run: `poetry install --with docs`

- To include test and docs dependencies run: `poetry install --with test,docs`

If you require a requirements.txt file you can run:

`poetry export -f requirements.txt --output requirements.txt --without-hashes`

### Pre-commit

We use pre-commit to make sure the code is consistently formatted. To make sure that pre-commit is run every time you commit changes, simply run `pre-commit install`

To build the codeflare-sdk pre-commit image run `podman build -f .github/build/Containerfile .` from the root directory.

### Testing

- To install codeflare-sdk in editable mode, run `pip install -e .` from the repo root.
Expand Down
Loading