Skip to content

Commit

Permalink
Merge pull request #1 from kscalelabs/fastapi-base
Browse files Browse the repository at this point in the history
fastapi base
  • Loading branch information
codekansas committed May 20, 2024
2 parents 2a790cc + ee6c50f commit 7dd7b56
Show file tree
Hide file tree
Showing 42 changed files with 19,540 additions and 76 deletions.
3 changes: 3 additions & 0 deletions .darglint
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[darglint]

docstring_style=google
Empty file added .env
Empty file.
47 changes: 47 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Publish Python Package

on:
release:
types: [created]
workflow_dispatch:

permissions:
contents: read
id-token: write

concurrency:
group: "publish"
cancel-in-progress: true

jobs:
publish:
timeout-minutes: 10
name: Build and publish

# We don't need to run on all platforms since this package is
# platform-agnostic. The output wheel is something like
# "monotonic_attention-<version>-py3-none-any.whl".
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build wheel
- name: Build package
run: python -m build --sdist --wheel --outdir dist/ .

- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
# with:
# user: __token__
# password: ${{ secrets.PYPI_API_TOKEN }}
43 changes: 0 additions & 43 deletions .github/workflows/static.yml

This file was deleted.

85 changes: 85 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Python Checks

on:
push:
branches:
- master
pull_request:
branches:
- master
types:
- opened
- reopened
- synchronize
- ready_for_review

concurrency:
group: tests-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
run-tests:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "20"

- name: Restore cache
id: restore-cache
uses: actions/cache/restore@v3
with:
path: |
${{ env.pythonLocation }}
.mypy_cache/
node_modules/
key: tests-${{ github.event.pull_request.base.sha || github.sha }}
restore-keys: |
tests-
- name: Install Node package
working-directory: frontend
run: |
npm install
- name: Run tests
working-directory: frontend
run: |
npm test -- --watchAll=false
- name: Build frontend
run: |
npm run build
working-directory: frontend

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install Python package
run: |
pip install --upgrade --upgrade-strategy eager -e '.[dev]'
- name: Run static checks
run: |
mkdir -p .mypy_cache
make static-checks
- name: Run unit tests
run: |
make test
- name: Save cache
uses: actions/cache/save@v3
if: github.ref == 'refs/heads/master'
with:
path: |
${{ env.pythonLocation }}
.mypy_cache/
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# .gitignore

# Python
*.py[oc]
__pycache__/
*.egg-info
.eggs/
.mypy_cache/*
.pyre/
.pytest_cache/
.ruff_cache/
.dmypy.json

# Databases
*.db

# Build artifacts
build/
dist/
*.so
out*/

# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Benjamin Bolte

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include store/ *.py *.txt py.typed MANIFEST.in
66 changes: 66 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Makefile

define HELP_MESSAGE
store

# Installing

1. Create a new Conda environment: `conda create --name store python=3.11`
2. Activate the environment: `conda activate store`
3. Install the package: `make install-dev`

# Running Tests

1. Run autoformatting: `make format`
2. Run static checks: `make static-checks`
3. Run unit tests: `make test`

endef
export HELP_MESSAGE

all:
@echo "$$HELP_MESSAGE"
.PHONY: all

# ------------------------ #
# Build #
# ------------------------ #

install:
@pip install --verbose -e .
.PHONY: install

install-dev:
@pip install --verbose -e '.[dev]'
.PHONY: install

build-ext:
@python setup.py build_ext --inplace
.PHONY: build-ext

clean:
rm -rf build dist *.so **/*.so **/*.pyi **/*.pyc **/*.pyd **/*.pyo **/__pycache__ *.egg-info .eggs/ .ruff_cache/
.PHONY: clean

# ------------------------ #
# Static Checks #
# ------------------------ #

format:
@black store
@ruff format store
.PHONY: format

static-checks:
@black --diff --check store
@ruff check store
@mypy --install-types --non-interactive store
.PHONY: lint

# ------------------------ #
# Unit tests #
# ------------------------ #

test:
python -m pytest
.PHONY: test
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# store

This is the code for our online store. This is a simple store for buying and selling humanoid robots.

## Frontend

To develop just the frontend, see the [frontend README](../frontend/README.md).

## Full

To develop the full stack, start FastAPI and React in separate terminals:

### FastAPI

Serve the FastAPI application in development mode:

```bash
fastapi dev 'store/app/main.py'
```

### React

Automatically rebuild the React frontend code when a file is changed:

```bash
cd frontend
npm watch
```
12 changes: 12 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Dockerfile

FROM python:3.11-slim

WORKDIR /app

# Copies files and installs the project.
ADD . /app
RUN pip install .

# Runs the application.
CMD ["uvicorn", "store.app.main:app", "--host", "0.0.0.0", "--port", "80"]
23 changes: 23 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
25 changes: 25 additions & 0 deletions frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frontend

This is the frontend of the project, which builds a static website using React.

## Setup

Install requirements:

```bash
cd frontend # This directory
nvm use 20.10.0
npm install
```

Start server:

```bash
npm start
```

Build static files:

```bash
npm run build
```
5 changes: 5 additions & 0 deletions frontend/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"watch": ["src"],
"ext": "js,jsx,ts,tsx,css,html",
"exec": "npm run build"
}
Loading

0 comments on commit 7dd7b56

Please sign in to comment.