Skip to content

Commit

Permalink
Boostrap the project
Browse files Browse the repository at this point in the history
  • Loading branch information
w0rp committed Nov 21, 2023
1 parent 74cc7f6 commit 4c1acae
Show file tree
Hide file tree
Showing 17 changed files with 1,293 additions and 1 deletion.
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: CI

on: # yamllint disable-line rule:truthy
push:
paths-ignore:
- README.md
- LICENSE
branches:
- '**'

jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
lfs: true
- name: Run tests
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
# Install poetry first, no virtualenv.
- run: pip install -r poetry.txt
- run: poetry config virtualenvs.create false
# Install dependencies with poetry.
- run: poetry install
- name: Run pytest
run: pytest
- name: Run Pyright
if: success() || failure()
run: pyright
- name: Run flake8
if: success() || failure()
run: flake8
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11.6
8 changes: 8 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
extends: default

ignore: |
.git
.venv
dist
build
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.11

WORKDIR /code

COPY ./pyproject.toml /code/pyproject.toml
COPY ./poetry.lock /code/poetry.lock
COPY ./poetry.txt /code/poetry.txt

RUN pip install --no-cache-dir -r poetry.txt
RUN poetry config virtualenvs.create false
RUN poetry install --only main

# Copy project directories after installation to use caching.
COPY ./densechat_api /code/densechat_api

EXPOSE 8000
CMD ["uvicorn", "densechat_api.api:app", "--host", "0.0.0.0", "--port", "8000"]
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# densechat-api
A RestAPI for densechat.ai

A RestAPI for [densechat.ai](https://densechat.ai).

## Development

Follow these steps to configure the project and run it locally.

1. Check that your Python version matches the project: `cat .python-version`
2. Install [poetry](https://python-poetry.org/): `python -m pip install -r poetry.txt`
3. Run poetry: `poetry install`

To update dependencies later, run `poetry update` and commit `poetry.lock`.
Empty file added densechat_api/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions densechat_api/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .main import app

__all__ = [
'app',
]
14 changes: 14 additions & 0 deletions densechat_api/api/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from fastapi import FastAPI
from starlette.responses import RedirectResponse

app = FastAPI(
title="densechat",
description="The Densechat API.",
version="0.1.0",
)


# Redirect / to /docs to make life easier for developers.
@app.get('/', include_in_schema=False)
async def index_view() -> RedirectResponse:
return RedirectResponse('/docs', 302)
Empty file added densechat_api/tests/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions densechat_api/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Configuration for all tests.
"""
3 changes: 3 additions & 0 deletions densechat_api/tests/test_nothing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# A dummy test.
def test_nothing():
pass
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
app:
build: .
command: uvicorn densechat_api.api:app --host 0.0.0.0 --port 8000 --reload
volumes:
- ./densechat_api:/code/densechat_api
ports:
- 8000:8000
restart: unless-stopped
1,119 changes: 1,119 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions poetry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Make poetry install files to ./.venv
[virtualenvs]
in-project = true
2 changes: 2 additions & 0 deletions poetry.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Install this file outside of virtualenv to set up poetry.
poetry>=1.7.0
56 changes: 56 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[tool.poetry]
name = "densechat-api"
version = "0.1.0"
description = "An AI Rest API: https://densechat.ai"
authors = ["Dense Analysis <[email protected]>"]

[build-system]
requires = ["poetry-core>=1.8.1"]
build-backend = "poetry.core.masonry.api"

# Base and Production-bound dependencies
[tool.poetry.dependencies]
python = "^3.11"
# The API libray itself.
fastapi = "^0.104.1"
# Needed for running FastAPI via ASGI.
uvicorn = {extras = ["standard"], version = "^0.22.0"}
# requests will be needed to contact other APIs.
requests = "^2.31.0"

# Dependencies just for developer machines and CI.
[tool.poetry.dev-dependencies]
# pytest and useful pytest libraries and tools.
pytest = "^7.4.0"
pytest-cov = "4.1.0"
pytest-mock = "3.11.1"
pytest-asyncio = "0.21.0"
requests-mock = "^1.7.0"
# Linting and fixing code.
flake8 = "6.0.0"
isort = "5.12.0"
flake8-isort = "6.1.0"
# Type checking.
pyright = "1.1.335"

# isort settings, for sorting imports.
[tool.isort]
multi_line_output = 3
known_first_party = "densechat_api"
skip = "migrations,.venv,typings"

# Settings for type checking.
[tool.pyright]
venvPath = "./"
venv = ".venv"
pythonVersion = "3.11"
reportMissingModuleSource = "error"
typeCheckingMode = "strict"

# Settings for pytest
[tool.pytest]
addopts = "--tb=short -vv"
filterwarnings = [
# Report unhandled async code errors.
"error::pytest.PytestUnhandledCoroutineWarning",
]
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# flake8 doesn't support pyproject.toml yet.
[flake8]
exclude = .git,__pycache__,.venv

0 comments on commit 4c1acae

Please sign in to comment.