Skip to content

Commit

Permalink
Merge pull request #10 from hadpro24/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
hadpro24 authored Jun 28, 2021
2 parents 772adc9 + 9a2f6dc commit e8cfe3a
Show file tree
Hide file tree
Showing 25 changed files with 125 additions and 53 deletions.
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
include LICENSE
include README.md
recursive-include docs *
recursive-include nimba/templates *
recursive-include nimba/staticfiles *
recursive-include scripts *
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Quit the server with CONTROL-C.
Open <a href="http://127.0.0.1:8000" target="_blank">`http://127.0.0.1:8000`</a> in your navigator
![Screenshot](https://github.com/hadpro24/nimba-framework/blob/main/result.png?raw=true)

continue directly with <a href="https://docs.nimbasolution.com/tutorial">tutorial</a>

## Licence

This project is licensed under the terms of Nimba solution compagny.
Expand Down
4 changes: 3 additions & 1 deletion docs/features.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Features
# Features

Comming soom...
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Quit the server with CONTROL-C.
Open <a href="http://127.0.0.1:8000" target="_blank">`http://127.0.0.1:8000`</a> in your navigator
![Screenshot](https://github.com/hadpro24/nimba-framework/blob/main/result.png?raw=true)

Continue directly with <a href="https://docs.nimbasolution.com/tutorial">tutorial</a>

## Licence

This project is licensed under the terms of Nimba solution compagny.
Expand Down
1 change: 1 addition & 0 deletions docs/tutorial/css-style.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Partie 4 - CSS and JavaScript
1 change: 1 addition & 0 deletions docs/tutorial/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Parite 1 - Setup
3 changes: 3 additions & 0 deletions docs/tutorial/models.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Partie 6 - Models

### comming...
1 change: 1 addition & 0 deletions docs/tutorial/path-params.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Partie 2 - Endpoint
1 change: 1 addition & 0 deletions docs/tutorial/post-params.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Partie 5 - POST data
1 change: 1 addition & 0 deletions docs/tutorial/query-params.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Partie 3 - Query parameters
Empty file.
1 change: 1 addition & 0 deletions examples/awesome_app/app/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#write your models here
1 change: 1 addition & 0 deletions examples/awesome_app/app/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#write your test here
10 changes: 10 additions & 0 deletions examples/awesome_app/app/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from nimba.http import router, render

@router('/')
def home(request):
return render('awesome_app/home.html')


@router('/articles')
def home(request):
return 'testing <h1>OK</h1>'
17 changes: 17 additions & 0 deletions examples/awesome_app/mask.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pathlib
import sys

def main():
try:
from nimba.commands import mont_nimba
except ImportError as e:
raise ImportError(
"Couldn't import nimba server. Active your environnement"
"or install nimba framework (ex: pip install nimba-framework)"
)
mont_nimba(sys.argv, pathlib.Path(__file__).parent.absolute())

if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions examples/awesome_app/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#all settings application
42 changes: 42 additions & 0 deletions examples/awesome_app/templates/awesome_app/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Nimba Framework</title>
<link rel="icon" href="{{ load_static('nimba/img/nimba.ico') }}" />
<style type="text/css">
.contenair {
width: 70%;
margin: 20px auto;
padding: 15px 10px;
border: 2px solid #E6E6E6;
border-radius: 10px;
text-align: center;
background-color: #fff;
box-shadow: 10px 5px 5px #EEEEF0;
font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Open Sans,Helvetica Neue,sans-serif;;
}
img{
width: 100px;
}
body{
background-color: #F6F6F6;
}
</style>
</head>
<body>
<div class="contenair">
<h1>Nimba Framework successfully installed</h1>
<p>Nimba Framework is a modern, fast (coding), web framework with python</p>
<img src="{{ load_static('nimba/img/nimba-logo.png') }}">
<p>
Everything you need to know about Nimba Framework at <a href="https://docs.nimbasolution.com/" target="_blank">https://docs.nimbasolution.com</a>
</p>
<hr>
<p><em>
Thanks <a href="https://nimbasolution.com" target="_blank">Nimba Solution</a> for Licence
</em></p>
</div>
</body>
</html>
30 changes: 3 additions & 27 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,11 @@ nav:
- features.md
- Tutorial - User Guide:
- tutorial/index.md
- tutorial/first-steps.md
- tutorial/path-params.md
- tutorial/query-params.md
- tutorial/body.md
- Dependencies:
- tutorial/dependencies/index.md
- tutorial/dependencies/classes-as-dependencies.md
- tutorial/dependencies/sub-dependencies.md
- tutorial/dependencies/dependencies-in-path-operation-decorators.md
- tutorial/dependencies/global-dependencies.md
- tutorial/dependencies/dependencies-with-yield.md
- Security:
- tutorial/security/index.md
- tutorial/security/first-steps.md
- tutorial/security/get-current-user.md
- tutorial/security/simple-oauth2.md
- tutorial/security/oauth2-jwt.md
- tutorial/middleware.md
- tutorial/cors.md
- tutorial/sql-databases.md
- tutorial/bigger-applications.md
- tutorial/background-tasks.md
- tutorial/metadata.md
- tutorial/static-files.md
- tutorial/testing.md
- tutorial/debugging.md
- tutorial/css-style.md
- tutorial/post-params.md
- tutorial/models.md
- Advanced User Guide:
- advanced/index.md
- advanced/path-operation-advanced-configuration.md
Expand All @@ -83,9 +62,6 @@ nav:
- deployment/index.md
- deployment/versions.md
- deployment/https.md
- deployment/deta.md
- deployment/docker.md
- deployment/manually.md
- contributing.md
- release-notes.md
extra:
Expand Down
4 changes: 2 additions & 2 deletions nimba/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
import pathlib

if __name__ == '__main__':
from nimba.commands import mont_nimba
mont_nimba(sys.argv, pathlib.Path(__file__).parent.absolute())
from nimba.apps import mont_nimba
mont_nimba()
3 changes: 2 additions & 1 deletion nimba/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

def mont_nimba():
#create app
from nimba.core.welcom import home_default
argv = sys.argv
path_app = pathlib.Path(__file__).parent.absolute()
utility = CommandUtility(path_app, argv)
utility.execute()
utility.execute(home_default)
21 changes: 15 additions & 6 deletions nimba/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import pathlib
import optparse
import traceback
import importlib

from nimba.commands.createapp import CreateApp
from nimba.core.server import Application
from wsgiref.validate import validator

class CommandUtility:
"""
Expand All @@ -21,7 +23,7 @@ def __init__(self, path_app, argv=None):
except IndexError:
self.subcommand = 'help'

def execute(self):
def execute(self, app):
"""
exectue command
"""
Expand Down Expand Up @@ -51,9 +53,13 @@ def execute(self):
#runserver
if self.subcommand == 'serve':
if options.noreload:
Application(self.path_app).run('--noreload', options)
Application(
self.path_app, validator(app)
).run('--noreload', options)
else:
Application(self.path_app).run('--reload', options)
Application(
self.path_app, validator(app)
).run('--reload', options)
elif self.subcommand == 'create':
app = CreateApp(options.app, self.prog_name)
try:
Expand All @@ -69,7 +75,10 @@ def execute(self):

def mont_nimba(argv, path_app):
#create app
# argv = sys.argv
# path_app = pathlib.Path(__file__).parent.absolute()
from nimba.core.welcom import home_default
view_module = importlib.import_module('app.views')
for attr in dir(view_module):
if hasattr(attr, '__call__'):
locals()[attr] = getattr(view_module, attr)
utility = CommandUtility(path_app, argv)
utility.execute()
utility.execute(home_default)
17 changes: 10 additions & 7 deletions nimba/commands/createapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@

from nimba.commands.base import Loader
from nimba.core.exceptions import AppNameIncorrect, CommandError

from nimba.core.welcom import DEFAULT_DIRECTORY_INDEX_TEMPLATE

manager_file = """#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pathlib
import sys
from app.views import * #import your view
def main():
try:
from nimba.commands import mont_nimba
Expand All @@ -30,11 +28,12 @@ def main():
if __name__ == '__main__':
main()
"""
import_view = """from nimba.http import router, render

import_view = f"""from nimba.http import router, render
@router('/')
def home(request):
return "Nimba Framework installed succesfuly!"
return render('awesome_app/home.html')
"""

import_test = """#write your test here """
Expand Down Expand Up @@ -76,8 +75,12 @@ def handle(self):
#create application
os.makedirs(path_application)
os.makedirs(os.path.join(path_application, 'app'))
os.makedirs(os.path.join(path_application, 'templates'))
os.makedirs(os.path.join(path_application, 'static'))
os.makedirs(os.path.join(path_application, 'templates/awesome_app'))
os.makedirs(os.path.join(path_application, 'staticfiles'))
#template
f = open(os.path.join(path_application, 'templates/awesome_app', 'home.html'), 'w+')
f.write(DEFAULT_DIRECTORY_INDEX_TEMPLATE)
f.close()
#init
f = open(os.path.join(path_application, 'app', '__init__.py'), 'w+')
f.close()
Expand Down
8 changes: 3 additions & 5 deletions nimba/core/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import sys
import os
import importlib
from wsgiref.validate import validator
from wsgiref import simple_server
import optparse

Expand All @@ -21,19 +20,18 @@
from watchdog.events import FileSystemEventHandler
from watchdog.events import PatternMatchingEventHandler

from nimba.core.welcom import home_default

LISTEN_QUEUE = 128
can_open_by_fd = not platform.system() == "Windows" and hasattr(socket, "fromfd")

class Application:
def __init__(self, path_file):
def __init__(self, path_file, app_view):
self.name = '.'.join(str(path_file)[1:].split('/'))
self.app_path = path_file
self.httpd = None
self.server_process = None
self.port = 8000
self.host = '127.0.0.1'
self.app_view = app_view
os.environ.setdefault('PROJECT_MASK_PATH', str(path_file))


Expand Down Expand Up @@ -111,7 +109,7 @@ def log_server_status(self, host, port):
def _serve(self, host, port):
host, port = host, int(port)
srv = simple_server.make_server(
host, port, validator(home_default)
host, port, self.app_view
)
print('Starting server in PID %s' % os.getpid())
self.log_server_status(host, port)
Expand Down
4 changes: 2 additions & 2 deletions nimba/core/welcom.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from nimba.http import router, render
from nimba.http import router

DEFAULT_DIRECTORY_INDEX_TEMPLATE = """
<!DOCTYPE html>
Expand Down Expand Up @@ -37,7 +37,7 @@
</p>
<hr>
<p><em>
Thanks <a href="nimbasolution.com" target="_blank">Nimba Solution</a> for Licence
Thanks <a href="https://nimbasolution.com" target="_blank">Nimba Solution</a> for Licence
</em></p>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = nimba
version = 0.0.3
version = 0.0.5
description = Nimba Framework is a modern, fast (coding), web framework with Python.
long_description = file: README.rst
keywords = python, python3, framework, nimba, nimba-solution, web
Expand Down

0 comments on commit e8cfe3a

Please sign in to comment.