Skip to content

Add poetry #85

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

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8685c87
add echo as an extra param to allow disabling logs from db
itay-dar-lmnd Jul 24, 2024
86e90c3
Merge pull request #1 from itay-dar-lmnd/feature_allow_disable_orm_logs
itay-dar-lmnd Jul 24, 2024
ea672f4
Merge remote-tracking branch 'upstream/main'
itay-dar-lmnd Sep 15, 2024
d9469bb
refactor project structure. apply decoupling between pynest and fasta…
itay-dar-lmnd Oct 31, 2024
070dd7d
fix examples according to new project structure
itay-dar-lmnd Oct 31, 2024
2cd4f6e
fix unit tests to match new project structure
itay-dar-lmnd Oct 31, 2024
64b6cd6
fix cli templates to work with the new project structure
itay-dar-lmnd Oct 31, 2024
fd4e764
fix cli ro work with new file structure
itay-dar-lmnd Oct 31, 2024
f0980ea
fix docs
itay-dar-lmnd Oct 31, 2024
517f6a7
remove unused files
itay-dar-lmnd Oct 31, 2024
ccc2462
fix core components
itay-dar-lmnd Oct 31, 2024
f9e5cc3
migrate project from setuptools and pip to poetry!
itay-dar-lmnd Oct 31, 2024
01071d9
refactor Duplicate Module class name for better maintainabillity
itay-dar-lmnd Oct 31, 2024
7f689e7
run black
itay-dar-lmnd Oct 31, 2024
2dec5b3
fix imports error
itay-dar-lmnd Oct 31, 2024
caa39af
fix github actions
itay-dar-lmnd Oct 31, 2024
0386af5
fix github actions
itay-dar-lmnd Oct 31, 2024
6d5bc74
fix github actions
itay-dar-lmnd Oct 31, 2024
663da03
fix github actions
itay-dar-lmnd Oct 31, 2024
155189e
fix github actions
itay-dar-lmnd Oct 31, 2024
1089093
fix async orm template
itay-dar-lmnd Oct 31, 2024
5532823
make deploy docs work with poetry
itay-dar-lmnd Nov 1, 2024
17cabb8
fix docs
itay-dar-lmnd Dec 4, 2024
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
34 changes: 16 additions & 18 deletions .github/workflows/cli_test.yaml
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
name: CLI Test

on: [ push, workflow_call, pull_request ]
on: [push, workflow_call, pull_request]

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
app_type: [ "Blank", "SyncORM", "AsyncORM", "MongoDB", "PostgresSync", "PostgresAsync", "MySQLSync", "MySQLAsync" ]
app_type: ["Blank", "SyncORM", "AsyncORM", "MongoDB", "PostgresSync", "PostgresAsync", "MySQLSync", "MySQLAsync"]

steps:
- name: Check out repository code
uses: actions/checkout@v2
uses: actions/checkout@v3

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

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
pip install poetry
poetry install

- name: Test CLI Commands
run: |
app_name="${{ matrix.app_type }}App"
case "${{ matrix.app_type }}" in
"Blank")
pynest generate application -n "$app_name"
poetry run pynest generate application -n "$app_name"
;;
"SyncORM")
pynest generate application -n "$app_name" -db sqlite
poetry run pynest generate application -n "$app_name" -db sqlite
;;
"AsyncORM")
pynest generate application -n "$app_name" -db sqlite --is-async
poetry run pynest generate application -n "$app_name" -db sqlite --is-async
;;
"MongoDB")
pynest generate application -n "$app_name" -db mongodb
poetry run pynest generate application -n "$app_name" -db mongodb
;;
"PostgresSync")
pynest generate application -n "$app_name" -db postgresql
poetry run pynest generate application -n "$app_name" -db postgresql
;;
"PostgresAsync")
pynest generate application -n "$app_name" -db postgresql --is-async
poetry run pynest generate application -n "$app_name" -db postgresql --is-async
;;
"MySQLSync")
pynest generate application -n "$app_name" -db mysql
poetry run pynest generate application -n "$app_name" -db mysql
;;
"MySQLAsync")
pynest generate application -n "$app_name" -db mysql --is-async
poetry run pynest generate application -n "$app_name" -db mysql --is-async
;;
esac

cd "$app_name"
pynest generate resource -n user
poetry run pynest generate resource -n user

- name: Verify Boilerplate
run: |
Expand All @@ -74,7 +74,6 @@ jobs:
exit 1
fi


# List of expected files
declare -a files=("main.py" "requirements.txt" "README.md")
declare -a src_level_files=("app_module.py" "app_service.py" "app_controller.py")
Expand All @@ -100,7 +99,6 @@ jobs:
fi
done


# Check each file in the list of module_files
for file in "${module_files[@]}"; do
if [ -f "$app_name/src/user/$file" ]; then
Expand Down
12 changes: 5 additions & 7 deletions .github/workflows/deploy_docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ name: Deploy Docs

on: [workflow_call, workflow_dispatch]

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true
Expand All @@ -27,15 +25,15 @@ jobs:
- name: Copy License File
run: cp LICENSE docs/license.md

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

- name: Install MKDocs
- name: Install dependencies
run: |
pip install --upgrade pip
pip install mkdocs-material mkdocstrings-python
pip install poetry
poetry install --with docs

