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

refactor: update package strategy in rest_api #3148

Merged
merged 7 commits into from
Sep 5, 2022
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
2 changes: 1 addition & 1 deletion .github/utils/generate_openapi_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from rest_api.utils import get_openapi_specs, get_app, get_pipelines # pylint: disable=wrong-import-position
from haystack import __version__ # pylint: disable=wrong-import-position

REST_PATH = Path("./rest_api").absolute()
REST_PATH = Path("./rest_api/rest_api").absolute()
PIPELINE_PATH = str(REST_PATH / "pipeline" / "pipeline_empty.haystack-pipeline.yml")
APP_PATH = str(REST_PATH / "application.py")
DOCS_PATH = Path("./docs") / "_src" / "api" / "openapi"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:

- name: Pylint
run: |
pylint -ry -j 0 haystack/ rest_api/ ui/
pylint -ry -j 0 haystack/ rest_api/rest_api ui/

- uses: act10ns/slack@v1
with:
Expand Down
File renamed without changes.
72 changes: 72 additions & 0 deletions rest_api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "rest-api"
description = 'API server for Haystack (https://github.com/deepset-ai/haystack)'
readme = "README.md"
requires-python = ">=3.7"
license = "Apache-2.0"
keywords = []
authors = [
{ name = "deepset.ai", email = "malte.pietsch@deepset.ai" },
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
masci marked this conversation as resolved.
Show resolved Hide resolved
]
dependencies = [
"farm-haystack",
"fastapi<1",
"uvicorn<1",
"gunicorn<21",
"python-multipart<1", # optional FastAPI dependency for form data
]
dynamic = ["version"]

[project.urls]
Documentation = "https://github.com/unknown/rest-api#readme"
Issues = "https://github.com/unknown/rest-api/issues"
Source = "https://github.com/unknown/rest-api"
masci marked this conversation as resolved.
Show resolved Hide resolved

[tool.hatch.version]
path = "rest_api/__about__.py"
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, this is new!

I've googled it quickly and found some references in SO, but no official docs. Is it a style choice or something actually recommended for packages? I like it, and if it's a standard I'd like to see it in Haystack as well someday in place of the VERSION.txt file 🤩

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it's standard but it looks like a good practice. I got it from the default template used by hatch when you bootstrap a new project, it can be definitely ported to Haystack at some point


[tool.hatch.build.targets.sdist]
[tool.hatch.build.targets.wheel]

[tool.hatch.envs.default]
dependencies = [
"pytest",
"pytest-cov",
]
[tool.hatch.envs.default.scripts]
cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=rest_api --cov=tests"
no-cov = "cov --no-cov"

[[tool.hatch.envs.test.matrix]]
python = ["37", "38", "39", "310"]

[tool.coverage.run]
branch = true
parallel = true
omit = [
"rest_api/__about__.py",
]

[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]
10 changes: 10 additions & 0 deletions rest_api/rest_api/__about__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import logging

from pathlib import Path


__version__ = "0.0.0"
try:
__version__ = open(Path(__file__).parent.parent / "VERSION.txt", "r").read()
except Exception as e:
logging.exception("No VERSION.txt found!")
File renamed without changes.
File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Dict, Any

import collections
from collections.abc import Mapping
import logging
import time
import json
Expand Down Expand Up @@ -72,7 +72,7 @@ def _process_request(pipeline, request) -> Dict[str, Any]:

# format targeted node filters (e.g. "params": {"Retriever": {"filters": {"value"}}})
for key in params.keys():
if isinstance(params[key], collections.Mapping) and "filters" in params[key].keys():
if isinstance(params[key], Mapping) and "filters" in params[key].keys():
params[key]["filters"] = _format_filters(params[key]["filters"])

result = pipeline.run(query=request.query, params=params, debug=request.debug)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 0 additions & 45 deletions rest_api/setup.py

This file was deleted.