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

Run tests against fondant package with tox #283

Merged
merged 7 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
23 changes: 4 additions & 19 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,11 @@ jobs:
run: |
pip install --upgrade pip
pip install poetry==1.4.0
poetry install --all-extras
- name: Test with pre-commit
run: poetry run pre-commit run --all-files --show-diff-on-failure
- name: Check licenses
run: |
poetry export -f requirements.txt --output /tmp/requirements.txt
poetry run liccheck -s license_strategy.ini -r /tmp/requirements.txt -l PARANOID
- name: Shadow-run pylint
# Check if pylint catches errors not caught by our pre-commit checks to validate switch
# to ruff
run: |
pip install pylint==2.16.4
pylint fondant --exit-zero
- name: Test with pytest
run: |
poetry run pytest tests --cov fondant --cov-report term-missing
poetry install --all-extras --with test
- name: Test with tox
run: poetry run tox
- name: Coveralls
run: |
pip install "coveralls<4"
coveralls --service github
run: poetry run coveralls --service github
env:
COVERALLS_PARALLEL: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 1 addition & 2 deletions components/caption_images/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import numpy as np
import pandas as pd
import torch
from fondant.component import PandasTransformComponent
from PIL import Image
from transformers import BatchEncoding, BlipForConditionalGeneration, BlipProcessor

from fondant.component import PandasTransformComponent

logger = logging.getLogger(__name__)


Expand Down
3 changes: 1 addition & 2 deletions components/download_images/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
import urllib

import dask.dataframe as dd
from resizer import Resizer

from fondant.component import DaskTransformComponent
from resizer import Resizer

logger = logging.getLogger(__name__)

Expand Down
1 change: 0 additions & 1 deletion components/embedding_based_laion_retrieval/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import pandas as pd
from clip_client import ClipClient, Modality

from fondant.component import PandasTransformComponent

logger = logging.getLogger(__name__)
Expand Down
3 changes: 1 addition & 2 deletions components/filter_comments/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import logging

import dask.dataframe as dd
from utils.text_extraction import get_comments_to_code_ratio

from fondant.component import DaskTransformComponent
from utils.text_extraction import get_comments_to_code_ratio

logger = logging.getLogger(__name__)

Expand Down
1 change: 0 additions & 1 deletion components/filter_image_resolution/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import numpy as np
import pandas as pd

from fondant.component import PandasTransformComponent

logger = logging.getLogger(__name__)
Expand Down
1 change: 0 additions & 1 deletion components/filter_line_length/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging

import dask.dataframe as dd

from fondant.component import DaskTransformComponent

logger = logging.getLogger(__name__)
Expand Down
3 changes: 1 addition & 2 deletions components/image_cropping/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

import dask.dataframe as dd
import numpy as np
from fondant.component import DaskTransformComponent
from image_crop import remove_borders
from PIL import Image

from fondant.component import DaskTransformComponent

logger = logging.getLogger(__name__)


Expand Down
3 changes: 1 addition & 2 deletions components/image_embedding/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import numpy as np
import pandas as pd
import torch
from fondant.component import PandasTransformComponent
from PIL import Image
from transformers import CLIPProcessor, CLIPVisionModelWithProjection

from fondant.component import PandasTransformComponent

logger = logging.getLogger(__name__)


Expand Down
1 change: 0 additions & 1 deletion components/image_resolution_extraction/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import imagesize
import numpy as np
import pandas as pd

from fondant.component import PandasTransformComponent

logger = logging.getLogger(__name__)
Expand Down
1 change: 0 additions & 1 deletion components/language_filter/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import fasttext
import pandas as pd

from fondant.component import PandasTransformComponent

