Skip to content

Commit

Permalink
refactor: Change project file structure
Browse files Browse the repository at this point in the history
The commit renames several files and directories in the project to adhere to a new naming convention. The changes include renaming the project directory, source files, configuration files, and documentation files. This refactor improves consistency and readability of the codebase.
  • Loading branch information
SakuraIsayeki committed Jul 19, 2023
1 parent 1786888 commit 1c03fae
Show file tree
Hide file tree
Showing 43 changed files with 92 additions and 106 deletions.
8 changes: 0 additions & 8 deletions wowskarma.api.minimap/.coveragerc

This file was deleted.

2 changes: 0 additions & 2 deletions wowskarma.api.minimap/mkdocs.yml

This file was deleted.

8 changes: 8 additions & 0 deletions wowskarma_api_minimap/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[run]
source = wowskarma_api_minimap

[report]
omit =
*/python?.?/*
*/site-packages/nose/*
wowskarma_api_minimap/__main__.py
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Lets take a look at the structure of this template:
├── Makefile # A collection of utilities to manage the project
├── MANIFEST.in # A list of files to include in a package
├── mkdocs.yml # Configuration for documentation site
├── wowskarma.api.minimap # The main python package for the project
├── wowskarma_api_minimap # The main python package for the project
│   ├── base.py # The base module for the project
│   ├── __init__.py # This tells Python that this is a package
│   ├── __main__.py # The entry point for the project
Expand Down Expand Up @@ -109,7 +109,7 @@ I had to do some tricks to read that version variable inside the setuptools
I decided to keep the version in a static file because it is easier to read from
wherever I want without the need to install the package.

e.g: `cat wowskarma.api.minimap/VERSION` will get the project version without harming
e.g: `cat wowskarma_api_minimap/VERSION` will get the project version without harming
with module imports or anything else, it is useful for CI, logs and debugging.

### Why to include `tests`, `history` and `Containerfile` as part of the release?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# How to develop on this project

wowskarma.api.minimap welcomes contributions from the community.
wowskarma_api_minimap welcomes contributions from the community.

**You need PYTHON3!**

This instructions are for linux base systems. (Linux, MacOS, BSD, etc.)
## Setting up your own fork of this repo.

- On github interface click on `Fork` button.
- Clone your fork of this repo. `git clone [email protected]:YOUR_GIT_USERNAME/wowskarma.api.minimap.git`
- Enter the directory `cd wowskarma.api.minimap`
- Add upstream repo `git remote add upstream https://github.com/SakuraIsayeki/wowskarma.api.minimap`
- Clone your fork of this repo. `git clone [email protected]:YOUR_GIT_USERNAME/wowskarma_api_minimap.git`
- Enter the directory `cd wowskarma_api_minimap`
- Add upstream repo `git remote add upstream https://github.com/SakuraIsayeki/wowskarma_api_minimap`

## Setting up your own virtual environment

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@

# Base Image for builder
FROM python:3.9 as builder
FROM python:3.10 as builder

# Install Requirements
COPY requirements.txt /
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /wheels -r requirements.txt


# Build the app image
FROM python:3.9
FROM python:3.10

# Create directory for the app user
RUN mkdir -p /home/app
Expand All @@ -33,4 +32,4 @@ RUN chown -R app:app $APP_HOME

USER app

CMD ["uvicorn", "wowskarma.api.minimap.app:app", "--host=0.0.0.0","--port=8000","--reload"]
CMD ["uvicorn", "src.app:app", "--host=0.0.0.0","--port=8000","--reload"]
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ lint: ## Run pep8, black, mypy linters.

.PHONY: test
test: lint ## Run tests and generate coverage report.
$(ENV_PREFIX)pytest -v --cov-config .coveragerc --cov=wowskarma.api.minimap -l --tb=short --maxfail=1 tests/
$(ENV_PREFIX)pytest -v --cov-config .coveragerc --cov=wowskarma_api_minimap -l --tb=short --maxfail=1 tests/
$(ENV_PREFIX)coverage xml
$(ENV_PREFIX)coverage html

Expand Down Expand Up @@ -101,15 +101,15 @@ switch-to-poetry: ## Switch to poetry package manager.
@poetry init --no-interaction --name=a_flask_test --author=rochacbruno
@echo "" >> pyproject.toml
@echo "[tool.poetry.scripts]" >> pyproject.toml
@echo "wowskarma.api.minimap = 'wowskarma.api.minimap.__main__:main'" >> pyproject.toml
@echo "wowskarma_api_minimap = 'wowskarma_api_minimap.__main__:main'" >> pyproject.toml
@cat requirements.txt | while read in; do poetry add --no-interaction "$${in}"; done
@cat requirements-test.txt | while read in; do poetry add --no-interaction "$${in}" --dev; done
@poetry install --no-interaction
@mkdir -p .github/backup
@mv requirements* .github/backup
@mv setup.py .github/backup
@echo "You have switched to https://python-poetry.org/ package manager."
@echo "Please run 'poetry shell' or 'poetry run wowskarma.api.minimap'"
@echo "Please run 'poetry shell' or 'poetry run wowskarma_api_minimap'"

.PHONY: init
init: ## Initialize the project based on an application template.
Expand All @@ -118,27 +118,27 @@ init: ## Initialize the project based on an application template.
.PHONY: shell
shell: ## Open a shell in the project.
@if [ "$(USING_POETRY)" ]; then poetry shell; exit; fi
@./.venv/bin/ipython -c "from wowskarma.api.minimap import *"
@./.venv/bin/ipython -c "from wowskarma_api_minimap import *"

.PHONY: docker-build
docker-build: ## Builder docker images
@docker-compose -f docker-compose-dev.yaml -p wowskarma.api.minimap build
@docker-compose -f docker-compose-dev.yaml -p wowskarma_api_minimap build

.PHONY: docker-run
docker-run: ## Run docker development images
@docker-compose -f docker-compose-dev.yaml -p wowskarma.api.minimap up -d
@docker-compose -f docker-compose-dev.yaml -p wowskarma_api_minimap up -d

.PHONY: docker-stop
docker-stop: ## Bring down docker dev environment
@docker-compose -f docker-compose-dev.yaml -p wowskarma.api.minimap down
@docker-compose -f docker-compose-dev.yaml -p wowskarma_api_minimap down

.PHONY: docker-ps
docker-ps: ## Bring down docker dev environment
@docker-compose -f docker-compose-dev.yaml -p wowskarma.api.minimap ps
@docker-compose -f docker-compose-dev.yaml -p wowskarma_api_minimap ps

.PHONY: docker-log
docker-logs: ## Bring down docker dev environment
@docker-compose -f docker-compose-dev.yaml -p wowskarma.api.minimap logs -f app
@docker-compose -f docker-compose-dev.yaml -p wowskarma_api_minimap logs -f app

# This project has been generated from rochacbruno/fastapi-project-template
# __author__ = 'rochacbruno'
Expand Down
66 changes: 33 additions & 33 deletions wowskarma.api.minimap/README.md → wowskarma_api_minimap/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# WOWS Karma - Minimap API

[![codecov](https://codecov.io/gh/SakuraIsayeki/wowskarma.api.minimap/branch/main/graph/badge.svg?token=wowskarma.api.minimap_token_here)](https://codecov.io/gh/SakuraIsayeki/wowskarma.api.minimap)
[![CI](https://github.com/SakuraIsayeki/wowskarma.api.minimap/actions/workflows/main.yml/badge.svg)](https://github.com/SakuraIsayeki/wowskarma.api.minimap/actions/workflows/main.yml)
[![codecov](https://codecov.io/gh/SakuraIsayeki/wowskarma_api_minimap/branch/main/graph/badge.svg?token=wowskarma_api_minimap_token_here)](https://codecov.io/gh/SakuraIsayeki/wowskarma_api_minimap)
[![CI](https://github.com/SakuraIsayeki/wowskarma_api_minimap/actions/workflows/main.yml/badge.svg)](https://github.com/SakuraIsayeki/wowskarma_api_minimap/actions/workflows/main.yml)

Standalone Minimap rendering microservice to render World of Warships replays.

Expand All @@ -10,39 +10,39 @@ Standalone Minimap rendering microservice to render World of Warships replays.
from source
```bash
git clone https://github.com/SakuraIsayeki/WOWS-Karma wows-karma
cd wows-karma/wowskarma.api.minimap
cd wows-karma/wowskarma_api_minimap
make install
```

from pypi

```bash
pip install wowskarma.api.minimap
pip install wowskarma_api_minimap
```

## Executing

```bash
$ wowskarma.api.minimap run --port 8080
$ wowskarma_api_minimap run --port 8080
```

or

```bash
python -m wowskarma.api.minimap run --port 8080
python -m wowskarma_api_minimap run --port 8080
```

or

```bash
$ uvicorn wowskarma.api.minimap:app
$ uvicorn wowskarma_api_minimap:app
```

## CLI

```bash
wowskarma.api.minimap --help
Usage: wowskarma.api.minimap [OPTIONS] COMMAND [ARGS]...
wowskarma_api_minimap --help
Usage: wowskarma_api_minimap [OPTIONS] COMMAND [ARGS]...

Options:
--install-completion [bash|zsh|fish|powershell|pwsh]
Expand All @@ -61,7 +61,7 @@ Commands:
### Creating a user

```bash
wowskarma.api.minimap create-user --help
wowskarma_api_minimap create-user --help
Usage: src create-user [OPTIONS] USERNAME PASSWORD

Create user
Expand All @@ -78,15 +78,15 @@ Options:
**IMPORTANT** To create an admin user on the first run:

```bash
wowskarma.api.minimap create-user admin admin --superuser
wowskarma_api_minimap create-user admin admin --superuser
```

### The Shell

You can enter an interactive shell with all the objects imported.

```bash
wowskarma.api.minimap shell
wowskarma_api_minimap shell
Auto imports: ['app', 'settings', 'User', 'engine', 'cli', 'create_user', 'select', 'session', 'Content']

In [1]: session.query(Content).all()
Expand All @@ -100,12 +100,12 @@ Out[3]: [Content(text='string', title='string', created_time='2021-09-14T19:25:0

## API

Run with `wowskarma.api.minimap run` and access http://127.0.0.1:8000/docs
Run with `wowskarma_api_minimap run` and access http://127.0.0.1:8000/docs

![](https://raw.githubusercontent.com/rochacbruno/fastapi-project-template/master/docs/api.png)


**For some api calls you must authenticate** using the user created with `wowskarma.api.minimap create-user`.
**For some api calls you must authenticate** using the user created with `wowskarma_api_minimap create-user`.

## Testing

Expand Down Expand Up @@ -138,18 +138,18 @@ tests/test_user_api.py::test_user_create PASSED [100%]
----------- coverage: platform linux, python 3.9.6-final-0 -----------
Name Stmts Miss Cover
-----------------------------------------------------
wowskarma.api.minimap/__init__.py 4 0 100%
wowskarma.api.minimap/app.py 16 1 94%
wowskarma.api.minimap/cli.py 21 0 100%
wowskarma.api.minimap/config.py 5 0 100%
wowskarma.api.minimap/db.py 10 0 100%
wowskarma.api.minimap/models/__init__.py 0 0 100%
wowskarma.api.minimap/models/content.py 47 1 98%
wowskarma.api.minimap/routes/__init__.py 11 0 100%
wowskarma.api.minimap/routes/content.py 52 25 52%
wowskarma.api.minimap/routes/security.py 15 1 93%
wowskarma.api.minimap/routes/user.py 52 26 50%
wowskarma.api.minimap/security.py 103 12 88%
wowskarma_api_minimap/__init__.py 4 0 100%
wowskarma_api_minimap/app.py 16 1 94%
wowskarma_api_minimap/cli.py 21 0 100%
wowskarma_api_minimap/config.py 5 0 100%
wowskarma_api_minimap/db.py 10 0 100%
wowskarma_api_minimap/models/__init__.py 0 0 100%
wowskarma_api_minimap/models/content.py 47 1 98%
wowskarma_api_minimap/routes/__init__.py 11 0 100%
wowskarma_api_minimap/routes/content.py 52 25 52%
wowskarma_api_minimap/routes/security.py 15 1 93%
wowskarma_api_minimap/routes/user.py 52 26 50%
wowskarma_api_minimap/security.py 103 12 88%
-----------------------------------------------------
TOTAL 336 66 80%

Expand All @@ -171,7 +171,7 @@ make fmt # formats the code
This project uses [Dynaconf](https://dynaconf.com) to manage configuration.

```py
from wowskarma.api.minimap.config import settings
from wowskarma_api_minimap.config import settings
```

## Acessing variables
Expand Down Expand Up @@ -200,14 +200,14 @@ dynaconf_merge = true
echo = true
```

> `dynaconf_merge` is a boolean that tells if the settings should be merged with the default settings defined in wowskarma.api.minimap/default.toml.
> `dynaconf_merge` is a boolean that tells if the settings should be merged with the default settings defined in wowskarma_api_minimap/default.toml.
### As environment variables
```bash
export wowskarma.api.minimap_KEY=value
export wowskarma.api.minimap_KEY="@int 42"
export wowskarma.api.minimap_KEY="@jinja {{ this.db.uri }}"
export wowskarma.api.minimap_DB__uri="@jinja {{ this.db.uri | replace('db', 'data') }}"
export wowskarma_api_minimap_KEY=value
export wowskarma_api_minimap_KEY="@int 42"
export wowskarma_api_minimap_KEY="@jinja {{ this.db.uri }}"
export wowskarma_api_minimap_DB__uri="@jinja {{ this.db.uri | replace('db', 'data') }}"
```

### Secrets
Expand All @@ -221,7 +221,7 @@ can read those variables.
### Switching environments

```bash
wowskarma.api.minimap_ENV=production wowskarma.api.minimap run
wowskarma_api_minimap_ENV=production wowskarma_api_minimap run
```

Read more on https://dynaconf.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ services:
ports:
- "8000:8000"
environment:
- wowskarma.api.minimap_DB__uri=postgresql://postgres:postgres@db:5432/src
- wowskarma.api.minimap_DB__connect_args={}
- wowskarma_api_minimap_DB__uri=postgresql://postgres:postgres@db:5432/wowskarma_api_minimap_dev
- wowskarma_api_minimap_DB__connect_args={}
volumes:
- .:/home/app/web
depends_on:
- db
db:
build: postgres
image: wowskarma.api.minimap_postgres-13-alpine-multi-user
image: wowskarma_api_minimap_postgres-13-alpine-multi-user
volumes:
- $HOME/.postgres/wowskarma.api.minimap_db/data/postgresql:/var/lib/postgresql/data
- $HOME/.postgres/wowskarma_api_minimap_db/data/postgresql:/var/lib/postgresql/data
ports:
- 5435:5432
environment:
- POSTGRES_DBS=src, wowskarma.api.minimap_test
- POSTGRES_DBS=wowskarma_api_minimap_dev
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
File renamed without changes
File renamed without changes.
2 changes: 2 additions & 0 deletions wowskarma_api_minimap/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
site_name: wowskarma_api_minimap
theme: readthedocs
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@ def read_requirements(path):


setup(
name="wowskarma.api.minimap",
version=read("wowskarma.api.minimap", "VERSION"),
description="Awesome src created by SakuraIsayeki",
url="https://github.com/SakuraIsayeki/wowskarma.api.minimap/",
name="wowskarma_api_minimap",
version=read("src", "VERSION"),
description="Standalone Minimap rendering microservice to render World of Warships replays.",
url="https://github.com/SakuraIsayeki/WOWS-Karma/",
long_description=read("README.md"),
long_description_content_type="text/markdown",
author="SakuraIsayeki",
packages=find_packages(exclude=["tests", ".github"]),
install_requires=read_requirements("requirements.txt"),
entry_points={
"console_scripts": ["wowskarma.api.minimap = wowskarma.api.minimap.__main__:main"]
}
entry_points={"console_scripts": ["wowskarma_api_minimap = src.__main__:main"]},
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,13 @@ def read(*paths, **kwargs):
"""

app = FastAPI(
title="src",
title="wowskarma_api_minimap",
description=description,
version=read("VERSION"),
terms_of_service="http://wowskarma.api.minimap.com/terms/",
contact={
"name": "SakuraIsayeki",
"url": "http://wowskarma.api.minimap.com/contact/",
"email": "[email protected]",
},
license_info={
"name": "The Unlicense",
"url": "https://unlicense.org",
"name": "Sakura Isayeki",
"url": "https://github.com/SakuraIsayeki",
"email": "[email protected]",
},
)

Expand Down
Loading

0 comments on commit 1c03fae

Please sign in to comment.