- name: Build docs
run: mkdocs build --clean
Expand All @@ -50,4 +48,4 @@ jobs:

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
uses: actions/deploy-pages@v1
20 changes: 10 additions & 10 deletions .github/workflows/integration_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ jobs:

steps:
- name: Check out repository code
uses: actions/checkout@v2
uses: actions/checkout@v3

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

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
pip install poetry
poetry install

- name: Start Application
run: |
Expand All @@ -38,15 +38,15 @@ jobs:
fi

if [ "${{ matrix.app_type }}" == "Blank" ]; then
pynest generate application -n "$app_name"
poetry run pynest generate application -n "$app_name"
else
pynest generate application -n "$app_name" -db sqlite $is_async
pip install aiosqlite
poetry run pynest generate application -n "$app_name" -db sqlite $is_async
poetry add aiosqlite
fi

cd "$app_name"
pynest generate resource -n user
uvicorn "src.app_module:http_server" --host "0.0.0.0" --port 8000 --reload &
poetry run pynest generate resource -n user
poetry run uvicorn "src.app_module:http_server" --host "0.0.0.0" --port 8000 --reload &

- name: Wait for the server to start
run: sleep 10
Expand Down
32 changes: 17 additions & 15 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@ on: [push, workflow_call, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3

- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install Python
id: setup_python
uses: actions/setup-python@v4
with:
python-version: |
3.7
3.8
3.9
3.10
3.11
- name: Install dependencies
run: |
pip install poetry
poetry install --with test

- name: Run tests
run: |
pip install -r requirements-tests.txt
pytest tests
- name: Run tests
run: |
poetry run pytest tests
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,26 @@

PyNest is designed to help structure your APIs in an intuitive, easy to understand, and enjoyable way.

With PyNest, you can build scalable and maintainable APIs with ease. The framework supports dependency injection, type
`With PyNest, you can build scalable and maintainable APIs with ease. The framework supports dependency injection, type
annotations, decorators, and code generation, making it easy to write clean and testable code.

This framework is not a direct port of NestJS to Python but rather a re-imagining of the framework specifically for
Python developers, including backend engineers and ML engineers. It aims to assist them in building better and faster
APIs for their data applications.

`
## Getting Started

To get started with PyNest, you'll need to install it using pip:

```bash
pip install pynest-api
```
=== "pip"
```bash
pip install pynest-api
```

=== "Poetry"
```bash
poetry add pynest-api
```

### Start with cli

Expand All @@ -47,13 +53,15 @@ pynest generate appplication -n my_app_name
this command will create a new project with the following structure:

```text
├── app.py
├── main.py
├── requirements.txt
├── .gitignore
├── README.md
├── src
│ ├── __init__.py
│ ├── app_module.py
│ ├── app_controller.py
│ ├── app_service.py
```

once you have created your app, get into the folder and run the following command:
Expand All @@ -65,7 +73,7 @@ cd my_app_name
run the server with the following command:

```bash
uvicorn "app:app" --host "0.0.0.0" --port "8000" --reload
uvicorn "src.app_module:http_server" --host "0.0.0.0" --port "8000" --reload
```

Now you can visit [OpenAPI](http://localhost:8000/docs) in your browser to see the default API documentation.
Expand All @@ -75,20 +83,20 @@ Now you can visit [OpenAPI](http://localhost:8000/docs) in your browser to see t
To add a new module to your application, you can use the pynest generate module command:

```bash
pynest generate resource -n users
pynest generate resource -n user
```

This will create a new resource called ```users``` in your application with the following structure under the ```src```
This will create a new resource called ```user``` in your application with the following structure under the ```src```
folder:

```text
├── users
│ ├── __init__.py
│ ├── users_controller.py
│ ├── users_service.py
│ ├── users_model.py
│ ├── users_entity.py
│ ├── users_module.py
│ ├── user_controller.py
│ ├── user_service.py
│ ├── user_model.py
│ ├── user_entity.py
│ ├── user_module.py
```

The users module will immediately register itself with the application and will be available for use.
Expand All @@ -113,6 +121,7 @@ and their descriptions:
- `--app-name`/`-n`: The name of the nest app (required).
- `--db-type`/`-db`: The type of the database (optional). You can specify PostgreSQL, MySQL, SQLite, or MongoDB.
- `--is-async`: Whether the project should be asynchronous (optional, default is False).
- `--is-cli`: For creating CLI-based application (optional, default is False).

### `generate` command group

Expand All @@ -133,7 +142,7 @@ and their descriptions:
`pynest generate application -n my_app_name -db postgresql --is-async`

* create new module -
`pynest generate resource -n users`
`pynest generate resource -n user`

## Key Features

Expand Down Expand Up @@ -162,15 +171,6 @@ controllers, services, and providers with types to make your code more robust.
PyNest includes a code generation tool that can create boilerplate code for modules, controllers, and other components.
This saves you time and helps you focus on writing the code that matters.

## Future Plans

- [ ] Create plugins Marketplace for modules where developers can share their modules and download modules created by
others.
- [ ] Implement IOC mechanism and introduce Module decorator
- [ ] Add support for new databases
- [ ] Create out-of-the-box authentication module that can be easily integrated into any application.
- [ ] Add support for other testing frameworks and create testing templates.
- [ ] Add support for other web frameworks (Litestar, blackship, etc.) - Same Architecture, different engine.

## Contributing

Expand Down
Loading
Loading