Skip to content

Commit

Permalink
Use poetry instead of pipenv for developer/testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Lingepumpe committed Apr 23, 2023
1 parent 9037a72 commit 66a6b9f
Show file tree
Hide file tree
Showing 13 changed files with 3,661 additions and 151 deletions.
62 changes: 53 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

jobs:
test:
Expand All @@ -13,19 +13,63 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.7
id: setup-python
uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Install Flair dependencies
run: pip install -e .
- name: Install unittest dependencies
run: pip install -r requirements-dev.txt
- name: Show installed dependencies
run: pip freeze
#----------------------------------------------
# Try to load cached poetry installation
#----------------------------------------------
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v3
with:
path: |
~/.local
~/.cache/pypoetry
key: poetry-0 # increment to reset cache
#----------------------------------------------
# Install poetry if not using cached
#----------------------------------------------
- name: Install Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
virtualenvs-in-project: true
#----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
with:
virtualenvs-in-project: true
run: poetry install --no-interaction --no-root
#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install project
with:
virtualenvs-in-project: true
run: poetry install --no-interaction
#----------------------------------------------
# run test suite
#----------------------------------------------
- name: Cache downloaded models/datasets
uses: actions/cache@v3
with:
path: ./cache
key: cache-v1.1
- name: Run tests
run: pytest --runintegration --durations=0 -vv
run: |
source .venv/bin/activate
python -c 'import flair'
pytest --runintegration --durations=0 -vv
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,5 @@ venv.bak/
# mypy
.mypy_cache/

Pipfile.lock

resources/taggers/
regression_train/
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.3.0
hooks:
- id: black-jupyter
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
37 changes: 24 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@ side, please stick to the following process:
1. Check if there is already [an issue](https://github.com/zalandoresearch/flair/issues) for your concern.
2. If there is not, open a new one to start a discussion. We hate to close finished PRs!
3. If we decide your concern needs code changes, we would be happy to accept a pull request. Please consider the
commit guidelines below.
commit guidelines below.

In case you just want to help out and don't know where to start,
[issues with "help wanted" label](https://github.com/zalandoresearch/flair/labels/help%20wanted) are good for
first-time contributors.


## Git Commit Guidelines

If there is already a ticket, use this number at the start of your commit message.
Use meaningful commit messages that described what you did.

**Example:** `GH-42: Added new type of embeddings: DocumentEmbedding.`


## Developing locally

For contributors looking to get deeper into the API we suggest cloning the repository and checking out the unit
Expand All @@ -29,41 +27,54 @@ the code should hopefully be easy.

### Setup

You can either use [Pipenv](https://pipenv.readthedocs.io/) for this:
We use [poetry](https://python-poetry.org) for dependency and virtual environment management. Additionally
[pre-commit](https://pre-commit.com/) is recommended to do code formatting and checking on your code when you commit.
Install poetry and pre-commit on your system if you have not already. Using the [pipx](https://pypa.github.io/pipx/)
package installer:

```bash
pipenv install --dev && pipenv shell
```
# Install pipx and make sure the PATH is set up
pip install pipx
python -m pipx ensurepath

Or create a python environment of your preference and run:
```bash
pip install -r requirements-dev.txt
# Install pre-commit and poetry via pipx
pipx install pre-commit
pipx install poetry
```

### Git pre-commit Hooks
After installing the dependencies, install `pre-commit` hooks via:
After these pre-conditions are met, switch into the checked out flair folder.

```bash
# Activate on-commit formatting and checks
pre-commit install
```

This will automatically run code formatters black and isort for each git commit.
# Install dependencies (including dev dependencies)
poetry install

# You can turn on the installed environment
poetry shell
```

### Tests

To only run typechecks and check the code formatting execute:

```bash
pytest flair
```

To run all basic tests execute:

```bash
pytest
```

To run integration tests execute:

```bash
pytest --runintegration
```

The integration tests will train small models and therefore take more time.
In general, it is recommended to ensure all basic tests are running through before testing the integration tests

Expand Down
2 changes: 0 additions & 2 deletions MAINTAINERS

This file was deleted.

22 changes: 0 additions & 22 deletions Pipfile

This file was deleted.

Loading

0 comments on commit 66a6b9f

Please sign in to comment.