logger = logging.getLogger(__name__)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Unit test for language filter component."""
import pandas as pd
from fondant.component_spec import ComponentSpec

from components.language_filter.src.main import LanguageFilterComponent
from fondant.component_spec import ComponentSpec


def test_run_component_test():
Expand Down
1 change: 0 additions & 1 deletion components/load_from_hf_hub/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import typing as t

import dask.dataframe as dd

from fondant.component import LoadComponent

logger = logging.getLogger(__name__)
Expand Down
3 changes: 1 addition & 2 deletions components/pii_redaction/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import logging

import dask.dataframe as dd
from fondant.component import DaskTransformComponent
from pii_detection import scan_pii
from pii_redaction import redact_pii

from fondant.component import DaskTransformComponent

logger = logging.getLogger(__name__)


Expand Down
1 change: 0 additions & 1 deletion components/prompt_based_laion_retrieval/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import pandas as pd
from clip_client import ClipClient, Modality

from fondant.component import PandasTransformComponent

logger = logging.getLogger(__name__)
Expand Down
3 changes: 1 addition & 2 deletions components/segment_images/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
import numpy as np
import pandas as pd
import torch
from fondant.component import PandasTransformComponent
from palette import palette
from PIL import Image
from transformers import AutoModelForSemanticSegmentation, BatchFeature, SegformerImageProcessor

from fondant.component import PandasTransformComponent

logger = logging.getLogger(__name__)


Expand Down
1 change: 0 additions & 1 deletion components/text_normalization/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import List

import pandas as pd

from fondant.component import PandasTransformComponent

logger = logging.getLogger(__name__)
Expand Down
3 changes: 1 addition & 2 deletions components/write_to_hf_hub/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
# Define the schema for the struct using PyArrow
import huggingface_hub
from datasets.features.features import generate_from_arrow_type
from PIL import Image

from fondant.component import WriteComponent
from PIL import Image

logger = logging.getLogger(__name__)

Expand Down
1 change: 0 additions & 1 deletion fondant/components

This file was deleted.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ pandas = { version = ">= 1.3.5", optional = true }
pipelines = ["kfp", "kubernetes"]

[tool.poetry.group.test.dependencies]
liccheck = "^0.7.3"
pre-commit = "^3.1.1"
pytest = "^7.2.2"
pytest-cov = "^4.1.0"
tox = "^4.6.4"
tox-gh-actions = "^3.1.3"
coveralls = "^3.3.1"

[tool.poetry.group.docs.dependencies]
mkdocs-material = "^9.1.8"
Expand Down
6 changes: 3 additions & 3 deletions scripts/pre-build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# This script copies the components/ directory to fondant/components, replacing the symlink
# This script copies the components/ directory to src/fondant/components, replacing the symlink
# It should be run before building the fondant package'
# This script makes changes to the local files, which should not be committed to git
set -e
Expand All @@ -8,6 +8,6 @@ scripts_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
root_path=$(dirname "$scripts_path")

pushd "$root_path"
rm fondant/components
cp -r components/ fondant/
rm -rf src/fondant/components
cp -r components/ src/fondant/
popd
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from unittest.mock import patch

import pytest

from fondant.cli import ImportFromStringError, compile, pipeline_from_string, run
from fondant.pipeline import Pipeline

Expand Down
1 change: 0 additions & 1 deletion tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import pytest
import yaml

from fondant.compiler import DockerCompiler
from fondant.pipeline import ComponentOp, Pipeline

Expand Down
1 change: 0 additions & 1 deletion tests/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import pandas as pd
import pytest
import yaml

from fondant.component import (
Component,
DaskTransformComponent,
Expand Down
1 change: 0 additions & 1 deletion tests/test_component_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import pytest
import yaml

from fondant.component_spec import ComponentSpec, ComponentSubset, KubeflowComponentSpec
from fondant.exceptions import InvalidComponentSpec
from fondant.schema import Type
Expand Down
1 change: 0 additions & 1 deletion tests/test_data_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import dask.dataframe as dd
import pytest

from fondant.component_spec import ComponentSpec
from fondant.data_io import DaskDataLoader, DaskDataWriter
from fondant.manifest import Manifest
Expand Down
1 change: 0 additions & 1 deletion tests/test_import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from unittest import mock

import pytest

from fondant.import_utils import (
is_datasets_available,
is_kfp_available,
Expand Down
1 change: 0 additions & 1 deletion tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from pathlib import Path

import pytest

from fondant.exceptions import InvalidManifest
from fondant.manifest import Field, Index, Manifest, Subset, Type

Expand Down
1 change: 0 additions & 1 deletion tests/test_manifest_evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import pytest
import yaml

from fondant.component_spec import ComponentSpec
from fondant.manifest import Manifest

Expand Down
1 change: 0 additions & 1 deletion tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import pytest
import yaml

from fondant.exceptions import InvalidPipelineDefinition
from fondant.pipeline import ComponentOp, ComponentSpec, Pipeline

Expand Down
1 change: 0 additions & 1 deletion tests/test_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pyarrow as pa
import pytest

from fondant.exceptions import InvalidTypeSchema
from fondant.schema import Type

Expand Down
42 changes: 42 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[tox]
isolated_build = True
envlist =
pre-commit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do these dependencies only get built when running tox then? does it automatically invoke pip install on them since we no longer have them in the pyproject.toml

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, installs in this file are only installed by tox when executing the related environment. If a dependency is only needed for a single environment type, I moved them from pyproject.toml to here, and I added tox to pyproject.toml.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright thanks for the clarification

check-licenses
py{38,39,310,311}

[gh-actions]
python =
3.8: py38
3.9: py39
3.10: pre-commit,check-licenses, py310
3.11: py311

[testenv:pre-commit]
deps=pre-commit
commands=pre-commit run --all-files --show-diff-on-failure

[testenv:check-licenses]
deps=
liccheck==0.7.3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have soft dependency versions here like we had in pyproject.toml? (same for pytest, and pytest-cov)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Updated.

commands=
poetry lock
poetry install --all-extras
poetry show
poetry export -f requirements.txt --output /tmp/requirements.txt
poetry run liccheck -s license_strategy.ini -r /tmp/requirements.txt -l PARANOID

[testenv]
setenv=PYTHONPATH = {toxinidir}:{toxinidir}
deps=
pytest==7.4.0
pytest-cov==4.1.0
allowlist_externals=
poetry
/usr/bin/bash
commands=
bash ./scripts/pre-build.sh
poetry lock
poetry install --all-extras
poetry show
poetry run python -m pytest tests --cov fondant --cov-report term-missing