diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..51b50a0 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 100 \ No newline at end of file diff --git a/.github/workflows/github-actions-ci.yml b/.github/workflows/github-actions-ci.yml index ede2434..1bb234d 100644 --- a/.github/workflows/github-actions-ci.yml +++ b/.github/workflows/github-actions-ci.yml @@ -16,8 +16,8 @@ jobs: steps: - name: Check out repository code uses: actions/checkout@v3 - - name: Build Image - run: make ci-build + - name: Build Dev Image + run: make ci-build-dev - name: Linting run: make ci-lint - name: Unit Test diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..df2df48 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,6 @@ +[MESSAGES CONTROL] +disable= + missing-docstring, + too-few-public-methods, + too-many-arguments, + too-many-public-methods diff --git a/Dockerfile b/Dockerfile index f8e3cfb..15abdaf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ FROM python:3.8-slim +ARG install_dev=n COPY requirements.build.txt ./ RUN pip install --disable-pip-version-check \ @@ -8,7 +9,17 @@ COPY requirements.txt ./ RUN pip install --disable-pip-version-check \ -r requirements.txt +COPY requirements.dev.txt ./ +RUN if [ "${install_dev}" = "y" ]; then \ + pip install --disable-pip-version-check --user \ + -r requirements.txt \ + -r requirements.dev.txt; \ + fi + COPY spacy_keyword_extraction_api ./spacy_keyword_extraction_api COPY static ./static +COPY tests ./tests + +COPY .flake8 .pylintrc ./ CMD ["python3", "-m", "uvicorn", "spacy_keyword_extraction_api.main:create_app", "--factory", "--host", "0.0.0.0", "--port", "8000"] diff --git a/Makefile b/Makefile index 2ad4404..851deb0 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,29 @@ DOCKER_COMPOSE = $(DOCKER_COMPOSE_DEV) build: $(DOCKER_COMPOSE) build spacy-keyword-extraction-api +build-dev: + $(DOCKER_COMPOSE) build spacy-keyword-extraction-api-dev + +flake8: + $(DOCKER_COMPOSE) run --rm spacy-keyword-extraction-api-dev \ + python -m flake8 spacy_keyword_extraction_api tests + +pylint: + $(DOCKER_COMPOSE) run --rm spacy-keyword-extraction-api-dev \ + python -m pylint spacy_keyword_extraction_api tests + +mypy: + $(DOCKER_COMPOSE) run --rm spacy-keyword-extraction-api-dev \ + python -m mypy spacy_keyword_extraction_api tests + +lint: flake8 pylint mypy + +pytest: + $(DOCKER_COMPOSE) run --rm spacy-keyword-extraction-api-dev \ + python -m pytest spacy_keyword_extraction_api tests + +test: lint pytest + start: $(DOCKER_COMPOSE) up -d spacy-keyword-extraction-api @@ -22,8 +45,11 @@ logs: ci-build: $(MAKE) DOCKER_COMPOSE="$(DOCKER_COMPOSE_CI)" build +ci-build-dev: + $(MAKE) DOCKER_COMPOSE="$(DOCKER_COMPOSE_CI)" build-dev + ci-lint: - echo "Dummy lint" + $(MAKE) DOCKER_COMPOSE="$(DOCKER_COMPOSE_CI)" lint ci-unittest: - echo "Dummy unittest" + $(MAKE) DOCKER_COMPOSE="$(DOCKER_COMPOSE_CI)" pytest diff --git a/docker-compose.yml b/docker-compose.yml index 07b3a64..07d9439 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,3 +4,13 @@ services: context: . dockerfile: Dockerfile image: ${IMAGE_REPO}:${IMAGE_TAG} + + spacy-keyword-extraction-api-dev: + build: + context: . + dockerfile: Dockerfile + args: + install_dev: y + image: ${IMAGE_REPO}-dev:${IMAGE_TAG} + command: /bin/sh -c exit 0 + entrypoint: [] diff --git a/requirements.dev.txt b/requirements.dev.txt new file mode 100644 index 0000000..2d4b04b --- /dev/null +++ b/requirements.dev.txt @@ -0,0 +1,4 @@ +flake8==7.1.1 +pylint==3.2.7 +pytest==8.3.3 +mypy==1.11.2 diff --git a/tests/unit_test/__init__.py b/tests/unit_test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit_test/main_test.py b/tests/unit_test/main_test.py new file mode 100644 index 0000000..95a65da --- /dev/null +++ b/tests/unit_test/main_test.py @@ -0,0 +1,9 @@ +from fastapi.testclient import TestClient + +from spacy_keyword_extraction_api.main import create_app + + +def test_read_main(): + client = TestClient(create_app()) + response = client.get("/") + assert response.status_code == 200