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

Use poetry instead of pipenv for developer/testing #3214

Merged
merged 3 commits into from
Apr 27, 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
50 changes: 41 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,51 @@ 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
#----------------------------------------------
# Lock dependencies to get fresh versions
#----------------------------------------------
- name: Run poetry lock
run: poetry lock
#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
run: |
poetry config virtualenvs.in-project true
poetry install --no-interaction --no-root
#----------------------------------------------
# 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/
30 changes: 0 additions & 30 deletions .pre-commit-config.yaml

This file was deleted.

41 changes: 20 additions & 21 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,48 +27,49 @@ the code should hopefully be easy.

### Setup

You can either use [Pipenv](https://pipenv.readthedocs.io/) for this:
Flair requires python-3.7 or higher. To make sure your code also runs on the oldest supported
python version, it is recommended to use python-3.7.x for flair development.

```bash
pipenv install --dev && pipenv shell
```
We use [poetry](https://python-poetry.org) for dependency and virtual environment management.
Install poetry following the official guide at https://python-poetry.org/docs/#installation - using the official installer
or via [pipx](https://pypa.github.io/pipx/).

Or create a python environment of your preference and run:
```bash
pip install -r requirements-dev.txt
```
After the pre-conditions are met, switch into the checked out flair folder.

### Git pre-commit Hooks
After installing the dependencies, install `pre-commit` hooks via:
```bash
pre-commit install
```
# Install dependencies (including dev dependencies)
poetry install

This will automatically run code formatters black and isort for each git commit.
# 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

### Code Formatting

To ensure a standardized code style we use the formatter [black](https://github.com/ambv/black) and for standardizing imports we use [isort](https://github.com/PyCQA/isort).
If your code is not formatted properly, the tests will fail.

If you set up pre-commit hooks, every git commit will automatically run these formatters. Otherwise you can also manually run them, or let your IDE run them on every file save.
Running from the command line works via `black flair/ && isort flair/` in the flair root folder.
To ensure a standardized code style we use the formatter [black](https://github.com/ambv/black) and for standardizing
imports we use [isort](https://github.com/PyCQA/isort). If your code is not formatted properly, the tests will fail.
We recommend configuring your IDE to run these formatters for you, but you can also always run them manually via
`black . && isort .` in the flair root folder.
2 changes: 0 additions & 2 deletions MAINTAINERS

This file was deleted.

22 changes: 0 additions & 22 deletions Pipfile

This file was deleted.

Loading