Compare commits
145 Commits
ticket-769
...
main
|
@ -0,0 +1,10 @@
|
|||
__pycache__
|
||||
.venv
|
||||
venvog
|
||||
*.deb
|
||||
*.build
|
||||
*.dsc
|
||||
*.changes
|
||||
*.buildinfo
|
||||
*.tar.gz
|
||||
*-stamp
|
|
@ -1,69 +0,0 @@
|
|||
# GitLib
|
||||
|
||||
La `gitapi.py` es una API para OgGit, escrita en Python/Flask.
|
||||
|
||||
Es un servidor HTTP que recibe comandos y ejecuta acciones de mantenimiento incluyendo la creación y eliminación de repositorios.
|
||||
|
||||
|
||||
# Instalación de dependencias para python
|
||||
|
||||
La conversion del código a Python 3 requiere actualmente los paquetes especificados en `requirements.txt`
|
||||
|
||||
Para instalar dependencias de python se usa el modulo venv (https://docs.python.org/3/library/venv.html) que instala todas las dependencias en un entorno independiente del sistema.
|
||||
|
||||
|
||||
# Uso
|
||||
|
||||
|
||||
## Distribuciones antiguas (18.04)
|
||||
|
||||
sudo apt install -y python3.8 python3.8-venv python3-venv libarchive-dev
|
||||
python3.8 -m venv venvog
|
||||
. venvog/bin/activate
|
||||
python3.8 -m pip install --upgrade pip
|
||||
pip3 install -r requirements.txt
|
||||
|
||||
Ejecutar con:
|
||||
|
||||
./gitapi.py
|
||||
|
||||
|
||||
## Uso
|
||||
|
||||
**Nota:** Ejecutar como `opengnsys`, ya que gestiona las imágenes que se encuentran en `/opt/opengnsys/images`.
|
||||
|
||||
$ . venvog/bin/activate
|
||||
$ ./gitapi.py
|
||||
|
||||
|
||||
# Documentación
|
||||
|
||||
Se puede generar documentación de Python con una utilidad como pdoc3 (hay multiples alternativas posibles):
|
||||
|
||||
# Instalar pdoc3
|
||||
pip install --user pdoc3
|
||||
|
||||
# Generar documentación
|
||||
pdoc3 --force --html opengnsys_git_installer.py
|
||||
|
||||
# Funcionamiento
|
||||
|
||||
## Requisitos
|
||||
|
||||
La gitapi esta diseñada para funcionar dentro de un entorno opengnsys existente. Se debe instalar en un ogrepository.
|
||||
|
||||
## Ejemplo de API
|
||||
|
||||
### Obtener lista de ramas
|
||||
|
||||
$ curl -L http://localhost:5000/repositories/linux/branches
|
||||
{
|
||||
"branches": [
|
||||
"master"
|
||||
]
|
||||
}
|
||||
|
||||
### Sincronizar con repositorio remoto
|
||||
|
||||
curl --header "Content-Type: application/json" --data '{"remote_repository":"foobar"}' -X POST -L http://localhost:5000/repositories/linux/sync
|
||||
|
361
api/gitapi.py
|
@ -1,361 +0,0 @@
|
|||
from flask import Flask, jsonify
|
||||
import os.path
|
||||
import os
|
||||
import git
|
||||
import shutil
|
||||
import subprocess
|
||||
import uuid
|
||||
from opengnsys_git_installer import OpengnsysGitInstaller
|
||||
from flask import Flask, request
|
||||
from flask_executor import Executor
|
||||
import subprocess
|
||||
from flask import stream_with_context, Response
|
||||
import paramiko
|
||||
|
||||
repositories_base_path = "/opt/opengnsys/images"
|
||||
|
||||
# Create an instance of the Flask class
|
||||
app = Flask(__name__)
|
||||
executor = Executor(app)
|
||||
|
||||
|
||||
|
||||
tasks = {}
|
||||
|
||||
|
||||
|
||||
def do_repo_backup(repo, params):
|
||||
|
||||
gitrepo = git.Repo(f"{repositories_base_path}/{repo}.git")
|
||||
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
|
||||
ssh.connect(params["ssh_server"], params["ssh_port"], params["ssh_user"])
|
||||
sftp = ssh.open_sftp()
|
||||
|
||||
|
||||
with sftp.file(params["filename"], mode='wb+') as remote_file:
|
||||
gitrepo.archive(remote_file, format="tar.gz")
|
||||
|
||||
|
||||
return True
|
||||
|
||||
def do_repo_sync(repo, params):
|
||||
gitrepo = git.Repo(f"{repositories_base_path}/{repo}.git")
|
||||
|
||||
# Recreate the remote every time, it might change
|
||||
if "backup" in gitrepo.remotes:
|
||||
gitrepo.delete_remote("backup")
|
||||
|
||||
backup_repo = gitrepo.create_remote("backup", params["remote_repository"])
|
||||
pushrets = backup_repo.push("*:*")
|
||||
results = []
|
||||
|
||||
# This gets returned to the API
|
||||
for ret in pushrets:
|
||||
results = results + [ {"local_ref" : ret.local_ref.name, "remote_ref" : ret.remote_ref.name, "summary" : ret.summary }]
|
||||
|
||||
return results
|
||||
|
||||
def do_repo_gc(repo):
|
||||
gitrepo = git.Repo(f"{repositories_base_path}/{repo}.git")
|
||||
|
||||
gitrepo.git.gc()
|
||||
return True
|
||||
|
||||
|
||||
# Define a route for the root URL
|
||||
@app.route('/')
|
||||
def home():
|
||||
"""
|
||||
Home route that returns a JSON response with a welcome message for the OpenGnsys Git API.
|
||||
|
||||
Returns:
|
||||
Response: A Flask JSON response containing a welcome message.
|
||||
"""
|
||||
return jsonify({
|
||||
"message": "OpenGnsys Git API"
|
||||
})
|
||||
|
||||
@app.route('/repositories')
|
||||
def get_repositories():
|
||||
"""
|
||||
Retrieve a list of Git repositories.
|
||||
|
||||
This endpoint scans the OpenGnsys image path for directories that
|
||||
appear to be Git repositories (i.e., they contain a "HEAD" file).
|
||||
It returns a JSON response containing the names of these repositories.
|
||||
|
||||
Returns:
|
||||
Response: A JSON response with a list of repository names or an
|
||||
error message if the repository storage is not found.
|
||||
- 200 OK: When the repositories are successfully retrieved.
|
||||
- 500 Internal Server Error: When the repository storage is not found.
|
||||
|
||||
Example JSON response:
|
||||
{
|
||||
"repositories": ["repo1", "repo2"]
|
||||
}
|
||||
"""
|
||||
|
||||
if not os.path.isdir(repositories_base_path):
|
||||
return jsonify({"error": "Repository storage not found, git functionality may not be installed."}), 500
|
||||
|
||||
repos = []
|
||||
for entry in os.scandir(repositories_base_path):
|
||||
if entry.is_dir(follow_symlinks=False) and os.path.isfile(os.path.join(entry.path, "HEAD")):
|
||||
name = entry.name
|
||||
if name.endswith(".git"):
|
||||
name = name[:-4]
|
||||
|
||||
repos = repos + [name]
|
||||
|
||||
return jsonify({
|
||||
"repositories": repos
|
||||
})
|
||||
|
||||
@app.route('/repositories/<repo>', methods=['PUT'])
|
||||
def create_repo(repo):
|
||||
"""
|
||||
Create a new Git repository.
|
||||
|
||||
This endpoint creates a new Git repository with the specified name.
|
||||
If the repository already exists, it returns a status message indicating so.
|
||||
|
||||
Args:
|
||||
repo (str): The name of the repository to be created.
|
||||
|
||||
Returns:
|
||||
Response: A JSON response with a status message and HTTP status code.
|
||||
- 200: If the repository already exists.
|
||||
- 201: If the repository is successfully created.
|
||||
"""
|
||||
repo_path = os.path.join(repositories_base_path, repo + ".git")
|
||||
if os.path.isdir(repo_path):
|
||||
return jsonify({"status": "Repository already exists"}), 200
|
||||
|
||||
|
||||
installer = OpengnsysGitInstaller()
|
||||
installer._init_git_repo(repo + ".git")
|
||||
|
||||
|
||||
return jsonify({"status": "Repository created"}), 201
|
||||
|
||||
|
||||
@app.route('/repositories/<repo>/sync', methods=['POST'])
|
||||
def sync_repo(repo):
|
||||
"""
|
||||
Synchronize a repository with a remote repository.
|
||||
|
||||
This endpoint triggers the synchronization process for a specified repository.
|
||||
It expects a JSON payload with the remote repository details.
|
||||
|
||||
Args:
|
||||
repo (str): The name of the repository to be synchronized.
|
||||
|
||||
Returns:
|
||||
Response: A JSON response indicating the status of the synchronization process.
|
||||
- 200: If the synchronization process has started successfully.
|
||||
- 400: If the request payload is missing or invalid.
|
||||
- 404: If the specified repository is not found.
|
||||
"""
|
||||
repo_path = os.path.join(repositories_base_path, repo + ".git")
|
||||
if not os.path.isdir(repo_path):
|
||||
return jsonify({"error": "Repository not found"}), 404
|
||||
|
||||
|
||||
data = request.json
|
||||
|
||||
if data is None:
|
||||
return jsonify({"error" : "Parameters missing"}), 400
|
||||
|
||||
dest_repo = data["remote_repository"]
|
||||
|
||||
|
||||
future = executor.submit(do_repo_sync, repo, data)
|
||||
task_id = str(uuid.uuid4())
|
||||
tasks[task_id] = future
|
||||
return jsonify({"status": "started", "task_id" : task_id}), 200
|
||||
|
||||
|
||||
@app.route('/repositories/<repo>/backup', methods=['POST'])
|
||||
def backup_repo(repo):
|
||||
"""
|
||||
Backup a specified repository.
|
||||
|
||||
Endpoint: POST /repositories/<repo>/backup
|
||||
|
||||
Args:
|
||||
repo (str): The name of the repository to back up.
|
||||
|
||||
Request Body (JSON):
|
||||
ssh_port (int, optional): The SSH port to use for the backup. Defaults to 22.
|
||||
|
||||
Returns:
|
||||
Response: A JSON response indicating the status of the backup operation.
|
||||
- If the repository is not found, returns a 404 error with a message.
|
||||
- If the request body is missing, returns a 400 error with a message.
|
||||
- If the backup process starts successfully, returns a 200 status with the task ID.
|
||||
|
||||
Notes:
|
||||
- The repository path is constructed by appending ".git" to the repository name.
|
||||
- The backup operation is performed asynchronously using a thread pool executor.
|
||||
- The task ID of the backup operation is generated using UUID and stored in a global tasks dictionary.
|
||||
"""
|
||||
repo_path = os.path.join(repositories_base_path, repo + ".git")
|
||||
if not os.path.isdir(repo_path):
|
||||
return jsonify({"error": "Repository not found"}), 404
|
||||
|
||||
|
||||
data = request.json
|
||||
if data is None:
|
||||
return jsonify({"error" : "Parameters missing"}), 400
|
||||
|
||||
|
||||
if not "ssh_port" in data:
|
||||
data["ssh_port"] = 22
|
||||
|
||||
|
||||
future = executor.submit(do_repo_backup, repo, data)
|
||||
task_id = str(uuid.uuid4())
|
||||
tasks[task_id] = future
|
||||
|
||||
return jsonify({"status": "started", "task_id" : task_id}), 200
|
||||
|
||||
@app.route('/repositories/<repo>/gc', methods=['POST'])
|
||||
def gc_repo(repo):
|
||||
"""
|
||||
Initiates a garbage collection (GC) process for a specified Git repository.
|
||||
|
||||
This endpoint triggers an asynchronous GC task for the given repository.
|
||||
The task is submitted to an executor, and a unique task ID is generated
|
||||
and returned to the client.
|
||||
|
||||
Args:
|
||||
repo (str): The name of the repository to perform GC on.
|
||||
|
||||
Returns:
|
||||
Response: A JSON response containing the status of the request and
|
||||
a unique task ID if the repository is found, or an error
|
||||
message if the repository is not found.
|
||||
"""
|
||||
repo_path = os.path.join(repositories_base_path, repo + ".git")
|
||||
if not os.path.isdir(repo_path):
|
||||
return jsonify({"error": "Repository not found"}), 404
|
||||
|
||||
future = executor.submit(do_repo_gc, repo)
|
||||
task_id = str(uuid.uuid4())
|
||||
tasks[task_id] = future
|
||||
|
||||
return jsonify({"status": "started", "task_id" : task_id}), 200
|
||||
|
||||
|
||||
@app.route('/tasks/<task_id>/status')
|
||||
def tasks_status(task_id):
|
||||
"""
|
||||
Endpoint to check the status of a specific task.
|
||||
|
||||
Args:
|
||||
task_id (str): The unique identifier of the task.
|
||||
|
||||
Returns:
|
||||
Response: A JSON response containing the status of the task.
|
||||
- If the task is not found, returns a 404 error with an error message.
|
||||
- If the task is completed, returns a 200 status with the result.
|
||||
- If the task is still in progress, returns a 202 status indicating the task is in progress.
|
||||
"""
|
||||
if not task_id in tasks:
|
||||
return jsonify({"error": "Task not found"}), 404
|
||||
|
||||
future = tasks[task_id]
|
||||
|
||||
if future.done():
|
||||
result = future.result()
|
||||
return jsonify({"status" : "completed", "result" : result}), 200
|
||||
else:
|
||||
return jsonify({"status" : "in progress"}), 202
|
||||
|
||||
|
||||
|
||||
@app.route('/repositories/<repo>', methods=['DELETE'])
|
||||
def delete_repo(repo):
|
||||
"""
|
||||
Deletes a Git repository.
|
||||
|
||||
This endpoint deletes a Git repository specified by the `repo` parameter.
|
||||
If the repository does not exist, it returns a 404 error with a message
|
||||
indicating that the repository was not found. If the repository is successfully
|
||||
deleted, it returns a 200 status with a message indicating that the repository
|
||||
was deleted.
|
||||
|
||||
Args:
|
||||
repo (str): The name of the repository to delete.
|
||||
|
||||
Returns:
|
||||
Response: A JSON response with a status message and the appropriate HTTP status code.
|
||||
"""
|
||||
repo_path = os.path.join(repositories_base_path, repo + ".git")
|
||||
if not os.path.isdir(repo_path):
|
||||
return jsonify({"error": "Repository not found"}), 404
|
||||
|
||||
|
||||
shutil.rmtree(repo_path)
|
||||
return jsonify({"status": "Repository deleted"}), 200
|
||||
|
||||
|
||||
|
||||
|
||||
@app.route('/repositories/<repo>/branches')
|
||||
def get_repository_branches(repo):
|
||||
"""
|
||||
Retrieve the list of branches for a given repository.
|
||||
|
||||
Args:
|
||||
repo (str): The name of the repository.
|
||||
|
||||
Returns:
|
||||
Response: A JSON response containing a list of branch names or an error message if the repository is not found.
|
||||
- 200: A JSON object with a "branches" key containing a list of branch names.
|
||||
- 404: A JSON object with an "error" key containing the message "Repository not found" if the repository does not exist.
|
||||
"""
|
||||
repo_path = os.path.join(repositories_base_path, repo + ".git")
|
||||
if not os.path.isdir(repo_path):
|
||||
return jsonify({"error": "Repository not found"}), 404
|
||||
|
||||
gitRepo = git.Repo(repo_path)
|
||||
|
||||
branches = []
|
||||
for branch in gitRepo.branches:
|
||||
branches = branches + [branch.name]
|
||||
|
||||
|
||||
return jsonify({
|
||||
"branches": branches
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
@app.route('/health')
|
||||
def health_check():
|
||||
"""
|
||||
Health check endpoint.
|
||||
|
||||
This endpoint returns a JSON response indicating the health status of the application.
|
||||
|
||||
Returns:
|
||||
Response: A JSON response with a status key set to "OK". Currently it always returns
|
||||
a successful value, but this endpoint can still be used to check that the API is
|
||||
active and functional.
|
||||
|
||||
"""
|
||||
return jsonify({
|
||||
"status": "OK"
|
||||
})
|
||||
|
||||
# Run the Flask app
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='0.0.0.0')
|
||||
|
||||
|
|
@ -1 +0,0 @@
|
|||
../installer/opengnsys_git_installer.py
|
|
@ -1,27 +0,0 @@
|
|||
bcrypt==4.0.1
|
||||
cffi==1.15.1
|
||||
click==8.0.4
|
||||
colorterm==0.3
|
||||
contextvars==2.4
|
||||
cryptography==40.0.2
|
||||
dataclasses==0.8
|
||||
Flask==2.0.3
|
||||
Flask-Executor==1.0.0
|
||||
gitdb==4.0.9
|
||||
GitPython==3.1.20
|
||||
immutables==0.19
|
||||
importlib-metadata==4.8.3
|
||||
itsdangerous==2.0.1
|
||||
Jinja2==3.0.3
|
||||
libarchive==0.4.7
|
||||
MarkupSafe==2.0.1
|
||||
nose==1.3.7
|
||||
paramiko==3.5.0
|
||||
pkg_resources==0.0.0
|
||||
pycparser==2.21
|
||||
PyNaCl==1.5.0
|
||||
smmap==5.0.0
|
||||
termcolor==1.1.0
|
||||
typing_extensions==4.1.1
|
||||
Werkzeug==2.0.3
|
||||
zipp==3.6.0
|
|
@ -1,99 +0,0 @@
|
|||
# GitLib
|
||||
|
||||
La `gitlib.py` es una librería de Python también usable como programa de línea
|
||||
de comandos para pruebas.
|
||||
|
||||
Contiene las funciones de gestión de git, y la parte de línea de comandos permite ejecutarlas sin necesitar escribir un programa que use la librería.
|
||||
|
||||
|
||||
# Instalación de dependencias para python
|
||||
|
||||
La conversion del código a Python 3 requiere actualmente los paquetes especificados en `requirements.txt`
|
||||
|
||||
Para instalar dependencias de python se usa el modulo venv (https://docs.python.org/3/library/venv.html) que instala todas las dependencias en un entorno independiente del sistema.
|
||||
|
||||
|
||||
# Uso
|
||||
|
||||
|
||||
## Distribuciones antiguas (18.04)
|
||||
|
||||
sudo apt install -y python3.8 python3.8-venv python3.8-dev python3-venv libarchive-dev libblkid-dev pkg-config libacl1-dev
|
||||
python3.8 -m venv venvog
|
||||
. venvog/bin/activate
|
||||
python3.8 -m pip install --upgrade pip
|
||||
pip3 install -r requirements.txt
|
||||
|
||||
Ejecutar con:
|
||||
|
||||
./gitlib.py
|
||||
|
||||
En modo de linea de comando, hay ayuda que se puede ver con:
|
||||
|
||||
./gitlib.py --help
|
||||
|
||||
|
||||
Los comandos que comienzan por `--test` existen para hacer pruebas internas, y existen temporalmente para probar partes especificas del código. Es posible que necesiten condiciones especificas para funcionar, y van a eliminarse al completarse el desarrollo.
|
||||
|
||||
## Uso
|
||||
|
||||
**Nota:** Preferiblemente ejecutar como `root`, ya que `sudo` borra los cambios a las variables de entorno realizadas por venv. El resultado probable es un error de falta de módulos de Python, o un fallo del programa por usar dependencias demasiado antiguas.
|
||||
|
||||
# . venv/bin/activate
|
||||
# ./opengnsys_git_installer.py
|
||||
|
||||
|
||||
### Inicializar un repositorio:
|
||||
|
||||
./gitlib.py --init-repo-from /dev/sda2 --repo linux
|
||||
|
||||
|
||||
Esto inicializa el repositorio 'linux' con el contenido /mnt/sda2.
|
||||
|
||||
`--repo` especifica el nombre de uno de los repositorios fijados durante la instalación de git (ver git installer).
|
||||
|
||||
El repositorio de sube al ogrepository, que se obtiene del parámetro de arranque pasado al kernel.
|
||||
|
||||
### Clonar un repositorio:
|
||||
|
||||
./gitlib.py --clone-repo-to /dev/sda2 --boot-device /dev/sda --repo linux
|
||||
|
||||
Esto clona un repositorio del ogrepository. El destino es un dispositivo físico que se va a formatear con el sistema de archivos necesario.
|
||||
|
||||
`--boot-device` especifica el dispositivo de arranque donde se va a instalar el bootloader (GRUB o similar)
|
||||
|
||||
`--repo` es el nombre de repositorio contenido en ogrepository.
|
||||
|
||||
# Documentación
|
||||
|
||||
Se puede generar documentación de Python con una utilidad como pdoc3 (hay multiples alternativas posibles):
|
||||
|
||||
# Instalar pdoc3
|
||||
pip install --user pdoc3
|
||||
|
||||
# Generar documentación
|
||||
pdoc3 --force --html opengnsys_git_installer.py
|
||||
|
||||
# Funcionamiento
|
||||
|
||||
## Requisitos
|
||||
|
||||
La gitlib esta diseñada para funcionar dentro de un entorno opengnsys existente. Invoca algunos de los comandos de opengnsys internamente, y lee los parámetros pasados al kernel en el oglive.
|
||||
|
||||
|
||||
## Metadatos
|
||||
|
||||
Git no es capaz de almacenar datos de atributos extendidos, sockets y otros tipos de archivos especiales. El gitlib los almacena en .opengnsys-metadata en
|
||||
el raíz del repositorio.
|
||||
|
||||
Los datos se guardan en archivos de tipo `jsonl`, una estructura de JSON por linea. Esto es para facilitar aplicaciones parciales solo aplicando el efecto de las lineas necesarias.
|
||||
|
||||
Existen estos archivos:
|
||||
|
||||
* `acls.jsonl`: ACLs
|
||||
* `empty_directories.jsonl`: Directorios vacíos, ya que Git no es capaz de guardarlos
|
||||
* `filesystems.json`: Información sobre sistemas de archivos: tipos, tamaños, UUIDs
|
||||
* `gitignores.jsonl`: Lista de archivos .gitignore (los renombramos para que no interfieran con git)
|
||||
* `metadata.json`: Metadatos generales acerca del repositorio
|
||||
* `special_files.jsonl`: Archivos especiales como sockets
|
||||
* `xattrs.jsonl`: Atributos extendidos
|
|
@ -1,25 +0,0 @@
|
|||
# Instalar de Admin
|
||||
|
||||
. venv/bin/activate
|
||||
./opengnsys_git_installer.py
|
||||
|
||||
# Inicializar el repo a partir de los datos de una maquina modelo:
|
||||
|
||||
Ejecutar en oglive corriendo en la maquina modelo
|
||||
|
||||
. venv/bin/activate
|
||||
./gitlib.py --init-repo-from /dev/sda2 --repo linux
|
||||
|
||||
|
||||
# Usar git para desplegar sobre una maquina nueva:
|
||||
|
||||
|
||||
Ejecutar en oglive corriendo en la maquina de destino.
|
||||
|
||||
Preparar el disco creando partición boot/EFI y partición de datos.
|
||||
|
||||
|
||||
. venv/bin/activate
|
||||
./gitlib.py --clone-repo-to /dev/sda2 --repo linux --boot-device /dev/sda
|
||||
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
import unittest
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import urllib.request
|
||||
import tarfile
|
||||
import subprocess
|
||||
from shutil import rmtree
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
parent_dir = str(Path(__file__).parent.parent.absolute())
|
||||
sys.path.append(parent_dir)
|
||||
sys.path.append("/opengnsys/installer")
|
||||
print(parent_dir)
|
||||
|
||||
from gitlib import OpengnsysGitLibrary
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class GitTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.logger = logging.getLogger("OpengnsysTest")
|
||||
self.oggit = OpengnsysGitLibrary()
|
||||
|
||||
self.logger.info("setUp()")
|
||||
if not hasattr(self, 'init_complete'):
|
||||
self.init_complete = True
|
||||
def test_init(self):
|
||||
self.assertIsNotNone(self.oggit)
|
||||
def test_acls(self):
|
||||
self.oggit.ogCreateAcl()
|
||||
|
||||
def test_sync_local(self):
|
||||
# self.oggit.ogSyncLocalGitImage()
|
||||
None
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)20s - [%(levelname)5s] - %(message)s')
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.info("Inicio del programa")
|
||||
|
||||
unittest.main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
1808
gitlib/gitlib.py
|
@ -1,9 +0,0 @@
|
|||
gitdb==4.0.11
|
||||
GitPython==3.1.43
|
||||
libarchive==0.4.7
|
||||
libarchive-c==5.1
|
||||
nose==1.3.7
|
||||
pylibacl==0.7.0
|
||||
pylibblkid==0.3
|
||||
pyxattr==0.8.1
|
||||
smmap==5.0.1
|
|
@ -0,0 +1,84 @@
|
|||
# Git component installer
|
||||
|
||||
This directory contains the installer for the git component for OpenGnsys.
|
||||
|
||||
It downloads, installs and configures Forgejo, creates the default repositories and configures SSH keys.
|
||||
|
||||
# Quick Installation
|
||||
|
||||
## Ubuntu 24.04
|
||||
|
||||
### Add the repository
|
||||
|
||||
|
||||
Create the file `/etc/apt/sources.list.d/opengnsys.sources` with these contents:
|
||||
|
||||
Types: deb
|
||||
URIs: https://ognproject.evlt.uma.es/debian-opengnsys/
|
||||
Suites: noble
|
||||
Components: main
|
||||
Signed-By:
|
||||
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
.
|
||||
mDMEZzx/SxYJKwYBBAHaRw8BAQdAa83CuAJ5/+7Pn9LHT/k34EAGpx5FnT/ExHSj
|
||||
XZG1JES0Ik9wZW5HbnN5cyA8b3Blbmduc3lzQG9wZW5nbnN5cy5lcz6ImQQTFgoA
|
||||
QRYhBC+J38Xsso227ZbDVt2S5xJQRhKDBQJnPH9LAhsDBQkFo5qABQsJCAcCAiIC
|
||||
BhUKCQgLAgQWAgMBAh4HAheAAAoJEN2S5xJQRhKDW/MBAO6swnpwdrbm48ypMyPh
|
||||
NboxvF7rCqBqHWwRHvkvrq7pAP9zd98r7z2AvqVXZxnaCsLTUNMEL12+DVZAUZ1G
|
||||
EquRBbg4BGc8f0sSCisGAQQBl1UBBQEBB0B6D6tkrwXSHi7ebGYsiMPntqwdkQ/S
|
||||
84SFTlSxRqdXfgMBCAeIfgQYFgoAJhYhBC+J38Xsso227ZbDVt2S5xJQRhKDBQJn
|
||||
PH9LAhsMBQkFo5qAAAoJEN2S5xJQRhKDJ+cBAM9jYbeq5VXkHLfODeVztgSXnSUe
|
||||
yklJ18oQmpeK5eWeAQDKYk/P0R+1ZJDItxkeP6pw62bCDYGQDvdDGPMAaIT6CA==
|
||||
=xcNc
|
||||
-----END PGP PUBLIC KEY BLOCK-----
|
||||
|
||||
It's required to run `apt update` after creating this file
|
||||
|
||||
### Install packages
|
||||
|
||||
sudo apt install -y python3-git opengnsys-libarchive-c python3-termcolor python3-requests python3-tqdm bsdextrautils
|
||||
|
||||
## Adding SSH Keys to oglive
|
||||
|
||||
The Git system accesses the ogrepository via SSH. To function, it needs the oglive to have an SSH key, and for the ogrepository to accept it.
|
||||
|
||||
The Git installer can make the required changes by extracting an SSH key from an oglive and installing it in Forgejo. If there is a local ogboot installation, the installer will do this automatically. If there is not, it is necessary to provide the installer with an oglive from which to extract the key using the `--oglive-file` or `--oglive-url` parameter.
|
||||
|
||||
For example:
|
||||
|
||||
./opengnsys_git_installer.py --oglive-url https://example.com/ogLive-noble.iso
|
||||
|
||||
The installer will proceed to download the file, mount the ISO, and extract the key.
|
||||
|
||||
To perform the process after completing the installation and only add a key to an existing installation, use the `--set-ssh-key` parameter:
|
||||
|
||||
./opengnsys_git_installer.py --set-ssh-key --oglive-url https://example.com/ogLive-noble.iso
|
||||
|
||||
|
||||
# Running the Installer
|
||||
|
||||
# ./opengnsys_git_installer.py
|
||||
|
||||
It must be run as `root`.
|
||||
|
||||
The installer downloads and installs Forgejo, a web interface for Git. The configuration is automatically generated.
|
||||
|
||||
Forgejo manages the repositories and SSH access, so it must always be running. By default, it is installed on port 3000.
|
||||
|
||||
The default user is `oggit` with the password `opengnsys`.
|
||||
|
||||
# Packages with Dependencies
|
||||
|
||||
The OgGit system requires Python modules that are not included in Ubuntu 24.04 or have outdated versions.
|
||||
|
||||
The package sources can be found in oggit/packages.
|
||||
|
||||
# Source Code Documentation
|
||||
|
||||
Python documentation can be generated using a utility like pdoc3 (there are multiple possible alternatives):
|
||||
|
||||
# Install pdoc3
|
||||
pip install --user pdoc3
|
||||
|
||||
# Generate documentation
|
||||
pdoc3 --force --html opengnsys_git_installer.py
|
|
@ -1,57 +1,82 @@
|
|||
# Instalación de dependencias para python
|
||||
# Instalador de componente Git
|
||||
|
||||
La conversion del código a Python 3 requiere actualmente los paquetes especificados en `requirements.txt`
|
||||
|
||||
Para instalar dependencias de python se usa el modulo venv (https://docs.python.org/3/library/venv.html) que instala todas las dependencias en un entorno independiente del sistema.
|
||||
Este directorio contiene el instalador de Git para OpenGnsys.
|
||||
|
||||
Descarga, instala y configura Forgejo, crea los repositorios por defecto, y configura claves de SSH.
|
||||
|
||||
# Instalación rápida
|
||||
|
||||
## Ubuntu 24.04
|
||||
|
||||
## Distribuciones antiguas (18.04)
|
||||
### Agregar repositorio
|
||||
|
||||
**Nota:** En 18.04, `uname` solo se encuentra en `/bin`, lo que causa un error inocuo en el log durante la creación de los repositorios:
|
||||
Crear el archivo `/etc/apt/sources.list.d/opengnsys.sources` con este contenido:
|
||||
|
||||
Failed checking if running in CYGWIN due to: FileNotFoundError(2, 'No such file or directory')
|
||||
Types: deb
|
||||
URIs: https://ognproject.evlt.uma.es/debian-opengnsys/opengnsys
|
||||
Suites: noble
|
||||
Components: main
|
||||
Signed-By:
|
||||
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
.
|
||||
mDMEZzx/SxYJKwYBBAHaRw8BAQdAa83CuAJ5/+7Pn9LHT/k34EAGpx5FnT/ExHSj
|
||||
XZG1JES0Ik9wZW5HbnN5cyA8b3Blbmduc3lzQG9wZW5nbnN5cy5lcz6ImQQTFgoA
|
||||
QRYhBC+J38Xsso227ZbDVt2S5xJQRhKDBQJnPH9LAhsDBQkFo5qABQsJCAcCAiIC
|
||||
BhUKCQgLAgQWAgMBAh4HAheAAAoJEN2S5xJQRhKDW/MBAO6swnpwdrbm48ypMyPh
|
||||
NboxvF7rCqBqHWwRHvkvrq7pAP9zd98r7z2AvqVXZxnaCsLTUNMEL12+DVZAUZ1G
|
||||
EquRBbg4BGc8f0sSCisGAQQBl1UBBQEBB0B6D6tkrwXSHi7ebGYsiMPntqwdkQ/S
|
||||
84SFTlSxRqdXfgMBCAeIfgQYFgoAJhYhBC+J38Xsso227ZbDVt2S5xJQRhKDBQJn
|
||||
PH9LAhsMBQkFo5qAAAoJEN2S5xJQRhKDJ+cBAM9jYbeq5VXkHLfODeVztgSXnSUe
|
||||
yklJ18oQmpeK5eWeAQDKYk/P0R+1ZJDItxkeP6pw62bCDYGQDvdDGPMAaIT6CA==
|
||||
=xcNc
|
||||
-----END PGP PUBLIC KEY BLOCK-----
|
||||
|
||||
Se arregla con el symlink incluido en las instrucciones mas abajo.
|
||||
Es necesario ejecutar `apt update` después de crear el archivo.
|
||||
|
||||
### Instalar paquetes:
|
||||
|
||||
sudo apt install -y python3-git opengnsys-libarchive-c python3-termcolor python3-requests python3-tqdm bsdextrautils
|
||||
|
||||
|
||||
sudo apt install -y python3.8 python3.8-venv python3-venv libarchive-dev
|
||||
sudo ln -sf /bin/uname /usr/bin/
|
||||
python3.8 -m venv venvog
|
||||
. venvog/bin/activate
|
||||
python3.8 -m pip install --upgrade pip
|
||||
pip3 install -r requirements.txt
|
||||
## Agregar claves de SSH a oglive
|
||||
|
||||
Ejecutar con:
|
||||
El sistema de Git accede al ogrepository por SSH. Para funcionar, necesita que el oglive tenga una clave de SSH, y que el ogrepository la acepte.
|
||||
|
||||
python3.8 ./opengnsys_git_installer.py
|
||||
El instalador de Git puede realizar los cambios requeridos, extrayendo una clave de SSH de un oglive e instalándola en Forgejo. Si hay una instalación de ogboot local, el instalador lo hará automáticamente. Si no la hay, es necesario darle al instalador un oglive del que extraer la clave con el parámetro `--oglive-file` o `--oglive-url`.
|
||||
|
||||
## Distribuciones nuevas (22.04)
|
||||
Por ejemplo:
|
||||
|
||||
sudo apt install python3 python3-venv libarchive-dev
|
||||
python3 -m venv venvog
|
||||
. venvog/bin/activate
|
||||
python3 -m pip install --upgrade pip
|
||||
pip3 install -r requirements.txt
|
||||
./opengnsys_git_installer.py --oglive-url https://example.com/ogLive-noble.iso
|
||||
|
||||
## Agregar clave de SSH si es necesario
|
||||
El instalador procederá a descargar el archivo, montar el ISO, y extraer la clave.
|
||||
|
||||
El proceso falla si no hay clave de SSH en la imagen. Utilizar:
|
||||
Para hacer el proceso después de haber completado la instalación y solo agregar una clave a una instalación existente, usar el parámetro `--set-ssh-key`:
|
||||
|
||||
/opt/opengnsys/bin/setsslkey
|
||||
|
||||
para agregarla.
|
||||
./opengnsys_git_installer.py --set-ssh-key --oglive-url https://example.com/ogLive-noble.iso
|
||||
|
||||
# Ejecutar
|
||||
|
||||
**Nota:** Preferiblemente ejecutar como `root`, ya que `sudo` borra los cambios a las variables de entorno realizadas por venv. El resultado probable es un error de falta de módulos de Python, o un fallo del programa por usar dependencias demasiado antiguas.
|
||||
|
||||
# . venv/bin/activate
|
||||
# ./opengnsys_git_installer.py
|
||||
|
||||
# Documentación
|
||||
Debe ejecutarse como `root`.
|
||||
|
||||
El instalador descarga e instala Forgejo, un interfaz web de Git. La configuración se genera automáticamente.
|
||||
|
||||
Forgejo gestiona los repositorios y el acceso por SSH, por lo cual debe quedarse siempre corriendo. Por defecto se instala en el puerto 3000.
|
||||
|
||||
El usuario por defecto es `oggit` con password `opengnsys`.
|
||||
|
||||
|
||||
# Paquetes con dependencias
|
||||
|
||||
El sistema OgGit requiere módulos de Python que no vienen en Ubuntu 24.04 o tienen versiones demasiado antiguas.
|
||||
|
||||
Los paquetes se pueden obtener desde el repositorio de OpenGnsys (ver arriba).
|
||||
|
||||
Los fuentes de los paquetes se encuentran en oggit/packages.
|
||||
|
||||
# Documentación de código fuente
|
||||
|
||||
Se puede generar documentación de Python con una utilidad como pdoc3 (hay multiples alternativas posibles):
|
||||
|
||||
|
|
|
@ -0,0 +1,656 @@
|
|||
opengnsys-gitinstaller (0.5dev3) UNRELEASED; urgency=medium
|
||||
|
||||
[ OpenGnsys ]
|
||||
* Initial release.
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* First commit
|
||||
* Add installer
|
||||
* Add requirements file
|
||||
|
||||
[ lgromero ]
|
||||
* refs #734 Creates first skeleton of symfony+swagger project
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Add Gitlib
|
||||
|
||||
[ lgromero ]
|
||||
* refs #734 Changes OgBootBundle name and adds a first endpoint to test
|
||||
* refs #734 Adds template of repository and branch endpoints
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Update docs to account for changes
|
||||
* Trivial API server
|
||||
* Ticket #753: Add repository listing
|
||||
* Ticket #735: List branches in repo
|
||||
* Add testing instructions
|
||||
* Agregar manejo de errrores
|
||||
* Ticket #741: Crear repo Ticket #736: Eliminar repo
|
||||
|
||||
[ lgromero ]
|
||||
* refs #734 Adds README for Api installation
|
||||
* refs #734 Control of errores and http codes in controler
|
||||
* refs #734 Renemas oggitservice
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Ticket #738, ticket #739: repo and sync backup protoype
|
||||
|
||||
[ lgromero ]
|
||||
* refs #734 Adds new endpoints sync and backup and status endpoint
|
||||
* refs #734 Adds nelmio api doc configuration
|
||||
* Adds .env file to root
|
||||
* refs #734 use environment variables in .env files and disable web depuration toolbar
|
||||
* refs #734 fix typo in .env and use oggit_url environment variable
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Ticket #738, ticket #739: git sync and backup
|
||||
|
||||
[ Nicolas Arenas ]
|
||||
* Add docker container files
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Ticket #737: GC
|
||||
* Use Paramiko and Gitpython for backups
|
||||
|
||||
[ Nicolas Arenas ]
|
||||
* Add mock api for testing dockerfile
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Ticket #740, listen on all hosts
|
||||
|
||||
[ lgromero ]
|
||||
* refs #734 Removes innecesaries parameters and changes php platform to 8.2
|
||||
* refs #734 just changes name and description in swagger web page
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Remove duplicated import
|
||||
* Documentation prototype
|
||||
* Update to 24.04, solves deployment issue
|
||||
* Add more documentation
|
||||
* Add API README
|
||||
* Add API examples
|
||||
* Update list of package requirements in oglive
|
||||
* Fix commandline parsing bug
|
||||
* Revert experimental Windows change
|
||||
* Fix ticket #770: Re-parse filesystems list after mounting
|
||||
* Use oglive server if ogrepository is not set
|
||||
* Ticket #770: Add sanity check
|
||||
* Ticket #771: Correctly create directories on metadata restoration
|
||||
* Ticket #780: Unmount before clone if needed
|
||||
* Fix ticket #800: sudo doesn't work
|
||||
|
||||
[ Vadim Trochinsky ]
|
||||
* Fix ticket #802: .git directory in filesystem root
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Fix ticket #805: Remove .git directory if it already exists when checking out
|
||||
* Ticket #770: Correctly update metadata when mounting and unmounting
|
||||
* Ticket #804: Move log
|
||||
* Fix ticket #902: .git directories can't be checked out
|
||||
* Lint fixes
|
||||
* Remove unused code
|
||||
* Lint fixes
|
||||
* Lint fixes
|
||||
* Lint fixes
|
||||
* Additional logging message
|
||||
* Lint fix
|
||||
* Fix ticket #907: mknod fails due to path not found
|
||||
* Initial implementation for commit, push, fetch.
|
||||
* Don't fail on empty lines in metadata, just skip them
|
||||
* Add documentation and functionality to progress hook (not used yet)
|
||||
* Pylint fixes
|
||||
* Ticket #908: Remove some unneeded warnings
|
||||
* Fix progress report
|
||||
* Ticket #906: Fix permissions on directories
|
||||
* Make pylint happy
|
||||
* Mount fix
|
||||
* Ticket #808: Initial implementation
|
||||
* Initial forgejo install
|
||||
* Deduplicate key extraction
|
||||
* Fix installer bugs and add documentation
|
||||
* Change user to oggit
|
||||
* Fix NTFS ID modification implementation
|
||||
* Implement system-specific EFI data support
|
||||
* Fix encoding when reading system uuid
|
||||
* Fix and refactor slightly EFI implementation
|
||||
* Add Windows BCD decoding tool
|
||||
* Check module loading and unloading, modprobe works on oglive now
|
||||
* Make EFI deployment more flexible
|
||||
* Add organization API call
|
||||
* Fix bash library path
|
||||
* Fix repo paths for forgejo
|
||||
* Update documentation
|
||||
* Sync to ensure everything is written
|
||||
* Refactoring and more pydoc
|
||||
* Add more documentation
|
||||
* Improve installer documentation
|
||||
* Improve gitlib instructions
|
||||
* Add missing files
|
||||
* Partial setsshkey implementation
|
||||
* Fix SSH key generation and extraction
|
||||
* Initial package contents
|
||||
* Add Debian packaging
|
||||
* Add pylkid
|
||||
* Add pyblkid debian files
|
||||
* Use packaged pyblkid
|
||||
* More detailed API logging
|
||||
* Improve logging
|
||||
* Add oglive key to forgejo
|
||||
* Add original source
|
||||
* Always re-download forgejo, even if installed.
|
||||
* Remove obsolete code that stopped being relevant with Forgejo
|
||||
* Move python modules to /opt/opengnsys-modules
|
||||
* Use absolute paths in initrd modification
|
||||
* Add timestamp to ssh key title, forgejo doesn't like duplicates
|
||||
* Skip past symlinks and problems in oglive modification
|
||||
* Get keys from squashfs instead of initrd to work with current oglive packaging
|
||||
* Fix trivial bug
|
||||
* Move modules to /usr/share/opengnsys
|
||||
* Move packages to /usr/share
|
||||
|
||||
[ Angel Rodriguez ]
|
||||
* Add gitlib/README-en.md
|
||||
* Add api/README-en.md
|
||||
* Add installer/README-en.md
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Skip NTFS code on non-Windows
|
||||
* Store and restore GPT partition UUIDs
|
||||
* Update READMEs
|
||||
* BCD constants
|
||||
* Use tqdm
|
||||
* Constants
|
||||
* Add extra mounts update
|
||||
* Better status reports
|
||||
* Make log filename machine-dependent Move kernel args parsing
|
||||
* Make unmounting more robust
|
||||
* Improve repository initialization
|
||||
* Make --pull work like the other commands
|
||||
* Add packages
|
||||
* Update documentation
|
||||
* Ignore python cache
|
||||
* Ignore more files
|
||||
* add python libarchive-c original package
|
||||
* Add pyblkid copyright file
|
||||
* Add make_orig script
|
||||
* Reorder and fix for ogrepository reorganization
|
||||
* Restructure git installer to work without ogboot on the same machine, update docs
|
||||
* Update english documentation
|
||||
* Improve installation process, make it possible to extract keys from oglive
|
||||
* Fix namespaces
|
||||
* Fix ogrepository paths
|
||||
* Change git repo path
|
||||
* Improvements for logging and error handling
|
||||
* Fix HTTP exception handling
|
||||
* Improve task management, cleanup when there are too many
|
||||
* More error logging
|
||||
* Mark git repo as a safe directory
|
||||
* Rework the ability to use a custom SSH key
|
||||
* Log every request
|
||||
* Branch deletion
|
||||
* Make branch deletion RESTful
|
||||
* Initial version of the API server
|
||||
* Add original repo_api
|
||||
* Convert to blueprint
|
||||
* Add port argument
|
||||
* Fix error handling
|
||||
* Add README
|
||||
* Load swagger from disk
|
||||
* Fix repository URL
|
||||
* Bump forgejo version
|
||||
* Add helpful script
|
||||
* Fix port argument
|
||||
* Refactoring for package support
|
||||
* Remove old code
|
||||
* Refactoring for packaging
|
||||
* opengnsys-forgejo package
|
||||
* Fix post-install for forgejo deployment
|
||||
* Fixes for running under gunicorn
|
||||
* Debian packaging
|
||||
* Add branches and tags creation endpoints
|
||||
* Add missing file
|
||||
* Rename service
|
||||
* Add templates
|
||||
* Disable tests
|
||||
* Fix permission problem
|
||||
* Fix ini path
|
||||
* Update changelog
|
||||
* Update changelog
|
||||
* Add package files
|
||||
* Add git image creation script
|
||||
* Slightly improve API for ogrepo usability
|
||||
* First commit
|
||||
* Add installer
|
||||
* Add requirements file
|
||||
|
||||
[ lgromero ]
|
||||
* refs #734 Creates first skeleton of symfony+swagger project
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Add Gitlib
|
||||
|
||||
[ lgromero ]
|
||||
* refs #734 Changes OgBootBundle name and adds a first endpoint to test
|
||||
* refs #734 Adds template of repository and branch endpoints
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Update docs to account for changes
|
||||
* Trivial API server
|
||||
* Ticket #753: Add repository listing
|
||||
* Ticket #735: List branches in repo
|
||||
* Add testing instructions
|
||||
* Agregar manejo de errrores
|
||||
* Ticket #741: Crear repo Ticket #736: Eliminar repo
|
||||
|
||||
[ lgromero ]
|
||||
* refs #734 Adds README for Api installation
|
||||
* refs #734 Control of errores and http codes in controler
|
||||
* refs #734 Renemas oggitservice
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Ticket #738, ticket #739: repo and sync backup protoype
|
||||
|
||||
[ lgromero ]
|
||||
* refs #734 Adds new endpoints sync and backup and status endpoint
|
||||
* refs #734 Adds nelmio api doc configuration
|
||||
* Adds .env file to root
|
||||
* refs #734 use environment variables in .env files and disable web depuration toolbar
|
||||
* refs #734 fix typo in .env and use oggit_url environment variable
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Ticket #738, ticket #739: git sync and backup
|
||||
|
||||
[ Nicolas Arenas ]
|
||||
* Add docker container files
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Ticket #737: GC
|
||||
* Use Paramiko and Gitpython for backups
|
||||
|
||||
[ Nicolas Arenas ]
|
||||
* Add mock api for testing dockerfile
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Ticket #740, listen on all hosts
|
||||
|
||||
[ lgromero ]
|
||||
* refs #734 Removes innecesaries parameters and changes php platform to 8.2
|
||||
* refs #734 just changes name and description in swagger web page
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Remove duplicated import
|
||||
* Documentation prototype
|
||||
* Update to 24.04, solves deployment issue
|
||||
* Add more documentation
|
||||
* Add API README
|
||||
* Add API examples
|
||||
* Update list of package requirements in oglive
|
||||
* Fix commandline parsing bug
|
||||
* Revert experimental Windows change
|
||||
* Fix ticket #770: Re-parse filesystems list after mounting
|
||||
* Use oglive server if ogrepository is not set
|
||||
* Ticket #770: Add sanity check
|
||||
* Ticket #771: Correctly create directories on metadata restoration
|
||||
* Ticket #780: Unmount before clone if needed
|
||||
* Fix ticket #800: sudo doesn't work
|
||||
|
||||
[ Vadim Trochinsky ]
|
||||
* Fix ticket #802: .git directory in filesystem root
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Fix ticket #805: Remove .git directory if it already exists when checking out
|
||||
* Ticket #770: Correctly update metadata when mounting and unmounting
|
||||
* Ticket #804: Move log
|
||||
* Fix ticket #902: .git directories can't be checked out
|
||||
* Lint fixes
|
||||
* Remove unused code
|
||||
* Lint fixes
|
||||
* Lint fixes
|
||||
* Lint fixes
|
||||
* Additional logging message
|
||||
* Lint fix
|
||||
* Fix ticket #907: mknod fails due to path not found
|
||||
* Initial implementation for commit, push, fetch.
|
||||
* Don't fail on empty lines in metadata, just skip them
|
||||
* Add documentation and functionality to progress hook (not used yet)
|
||||
* Pylint fixes
|
||||
* Ticket #908: Remove some unneeded warnings
|
||||
* Fix progress report
|
||||
* Ticket #906: Fix permissions on directories
|
||||
* Make pylint happy
|
||||
* Mount fix
|
||||
* Ticket #808: Initial implementation
|
||||
* Initial forgejo install
|
||||
* Deduplicate key extraction
|
||||
* Fix installer bugs and add documentation
|
||||
* Change user to oggit
|
||||
* Fix NTFS ID modification implementation
|
||||
* Implement system-specific EFI data support
|
||||
* Fix encoding when reading system uuid
|
||||
* Fix and refactor slightly EFI implementation
|
||||
* Add Windows BCD decoding tool
|
||||
* Check module loading and unloading, modprobe works on oglive now
|
||||
* Make EFI deployment more flexible
|
||||
* Add organization API call
|
||||
* Fix bash library path
|
||||
* Fix repo paths for forgejo
|
||||
* Update documentation
|
||||
* Sync to ensure everything is written
|
||||
* Refactoring and more pydoc
|
||||
* Add more documentation
|
||||
* Improve installer documentation
|
||||
* Improve gitlib instructions
|
||||
* Add missing files
|
||||
* Partial setsshkey implementation
|
||||
* Fix SSH key generation and extraction
|
||||
* Initial package contents
|
||||
* Add Debian packaging
|
||||
* Add pylkid
|
||||
* Add pyblkid debian files
|
||||
* Use packaged pyblkid
|
||||
* More detailed API logging
|
||||
* Improve logging
|
||||
* Add oglive key to forgejo
|
||||
* Add original source
|
||||
* Always re-download forgejo, even if installed.
|
||||
* Remove obsolete code that stopped being relevant with Forgejo
|
||||
* Move python modules to /opt/opengnsys-modules
|
||||
* Use absolute paths in initrd modification
|
||||
* Add timestamp to ssh key title, forgejo doesn't like duplicates
|
||||
* Skip past symlinks and problems in oglive modification
|
||||
* Get keys from squashfs instead of initrd to work with current oglive packaging
|
||||
* Fix trivial bug
|
||||
* Move modules to /usr/share/opengnsys
|
||||
* Move packages to /usr/share
|
||||
|
||||
[ Angel Rodriguez ]
|
||||
* Add gitlib/README-en.md
|
||||
* Add api/README-en.md
|
||||
* Add installer/README-en.md
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Skip NTFS code on non-Windows
|
||||
* Store and restore GPT partition UUIDs
|
||||
* Update READMEs
|
||||
* BCD constants
|
||||
* Use tqdm
|
||||
* Constants
|
||||
* Add extra mounts update
|
||||
* Better status reports
|
||||
* Make log filename machine-dependent Move kernel args parsing
|
||||
* Make unmounting more robust
|
||||
* Improve repository initialization
|
||||
* Make --pull work like the other commands
|
||||
* Add packages
|
||||
* Update documentation
|
||||
* Ignore python cache
|
||||
* Ignore more files
|
||||
* add python libarchive-c original package
|
||||
* Add pyblkid copyright file
|
||||
* Add make_orig script
|
||||
* Reorder and fix for ogrepository reorganization
|
||||
* Restructure git installer to work without ogboot on the same machine, update docs
|
||||
* Update english documentation
|
||||
* Improve installation process, make it possible to extract keys from oglive
|
||||
* Fix namespaces
|
||||
* Fix ogrepository paths
|
||||
* Change git repo path
|
||||
* Improvements for logging and error handling
|
||||
* Fix HTTP exception handling
|
||||
* Improve task management, cleanup when there are too many
|
||||
* More error logging
|
||||
* Mark git repo as a safe directory
|
||||
* Rework the ability to use a custom SSH key
|
||||
* Log every request
|
||||
* Branch deletion
|
||||
* Make branch deletion RESTful
|
||||
* Initial version of the API server
|
||||
* Add original repo_api
|
||||
* Convert to blueprint
|
||||
* Add port argument
|
||||
* Fix error handling
|
||||
* Add README
|
||||
* Load swagger from disk
|
||||
* Fix repository URL
|
||||
* Bump forgejo version
|
||||
* Add helpful script
|
||||
* Fix port argument
|
||||
* Refactoring for package support
|
||||
* Remove old code
|
||||
* Refactoring for packaging
|
||||
* opengnsys-forgejo package
|
||||
* Fix post-install for forgejo deployment
|
||||
* Fixes for running under gunicorn
|
||||
* Debian packaging
|
||||
* Add branches and tags creation endpoints
|
||||
* Add missing file
|
||||
* Rename service
|
||||
* Add templates
|
||||
* Disable tests
|
||||
* Fix permission problem
|
||||
* Fix ini path
|
||||
* Update changelog
|
||||
* Update changelog
|
||||
* Add package files
|
||||
* Add git image creation script
|
||||
* Slightly improve API for ogrepo usability
|
||||
* Update changelog
|
||||
* First commit
|
||||
* Add installer
|
||||
* Add requirements file
|
||||
|
||||
[ lgromero ]
|
||||
* refs #734 Creates first skeleton of symfony+swagger project
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Add Gitlib
|
||||
|
||||
[ lgromero ]
|
||||
* refs #734 Changes OgBootBundle name and adds a first endpoint to test
|
||||
* refs #734 Adds template of repository and branch endpoints
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Update docs to account for changes
|
||||
* Trivial API server
|
||||
* Ticket #753: Add repository listing
|
||||
* Ticket #735: List branches in repo
|
||||
* Add testing instructions
|
||||
* Agregar manejo de errrores
|
||||
* Ticket #741: Crear repo Ticket #736: Eliminar repo
|
||||
|
||||
[ lgromero ]
|
||||
* refs #734 Adds README for Api installation
|
||||
* refs #734 Control of errores and http codes in controler
|
||||
* refs #734 Renemas oggitservice
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Ticket #738, ticket #739: repo and sync backup protoype
|
||||
|
||||
[ lgromero ]
|
||||
* refs #734 Adds new endpoints sync and backup and status endpoint
|
||||
* refs #734 Adds nelmio api doc configuration
|
||||
* Adds .env file to root
|
||||
* refs #734 use environment variables in .env files and disable web depuration toolbar
|
||||
* refs #734 fix typo in .env and use oggit_url environment variable
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Ticket #738, ticket #739: git sync and backup
|
||||
|
||||
[ Nicolas Arenas ]
|
||||
* Add docker container files
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Ticket #737: GC
|
||||
* Use Paramiko and Gitpython for backups
|
||||
|
||||
[ Nicolas Arenas ]
|
||||
* Add mock api for testing dockerfile
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Ticket #740, listen on all hosts
|
||||
|
||||
[ lgromero ]
|
||||
* refs #734 Removes innecesaries parameters and changes php platform to 8.2
|
||||
* refs #734 just changes name and description in swagger web page
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Remove duplicated import
|
||||
* Documentation prototype
|
||||
* Update to 24.04, solves deployment issue
|
||||
* Add more documentation
|
||||
* Add API README
|
||||
* Add API examples
|
||||
* Update list of package requirements in oglive
|
||||
* Fix commandline parsing bug
|
||||
* Revert experimental Windows change
|
||||
* Fix ticket #770: Re-parse filesystems list after mounting
|
||||
* Use oglive server if ogrepository is not set
|
||||
* Ticket #770: Add sanity check
|
||||
* Ticket #771: Correctly create directories on metadata restoration
|
||||
* Ticket #780: Unmount before clone if needed
|
||||
* Fix ticket #800: sudo doesn't work
|
||||
|
||||
[ Vadim Trochinsky ]
|
||||
* Fix ticket #802: .git directory in filesystem root
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Fix ticket #805: Remove .git directory if it already exists when checking out
|
||||
* Ticket #770: Correctly update metadata when mounting and unmounting
|
||||
* Ticket #804: Move log
|
||||
* Fix ticket #902: .git directories can't be checked out
|
||||
* Lint fixes
|
||||
* Remove unused code
|
||||
* Lint fixes
|
||||
* Lint fixes
|
||||
* Lint fixes
|
||||
* Additional logging message
|
||||
* Lint fix
|
||||
* Fix ticket #907: mknod fails due to path not found
|
||||
* Initial implementation for commit, push, fetch.
|
||||
* Don't fail on empty lines in metadata, just skip them
|
||||
* Add documentation and functionality to progress hook (not used yet)
|
||||
* Pylint fixes
|
||||
* Ticket #908: Remove some unneeded warnings
|
||||
* Fix progress report
|
||||
* Ticket #906: Fix permissions on directories
|
||||
* Make pylint happy
|
||||
* Mount fix
|
||||
* Ticket #808: Initial implementation
|
||||
* Initial forgejo install
|
||||
* Deduplicate key extraction
|
||||
* Fix installer bugs and add documentation
|
||||
* Change user to oggit
|
||||
* Fix NTFS ID modification implementation
|
||||
* Implement system-specific EFI data support
|
||||
* Fix encoding when reading system uuid
|
||||
* Fix and refactor slightly EFI implementation
|
||||
* Add Windows BCD decoding tool
|
||||
* Check module loading and unloading, modprobe works on oglive now
|
||||
* Make EFI deployment more flexible
|
||||
* Add organization API call
|
||||
* Fix bash library path
|
||||
* Fix repo paths for forgejo
|
||||
* Update documentation
|
||||
* Sync to ensure everything is written
|
||||
* Refactoring and more pydoc
|
||||
* Add more documentation
|
||||
* Improve installer documentation
|
||||
* Improve gitlib instructions
|
||||
* Add missing files
|
||||
* Partial setsshkey implementation
|
||||
* Fix SSH key generation and extraction
|
||||
* Initial package contents
|
||||
* Add Debian packaging
|
||||
* Add pylkid
|
||||
* Add pyblkid debian files
|
||||
* Use packaged pyblkid
|
||||
* More detailed API logging
|
||||
* Improve logging
|
||||
* Add oglive key to forgejo
|
||||
* Add original source
|
||||
* Always re-download forgejo, even if installed.
|
||||
* Remove obsolete code that stopped being relevant with Forgejo
|
||||
* Move python modules to /opt/opengnsys-modules
|
||||
* Use absolute paths in initrd modification
|
||||
* Add timestamp to ssh key title, forgejo doesn't like duplicates
|
||||
* Skip past symlinks and problems in oglive modification
|
||||
* Get keys from squashfs instead of initrd to work with current oglive packaging
|
||||
* Fix trivial bug
|
||||
* Move modules to /usr/share/opengnsys
|
||||
* Move packages to /usr/share
|
||||
|
||||
[ Angel Rodriguez ]
|
||||
* Add gitlib/README-en.md
|
||||
* Add api/README-en.md
|
||||
* Add installer/README-en.md
|
||||
|
||||
[ Vadim Troshchinskiy ]
|
||||
* Skip NTFS code on non-Windows
|
||||
* Store and restore GPT partition UUIDs
|
||||
* Update READMEs
|
||||
* BCD constants
|
||||
* Use tqdm
|
||||
* Constants
|
||||
* Add extra mounts update
|
||||
* Better status reports
|
||||
* Make log filename machine-dependent Move kernel args parsing
|
||||
* Make unmounting more robust
|
||||
* Improve repository initialization
|
||||
* Make --pull work like the other commands
|
||||
* Add packages
|
||||
* Update documentation
|
||||
* Ignore python cache
|
||||
* Ignore more files
|
||||
* add python libarchive-c original package
|
||||
* Add pyblkid copyright file
|
||||
* Add make_orig script
|
||||
* Reorder and fix for ogrepository reorganization
|
||||
* Restructure git installer to work without ogboot on the same machine, update docs
|
||||
* Update english documentation
|
||||
* Improve installation process, make it possible to extract keys from oglive
|
||||
* Fix namespaces
|
||||
* Fix ogrepository paths
|
||||
* Change git repo path
|
||||
* Improvements for logging and error handling
|
||||
* Fix HTTP exception handling
|
||||
* Improve task management, cleanup when there are too many
|
||||
* More error logging
|
||||
* Mark git repo as a safe directory
|
||||
* Rework the ability to use a custom SSH key
|
||||
* Log every request
|
||||
* Branch deletion
|
||||
* Make branch deletion RESTful
|
||||
* Initial version of the API server
|
||||
* Add original repo_api
|
||||
* Convert to blueprint
|
||||
* Add port argument
|
||||
* Fix error handling
|
||||
* Add README
|
||||
* Load swagger from disk
|
||||
* Fix repository URL
|
||||
* Bump forgejo version
|
||||
* Add helpful script
|
||||
* Fix port argument
|
||||
* Refactoring for package support
|
||||
* Remove old code
|
||||
* Refactoring for packaging
|
||||
* opengnsys-forgejo package
|
||||
* Fix post-install for forgejo deployment
|
||||
* Fixes for running under gunicorn
|
||||
* Debian packaging
|
||||
* Add branches and tags creation endpoints
|
||||
* Add missing file
|
||||
* Rename service
|
||||
* Add templates
|
||||
* Disable tests
|
||||
* Fix permission problem
|
||||
* Fix ini path
|
||||
* Update changelog
|
||||
* Update changelog
|
||||
* Add package files
|
||||
* Add git image creation script
|
||||
* Slightly improve API for ogrepo usability
|
||||
* Update changelog
|
||||
* Update changelog
|
||||
|
||||
-- OpenGnsys <opengnsys@opengnsys.com> Mon, 16 Jun 2025 21:23:34 +0000
|
|
@ -0,0 +1,29 @@
|
|||
Source: opengnsys-gitinstaller
|
||||
Section: unknown
|
||||
Priority: optional
|
||||
Maintainer: OpenGnsys <opengnsys@opengnsys.es>
|
||||
Rules-Requires-Root: no
|
||||
Build-Depends:
|
||||
debhelper-compat (= 13),
|
||||
Standards-Version: 4.6.2
|
||||
Homepage: https://opengnsys.es
|
||||
#Vcs-Browser: https://salsa.debian.org/debian/ogboot
|
||||
#Vcs-Git: https://salsa.debian.org/debian/ogboot.git
|
||||
|
||||
Package: opengnsys-gitinstaller
|
||||
Architecture: any
|
||||
Multi-Arch: foreign
|
||||
Depends:
|
||||
${shlibs:Depends},
|
||||
${misc:Depends},
|
||||
bsdextrautils,
|
||||
debconf (>= 1.5.0),
|
||||
opengnsys-libarchive-c,
|
||||
python3,
|
||||
python3-aniso8601,
|
||||
python3-git,
|
||||
python3-termcolor,
|
||||
python3-tqdm
|
||||
Conflicts:
|
||||
Description: Opengnsys installer library for OgGit
|
||||
Files for OpenGnsys Git support
|
|
@ -0,0 +1,43 @@
|
|||
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Source: <url://example.com>
|
||||
Upstream-Name: ogboot
|
||||
Upstream-Contact: <preferred name and address to reach the upstream project>
|
||||
|
||||
Files:
|
||||
*
|
||||
Copyright:
|
||||
<years> <put author's name and email here>
|
||||
<years> <likewise for another author>
|
||||
License: GPL-3.0+
|
||||
|
||||
Files:
|
||||
debian/*
|
||||
Copyright:
|
||||
2025 vagrant <vagrant@build>
|
||||
License: GPL-3.0+
|
||||
|
||||
License: GPL-3.0+
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
.
|
||||
This package is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Comment:
|
||||
On Debian systems, the complete text of the GNU General
|
||||
Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
||||
|
||||
# Please also look if there are files or directories which have a
|
||||
# different copyright/license attached and list them here.
|
||||
# Please avoid picking licenses with terms that are more restrictive than the
|
||||
# packaged work, as it may make Debian's contributions unacceptable upstream.
|
||||
#
|
||||
# If you need, there are some extra license texts available in two places:
|
||||
# /usr/share/debhelper/dh_make/licenses/
|
||||
# /usr/share/common-licenses/
|
|
@ -0,0 +1,2 @@
|
|||
opengnsys-gitinstaller_0.5_amd64.buildinfo unknown optional
|
||||
opengnsys-gitinstaller_0.5_amd64.deb unknown optional
|
|
@ -0,0 +1 @@
|
|||
/opt/opengnsys/ogrepository/oggit/lib
|
|
@ -0,0 +1 @@
|
|||
opengnsys_git_installer.py /opt/opengnsys/ogrepository/oggit/lib
|
|
@ -0,0 +1,2 @@
|
|||
misc:Depends=
|
||||
misc:Pre-Depends=
|
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/make -f
|
||||
|
||||
# See debhelper(7) (uncomment to enable).
|
||||
# Output every command that modifies files on the build system.
|
||||
#export DH_VERBOSE = 1
|
||||
|
||||
|
||||
# See FEATURE AREAS in dpkg-buildflags(1).
|
||||
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
|
||||
|
||||
# See ENVIRONMENT in dpkg-buildflags(1).
|
||||
# Package maintainers to append CFLAGS.
|
||||
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
|
||||
# Package maintainers to append LDFLAGS.
|
||||
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
|
||||
|
||||
|
||||
%:
|
||||
dh $@
|
||||
|
||||
|
||||
%:
|
||||
dh $@
|
||||
|
||||
# Ejecutar composer install durante la fase de construcción
|
||||
override_dh_auto_build:
|
||||
|
||||
|
||||
# dh_make generated override targets.
|
||||
# This is an example for Cmake (see <https://bugs.debian.org/641051>).
|
||||
#override_dh_auto_configure:
|
||||
# dh_auto_configure -- \
|
||||
# -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)
|
|
@ -0,0 +1,78 @@
|
|||
APP_NAME = OpenGnsys Git
|
||||
APP_SLOGAN =
|
||||
RUN_USER = {forgejo_user}
|
||||
WORK_PATH = {forgejo_work_path}
|
||||
RUN_MODE = prod
|
||||
|
||||
[database]
|
||||
DB_TYPE = sqlite3
|
||||
HOST = 127.0.0.1:3306
|
||||
NAME = forgejo
|
||||
USER = forgejo
|
||||
PASSWD =
|
||||
SCHEMA =
|
||||
SSL_MODE = disable
|
||||
PATH = {forgejo_db_path}
|
||||
LOG_SQL = false
|
||||
|
||||
[repository]
|
||||
ROOT = {forgejo_repository_root}
|
||||
|
||||
[server]
|
||||
SSH_DOMAIN = og-admin
|
||||
DOMAIN = og-admin
|
||||
HTTP_PORT = {forgejo_port}
|
||||
ROOT_URL = http://{forgejo_hostname}:{forgejo_port}/
|
||||
APP_DATA_PATH = {forgejo_data_path}
|
||||
DISABLE_SSH = false
|
||||
SSH_PORT = 22
|
||||
LFS_START_SERVER = true
|
||||
LFS_JWT_SECRET = {forgejo_lfs_jwt_secret}
|
||||
OFFLINE_MODE = true
|
||||
|
||||
[lfs]
|
||||
PATH = {forgejo_lfs_path}
|
||||
|
||||
[mailer]
|
||||
ENABLED = false
|
||||
|
||||
[service]
|
||||
REGISTER_EMAIL_CONFIRM = false
|
||||
ENABLE_NOTIFY_MAIL = false
|
||||
DISABLE_REGISTRATION = true
|
||||
ALLOW_ONLY_EXTERNAL_REGISTRATION = false
|
||||
ENABLE_CAPTCHA = false
|
||||
REQUIRE_SIGNIN_VIEW = false
|
||||
DEFAULT_KEEP_EMAIL_PRIVATE = false
|
||||
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
|
||||
DEFAULT_ENABLE_TIMETRACKING = true
|
||||
NO_REPLY_ADDRESS = noreply.localhost
|
||||
|
||||
[openid]
|
||||
ENABLE_OPENID_SIGNIN = true
|
||||
ENABLE_OPENID_SIGNUP = true
|
||||
|
||||
[cron.update_checker]
|
||||
ENABLED = true
|
||||
|
||||
[session]
|
||||
PROVIDER = file
|
||||
|
||||
[log]
|
||||
MODE = console
|
||||
LEVEL = info
|
||||
ROOT_PATH = {forgejo_log_path} #/tmp/log
|
||||
|
||||
[repository.pull-request]
|
||||
DEFAULT_MERGE_STYLE = merge
|
||||
|
||||
[repository.signing]
|
||||
DEFAULT_TRUST_MODEL = committer
|
||||
|
||||
[security]
|
||||
INSTALL_LOCK = true
|
||||
INTERNAL_TOKEN = {forgejo_internal_token}
|
||||
PASSWORD_HASH_ALGO = pbkdf2_hi
|
||||
|
||||
[oauth2]
|
||||
JWT_SECRET = {forgejo_jwt_secret}
|
|
@ -0,0 +1,11 @@
|
|||
[Service]
|
||||
RestartSec=10s
|
||||
Type=simple
|
||||
User={gitapi_user}
|
||||
Group={gitapi_group}
|
||||
WorkingDirectory={gitapi_work_path}
|
||||
ExecStart=/usr/bin/gunicorn -w 4 -b {gitapi_host}:{gitapi_port} gitapi:app
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
if [ ! -f "/etc/apt/sources.list.d/opengnsys.sources" ] ; then
|
||||
|
||||
cat > /etc/apt/sources.list.d/opengnsys.sources <<HERE
|
||||
Types: deb
|
||||
URIs: https://ognproject.evlt.uma.es/debian-opengnsys/opengnsys
|
||||
Suites: noble
|
||||
Components: main
|
||||
Signed-By:
|
||||
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
.
|
||||
mDMEZzx/SxYJKwYBBAHaRw8BAQdAa83CuAJ5/+7Pn9LHT/k34EAGpx5FnT/ExHSj
|
||||
XZG1JES0Ik9wZW5HbnN5cyA8b3Blbmduc3lzQG9wZW5nbnN5cy5lcz6ImQQTFgoA
|
||||
QRYhBC+J38Xsso227ZbDVt2S5xJQRhKDBQJnPH9LAhsDBQkFo5qABQsJCAcCAiIC
|
||||
BhUKCQgLAgQWAgMBAh4HAheAAAoJEN2S5xJQRhKDW/MBAO6swnpwdrbm48ypMyPh
|
||||
NboxvF7rCqBqHWwRHvkvrq7pAP9zd98r7z2AvqVXZxnaCsLTUNMEL12+DVZAUZ1G
|
||||
EquRBbg4BGc8f0sSCisGAQQBl1UBBQEBB0B6D6tkrwXSHi7ebGYsiMPntqwdkQ/S
|
||||
84SFTlSxRqdXfgMBCAeIfgQYFgoAJhYhBC+J38Xsso227ZbDVt2S5xJQRhKDBQJn
|
||||
PH9LAhsMBQkFo5qAAAoJEN2S5xJQRhKDJ+cBAM9jYbeq5VXkHLfODeVztgSXnSUe
|
||||
yklJ18oQmpeK5eWeAQDKYk/P0R+1ZJDItxkeP6pw62bCDYGQDvdDGPMAaIT6CA==
|
||||
=xcNc
|
||||
-----END PGP PUBLIC KEY BLOCK-----
|
||||
HERE
|
||||
fi
|
||||
|
||||
|
||||
apt update
|
||||
apt install -y python3-git opengnsys-libarchive-c python3-termcolor python3-requests python3-tqdm bsdextrautils
|
|
@ -0,0 +1,11 @@
|
|||
[Service]
|
||||
RestartSec=10s
|
||||
Type=simple
|
||||
User={forgejo_user}
|
||||
Group={forgejo_group}
|
||||
WorkingDirectory={forgejo_work_path}
|
||||
ExecStart={forgejo_bin} web --config {forgejo_app_ini}
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -0,0 +1,17 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
git clone https://github.com/dchevell/flask-executor opengnsys-flask-executor
|
||||
cd opengnsys-flask-executor
|
||||
version=`python3 ./setup.py --version`
|
||||
cd ..
|
||||
|
||||
if [ -d "opengnsys-flask-executor-${version}" ] ; then
|
||||
echo "Directory opengnsys-flask-executor-${version} already exists, won't overwrite"
|
||||
exit 1
|
||||
else
|
||||
rm -rf opengnsys-flask-executor/.git
|
||||
mv opengnsys-flask-executor "opengnsys-flask-executor-${version}"
|
||||
tar -c --xz -v -f "opengnsys-flask-executor_${version}.orig.tar.xz" "opengnsys-flask-executor-${version}"
|
||||
fi
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
name: Flask-Executor tests
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: ["3.7", "3.8", "3.9", "3.10"]
|
||||
flask-version: ["<2.2", ">=2.2"]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -q "flask ${{ matrix.flask-version }}"
|
||||
pip install -e .[test]
|
||||
- name: Test with pytest
|
||||
run: |
|
||||
pytest --cov=flask_executor/ --cov-report=xml
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v3
|
|
@ -0,0 +1,105 @@
|
|||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# celery beat schedule file
|
||||
celerybeat-schedule
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2018 Dave Chevell
|
||||
|
||||
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.
|
|
@ -0,0 +1,134 @@
|
|||
Flask-Executor
|
||||
==============
|
||||
|
||||
[](https://github.com/dchevell/flask-executor/actions/workflows/tests.yml)
|
||||
[](https://codecov.io/gh/dchevell/flask-executor)
|
||||
[](https://pypi.python.org/pypi/Flask-Executor)
|
||||
[](https://github.com/dchevell/flask-executor/blob/master/LICENSE)
|
||||
|
||||
Sometimes you need a simple task queue without the overhead of separate worker processes or powerful-but-complex libraries beyond your requirements. Flask-Executor is an easy to use wrapper for the `concurrent.futures` module that lets you initialise and configure executors via common Flask application patterns. It's a great way to get up and running fast with a lightweight in-process task queue.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
Flask-Executor is available on PyPI and can be installed with:
|
||||
|
||||
pip install flask-executor
|
||||
|
||||
|
||||
Quick start
|
||||
-----------
|
||||
|
||||
Here's a quick example of using Flask-Executor inside your Flask application:
|
||||
|
||||
```python
|
||||
from flask import Flask
|
||||
from flask_executor import Executor
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
executor = Executor(app)
|
||||
|
||||
|
||||
def send_email(recipient, subject, body):
|
||||
# Magic to send an email
|
||||
return True
|
||||
|
||||
|
||||
@app.route('/signup')
|
||||
def signup():
|
||||
# Do signup form
|
||||
executor.submit(send_email, recipient, subject, body)
|
||||
```
|
||||
|
||||
|
||||
Contexts
|
||||
--------
|
||||
|
||||
When calling `submit()` or `map()` Flask-Executor will wrap `ThreadPoolExecutor` callables with a
|
||||
copy of both the current application context and current request context. Code that must be run in
|
||||
these contexts or that depends on information or configuration stored in `flask.current_app`,
|
||||
`flask.request` or `flask.g` can be submitted to the executor without modification.
|
||||
|
||||
Note: due to limitations in Python's default object serialisation and a lack of shared memory space between subprocesses, contexts cannot be pushed to `ProcessPoolExecutor()` workers.
|
||||
|
||||
|
||||
Futures
|
||||
-------
|
||||
|
||||
You may want to preserve access to Futures returned from the executor, so that you can retrieve the
|
||||
results in a different part of your application. Flask-Executor allows Futures to be stored within
|
||||
the executor itself and provides methods for querying and returning them in different parts of your
|
||||
app::
|
||||
|
||||
```python
|
||||
@app.route('/start-task')
|
||||
def start_task():
|
||||
executor.submit_stored('calc_power', pow, 323, 1235)
|
||||
return jsonify({'result':'success'})
|
||||
|
||||
@app.route('/get-result')
|
||||
def get_result():
|
||||
if not executor.futures.done('calc_power'):
|
||||
return jsonify({'status': executor.futures._state('calc_power')})
|
||||
future = executor.futures.pop('calc_power')
|
||||
return jsonify({'status': done, 'result': future.result()})
|
||||
```
|
||||
|
||||
|
||||
Decoration
|
||||
----------
|
||||
|
||||
Flask-Executor lets you decorate methods in the same style as distributed task queues like
|
||||
Celery:
|
||||
|
||||
```python
|
||||
@executor.job
|
||||
def fib(n):
|
||||
if n <= 2:
|
||||
return 1
|
||||
else:
|
||||
return fib(n-1) + fib(n-2)
|
||||
|
||||
@app.route('/decorate_fib')
|
||||
def decorate_fib():
|
||||
fib.submit(5)
|
||||
fib.submit_stored('fibonacci', 5)
|
||||
fib.map(range(1, 6))
|
||||
return 'OK'
|
||||
```
|
||||
|
||||
|
||||
Default Callbacks
|
||||
-----------------
|
||||
|
||||
Future objects can have callbacks attached by using `Future.add_done_callback`. Flask-Executor
|
||||
lets you specify default callbacks that will be applied to all new futures created by the executor:
|
||||
|
||||
```python
|
||||
def some_callback(future):
|
||||
# do something with future
|
||||
|
||||
executor.add_default_done_callback(some_callback)
|
||||
|
||||
# Callback will be added to the below task automatically
|
||||
executor.submit(pow, 323, 1235)
|
||||
```
|
||||
|
||||
|
||||
Propagate Exceptions
|
||||
--------------------
|
||||
|
||||
Normally any exceptions thrown by background threads or processes will be swallowed unless explicitly
|
||||
checked for. To instead surface all exceptions thrown by background tasks, Flask-Executor can add
|
||||
a special default callback that raises any exceptions thrown by tasks submitted to the executor::
|
||||
|
||||
```python
|
||||
app.config['EXECUTOR_PROPAGATE_EXCEPTIONS'] = True
|
||||
```
|
||||
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
Check out the full documentation at [flask-executor.readthedocs.io](https://flask-executor.readthedocs.io)!
|
|
@ -0,0 +1,7 @@
|
|||
opengnsys-flask-executor (0.10.0) UNRELEASED; urgency=medium
|
||||
|
||||
Initial version
|
||||
*
|
||||
*
|
||||
|
||||
-- Vadim Troshchinskiy <vtroshchinskiy@qindel.com> Tue, 23 Dec 2024 10:47:04 +0000
|
|
@ -0,0 +1,28 @@
|
|||
Source: opengnsys-flask-executor
|
||||
Maintainer: OpenGnsys <opengnsys@opengnsys.org>
|
||||
Section: python
|
||||
Priority: optional
|
||||
Build-Depends: debhelper-compat (= 12),
|
||||
dh-python,
|
||||
libarchive-dev,
|
||||
python3-all,
|
||||
python3-mock,
|
||||
python3-pytest,
|
||||
python3-setuptools
|
||||
Standards-Version: 4.5.0
|
||||
Rules-Requires-Root: no
|
||||
Homepage: https://github.com/vojtechtrefny/pyblkid
|
||||
Vcs-Browser: https://github.com/vojtechtrefny/pyblkid
|
||||
Vcs-Git: https://github.com/vojtechtrefny/pyblkid
|
||||
|
||||
Package: opengnsys-flask-executor
|
||||
Architecture: all
|
||||
Depends: ${lib:Depends}, ${misc:Depends}, ${python3:Depends}
|
||||
Description: Python3 Flask-Executor module
|
||||
Sometimes you need a simple task queue without the overhead of separate worker
|
||||
processes or powerful-but-complex libraries beyond your requirements.
|
||||
.
|
||||
Flask-Executor is an easy to use wrapper for the concurrent.futures module that
|
||||
lets you initialise and configure executors via common Flask application patterns.
|
||||
It's a great way to get up and running fast with a lightweight in-process task queue.
|
||||
.
|
|
@ -0,0 +1,208 @@
|
|||
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Upstream-Name: python-libarchive-c
|
||||
Source: https://github.com/Changaco/python-libarchive-c
|
||||
|
||||
Files: *
|
||||
Copyright: 2014-2018 Changaco <changaco@changaco.oy.lc>
|
||||
License: CC-0
|
||||
|
||||
Files: tests/surrogateescape.py
|
||||
Copyright: 2015 Changaco <changaco@changaco.oy.lc>
|
||||
2011-2013 Victor Stinner <victor.stinner@gmail.com>
|
||||
License: BSD-2-clause or PSF-2
|
||||
|
||||
Files: debian/*
|
||||
Copyright: 2015 Jerémy Bobbio <lunar@debian.org>
|
||||
2019 Mattia Rizzolo <mattia@debian.org>
|
||||
License: permissive
|
||||
Copying and distribution of this package, with or without
|
||||
modification, are permitted in any medium without royalty
|
||||
provided the copyright notice and this notice are
|
||||
preserved.
|
||||
|
||||
License: BSD-2-clause
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
.
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
||||
License: PSF-2
|
||||
1. This LICENSE AGREEMENT is between the Python Software Foundation ("PSF"),
|
||||
and the Individual or Organization ("Licensee") accessing and otherwise using
|
||||
this software ("Python") in source or binary form and its associated
|
||||
documentation.
|
||||
.
|
||||
2. Subject to the terms and conditions of this License Agreement, PSF hereby
|
||||
grants Licensee a nonexclusive, royalty-free, world-wide license to
|
||||
reproduce, analyze, test, perform and/or display publicly, prepare derivative
|
||||
works, distribute, and otherwise use Python alone or in any derivative
|
||||
version, provided, however, that PSF's License Agreement and PSF's notice of
|
||||
copyright, i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 Python
|
||||
Software Foundation; All Rights Reserved" are retained in Python alone or in
|
||||
any derivative version prepared by Licensee.
|
||||
.
|
||||
3. In the event Licensee prepares a derivative work that is based on or
|
||||
incorporates Python or any part thereof, and wants to make the derivative
|
||||
work available to others as provided herein, then Licensee hereby agrees to
|
||||
include in any such work a brief summary of the changes made to Python.
|
||||
.
|
||||
4. PSF is making Python available to Licensee on an "AS IS" basis. PSF MAKES
|
||||
NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT
|
||||
NOT LIMITATION, PSF MAKES NO AND DISCLAIMS ANY REPRESENTATION OR WARRANTY OF
|
||||
MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF
|
||||
PYTHON WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.
|
||||
.
|
||||
5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON FOR ANY
|
||||
INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF
|
||||
MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, OR ANY DERIVATIVE
|
||||
THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
|
||||
.
|
||||
6. This License Agreement will automatically terminate upon a material breach
|
||||
of its terms and conditions.
|
||||
.
|
||||
7. Nothing in this License Agreement shall be deemed to create any
|
||||
relationship of agency, partnership, or joint venture between PSF and
|
||||
Licensee. This License Agreement does not grant permission to use PSF
|
||||
trademarks or trade name in a trademark sense to endorse or promote products
|
||||
or services of Licensee, or any third party.
|
||||
.
|
||||
8. By copying, installing or otherwise using Python, Licensee agrees to be
|
||||
bound by the terms and conditions of this License Agreement.
|
||||
|
||||
License: CC-0
|
||||
Statement of Purpose
|
||||
.
|
||||
The laws of most jurisdictions throughout the world automatically
|
||||
confer exclusive Copyright and Related Rights (defined below) upon
|
||||
the creator and subsequent owner(s) (each and all, an "owner") of an
|
||||
original work of authorship and/or a database (each, a "Work").
|
||||
.
|
||||
Certain owners wish to permanently relinquish those rights to a Work
|
||||
for the purpose of contributing to a commons of creative, cultural
|
||||
and scientific works ("Commons") that the public can reliably and
|
||||
without fear of later claims of infringement build upon, modify,
|
||||
incorporate in other works, reuse and redistribute as freely as
|
||||
possible in any form whatsoever and for any purposes, including
|
||||
without limitation commercial purposes. These owners may contribute
|
||||
to the Commons to promote the ideal of a free culture and the further
|
||||
production of creative, cultural and scientific works, or to gain
|
||||
reputation or greater distribution for their Work in part through the
|
||||
use and efforts of others.
|
||||
.
|
||||
For these and/or other purposes and motivations, and without any
|
||||
expectation of additional consideration or compensation, the person
|
||||
associating CC0 with a Work (the "Affirmer"), to the extent that he
|
||||
or she is an owner of Copyright and Related Rights in the Work,
|
||||
voluntarily elects to apply CC0 to the Work and publicly distribute
|
||||
the Work under its terms, with knowledge of his or her Copyright and
|
||||
Related Rights in the Work and the meaning and intended legal effect
|
||||
of CC0 on those rights.
|
||||
.
|
||||
1. Copyright and Related Rights. A Work made available under CC0 may
|
||||
be protected by copyright and related or neighboring rights
|
||||
("Copyright and Related Rights"). Copyright and Related Rights
|
||||
include, but are not limited to, the following:
|
||||
.
|
||||
i. the right to reproduce, adapt, distribute, perform, display,
|
||||
communicate, and translate a Work;
|
||||
ii. moral rights retained by the original author(s) and/or
|
||||
performer(s);
|
||||
iii. publicity and privacy rights pertaining to a person's image
|
||||
or likeness depicted in a Work;
|
||||
iv. rights protecting against unfair competition in regards to a
|
||||
Work, subject to the limitations in paragraph 4(a), below;
|
||||
v. rights protecting the extraction, dissemination, use and
|
||||
reuse of data in a Work;
|
||||
vi. database rights (such as those arising under Directive
|
||||
96/9/EC of the European Parliament and of the Council of 11
|
||||
March 1996 on the legal protection of databases, and under
|
||||
any national implementation thereof, including any amended or
|
||||
successor version of such directive); and
|
||||
vii. other similar, equivalent or corresponding rights throughout
|
||||
the world based on applicable law or treaty, and any national
|
||||
implementations thereof.
|
||||
.
|
||||
2. Waiver. To the greatest extent permitted by, but not in
|
||||
contravention of, applicable law, Affirmer hereby overtly, fully,
|
||||
permanently, irrevocably and unconditionally waives, abandons, and
|
||||
surrenders all of Affirmer's Copyright and Related Rights and
|
||||
associated claims and causes of action, whether now known or
|
||||
unknown (including existing as well as future claims and causes of
|
||||
action), in the Work (i) in all territories worldwide, (ii) for
|
||||
the maximum duration provided by applicable law or treaty
|
||||
(including future time extensions), (iii) in any current or future
|
||||
medium and for any number of copies, and (iv) for any purpose
|
||||
whatsoever, including without limitation commercial, advertising
|
||||
or promotional purposes (the "Waiver"). Affirmer makes the Waiver
|
||||
for the benefit of each member of the public at large and to the
|
||||
detriment of Affirmer's heirs and successors, fully intending that
|
||||
such Waiver shall not be subject to revocation, rescission,
|
||||
cancellation, termination, or any other legal or equitable action
|
||||
to disrupt the quiet enjoyment of the Work by the public as
|
||||
contemplated by Affirmer's express Statement of Purpose.
|
||||
.
|
||||
3. Public License Fallback. Should any part of the Waiver for any
|
||||
reason be judged legally invalid or ineffective under applicable law,
|
||||
then the Waiver shall be preserved to the maximum extent permitted
|
||||
taking into account Affirmer's express Statement of Purpose. In
|
||||
addition, to the extent the Waiver is so judged Affirmer hereby
|
||||
grants to each affected person a royalty-free, non transferable, non
|
||||
sublicensable, non exclusive, irrevocable and unconditional license
|
||||
to exercise Affirmer's Copyright and Related Rights in the Work (i)
|
||||
in all territories worldwide, (ii) for the maximum duration provided
|
||||
by applicable law or treaty (including future time extensions), (iii)
|
||||
in any current or future medium and for any number of copies, and
|
||||
(iv) for any purpose whatsoever, including without limitation
|
||||
commercial, advertising or promotional purposes (the "License"). The
|
||||
License shall be deemed effective as of the date CC0 was applied by
|
||||
Affirmer to the Work. Should any part of the License for any reason
|
||||
be judged legally invalid or ineffective under applicable law, such
|
||||
partial invalidity or ineffectiveness shall not invalidate the
|
||||
remainder of the License, and in such case Affirmer hereby affirms
|
||||
that he or she will not (i) exercise any of his or her remaining
|
||||
Copyright and Related Rights in the Work or (ii) assert any
|
||||
associated claims and causes of action with respect to the Work, in
|
||||
either case contrary to Affirmer's express Statement of Purpose.
|
||||
.
|
||||
4. Limitations and Disclaimers.
|
||||
.
|
||||
a. No trademark or patent rights held by Affirmer are waived,
|
||||
abandoned, surrendered, licensed or otherwise affected by
|
||||
this document.
|
||||
b. Affirmer offers the Work as-is and makes no representations
|
||||
or warranties of any kind concerning the Work, express,
|
||||
implied, statutory or otherwise, including without limitation
|
||||
warranties of title, merchantability, fitness for a
|
||||
particular purpose, non infringement, or the absence of
|
||||
latent or other defects, accuracy, or the present or absence
|
||||
of errors, whether or not discoverable, all to the greatest
|
||||
extent permissible under applicable law.
|
||||
c. Affirmer disclaims responsibility for clearing rights of
|
||||
other persons that may apply to the Work or any use thereof,
|
||||
including without limitation any person's Copyright and
|
||||
Related Rights in the Work. Further, Affirmer disclaims
|
||||
responsibility for obtaining any necessary consents,
|
||||
permissions or other rights required for any use of the
|
||||
Work.
|
||||
d. Affirmer understands and acknowledges that Creative Commons
|
||||
is not a party to this document and has no duty or obligation
|
||||
with respect to this CC0 or use of the Work.
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/make -f
|
||||
|
||||
export LC_ALL=C.UTF-8
|
||||
export PYBUILD_NAME = libarchive-c
|
||||
#export PYBUILD_BEFORE_TEST = cp -av README.rst {build_dir}
|
||||
export PYBUILD_TEST_ARGS = -vv -s
|
||||
#export PYBUILD_AFTER_TEST = rm -v {build_dir}/README.rst
|
||||
# ./usr/lib/python3/dist-packages/libarchive/
|
||||
export PYBUILD_INSTALL_ARGS=--install-lib=/usr/share/opengnsys-modules/python3/dist-packages/
|
||||
%:
|
||||
dh $@ --with python3 --buildsystem=pybuild
|
||||
|
||||
override_dh_gencontrol:
|
||||
dh_gencontrol -- \
|
||||
-Vlib:Depends=$(shell dpkg-query -W -f '$${Depends}' libarchive-dev \
|
||||
| sed -E 's/.*(libarchive[[:alnum:].-]+).*/\1/')
|
||||
|
||||
override_dh_installdocs:
|
||||
# Nothing, we don't want docs
|
||||
|
||||
override_dh_installchangelogs:
|
||||
# Nothing, we don't want the changelog
|
|
@ -0,0 +1 @@
|
|||
3.0 (quilt)
|
|
@ -0,0 +1,2 @@
|
|||
Tests: upstream-tests
|
||||
Depends: @, python3-mock, python3-pytest
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
if ! [ -d "$AUTOPKGTEST_TMP" ]; then
|
||||
echo "AUTOPKGTEST_TMP not set." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cp -rv tests "$AUTOPKGTEST_TMP"
|
||||
cd "$AUTOPKGTEST_TMP"
|
||||
mkdir -v libarchive
|
||||
touch README.rst
|
||||
py.test-3 tests -vv -l -r a
|
|
@ -0,0 +1,20 @@
|
|||
# Minimal makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line.
|
||||
SPHINXOPTS =
|
||||
SPHINXBUILD = sphinx-build
|
||||
SPHINXPROJ = Flask-Executor
|
||||
SOURCEDIR = .
|
||||
BUILDDIR = _build
|
||||
|
||||
# Put it first so that "make" without argument is like "make help".
|
||||
help:
|
||||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||
|
||||
.PHONY: help Makefile
|
||||
|
||||
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||
%: Makefile
|
||||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
@ -0,0 +1,30 @@
|
|||
flask\_executor package
|
||||
=======================
|
||||
|
||||
Submodules
|
||||
----------
|
||||
|
||||
flask\_executor.executor module
|
||||
-------------------------------
|
||||
|
||||
.. automodule:: flask_executor.executor
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
flask\_executor.futures module
|
||||
------------------------------
|
||||
|
||||
.. automodule:: flask_executor.futures
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
|
||||
Module contents
|
||||
---------------
|
||||
|
||||
.. automodule:: flask_executor
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
|
@ -0,0 +1,7 @@
|
|||
flask_executor
|
||||
==============
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 4
|
||||
|
||||
flask_executor
|
|
@ -0,0 +1,172 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Configuration file for the Sphinx documentation builder.
|
||||
#
|
||||
# This file does only contain a selection of the most common options. For a
|
||||
# full list see the documentation:
|
||||
# http://www.sphinx-doc.org/en/master/config
|
||||
|
||||
# -- Path setup --------------------------------------------------------------
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
#
|
||||
import os
|
||||
import sys
|
||||
|
||||
from flask_executor import __version__
|
||||
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
|
||||
|
||||
# -- Project information -----------------------------------------------------
|
||||
|
||||
project = 'Flask-Executor'
|
||||
copyright = '2018, Dave Chevell'
|
||||
author = 'Dave Chevell'
|
||||
|
||||
# The short X.Y version
|
||||
version = '.'.join(__version__.split('.')[:2])
|
||||
# The full version, including alpha/beta/rc tags
|
||||
release = __version__
|
||||
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
|
||||
# If your documentation needs a minimal Sphinx version, state it here.
|
||||
#
|
||||
# needs_sphinx = '1.0'
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||
# ones.
|
||||
extensions = [
|
||||
'sphinx.ext.autodoc',
|
||||
'sphinx.ext.intersphinx',
|
||||
'sphinx.ext.viewcode',
|
||||
]
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
# The suffix(es) of source filenames.
|
||||
# You can specify multiple suffix as a list of string:
|
||||
#
|
||||
# source_suffix = ['.rst', '.md']
|
||||
source_suffix = '.rst'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
#
|
||||
# This is also used if you do content translation via gettext catalogs.
|
||||
# Usually you set "language" from the command line for these cases.
|
||||
language = None
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
# This pattern also affects html_static_path and html_extra_path .
|
||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = 'sphinx'
|
||||
|
||||
|
||||
# -- Options for HTML output -------------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
#
|
||||
html_theme = 'alabaster'
|
||||
|
||||
# Theme options are theme-specific and customize the look and feel of a theme
|
||||
# further. For a list of options available for each theme, see the
|
||||
# documentation.
|
||||
#
|
||||
# html_theme_options = {}
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
# html_static_path = ['_static']
|
||||
|
||||
# Custom sidebar templates, must be a dictionary that maps document names
|
||||
# to template names.
|
||||
#
|
||||
# The default sidebars (for documents that don't match any pattern) are
|
||||
# defined by theme itself. Builtin themes are using these templates by
|
||||
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
|
||||
# 'searchbox.html']``.
|
||||
#
|
||||
# html_sidebars = {}
|
||||
|
||||
|
||||
# -- Options for HTMLHelp output ---------------------------------------------
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'Flask-Executordoc'
|
||||
|
||||
|
||||
# -- Options for LaTeX output ------------------------------------------------
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
#
|
||||
# 'papersize': 'letterpaper',
|
||||
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#
|
||||
# 'pointsize': '10pt',
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
#
|
||||
# 'preamble': '',
|
||||
|
||||
# Latex figure (float) alignment
|
||||
#
|
||||
# 'figure_align': 'htbp',
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title,
|
||||
# author, documentclass [howto, manual, or own class]).
|
||||
latex_documents = [
|
||||
(master_doc, 'Flask-Executor.tex', 'Flask-Executor Documentation',
|
||||
'Dave Chevell', 'manual'),
|
||||
]
|
||||
|
||||
|
||||
# -- Options for manual page output ------------------------------------------
|
||||
|
||||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
(master_doc, 'flask-executor', 'Flask-Executor Documentation',
|
||||
[author], 1)
|
||||
]
|
||||
|
||||
|
||||
# -- Options for Texinfo output ----------------------------------------------
|
||||
|
||||
# Grouping the document tree into Texinfo files. List of tuples
|
||||
# (source start file, target name, title, author,
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
(master_doc, 'Flask-Executor', 'Flask-Executor Documentation',
|
||||
author, 'Flask-Executor', 'One line description of project.',
|
||||
'Miscellaneous'),
|
||||
]
|
||||
|
||||
|
||||
# -- Extension configuration -------------------------------------------------
|
||||
|
||||
# -- Options for intersphinx extension ---------------------------------------
|
||||
|
||||
# Example configuration for intersphinx: refer to the Python standard library.
|
||||
intersphinx_mapping = {
|
||||
'python': ('https://docs.python.org/3', None),
|
||||
'http://flask.pocoo.org/docs/': None,
|
||||
}
|
|
@ -0,0 +1,187 @@
|
|||
.. Flask-Executor documentation master file, created by
|
||||
sphinx-quickstart on Sun Sep 23 18:52:39 2018.
|
||||
You can adapt this file completely to your liking, but it should at least
|
||||
contain the root `toctree` directive.
|
||||
|
||||
Flask-Executor
|
||||
==============
|
||||
|
||||
.. module:: flask_executor
|
||||
|
||||
Flask-Executor is a `Flask`_ extension that makes it easy to work with :py:mod:`concurrent.futures`
|
||||
in your application.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
Flask-Executor is available on PyPI and can be installed with pip::
|
||||
|
||||
$ pip install flask-executor
|
||||
|
||||
Setup
|
||||
------
|
||||
|
||||
The Executor extension can either be initialized directly::
|
||||
|
||||
from flask import Flask
|
||||
from flask_executor import Executor
|
||||
|
||||
app = Flask(__name__)
|
||||
executor = Executor(app)
|
||||
|
||||
Or through the factory method::
|
||||
|
||||
executor = Executor()
|
||||
executor.init_app(app)
|
||||
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
To specify the type of executor to initialise, set ``EXECUTOR_TYPE`` inside your app configuration.
|
||||
Valid values are ``'thread'`` (default) to initialise a
|
||||
:class:`~concurrent.futures.ThreadPoolExecutor`, or ``'process'`` to initialise a
|
||||
:class:`~concurrent.futures.ProcessPoolExecutor`::
|
||||
|
||||
app.config['EXECUTOR_TYPE'] = 'thread'
|
||||
|
||||
To define the number of worker threads for a :class:`~concurrent.futures.ThreadPoolExecutor` or the
|
||||
number of worker processes for a :class:`~concurrent.futures.ProcessPoolExecutor`, set
|
||||
``EXECUTOR_MAX_WORKERS`` in your app configuration. Valid values are any integer or ``None`` (default)
|
||||
to let :py:mod:`concurrent.futures` pick defaults for you::
|
||||
|
||||
app.config['EXECUTOR_MAX_WORKERS'] = 5
|
||||
|
||||
If multiple executors are needed, :class:`flask_executor.Executor` can be initialised with a ``name``
|
||||
parameter. Named executors will look for configuration variables prefixed with the specified ``name``
|
||||
value, uppercased:
|
||||
|
||||
app.config['CUSTOM_EXECUTOR_TYPE'] = 'thread'
|
||||
app.config['CUSTOM_EXECUTOR_MAX_WORKERS'] = 5
|
||||
executor = Executor(app, name='custom')
|
||||
|
||||
|
||||
Basic Usage
|
||||
-----------
|
||||
|
||||
Flask-Executor supports the standard :class:`concurrent.futures.Executor` methods,
|
||||
:meth:`~concurrent.futures.Executor.submit` and :meth:`~concurrent.futures.Executor.map`::
|
||||
|
||||
def fib(n):
|
||||
if n <= 2:
|
||||
return 1
|
||||
else:
|
||||
return fib(n-1) + fib(n-2)
|
||||
|
||||
@app.route('/run_fib')
|
||||
def run_fib():
|
||||
executor.submit(fib, 5)
|
||||
executor.map(fib, range(1, 6))
|
||||
return 'OK'
|
||||
|
||||
Submitting a task via :meth:`~concurrent.futures.Executor.submit` returns a
|
||||
:class:`flask_executor.FutureProxy` object, a subclass of
|
||||
:class:`concurrent.futures.Future` object from which you can retrieve your job status or result.
|
||||
|
||||
|
||||
Contexts
|
||||
--------
|
||||
|
||||
When calling :meth:`~concurrent.futures.Executor.submit` or :meth:`~concurrent.futures.Executor.map`
|
||||
Flask-Executor will wrap `ThreadPoolExecutor` callables with a copy of both the current application
|
||||
context and current request context. Code that must be run in these contexts or that depends on
|
||||
information or configuration stored in :data:`flask.current_app`, :data:`flask.request` or
|
||||
:data:`flask.g` can be submitted to the executor without modification.
|
||||
|
||||
Note: due to limitations in Python's default object serialisation and a lack of shared memory space between subprocesses, contexts cannot be pushed to `ProcessPoolExecutor()` workers.
|
||||
|
||||
|
||||
Futures
|
||||
-------
|
||||
|
||||
:class:`flask_executor.FutureProxy` objects look and behave like normal :class:`concurrent.futures.Future`
|
||||
objects, but allow `flask_executor` to override certain methods and add additional behaviours.
|
||||
When submitting a callable to :meth:`~concurrent.futures.Future.add_done_callback`, callables are
|
||||
wrapped with a copy of both the current application context and current request context.
|
||||
|
||||
You may want to preserve access to Futures returned from the executor, so that you can retrieve the
|
||||
results in a different part of your application. Flask-Executor allows Futures to be stored within
|
||||
the executor itself and provides methods for querying and returning them in different parts of your
|
||||
app::
|
||||
|
||||
@app.route('/start-task')
|
||||
def start_task():
|
||||
executor.submit_stored('calc_power', pow, 323, 1235)
|
||||
return jsonify({'result':'success'})
|
||||
|
||||
@app.route('/get-result')
|
||||
def get_result():
|
||||
if not executor.futures.done('calc_power'):
|
||||
return jsonify({'status': executor.futures._state('calc_power')})
|
||||
future = executor.futures.pop('calc_power')
|
||||
return jsonify({'status': done, 'result': future.result()})
|
||||
|
||||
|
||||
Decoration
|
||||
----------
|
||||
|
||||
Flask-Executor lets you decorate methods in the same style as distributed task queues when using 'thread' executor type like
|
||||
`Celery`_::
|
||||
|
||||
@executor.job
|
||||
def fib(n):
|
||||
if n <= 2:
|
||||
return 1
|
||||
else:
|
||||
return fib(n-1) + fib(n-2)
|
||||
|
||||
@app.route('/decorate_fib')
|
||||
def decorate_fib():
|
||||
fib.submit(5)
|
||||
fib.submit_stored('fibonacci', 5)
|
||||
fib.map(range(1, 6))
|
||||
return 'OK'
|
||||
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
:caption: Contents:
|
||||
|
||||
api/modules
|
||||
|
||||
|
||||
Default Callbacks
|
||||
-----------------
|
||||
|
||||
:class:`concurrent.futures.Future` objects can have callbacks attached by using
|
||||
:meth:`~concurrent.futures.Future.add_done_callback`. Flask-Executor lets you specify default
|
||||
callbacks that will be applied to all new futures created by the executor::
|
||||
|
||||
def some_callback(future):
|
||||
# do something with future
|
||||
|
||||
executor.add_default_done_callback(some_callback)
|
||||
|
||||
# Callback will be added to the below task automatically
|
||||
executor.submit(pow, 323, 1235)
|
||||
|
||||
|
||||
Propagate Exceptions
|
||||
--------------------
|
||||
|
||||
Normally any exceptions thrown by background threads or processes will be swallowed unless explicitly
|
||||
checked for. To instead surface all exceptions thrown by background tasks, Flask-Executor can add
|
||||
a special default callback that raises any exceptions thrown by tasks submitted to the executor::
|
||||
|
||||
app.config['EXECUTOR_PROPAGATE_EXCEPTIONS'] = True
|
||||
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`modindex`
|
||||
* :ref:`search`
|
||||
|
||||
.. _Flask: http://flask.pocoo.org/
|
||||
.. _Celery: http://www.celeryproject.org/
|
|
@ -0,0 +1,5 @@
|
|||
from flask_executor.executor import Executor
|
||||
|
||||
|
||||
__all__ = ('Executor',)
|
||||
__version__ = '0.10.0'
|
|
@ -0,0 +1,273 @@
|
|||
import concurrent.futures
|
||||
import contextvars
|
||||
import copy
|
||||
import re
|
||||
|
||||
from flask import copy_current_request_context, current_app, g
|
||||
|
||||
from flask_executor.futures import FutureCollection, FutureProxy
|
||||
from flask_executor.helpers import InstanceProxy, str2bool
|
||||
|
||||
|
||||
def get_current_app_context():
|
||||
try:
|
||||
from flask.globals import _cv_app
|
||||
return _cv_app.get(None)
|
||||
except ImportError:
|
||||
from flask.globals import _app_ctx_stack
|
||||
return _app_ctx_stack.top
|
||||
|
||||
|
||||
def push_app_context(fn):
|
||||
app = current_app._get_current_object()
|
||||
_g = copy.copy(g)
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
with app.app_context():
|
||||
ctx = get_current_app_context()
|
||||
ctx.g = _g
|
||||
return fn(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def propagate_exceptions_callback(future):
|
||||
exc = future.exception()
|
||||
if exc:
|
||||
raise exc
|
||||
|
||||
|
||||
class ExecutorJob:
|
||||
"""Wraps a function with an executor so to allow the wrapped function to
|
||||
submit itself directly to the executor."""
|
||||
|
||||
def __init__(self, executor, fn):
|
||||
self.executor = executor
|
||||
self.fn = fn
|
||||
|
||||
def submit(self, *args, **kwargs):
|
||||
future = self.executor.submit(self.fn, *args, **kwargs)
|
||||
return future
|
||||
|
||||
def submit_stored(self, future_key, *args, **kwargs):
|
||||
future = self.executor.submit_stored(future_key, self.fn, *args, **kwargs)
|
||||
return future
|
||||
|
||||
def map(self, *iterables, **kwargs):
|
||||
results = self.executor.map(self.fn, *iterables, **kwargs)
|
||||
return results
|
||||
|
||||
|
||||
class Executor(InstanceProxy, concurrent.futures._base.Executor):
|
||||
"""An executor interface for :py:mod:`concurrent.futures` designed for
|
||||
working with Flask applications.
|
||||
|
||||
:param app: A Flask application instance.
|
||||
:param name: An optional name for the executor. This can be used to
|
||||
configure multiple executors. Named executors will look for
|
||||
environment variables prefixed with the name in uppercase,
|
||||
e.g. ``CUSTOM_EXECUTOR_TYPE``.
|
||||
"""
|
||||
|
||||
def __init__(self, app=None, name=''):
|
||||
self.app = app
|
||||
self._default_done_callbacks = []
|
||||
self.futures = FutureCollection()
|
||||
if re.match(r'^(\w+)?$', name) is None:
|
||||
raise ValueError(
|
||||
"Executor names may only contain letters, numbers or underscores"
|
||||
)
|
||||
self.name = name
|
||||
prefix = name.upper() + '_' if name else ''
|
||||
self.EXECUTOR_TYPE = prefix + 'EXECUTOR_TYPE'
|
||||
self.EXECUTOR_MAX_WORKERS = prefix + 'EXECUTOR_MAX_WORKERS'
|
||||
self.EXECUTOR_FUTURES_MAX_LENGTH = prefix + 'EXECUTOR_FUTURES_MAX_LENGTH'
|
||||
self.EXECUTOR_PROPAGATE_EXCEPTIONS = prefix + 'EXECUTOR_PROPAGATE_EXCEPTIONS'
|
||||
self.EXECUTOR_PUSH_APP_CONTEXT = prefix + 'EXECUTOR_PUSH_APP_CONTEXT'
|
||||
|
||||
if app is not None:
|
||||
self.init_app(app)
|
||||
|
||||
def init_app(self, app):
|
||||
"""Initialise application. This will also intialise the configured
|
||||
executor type:
|
||||
|
||||
* :class:`concurrent.futures.ThreadPoolExecutor`
|
||||
* :class:`concurrent.futures.ProcessPoolExecutor`
|
||||
"""
|
||||
app.config.setdefault(self.EXECUTOR_TYPE, 'thread')
|
||||
app.config.setdefault(self.EXECUTOR_PUSH_APP_CONTEXT, True)
|
||||
futures_max_length = app.config.setdefault(self.EXECUTOR_FUTURES_MAX_LENGTH, None)
|
||||
propagate_exceptions = app.config.setdefault(self.EXECUTOR_PROPAGATE_EXCEPTIONS, False)
|
||||
if futures_max_length is not None:
|
||||
self.futures.max_length = int(futures_max_length)
|
||||
if str2bool(propagate_exceptions):
|
||||
self.add_default_done_callback(propagate_exceptions_callback)
|
||||
self._self = self._make_executor(app)
|
||||
app.extensions[self.name + 'executor'] = self
|
||||
|
||||
def _make_executor(self, app):
|
||||
executor_max_workers = app.config.setdefault(self.EXECUTOR_MAX_WORKERS, None)
|
||||
if executor_max_workers is not None:
|
||||
executor_max_workers = int(executor_max_workers)
|
||||
executor_type = app.config[self.EXECUTOR_TYPE]
|
||||
if executor_type == 'thread':
|
||||
_executor = concurrent.futures.ThreadPoolExecutor
|
||||
elif executor_type == 'process':
|
||||
_executor = concurrent.futures.ProcessPoolExecutor
|
||||
else:
|
||||
raise ValueError("{} is not a valid executor type.".format(executor_type))
|
||||
return _executor(max_workers=executor_max_workers)
|
||||
|
||||
def _prepare_fn(self, fn, force_copy=False):
|
||||
if isinstance(self._self, concurrent.futures.ThreadPoolExecutor) \
|
||||
or force_copy:
|
||||
fn = copy_current_request_context(fn)
|
||||
if current_app.config[self.EXECUTOR_PUSH_APP_CONTEXT]:
|
||||
fn = push_app_context(fn)
|
||||
return fn
|
||||
|
||||
def submit(self, fn, *args, **kwargs):
|
||||
r"""Schedules the callable, fn, to be executed as fn(\*args \**kwargs)
|
||||
and returns a :class:`~flask_executor.futures.FutureProxy` object, a
|
||||
:class:`~concurrent.futures.Future` subclass representing
|
||||
the execution of the callable.
|
||||
|
||||
See also :meth:`concurrent.futures.Executor.submit`.
|
||||
|
||||
Callables are wrapped a copy of the current application context and the
|
||||
current request context. Code that depends on information or
|
||||
configuration stored in :data:`flask.current_app`,
|
||||
:data:`flask.request` or :data:`flask.g` can be run without
|
||||
modification.
|
||||
|
||||
Note: Because callables only have access to *copies* of the application
|
||||
or request contexts any changes made to these copies will not be
|
||||
reflected in the original view. Further, changes in the original app or
|
||||
request context that occur after the callable is submitted will not be
|
||||
available to the callable.
|
||||
|
||||
Example::
|
||||
|
||||
future = executor.submit(pow, 323, 1235)
|
||||
print(future.result())
|
||||
|
||||
:param fn: The callable to be executed.
|
||||
:param \*args: A list of positional parameters used with
|
||||
the callable.
|
||||
:param \**kwargs: A dict of named parameters used with
|
||||
the callable.
|
||||
|
||||
:rtype: flask_executor.FutureProxy
|
||||
"""
|
||||
fn = self._prepare_fn(fn)
|
||||
future = self._self.submit(fn, *args, **kwargs)
|
||||
for callback in self._default_done_callbacks:
|
||||
future.add_done_callback(callback)
|
||||
return FutureProxy(future, self)
|
||||
|
||||
def submit_stored(self, future_key, fn, *args, **kwargs):
|
||||
r"""Submits the callable using :meth:`Executor.submit` and stores the
|
||||
Future in the executor via a
|
||||
:class:`~flask_executor.futures.FutureCollection` object available at
|
||||
:data:`Executor.futures`. These futures can be retrieved anywhere
|
||||
inside your application and queried for status or popped from the
|
||||
collection. Due to memory concerns, the maximum length of the
|
||||
FutureCollection is limited, and the oldest Futures will be dropped
|
||||
when the limit is exceeded.
|
||||
|
||||
See :class:`flask_executor.futures.FutureCollection` for more
|
||||
information on how to query futures in a collection.
|
||||
|
||||
Example::
|
||||
|
||||
@app.route('/start-task')
|
||||
def start_task():
|
||||
executor.submit_stored('calc_power', pow, 323, 1235)
|
||||
return jsonify({'result':'success'})
|
||||
|
||||
@app.route('/get-result')
|
||||
def get_result():
|
||||
if not executor.futures.done('calc_power'):
|
||||
future_status = executor.futures._state('calc_power')
|
||||
return jsonify({'status': future_status})
|
||||
future = executor.futures.pop('calc_power')
|
||||
return jsonify({'status': done, 'result': future.result()})
|
||||
|
||||
:param future_key: Stores the Future for the submitted task inside the
|
||||
executor's ``futures`` object with the specified
|
||||
key.
|
||||
:param fn: The callable to be executed.
|
||||
:param \*args: A list of positional parameters used with
|
||||
the callable.
|
||||
:param \**kwargs: A dict of named parameters used with
|
||||
the callable.
|
||||
|
||||
:rtype: concurrent.futures.Future
|
||||
"""
|
||||
future = self.submit(fn, *args, **kwargs)
|
||||
self.futures.add(future_key, future)
|
||||
return future
|
||||
|
||||
def map(self, fn, *iterables, **kwargs):
|
||||
r"""Submits the callable, fn, and an iterable of arguments to the
|
||||
executor and returns the results inside a generator.
|
||||
|
||||
See also :meth:`concurrent.futures.Executor.map`.
|
||||
|
||||
Callables are wrapped a copy of the current application context and the
|
||||
current request context. Code that depends on information or
|
||||
configuration stored in :data:`flask.current_app`,
|
||||
:data:`flask.request` or :data:`flask.g` can be run without
|
||||
modification.
|
||||
|
||||
Note: Because callables only have access to *copies* of the application
|
||||
or request contexts
|
||||
any changes made to these copies will not be reflected in the original
|
||||
view. Further, changes in the original app or request context that
|
||||
occur after the callable is submitted will not be available to the
|
||||
callable.
|
||||
|
||||
:param fn: The callable to be executed.
|
||||
:param \*iterables: An iterable of arguments the callable will apply to.
|
||||
:param \**kwargs: A dict of named parameters to pass to the underlying
|
||||
executor's :meth:`~concurrent.futures.Executor.map`
|
||||
method.
|
||||
"""
|
||||
fn = self._prepare_fn(fn)
|
||||
return self._self.map(fn, *iterables, **kwargs)
|
||||
|
||||
def job(self, fn):
|
||||
"""Decorator. Use this to transform functions into `ExecutorJob`
|
||||
instances that can submit themselves directly to the executor.
|
||||
|
||||
Example::
|
||||
|
||||
@executor.job
|
||||
def fib(n):
|
||||
if n <= 2:
|
||||
return 1
|
||||
else:
|
||||
return fib(n-1) + fib(n-2)
|
||||
|
||||
future = fib.submit(5)
|
||||
results = fib.map(range(1, 6))
|
||||
"""
|
||||
if isinstance(self._self, concurrent.futures.ProcessPoolExecutor):
|
||||
raise TypeError(
|
||||
"Can't decorate {}: Executors that use multiprocessing "
|
||||
"don't support decorators".format(fn)
|
||||
)
|
||||
return ExecutorJob(executor=self, fn=fn)
|
||||
|
||||
def add_default_done_callback(self, fn):
|
||||
"""Registers callable to be attached to all newly created futures. When a
|
||||
callable is submitted to the executor,
|
||||
:meth:`concurrent.futures.Future.add_done_callback` is called for every default
|
||||
callable that has been set."
|
||||
|
||||
:param fn: The callable to be added to the list of default done callbacks for new
|
||||
Futures.
|
||||
"""
|
||||
|
||||
self._default_done_callbacks.append(fn)
|
|
@ -0,0 +1,107 @@
|
|||
from collections import OrderedDict
|
||||
from concurrent.futures import Future
|
||||
|
||||
from flask_executor.helpers import InstanceProxy
|
||||
|
||||
|
||||
class FutureCollection:
|
||||
"""A FutureCollection is an object to store and interact with
|
||||
:class:`concurrent.futures.Future` objects. It provides access to all
|
||||
attributes and methods of a Future by proxying attribute calls to the
|
||||
stored Future object.
|
||||
|
||||
To access the methods of a Future from a FutureCollection instance, include
|
||||
a valid ``future_key`` value as the first argument of the method call. To
|
||||
access attributes, call them as though they were a method with
|
||||
``future_key`` as the sole argument. If ``future_key`` does not exist, the
|
||||
call will always return None. If ``future_key`` does exist but the
|
||||
referenced Future does not contain the requested attribute an
|
||||
:exc:`AttributeError` will be raised.
|
||||
|
||||
To prevent memory exhaustion a FutureCollection instance can be bounded by
|
||||
number of items using the ``max_length`` parameter. As a best practice,
|
||||
Futures should be popped once they are ready for use, with the proxied
|
||||
attribute form used to determine whether a Future is ready to be used or
|
||||
discarded.
|
||||
|
||||
:param max_length: Maximum number of Futures to store. Oldest Futures are
|
||||
discarded first.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, max_length=50):
|
||||
self.max_length = max_length
|
||||
self._futures = OrderedDict()
|
||||
|
||||
def __contains__(self, future):
|
||||
return future in self._futures.values()
|
||||
|
||||
def __len__(self):
|
||||
return len(self._futures)
|
||||
|
||||
def __getattr__(self, attr):
|
||||
# Call any valid Future method or attribute
|
||||
def _future_attr(future_key, *args, **kwargs):
|
||||
if future_key not in self._futures:
|
||||
return None
|
||||
future_attr = getattr(self._futures[future_key], attr)
|
||||
if callable(future_attr):
|
||||
return future_attr(*args, **kwargs)
|
||||
return future_attr
|
||||
|
||||
return _future_attr
|
||||
|
||||
def _check_limits(self):
|
||||
if self.max_length is not None:
|
||||
while len(self._futures) > self.max_length:
|
||||
self._futures.popitem(last=False)
|
||||
|
||||
def add(self, future_key, future):
|
||||
"""Add a new Future. If ``max_length`` limit was defined for the
|
||||
FutureCollection, old Futures may be dropped to respect this limit.
|
||||
|
||||
:param future_key: Key for the Future to be added.
|
||||
:param future: Future to be added.
|
||||
"""
|
||||
if future_key in self._futures:
|
||||
raise ValueError("future_key {} already exists".format(future_key))
|
||||
self._futures[future_key] = future
|
||||
self._check_limits()
|
||||
|
||||
def pop(self, future_key):
|
||||
"""Return a Future and remove it from the collection. Futures that are
|
||||
ready to be used should always be popped so they do not continue to
|
||||
consume memory.
|
||||
|
||||
Returns ``None`` if the key doesn't exist.
|
||||
|
||||
:param future_key: Key for the Future to be returned.
|
||||
"""
|
||||
return self._futures.pop(future_key, None)
|
||||
|
||||
|
||||
class FutureProxy(InstanceProxy, Future):
|
||||
"""A FutureProxy is an instance proxy that wraps an instance of
|
||||
:class:`concurrent.futures.Future`. Since an executor can't be made to
|
||||
return a subclassed Future object, this proxy class is used to override
|
||||
instance behaviours whilst providing an agnostic method of accessing
|
||||
the original methods and attributes.
|
||||
:param future: An instance of :class:`~concurrent.futures.Future` that
|
||||
the proxy will provide access to.
|
||||
:param executor: An instance of :class:`flask_executor.Executor` which
|
||||
will be used to provide access to Flask context features.
|
||||
"""
|
||||
|
||||
def __init__(self, future, executor):
|
||||
self._self = future
|
||||
self._executor = executor
|
||||
|
||||
def add_done_callback(self, fn):
|
||||
fn = self._executor._prepare_fn(fn, force_copy=True)
|
||||
return self._self.add_done_callback(fn)
|
||||
|
||||
def __eq__(self, obj):
|
||||
return self._self == obj
|
||||
|
||||
def __hash__(self):
|
||||
return self._self.__hash__()
|
|
@ -0,0 +1,37 @@
|
|||
PROXIED_OBJECT = '__proxied_object'
|
||||
|
||||
|
||||
def str2bool(v):
|
||||
return str(v).lower() in ("yes", "true", "t", "1")
|
||||
|
||||
|
||||
class InstanceProxy(object):
|
||||
|
||||
def __init__(self, proxied_obj):
|
||||
self._self = proxied_obj
|
||||
|
||||
@property
|
||||
def _self(self):
|
||||
try:
|
||||
return object.__getattribute__(self, PROXIED_OBJECT)
|
||||
except AttributeError:
|
||||
return None
|
||||
|
||||
@_self.setter
|
||||
def _self(self, proxied_obj):
|
||||
object.__setattr__(self, PROXIED_OBJECT, proxied_obj)
|
||||
return self
|
||||
|
||||
def __getattribute__(self, attr):
|
||||
super_cls_dict = InstanceProxy.__dict__
|
||||
cls_dict = object.__getattribute__(self, '__class__').__dict__
|
||||
inst_dict = object.__getattribute__(self, '__dict__')
|
||||
if attr in cls_dict or attr in inst_dict or attr in super_cls_dict:
|
||||
return object.__getattribute__(self, attr)
|
||||
target_obj = object.__getattribute__(self, PROXIED_OBJECT)
|
||||
return object.__getattribute__(target_obj, attr)
|
||||
|
||||
def __repr__(self):
|
||||
class_name = object.__getattribute__(self, '__class__').__name__
|
||||
target_repr = repr(self._self)
|
||||
return '<%s( %s )>' % (class_name, target_repr)
|
|
@ -0,0 +1,52 @@
|
|||
import setuptools
|
||||
from setuptools.command.test import test
|
||||
import sys
|
||||
|
||||
try:
|
||||
from flask_executor import __version__ as version
|
||||
except ImportError:
|
||||
import re
|
||||
pattern = re.compile(r"__version__ = '(.*)'")
|
||||
with open('flask_executor/__init__.py') as f:
|
||||
version = pattern.search(f.read()).group(1)
|
||||
|
||||
|
||||
with open('README.md', 'r') as fh:
|
||||
long_description = fh.read()
|
||||
|
||||
|
||||
class pytest(test):
|
||||
|
||||
def run_tests(self):
|
||||
import pytest
|
||||
errno = pytest.main(self.test_args)
|
||||
sys.exit(errno)
|
||||
|
||||
|
||||
setuptools.setup(
|
||||
name='Flask-Executor',
|
||||
version=version,
|
||||
author='Dave Chevell',
|
||||
author_email='chevell@gmail.com',
|
||||
description='An easy to use Flask wrapper for concurrent.futures',
|
||||
long_description=long_description,
|
||||
long_description_content_type='text/markdown',
|
||||
url='https://github.com/dchevell/flask-executor',
|
||||
packages=setuptools.find_packages(exclude=['tests']),
|
||||
keywords=['flask', 'concurrent.futures'],
|
||||
classifiers=[
|
||||
"Programming Language :: Python :: 3",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Operating System :: OS Independent",
|
||||
],
|
||||
license='MIT',
|
||||
install_requires=['Flask'],
|
||||
extras_require={
|
||||
':python_version == "2.7"': ['futures>=3.1.1'],
|
||||
'test': ['pytest', 'pytest-cov', 'codecov', 'flask-sqlalchemy'],
|
||||
},
|
||||
test_suite='tests',
|
||||
cmdclass={
|
||||
'test': pytest
|
||||
}
|
||||
)
|
|
@ -0,0 +1,18 @@
|
|||
from flask import Flask
|
||||
import pytest
|
||||
|
||||
from flask_executor import Executor
|
||||
|
||||
|
||||
@pytest.fixture(params=['thread_push_app_context', 'thread_copy_app_context', 'process'])
|
||||
def app(request):
|
||||
app = Flask(__name__)
|
||||
app.config['EXECUTOR_TYPE'] = 'process' if request.param == 'process' else 'thread'
|
||||
app.config['EXECUTOR_PUSH_APP_CONTEXT'] = request.param == 'thread_push_app_context'
|
||||
|
||||
return app
|
||||
|
||||
@pytest.fixture
|
||||
def default_app():
|
||||
app = Flask(__name__)
|
||||
return app
|
|
@ -0,0 +1,376 @@
|
|||
import concurrent
|
||||
import concurrent.futures
|
||||
import logging
|
||||
import random
|
||||
import time
|
||||
from threading import local
|
||||
|
||||
import pytest
|
||||
from flask import current_app, g, request
|
||||
|
||||
from flask_executor import Executor
|
||||
from flask_executor.executor import propagate_exceptions_callback
|
||||
|
||||
|
||||
# Reusable functions for tests
|
||||
|
||||
def fib(n):
|
||||
if n <= 2:
|
||||
return 1
|
||||
else:
|
||||
return fib(n - 1) + fib(n - 2)
|
||||
|
||||
|
||||
def app_context_test_value(_=None):
|
||||
return current_app.config['TEST_VALUE']
|
||||
|
||||
|
||||
def request_context_test_value(_=None):
|
||||
return request.test_value
|
||||
|
||||
|
||||
def g_context_test_value(_=None):
|
||||
return g.test_value
|
||||
|
||||
|
||||
def fail():
|
||||
time.sleep(0.1)
|
||||
print(hello)
|
||||
|
||||
|
||||
def test_init(app):
|
||||
executor = Executor(app)
|
||||
assert 'executor' in app.extensions
|
||||
assert isinstance(executor, concurrent.futures._base.Executor)
|
||||
assert isinstance(executor._self, concurrent.futures._base.Executor)
|
||||
assert getattr(executor, 'shutdown')
|
||||
|
||||
|
||||
def test_factory_init(app):
|
||||
executor = Executor()
|
||||
executor.init_app(app)
|
||||
assert 'executor' in app.extensions
|
||||
assert isinstance(executor._self, concurrent.futures._base.Executor)
|
||||
|
||||
|
||||
def test_thread_executor_init(default_app):
|
||||
default_app.config['EXECUTOR_TYPE'] = 'thread'
|
||||
executor = Executor(default_app)
|
||||
assert isinstance(executor._self, concurrent.futures.ThreadPoolExecutor)
|
||||
assert isinstance(executor, concurrent.futures.ThreadPoolExecutor)
|
||||
|
||||
|
||||
def test_process_executor_init(default_app):
|
||||
default_app.config['EXECUTOR_TYPE'] = 'process'
|
||||
executor = Executor(default_app)
|
||||
assert isinstance(executor._self, concurrent.futures.ProcessPoolExecutor)
|
||||
assert isinstance(executor, concurrent.futures.ProcessPoolExecutor)
|
||||
|
||||
|
||||
def test_default_executor_init(default_app):
|
||||
executor = Executor(default_app)
|
||||
assert isinstance(executor._self, concurrent.futures.ThreadPoolExecutor)
|
||||
|
||||
|
||||
def test_invalid_executor_init(default_app):
|
||||
default_app.config['EXECUTOR_TYPE'] = 'invalid_value'
|
||||
try:
|
||||
executor = Executor(default_app)
|
||||
except ValueError:
|
||||
assert True
|
||||
else:
|
||||
assert False
|
||||
|
||||
|
||||
def test_submit(app):
|
||||
executor = Executor(app)
|
||||
with app.test_request_context(''):
|
||||
future = executor.submit(fib, 5)
|
||||
assert future.result() == fib(5)
|
||||
|
||||
|
||||
def test_max_workers(app):
|
||||
EXECUTOR_MAX_WORKERS = 10
|
||||
app.config['EXECUTOR_MAX_WORKERS'] = EXECUTOR_MAX_WORKERS
|
||||
executor = Executor(app)
|
||||
assert executor._max_workers == EXECUTOR_MAX_WORKERS
|
||||
assert executor._self._max_workers == EXECUTOR_MAX_WORKERS
|
||||
|
||||
|
||||
def test_thread_decorator_submit(default_app):
|
||||
default_app.config['EXECUTOR_TYPE'] = 'thread'
|
||||
executor = Executor(default_app)
|
||||
|
||||
@executor.job
|
||||
def decorated(n):
|
||||
return fib(n)
|
||||
|
||||
with default_app.test_request_context(''):
|
||||
future = decorated.submit(5)
|
||||
assert future.result() == fib(5)
|
||||
|
||||
|
||||
def test_thread_decorator_submit_stored(default_app):
|
||||
default_app.config['EXECUTOR_TYPE'] = 'thread'
|
||||
executor = Executor(default_app)
|
||||
|
||||
@executor.job
|
||||
def decorated(n):
|
||||
return fib(n)
|
||||
|
||||
with default_app.test_request_context():
|
||||
future = decorated.submit_stored('fibonacci', 35)
|
||||
assert executor.futures.done('fibonacci') is False
|
||||
assert future in executor.futures
|
||||
executor.futures.pop('fibonacci')
|
||||
assert future not in executor.futures
|
||||
|
||||
|
||||
def test_thread_decorator_map(default_app):
|
||||
iterable = list(range(5))
|
||||
default_app.config['EXECUTOR_TYPE'] = 'thread'
|
||||
executor = Executor(default_app)
|
||||
|
||||
@executor.job
|
||||
def decorated(n):
|
||||
return fib(n)
|
||||
|
||||
with default_app.test_request_context(''):
|
||||
results = decorated.map(iterable)
|
||||
for i, r in zip(iterable, results):
|
||||
assert fib(i) == r
|
||||
|
||||
|
||||
def test_process_decorator(default_app):
|
||||
''' Using decorators should fail with a TypeError when using the ProcessPoolExecutor '''
|
||||
default_app.config['EXECUTOR_TYPE'] = 'process'
|
||||
executor = Executor(default_app)
|
||||
try:
|
||||
@executor.job
|
||||
def decorated(n):
|
||||
return fib(n)
|
||||
except TypeError:
|
||||
pass
|
||||
else:
|
||||
assert 0
|
||||
|
||||
|
||||
def test_submit_app_context(default_app):
|
||||
test_value = random.randint(1, 101)
|
||||
default_app.config['TEST_VALUE'] = test_value
|
||||
executor = Executor(default_app)
|
||||
with default_app.test_request_context(''):
|
||||
future = executor.submit(app_context_test_value)
|
||||
assert future.result() == test_value
|
||||
|
||||
|
||||
def test_submit_g_context_process(default_app):
|
||||
test_value = random.randint(1, 101)
|
||||
executor = Executor(default_app)
|
||||
with default_app.test_request_context(''):
|
||||
g.test_value = test_value
|
||||
future = executor.submit(g_context_test_value)
|
||||
assert future.result() == test_value
|
||||
|
||||
|
||||
def test_submit_request_context(default_app):
|
||||
test_value = random.randint(1, 101)
|
||||
executor = Executor(default_app)
|
||||
with default_app.test_request_context(''):
|
||||
request.test_value = test_value
|
||||
future = executor.submit(request_context_test_value)
|
||||
assert future.result() == test_value
|
||||
|
||||
|
||||
def test_map_app_context(default_app):
|
||||
test_value = random.randint(1, 101)
|
||||
iterator = list(range(5))
|
||||
default_app.config['TEST_VALUE'] = test_value
|
||||
executor = Executor(default_app)
|
||||
with default_app.test_request_context(''):
|
||||
results = executor.map(app_context_test_value, iterator)
|
||||
for r in results:
|
||||
assert r == test_value
|
||||
|
||||
|
||||
def test_map_g_context_process(default_app):
|
||||
test_value = random.randint(1, 101)
|
||||
iterator = list(range(5))
|
||||
executor = Executor(default_app)
|
||||
with default_app.test_request_context(''):
|
||||
g.test_value = test_value
|
||||
results = executor.map(g_context_test_value, iterator)
|
||||
for r in results:
|
||||
assert r == test_value
|
||||
|
||||
|
||||
def test_map_request_context(default_app):
|
||||
test_value = random.randint(1, 101)
|
||||
iterator = list(range(5))
|
||||
executor = Executor(default_app)
|
||||
with default_app.test_request_context('/'):
|
||||
request.test_value = test_value
|
||||
results = executor.map(request_context_test_value, iterator)
|
||||
for r in results:
|
||||
assert r == test_value
|
||||
|
||||
|
||||
def test_executor_stored_future(default_app):
|
||||
executor = Executor(default_app)
|
||||
with default_app.test_request_context():
|
||||
future = executor.submit_stored('fibonacci', fib, 35)
|
||||
assert executor.futures.done('fibonacci') is False
|
||||
assert future in executor.futures
|
||||
executor.futures.pop('fibonacci')
|
||||
assert future not in executor.futures
|
||||
|
||||
|
||||
def test_set_max_futures(default_app):
|
||||
default_app.config['EXECUTOR_FUTURES_MAX_LENGTH'] = 10
|
||||
executor = Executor(default_app)
|
||||
assert executor.futures.max_length == default_app.config['EXECUTOR_FUTURES_MAX_LENGTH']
|
||||
|
||||
|
||||
def test_named_executor(default_app):
|
||||
name = 'custom'
|
||||
EXECUTOR_MAX_WORKERS = 5
|
||||
CUSTOM_EXECUTOR_MAX_WORKERS = 10
|
||||
default_app.config['EXECUTOR_MAX_WORKERS'] = EXECUTOR_MAX_WORKERS
|
||||
default_app.config['CUSTOM_EXECUTOR_MAX_WORKERS'] = CUSTOM_EXECUTOR_MAX_WORKERS
|
||||
executor = Executor(default_app)
|
||||
custom_executor = Executor(default_app, name=name)
|
||||
assert 'executor' in default_app.extensions
|
||||
assert name + 'executor' in default_app.extensions
|
||||
assert executor._self._max_workers == EXECUTOR_MAX_WORKERS
|
||||
assert executor._max_workers == EXECUTOR_MAX_WORKERS
|
||||
assert custom_executor._self._max_workers == CUSTOM_EXECUTOR_MAX_WORKERS
|
||||
assert custom_executor._max_workers == CUSTOM_EXECUTOR_MAX_WORKERS
|
||||
|
||||
|
||||
def test_named_executor_submit(app):
|
||||
name = 'custom'
|
||||
custom_executor = Executor(app, name=name)
|
||||
with app.test_request_context(''):
|
||||
future = custom_executor.submit(fib, 5)
|
||||
assert future.result() == fib(5)
|
||||
|
||||
|
||||
def test_named_executor_name(default_app):
|
||||
name = 'invalid name'
|
||||
try:
|
||||
executor = Executor(default_app, name=name)
|
||||
except ValueError:
|
||||
assert True
|
||||
else:
|
||||
assert False
|
||||
|
||||
|
||||
def test_default_done_callback(app):
|
||||
executor = Executor(app)
|
||||
|
||||
def callback(future):
|
||||
setattr(future, 'test', 'test')
|
||||
|
||||
executor.add_default_done_callback(callback)
|
||||
with app.test_request_context('/'):
|
||||
future = executor.submit(fib, 5)
|
||||
concurrent.futures.wait([future])
|
||||
assert hasattr(future, 'test')
|
||||
|
||||
|
||||
def test_propagate_exception_callback(app, caplog):
|
||||
caplog.set_level(logging.ERROR)
|
||||
app.config['EXECUTOR_PROPAGATE_EXCEPTIONS'] = True
|
||||
executor = Executor(app)
|
||||
with pytest.raises(NameError):
|
||||
with app.test_request_context('/'):
|
||||
future = executor.submit(fail)
|
||||
concurrent.futures.wait([future])
|
||||
future.result()
|
||||
|
||||
|
||||
def test_coerce_config_types(default_app):
|
||||
default_app.config['EXECUTOR_MAX_WORKERS'] = '5'
|
||||
default_app.config['EXECUTOR_FUTURES_MAX_LENGTH'] = '10'
|
||||
default_app.config['EXECUTOR_PROPAGATE_EXCEPTIONS'] = 'true'
|
||||
executor = Executor(default_app)
|
||||
with default_app.test_request_context():
|
||||
future = executor.submit_stored('fibonacci', fib, 35)
|
||||
|
||||
|
||||
def test_shutdown_executor(default_app):
|
||||
executor = Executor(default_app)
|
||||
assert executor._shutdown is False
|
||||
executor.shutdown()
|
||||
assert executor._shutdown is True
|
||||
|
||||
|
||||
def test_pre_init_executor(default_app):
|
||||
executor = Executor()
|
||||
|
||||
@executor.job
|
||||
def decorated(n):
|
||||
return fib(n)
|
||||
|
||||
assert executor
|
||||
executor.init_app(default_app)
|
||||
with default_app.test_request_context(''):
|
||||
future = decorated.submit(5)
|
||||
assert future.result() == fib(5)
|
||||
|
||||
|
||||
thread_local = local()
|
||||
|
||||
|
||||
def set_thread_local():
|
||||
if hasattr(thread_local, 'value'):
|
||||
raise ValueError('thread local already present')
|
||||
thread_local.value = True
|
||||
|
||||
|
||||
def clear_thread_local(response_or_exc):
|
||||
if hasattr(thread_local, 'value'):
|
||||
del thread_local.value
|
||||
return response_or_exc
|
||||
|
||||
|
||||
def test_teardown_appcontext_is_called(default_app):
|
||||
default_app.config['EXECUTOR_MAX_WORKERS'] = 1
|
||||
default_app.config['EXECUTOR_PUSH_APP_CONTEXT'] = True
|
||||
default_app.teardown_appcontext(clear_thread_local)
|
||||
|
||||
executor = Executor(default_app)
|
||||
with default_app.test_request_context():
|
||||
futures = [executor.submit(set_thread_local) for _ in range(2)]
|
||||
concurrent.futures.wait(futures)
|
||||
[propagate_exceptions_callback(future) for future in futures]
|
||||
|
||||
|
||||
try:
|
||||
import flask_sqlalchemy
|
||||
except ImportError:
|
||||
flask_sqlalchemy = None
|
||||
|
||||
|
||||
@pytest.mark.skipif(flask_sqlalchemy is None, reason="flask_sqlalchemy not installed")
|
||||
def test_sqlalchemy(default_app, caplog):
|
||||
default_app.config['SQLALCHEMY_ENGINE_OPTIONS'] = {'echo_pool': 'debug', 'echo': 'debug'}
|
||||
default_app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
|
||||
default_app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
default_app.config['EXECUTOR_PUSH_APP_CONTEXT'] = True
|
||||
default_app.config['EXECUTOR_MAX_WORKERS'] = 1
|
||||
db = flask_sqlalchemy.SQLAlchemy(default_app)
|
||||
|
||||
def test_db():
|
||||
return list(db.session.execute('select 1'))
|
||||
|
||||
executor = Executor(default_app)
|
||||
with default_app.test_request_context():
|
||||
for i in range(2):
|
||||
with caplog.at_level('DEBUG'):
|
||||
caplog.clear()
|
||||
future = executor.submit(test_db)
|
||||
concurrent.futures.wait([future])
|
||||
future.result()
|
||||
assert 'checked out from pool' in caplog.text
|
||||
assert 'being returned to pool' in caplog.text
|
|
@ -0,0 +1,97 @@
|
|||
import concurrent.futures
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
from flask_executor import Executor
|
||||
from flask_executor.futures import FutureCollection, FutureProxy
|
||||
from flask_executor.helpers import InstanceProxy
|
||||
|
||||
|
||||
def fib(n):
|
||||
if n <= 2:
|
||||
return 1
|
||||
else:
|
||||
return fib(n-1) + fib(n-2)
|
||||
|
||||
|
||||
def test_plain_future():
|
||||
executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
|
||||
futures = FutureCollection()
|
||||
future = executor.submit(fib, 33)
|
||||
futures.add('fibonacci', future)
|
||||
assert futures.done('fibonacci') is False
|
||||
assert futures._state('fibonacci') is not None
|
||||
assert future in futures
|
||||
futures.pop('fibonacci')
|
||||
assert future not in futures
|
||||
|
||||
def test_missing_future():
|
||||
futures = FutureCollection()
|
||||
assert futures.running('test') is None
|
||||
|
||||
def test_duplicate_add_future():
|
||||
executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
|
||||
futures = FutureCollection()
|
||||
future = executor.submit(fib, 33)
|
||||
futures.add('fibonacci', future)
|
||||
try:
|
||||
futures.add('fibonacci', future)
|
||||
except ValueError:
|
||||
assert True
|
||||
else:
|
||||
assert False
|
||||
|
||||
def test_futures_max_length():
|
||||
executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
|
||||
futures = FutureCollection(max_length=10)
|
||||
future = executor.submit(pow, 2, 4)
|
||||
futures.add(0, future)
|
||||
assert future in futures
|
||||
assert len(futures) == 1
|
||||
for i in range(1, 11):
|
||||
futures.add(i, executor.submit(pow, 2, 4))
|
||||
assert len(futures) == 10
|
||||
assert future not in futures
|
||||
|
||||
def test_future_proxy(default_app):
|
||||
executor = Executor(default_app)
|
||||
with default_app.test_request_context(''):
|
||||
future = executor.submit(pow, 2, 4)
|
||||
# Test if we're returning a subclass of Future
|
||||
assert isinstance(future, concurrent.futures.Future)
|
||||
assert isinstance(future, FutureProxy)
|
||||
concurrent.futures.wait([future])
|
||||
# test standard Future methods and attributes
|
||||
assert future._state == concurrent.futures._base.FINISHED
|
||||
assert future.done()
|
||||
assert future.exception(timeout=0) is None
|
||||
|
||||
def test_add_done_callback(default_app):
|
||||
"""Exceptions thrown in callbacks can't be easily caught and make it hard
|
||||
to test for callback failure. To combat this, a global variable is used to
|
||||
store the value of an exception and test for its existence.
|
||||
"""
|
||||
executor = Executor(default_app)
|
||||
global exception
|
||||
exception = None
|
||||
with default_app.test_request_context(''):
|
||||
future = executor.submit(time.sleep, 0.5)
|
||||
def callback(future):
|
||||
global exception
|
||||
try:
|
||||
executor.submit(time.sleep, 0)
|
||||
except RuntimeError as e:
|
||||
exception = e
|
||||
future.add_done_callback(callback)
|
||||
concurrent.futures.wait([future])
|
||||
assert exception is None
|
||||
|
||||
def test_instance_proxy():
|
||||
class TestProxy(InstanceProxy):
|
||||
pass
|
||||
x = TestProxy(concurrent.futures.Future())
|
||||
assert isinstance(x, concurrent.futures.Future)
|
||||
assert 'TestProxy' in repr(x)
|
||||
assert 'Future' in repr(x)
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
git clone https://github.com/python-restx/flask-restx opengnsys-flask-restx
|
||||
cd opengnsys-flask-restx
|
||||
git checkout 1.3.0
|
||||
version=`python3 ./setup.py --version`
|
||||
cd ..
|
||||
|
||||
if [ -d "opengnsys-flask-restx-${version}" ] ; then
|
||||
echo "Directory opengnsys-flask-restx-${version} already exists, won't overwrite"
|
||||
exit 1
|
||||
else
|
||||
rm -rf opengnsys-flask-restx/.git
|
||||
mv opengnsys-flask-restx "opengnsys-flask-restx-${version}"
|
||||
tar -c --xz -v -f "opengnsys-flask-restx_${version}.orig.tar.xz" "opengnsys-flask-restx-${version}"
|
||||
fi
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# EditorConfig is awesome: https://EditorConfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# Unix-style newlines with a newline ending every file
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
# Matches multiple files with brace expansion notation
|
||||
# Set default charset
|
||||
[*.{js,py}]
|
||||
charset = utf-8
|
||||
|
||||
# 4 space indentation
|
||||
[*.py]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
max_line_length = 120
|
|
@ -0,0 +1,44 @@
|
|||
---
|
||||
name: Bug Report
|
||||
about: Tell us how Flask-RESTX is broken
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
### ***** **BEFORE LOGGING AN ISSUE** *****
|
||||
|
||||
- Is this something you can **debug and fix**? Send a pull request! Bug fixes and documentation fixes are welcome.
|
||||
- Please check if a similar issue already exists or has been closed before. Seriously, nobody here is getting paid. Help us out and take five minutes to make sure you aren't submitting a duplicate.
|
||||
- Please review the [guidelines for contributing](https://github.com/python-restx/flask-restx/blob/master/CONTRIBUTING.rst)
|
||||
|
||||
### **Code**
|
||||
|
||||
```python
|
||||
from your_code import your_buggy_implementation
|
||||
```
|
||||
|
||||
### **Repro Steps** (if applicable)
|
||||
1. ...
|
||||
2. ...
|
||||
3. Broken!
|
||||
|
||||
### **Expected Behavior**
|
||||
A description of what you expected to happen.
|
||||
|
||||
### **Actual Behavior**
|
||||
A description of the unexpected, buggy behavior.
|
||||
|
||||
### **Error Messages/Stack Trace**
|
||||
If applicable, add the stack trace produced by the error
|
||||
|
||||
### **Environment**
|
||||
- Python version
|
||||
- Flask version
|
||||
- Flask-RESTX version
|
||||
- Other installed Flask extensions
|
||||
|
||||
### **Additional Context**
|
||||
|
||||
This is your last chance to provide any pertinent details, don't let this opportunity pass you by!
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
name: Question
|
||||
about: Ask a question
|
||||
title: ''
|
||||
labels: question
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Ask a question**
|
||||
A clear and concise question
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
|
@ -0,0 +1,25 @@
|
|||
## Proposed changes
|
||||
|
||||
At a high level, describe your reasoning for making these changes. If you are fixing a bug or resolving a feature request, **please include a link to the issue**.
|
||||
|
||||
## Types of changes
|
||||
|
||||
What types of changes does your code introduce?
|
||||
_Put an `x` in the boxes that apply_
|
||||
|
||||
- [ ] Bugfix (non-breaking change which fixes an issue)
|
||||
- [ ] New feature (non-breaking change which adds functionality)
|
||||
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
|
||||
|
||||
## Checklist
|
||||
|
||||
_Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._
|
||||
|
||||
- [ ] I have read the [guidelines for contributing](https://github.com/python-restx/flask-restx/blob/master/CONTRIBUTING.rst)
|
||||
- [ ] All unit tests pass on my local version with my changes
|
||||
- [ ] I have added tests that prove my fix is effective or that my feature works
|
||||
- [ ] I have added necessary documentation (if appropriate)
|
||||
|
||||
## Further comments
|
||||
|
||||
If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...
|
|
@ -0,0 +1,10 @@
|
|||
name: Lint
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: psf/black@stable
|
|
@ -0,0 +1,28 @@
|
|||
name: Release
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "*"
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Set up Python 3.8
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: 3.8
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install ".[dev]" wheel
|
||||
- name: Fetch web assets
|
||||
run: inv assets
|
||||
- name: Publish
|
||||
env:
|
||||
TWINE_USERNAME: "__token__"
|
||||
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
|
||||
run: |
|
||||
python setup.py sdist bdist_wheel
|
||||
twine upload dist/*
|
|
@ -0,0 +1,74 @@
|
|||
name: Tests
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- "*"
|
||||
push:
|
||||
branches:
|
||||
- "*"
|
||||
schedule:
|
||||
- cron: "0 1 * * *"
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
unit-tests:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
python-version: ["3.8", "3.9", "3.10", "3.11", "pypy3.8", "3.12"]
|
||||
flask: ["<3.0.0", ">=3.0.0"]
|
||||
steps:
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
allow-prereleases: true
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install "flask${{ matrix.flask }}"
|
||||
pip install ".[test]"
|
||||
- name: Test with inv
|
||||
run: inv cover qa
|
||||
- name: Codecov
|
||||
uses: codecov/codecov-action@v1
|
||||
with:
|
||||
file: ./coverage.xml
|
||||
bench:
|
||||
needs: unit-tests
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name == 'pull_request'
|
||||
steps:
|
||||
- name: Set up Python 3.8
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.8"
|
||||
- name: Checkout ${{ github.base_ref }}
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
ref: ${{ github.base_ref}}
|
||||
path: base
|
||||
- name: Checkout ${{ github.ref }}
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
ref: ${{ github.ref}}
|
||||
path: ref
|
||||
- name: Install dev dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -e "base[dev]"
|
||||
- name: Install ci dependencies for ${{ github.base_ref }}
|
||||
run: pip install -e "base[ci]"
|
||||
- name: Benchmarks for ${{ github.base_ref }}
|
||||
run: |
|
||||
cd base
|
||||
inv benchmark --max-time 4 --save
|
||||
mv .benchmarks ../ref/
|
||||
- name: Install ci dependencies for ${{ github.ref }}
|
||||
run: pip install -e "ref[ci]"
|
||||
- name: Benchmarks for ${{ github.ref }}
|
||||
run: |
|
||||
cd ref
|
||||
inv benchmark --max-time 4 --compare
|
|
@ -0,0 +1,70 @@
|
|||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
env/
|
||||
bin/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
cover
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
prof/
|
||||
histograms/
|
||||
.benchmarks
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
|
||||
# Atom
|
||||
*.cson
|
||||
|
||||
# Mr Developer
|
||||
.mr.developer.cfg
|
||||
.project
|
||||
.pydevproject
|
||||
|
||||
# Rope
|
||||
.ropeproject
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
*.pot
|
||||
|
||||
# Sphinx documentation
|
||||
doc/_build/
|
||||
|
||||
# Specifics
|
||||
flask_restx/static
|
||||
node_modules
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# Jet Brains
|
||||
.idea
|
|
@ -0,0 +1,63 @@
|
|||
# configure updates globally
|
||||
# default: all
|
||||
# allowed: all, insecure, False
|
||||
# update: all
|
||||
|
||||
# configure dependency pinning globally
|
||||
# default: True
|
||||
# allowed: True, False
|
||||
pin: False
|
||||
|
||||
# set the default branch
|
||||
# default: empty, the default branch on GitHub
|
||||
# branch: dev
|
||||
|
||||
# update schedule
|
||||
# default: empty
|
||||
# allowed: "every day", "every week", ..
|
||||
# schedule: "every day"
|
||||
|
||||
# search for requirement files
|
||||
# default: True
|
||||
# allowed: True, False
|
||||
# search: True
|
||||
|
||||
# Specify requirement files by hand, default is empty
|
||||
# default: empty
|
||||
# allowed: list
|
||||
# requirements:
|
||||
# - requirements/staging.txt:
|
||||
# # update all dependencies and pin them
|
||||
# update: all
|
||||
# pin: True
|
||||
# - requirements/dev.txt:
|
||||
# # don't update dependencies, use global 'pin' default
|
||||
# update: False
|
||||
# - requirements/prod.txt:
|
||||
# # update insecure only, pin all
|
||||
# update: insecure
|
||||
# pin: True
|
||||
|
||||
# add a label to pull requests, default is not set
|
||||
# requires private repo permissions, even on public repos
|
||||
# default: empty
|
||||
label_prs: update
|
||||
|
||||
# assign users to pull requests, default is not set
|
||||
# requires private repo permissions, even on public repos
|
||||
# default: empty
|
||||
# assignees:
|
||||
# - carl
|
||||
# - carlsen
|
||||
|
||||
# configure the branch prefix the bot is using
|
||||
# default: pyup-
|
||||
branch_prefix: pyup/
|
||||
|
||||
# set a global prefix for PRs
|
||||
# default: empty
|
||||
pr_prefix: "[PyUP]"
|
||||
|
||||
# allow to close stale PRs
|
||||
# default: True
|
||||
close_prs: True
|
|
@ -0,0 +1,342 @@
|
|||
Flask-RestX Changelog
|
||||
=====================
|
||||
|
||||
Basic structure is
|
||||
|
||||
::
|
||||
|
||||
ADD LINK (..) _section-VERSION
|
||||
VERSION
|
||||
-------
|
||||
ADD LINK (..) _bug_fixes-VERSION OR _enhancments-VERSION
|
||||
Bug Fixes or Enchancements
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Message (TICKET) [CONTRIBUTOR]
|
||||
|
||||
Opening a release
|
||||
-----------------
|
||||
|
||||
If you’re the first contributor, add a new semver release to the
|
||||
document. Place your addition in the correct category, giving a short
|
||||
description (matching something in a git commit), the issue ID (or PR ID
|
||||
if no issue opened), and your Github username for tracking contributors!
|
||||
|
||||
Releases prior to 0.3.0 were “best effort” filled out, but are missing
|
||||
some info. If you see your contribution missing info, please open a PR
|
||||
on the Changelog!
|
||||
|
||||
.. _section-1.3.0:
|
||||
1.3.0
|
||||
-----
|
||||
.. _bug_fixes-1.3.0
|
||||
Bug Fixes
|
||||
~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* Fixing werkzeug 3 deprecated version import. Import is replaced by new style version check with importlib (#573) [Ryu-CZ]
|
||||
* Fixing flask 3.0+ compatibility of `ModuleNotFoundError: No module named 'flask.scaffold'` Import error. (#567) [Ryu-CZ]
|
||||
* Fix wrong status code and message on responses when handling `HTTPExceptions` (#569) [lkk7]
|
||||
* Add flask 2 and flask 3 to testing matrix. [foarsitter]
|
||||
* Update internally pinned pytest-flask to 1.3.0 for Flask >=3.0.0 support. [peter-doggart]
|
||||
* Python 3.12 support. [foarsitter]
|
||||
* Fix wrong status code and message on responses when handling HTTPExceptions. [ikk7]
|
||||
* Update changelog Flask version table. [peter-doggart]
|
||||
* Remove temporary package version restrictions for flask < 3.0.0, werkzeug and jsonschema (jsonschema future deprecation warning remains. See #553). [peter-doggart]
|
||||
|
||||
.. _section-1.2.0:
|
||||
1.2.0
|
||||
-----
|
||||
.. _bug_fixes-1.2.0
|
||||
Bug Fixes
|
||||
~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* Fixing test as HTTP Header MIMEAccept expects quality-factor number in form of `X.X` (#547) [chipndell]
|
||||
* Introduce temporary restrictions on some package versions. (`flask<3.0.0`, `werkzeug<3.0.0`, `jsonschema<=4.17.3`) [peter-doggart]
|
||||
|
||||
|
||||
.. _enhancements-1.2.0:
|
||||
|
||||
Enhancements
|
||||
~~~~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* Drop support for python 3.7
|
||||
|
||||
|
||||
.. _section-1.1.0:
|
||||
1.1.0
|
||||
-----
|
||||
|
||||
.. _bug_fixes-1.1.0
|
||||
Bug Fixes
|
||||
~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* Update Swagger-UI to latest version to fix several security vulnerabiltiies. [peter-doggart]
|
||||
* Add a warning to the docs that nested Blueprints are not supported. [peter-doggart]
|
||||
* Add a note to the docs that flask-restx always registers the root (/) path. [peter-doggart]
|
||||
|
||||
.. _section-1.0.6:
|
||||
1.0.6
|
||||
-----
|
||||
|
||||
.. _bug_fixes-1.0.6
|
||||
Bug Fixes
|
||||
~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* Update Black to 2023 version [peter-doggart]
|
||||
* Fix minor bug introduced in 1.0.5 that changed the behaviour of how flask-restx propagates exceptions. (#512) [peter-doggart]
|
||||
* Update PyPi classifer to Production/Stable. [peter-doggart]
|
||||
* Add support for Python 3.11 (requires update to invoke ^2.0.0) [peter-doggart]
|
||||
|
||||
.. _section-1.0.5:
|
||||
1.0.5
|
||||
-----
|
||||
|
||||
.. _bug_fixes-1.0.5
|
||||
Bug Fixes
|
||||
~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* Fix failing pypy python setup in github actions
|
||||
* Fix compatibility with upcoming release of Flask 2.3+. (#485) [jdieter]
|
||||
|
||||
.. _section-1.0.2:
|
||||
1.0.2
|
||||
-----
|
||||
|
||||
.. _bug_fixes-1.0.2
|
||||
Bug Fixes
|
||||
~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* Properly remove six dependency
|
||||
|
||||
.. _section-1.0.1:
|
||||
1.0.1
|
||||
-----
|
||||
|
||||
.. _breaking-1.0.1
|
||||
|
||||
Breaking
|
||||
~~~~~~~~
|
||||
|
||||
Starting from this release, we only support python versions >= 3.7
|
||||
|
||||
.. _bug_fixes-1.0.1
|
||||
|
||||
Bug Fixes
|
||||
~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* Fix compatibility issue with werkzeug 2.1.0 (#423) [stacywsmith]
|
||||
|
||||
.. _enhancements-1.0.1:
|
||||
|
||||
Enhancements
|
||||
~~~~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* Drop support for python <3.7
|
||||
|
||||
.. _section-0.5.1:
|
||||
0.5.1
|
||||
-----
|
||||
|
||||
.. _bug_fixes-0.5.1
|
||||
|
||||
Bug Fixes
|
||||
~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* Optimize email regex (#372) [kevinbackhouse]
|
||||
|
||||
.. _section-0.5.0:
|
||||
0.5.0
|
||||
-----
|
||||
|
||||
.. _bug_fixes-0.5.0
|
||||
|
||||
Bug Fixes
|
||||
~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* Fix Marshaled nested wildcard field with ordered=True (#326) [bdscharf]
|
||||
* Fix Float Field Handling of None (#327) [bdscharf, TVLIgnacy]
|
||||
* Fix Werkzeug and Flask > 2.0 issues (#341) [hbusul]
|
||||
* Hotfix package.json [xuhdev]
|
||||
|
||||
.. _enhancements-0.5.0:
|
||||
|
||||
Enhancements
|
||||
~~~~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* Stop calling got_request_exception when handled explicitly (#349) [chandlernine, VolkaRancho]
|
||||
* Update doc links (#332) [EtiennePelletier]
|
||||
* Structure demo zoo app (#328) [mehul-anshumali]
|
||||
* Update Contributing.rst (#323) [physikerwelt]
|
||||
* Upgrade swagger-ui (#316) [xuhdev]
|
||||
|
||||
|
||||
.. _section-0.4.0:
|
||||
0.4.0
|
||||
-----
|
||||
|
||||
.. _bug_fixes-0.4.0
|
||||
|
||||
Bug Fixes
|
||||
~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* Fix Namespace error handlers when propagate_exceptions=True (#285) [mjreiss]
|
||||
* pin flask and werkzeug due to breaking changes (#308) [jchittum]
|
||||
* The Flask/Blueprint API moved to the Scaffold base class (#308) [jloehel]
|
||||
|
||||
|
||||
.. _enhancements-0.4.0:
|
||||
|
||||
Enhancements
|
||||
~~~~~~~~~~~~
|
||||
|
||||
::
|
||||
* added specs-url-scheme option for API (#237) [DustinMoriarty]
|
||||
* Doc enhancements [KAUTH, Abdur-rahmaanJ]
|
||||
* New example with loosely couple implementation [maurerle]
|
||||
|
||||
.. _section-0.3.0:
|
||||
|
||||
0.3.0
|
||||
-----
|
||||
|
||||
.. _bug_fixes-0.3.0:
|
||||
|
||||
Bug Fixes
|
||||
~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* Make error handlers order of registration respected when handling errors (#202) [avilaton]
|
||||
* add prefix to config setting (#114) [heeplr]
|
||||
* Doc fixes [openbrian, mikhailpashkov, rich0rd, Rich107, kashyapm94, SteadBytes, ziirish]
|
||||
* Use relative path for `api.specs_url` (#188) [jslay88]
|
||||
* Allow example=False (#203) [ogenstad]
|
||||
* Add support for recursive models (#110) [peterjwest, buggyspace, Drarok, edwardfung123]
|
||||
* generate choices schema without collectionFormat (#164) [leopold-p]
|
||||
* Catch TypeError in marshalling (#75) [robyoung]
|
||||
* Unable to access nested list propert (#91) [arajkumar]
|
||||
|
||||
.. _enhancements-0.3.0:
|
||||
|
||||
Enhancements
|
||||
~~~~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* Update Python versions [johnthagen]
|
||||
* allow strict mode when validating model fields (#186) [maho]
|
||||
* Make it possible to include "unused" models in the generated swagger documentation (#90)[volfpeter]
|
||||
|
||||
.. _section-0.2.0:
|
||||
|
||||
0.2.0
|
||||
-----
|
||||
|
||||
This release properly fixes the issue raised by the release of werkzeug
|
||||
1.0.
|
||||
|
||||
.. _bug-fixes-0.2.0:
|
||||
|
||||
Bug Fixes
|
||||
~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* Remove deprecated werkzeug imports (#35)
|
||||
* Fix OrderedDict imports (#54)
|
||||
* Fixing Swagger Issue when using @api.expect() on a request parser (#20)
|
||||
|
||||
.. _enhancements-0.2.0:
|
||||
|
||||
Enhancements
|
||||
~~~~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* use black to enforce a formatting codestyle (#60)
|
||||
* improve test workflows
|
||||
|
||||
.. _section-0.1.1:
|
||||
|
||||
0.1.1
|
||||
-----
|
||||
|
||||
This release is mostly a hotfix release to address incompatibility issue
|
||||
with the recent release of werkzeug 1.0.
|
||||
|
||||
.. _bug-fixes-0.1.1:
|
||||
|
||||
Bug Fixes
|
||||
~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* pin werkzeug version (#39)
|
||||
* register wildcard fields in docs (#24)
|
||||
* update package.json version accordingly with the flask-restx version and update the author (#38)
|
||||
|
||||
.. _enhancements-0.1.1:
|
||||
|
||||
Enhancements
|
||||
~~~~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* use github actions instead of travis-ci (#18)
|
||||
|
||||
.. _section-0.1.0:
|
||||
|
||||
0.1.0
|
||||
-----
|
||||
|
||||
.. _bug-fixes-0.1.0:
|
||||
|
||||
Bug Fixes
|
||||
~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* Fix exceptions/error handling bugs https://github.com/noirbizarre/flask-restplus/pull/706/files noirbizarre/flask-restplus#741
|
||||
* Fix illegal characters in JSON references to model names noirbizarre/flask-restplus#653
|
||||
* Support envelope parameter in Swagger documentation noirbizarre/flask-restplus#673
|
||||
* Fix polymorph field ambiguity noirbizarre/flask-restplus#691
|
||||
* Fix wildcard support for fields.Nested and fields.List noirbizarre/flask-restplus#739
|
||||
|
||||
.. _enhancements-0.1.0:
|
||||
|
||||
Enhancements
|
||||
~~~~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
* Api/Namespace individual loggers noirbizarre/flask-restplus#708
|
||||
* Various deprecated import changes noirbizarre/flask-restplus#732 noirbizarre/flask-restplus#738
|
||||
* Start the Flask-RESTX fork!
|
||||
* Rename all the things (#2 #9)
|
||||
* Set up releases from CI (#12)
|
||||
* Not a library enhancement but this was much needed - thanks @ziirish !
|
|
@ -0,0 +1,135 @@
|
|||
Contributing
|
||||
============
|
||||
|
||||
flask-restx is open-source and very open to contributions.
|
||||
|
||||
If you're part of a corporation with an NDA, and you may require updating the license.
|
||||
See Updating Copyright below
|
||||
|
||||
Submitting issues
|
||||
-----------------
|
||||
|
||||
Issues are contributions in a way so don't hesitate
|
||||
to submit reports on the `official bugtracker`_.
|
||||
|
||||
Provide as much informations as possible to specify the issues:
|
||||
|
||||
- the flask-restx version used
|
||||
- a stacktrace
|
||||
- installed applications list
|
||||
- a code sample to reproduce the issue
|
||||
- ...
|
||||
|
||||
|
||||
Submitting patches (bugfix, features, ...)
|
||||
------------------------------------------
|
||||
|
||||
If you want to contribute some code:
|
||||
|
||||
1. fork the `official flask-restx repository`_
|
||||
2. Ensure an issue is opened for your feature or bug
|
||||
3. create a branch with an explicit name (like ``my-new-feature`` or ``issue-XX``)
|
||||
4. do your work in it
|
||||
5. Commit your changes. Ensure the commit message includes the issue. Also, if contributing from a corporation, be sure to add a comment with the Copyright information
|
||||
6. rebase it on the master branch from the official repository (cleanup your history by performing an interactive rebase)
|
||||
7. add your change to the changelog
|
||||
8. submit your pull-request
|
||||
9. 2 Maintainers should review the code for bugfix and features. 1 maintainer for minor changes (such as docs)
|
||||
10. After review, a maintainer a will merge the PR. Maintainers should not merge their own PRs
|
||||
|
||||
There are some rules to follow:
|
||||
|
||||
- your contribution should be documented (if needed)
|
||||
- your contribution should be tested and the test suite should pass successfully
|
||||
- your code should be properly formatted (use ``black .`` to format)
|
||||
- your contribution should support both Python 2 and 3 (use ``tox`` to test)
|
||||
|
||||
You need to install some dependencies to develop on flask-restx:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ pip install -e .[dev]
|
||||
|
||||
An `Invoke <https://www.pyinvoke.org/>`_ ``tasks.py`` is provided to simplify the common tasks:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ inv -l
|
||||
Available tasks:
|
||||
|
||||
all Run tests, reports and packaging
|
||||
assets Fetch web assets -- Swagger. Requires NPM (see below)
|
||||
clean Cleanup all build artifacts
|
||||
cover Run tests suite with coverage
|
||||
demo Run the demo
|
||||
dist Package for distribution
|
||||
doc Build the documentation
|
||||
qa Run a quality report
|
||||
test Run tests suite
|
||||
tox Run tests against Python versions
|
||||
|
||||
To ensure everything is fine before submission, use ``tox``.
|
||||
It will run the test suite on all the supported Python version
|
||||
and ensure the documentation is generating.
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ tox
|
||||
|
||||
You also need to ensure your code is compliant with the flask-restx coding standards:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ inv qa
|
||||
|
||||
To ensure everything is fine before committing, you can launch the all in one command:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ inv qa tox
|
||||
|
||||
It will ensure the code meet the coding conventions, runs on every version on python
|
||||
and the documentation is properly generating.
|
||||
|
||||
.. _official flask-restx repository: https://github.com/python-restx/flask-restx
|
||||
.. _official bugtracker: https://github.com/python-restx/flask-restx/issues
|
||||
|
||||
Running a local Swagger Server
|
||||
------------------------------
|
||||
|
||||
For local development, you may wish to run a local server. running the following will install a swagger server
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ inv assets
|
||||
|
||||
NOTE: You'll need `NPM <https://docs.npmjs.com/getting-started/>`_ installed to do this.
|
||||
If you're new to NPM, also check out `nvm <https://github.com/creationix/nvm/blob/master/README.md>`_
|
||||
|
||||
Release process
|
||||
---------------
|
||||
|
||||
The new releases are pushed on `Pypi.org <https://pypi.org/>`_ automatically
|
||||
from `GitHub Actions <https://github.com/python-restx/flask-restx/actions?query=workflow%3ARelease>`_ when we add a new tag (unless the
|
||||
tests are failing).
|
||||
|
||||
In order to prepare a new release, you can use `bumpr <https://github.com/noirbizarre/bumpr>`_
|
||||
which automates a few things.
|
||||
You first need to install it, then run the ``bumpr`` command. You can then refer
|
||||
to the `documentation <https://bumpr.readthedocs.io/en/latest/commandline.html>`_
|
||||
for further details.
|
||||
For instance, you would run ``bumpr -m`` (replace ``-m`` with ``-p`` or ``-M``
|
||||
depending the expected version).
|
||||
|
||||
Updating Copyright
|
||||
------------------
|
||||
|
||||
If you're a part of a corporation with an NDA, you may be required to update the
|
||||
LICENSE file. This should be discussed and agreed upon by the project maintainers.
|
||||
|
||||
1. Check with your legal department first.
|
||||
2. Add an appropriate line to the LICENSE file.
|
||||
3. When making a commit, add the specific copyright notice.
|
||||
|
||||
Double check with your legal department about their regulations. Not all changes
|
||||
constitute new or unique work.
|
|
@ -0,0 +1,32 @@
|
|||
BSD 3-Clause License
|
||||
|
||||
Original work Copyright (c) 2013 Twilio, Inc
|
||||
Modified work Copyright (c) 2014 Axel Haustant
|
||||
Modified work Copyright (c) 2020 python-restx Authors
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -0,0 +1,5 @@
|
|||
include README.rst MANIFEST.in LICENSE
|
||||
recursive-include flask_restx *
|
||||
recursive-include requirements *.pip
|
||||
|
||||
global-exclude *.pyc
|
|
@ -0,0 +1,216 @@
|
|||
===========
|
||||
Flask RESTX
|
||||
===========
|
||||
|
||||
.. image:: https://github.com/python-restx/flask-restx/workflows/Tests/badge.svg?tag=1.3.0&event=push
|
||||
:target: https://github.com/python-restx/flask-restx/actions?query=workflow%3ATests
|
||||
:alt: Tests status
|
||||
.. image:: https://codecov.io/gh/python-restx/flask-restx/branch/master/graph/badge.svg
|
||||
:target: https://codecov.io/gh/python-restx/flask-restx
|
||||
:alt: Code coverage
|
||||
.. image:: https://readthedocs.org/projects/flask-restx/badge/?version=1.3.0
|
||||
:target: https://flask-restx.readthedocs.io/en/1.3.0/
|
||||
:alt: Documentation status
|
||||
.. image:: https://img.shields.io/pypi/l/flask-restx.svg
|
||||
:target: https://pypi.org/project/flask-restx
|
||||
:alt: License
|
||||
.. image:: https://img.shields.io/pypi/pyversions/flask-restx.svg
|
||||
:target: https://pypi.org/project/flask-restx
|
||||
:alt: Supported Python versions
|
||||
.. image:: https://badges.gitter.im/Join%20Chat.svg
|
||||
:target: https://gitter.im/python-restx?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
||||
:alt: Join the chat at https://gitter.im/python-restx
|
||||
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
|
||||
:target: https://github.com/psf/black
|
||||
:alt: Code style: black
|
||||
|
||||
|
||||
Flask-RESTX is a community driven fork of `Flask-RESTPlus <https://github.com/noirbizarre/flask-restplus>`_.
|
||||
|
||||
|
||||
Flask-RESTX is an extension for `Flask`_ that adds support for quickly building REST APIs.
|
||||
Flask-RESTX encourages best practices with minimal setup.
|
||||
If you are familiar with Flask, Flask-RESTX should be easy to pick up.
|
||||
It provides a coherent collection of decorators and tools to describe your API
|
||||
and expose its documentation properly using `Swagger`_.
|
||||
|
||||
|
||||
Compatibility
|
||||
=============
|
||||
|
||||
Flask-RESTX requires Python 3.8+.
|
||||
|
||||
On Flask Compatibility
|
||||
======================
|
||||
|
||||
Flask and Werkzeug moved to versions 2.0 in March 2020. This caused a breaking change in Flask-RESTX.
|
||||
|
||||
.. list-table:: RESTX and Flask / Werkzeug Compatibility
|
||||
:widths: 25 25 25
|
||||
:header-rows: 1
|
||||
|
||||
|
||||
* - Flask-RESTX version
|
||||
- Flask version
|
||||
- Note
|
||||
* - <= 0.3.0
|
||||
- < 2.0.0
|
||||
- unpinned in Flask-RESTX. Pin your projects!
|
||||
* - == 0.4.0
|
||||
- < 2.0.0
|
||||
- pinned in Flask-RESTX.
|
||||
* - >= 0.5.0
|
||||
- < 3.0.0
|
||||
- unpinned, import statements wrapped for compatibility
|
||||
* - == 1.2.0
|
||||
- < 3.0.0
|
||||
- pinned in Flask-RESTX.
|
||||
* - >= 1.3.0
|
||||
- >= 2.0.0 (Flask >= 3.0.0 support)
|
||||
- unpinned, import statements wrapped for compatibility
|
||||
* - trunk branch in Github
|
||||
- >= 2.0.0 (Flask >= 3.0.0 support)
|
||||
- unpinned, will address issues faster than releases.
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
You can install Flask-RESTX with pip:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ pip install flask-restx
|
||||
|
||||
or with easy_install:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ easy_install flask-restx
|
||||
|
||||
|
||||
Quick start
|
||||
===========
|
||||
|
||||
With Flask-RESTX, you only import the api instance to route and document your endpoints.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from flask import Flask
|
||||
from flask_restx import Api, Resource, fields
|
||||
|
||||
app = Flask(__name__)
|
||||
api = Api(app, version='1.0', title='TodoMVC API',
|
||||
description='A simple TodoMVC API',
|
||||
)
|
||||
|
||||
ns = api.namespace('todos', description='TODO operations')
|
||||
|
||||
todo = api.model('Todo', {
|
||||
'id': fields.Integer(readonly=True, description='The task unique identifier'),
|
||||
'task': fields.String(required=True, description='The task details')
|
||||
})
|
||||
|
||||
|
||||
class TodoDAO(object):
|
||||
def __init__(self):
|
||||
self.counter = 0
|
||||
self.todos = []
|
||||
|
||||
def get(self, id):
|
||||
for todo in self.todos:
|
||||
if todo['id'] == id:
|
||||
return todo
|
||||
api.abort(404, "Todo {} doesn't exist".format(id))
|
||||
|
||||
def create(self, data):
|
||||
todo = data
|
||||
todo['id'] = self.counter = self.counter + 1
|
||||
self.todos.append(todo)
|
||||
return todo
|
||||
|
||||
def update(self, id, data):
|
||||
todo = self.get(id)
|
||||
todo.update(data)
|
||||
return todo
|
||||
|
||||
def delete(self, id):
|
||||
todo = self.get(id)
|
||||
self.todos.remove(todo)
|
||||
|
||||
|
||||
DAO = TodoDAO()
|
||||
DAO.create({'task': 'Build an API'})
|
||||
DAO.create({'task': '?????'})
|
||||
DAO.create({'task': 'profit!'})
|
||||
|
||||
|
||||
@ns.route('/')
|
||||
class TodoList(Resource):
|
||||
'''Shows a list of all todos, and lets you POST to add new tasks'''
|
||||
@ns.doc('list_todos')
|
||||
@ns.marshal_list_with(todo)
|
||||
def get(self):
|
||||
'''List all tasks'''
|
||||
return DAO.todos
|
||||
|
||||
@ns.doc('create_todo')
|
||||
@ns.expect(todo)
|
||||
@ns.marshal_with(todo, code=201)
|
||||
def post(self):
|
||||
'''Create a new task'''
|
||||
return DAO.create(api.payload), 201
|
||||
|
||||
|
||||
@ns.route('/<int:id>')
|
||||
@ns.response(404, 'Todo not found')
|
||||
@ns.param('id', 'The task identifier')
|
||||
class Todo(Resource):
|
||||
'''Show a single todo item and lets you delete them'''
|
||||
@ns.doc('get_todo')
|
||||
@ns.marshal_with(todo)
|
||||
def get(self, id):
|
||||
'''Fetch a given resource'''
|
||||
return DAO.get(id)
|
||||
|
||||
@ns.doc('delete_todo')
|
||||
@ns.response(204, 'Todo deleted')
|
||||
def delete(self, id):
|
||||
'''Delete a task given its identifier'''
|
||||
DAO.delete(id)
|
||||
return '', 204
|
||||
|
||||
@ns.expect(todo)
|
||||
@ns.marshal_with(todo)
|
||||
def put(self, id):
|
||||
'''Update a task given its identifier'''
|
||||
return DAO.update(id, api.payload)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
|
||||
|
||||
Contributors
|
||||
============
|
||||
|
||||
Flask-RESTX is brought to you by @python-restx. Since early 2019 @SteadBytes,
|
||||
@a-luna, @j5awry, @ziirish volunteered to help @python-restx keep the project up
|
||||
and running, they did so for a long time! Since the beginning of 2023, the project
|
||||
is maintained by @peter-doggart with help from @ziirish.
|
||||
Of course everyone is welcome to contribute and we will be happy to review your
|
||||
PR's or answer to your issues.
|
||||
|
||||
|
||||
Documentation
|
||||
=============
|
||||
|
||||
The documentation is hosted `on Read the Docs <http://flask-restx.readthedocs.io/en/latest/>`_
|
||||
|
||||
|
||||
.. _Flask: https://flask.palletsprojects.com/
|
||||
.. _Swagger: https://swagger.io/
|
||||
|
||||
|
||||
Contribution
|
||||
============
|
||||
Want to contribute! That's awesome! Check out `CONTRIBUTING.rst! <https://github.com/python-restx/flask-restx/blob/master/CONTRIBUTING.rst>`_
|
|
@ -0,0 +1,25 @@
|
|||
[bumpr]
|
||||
file = flask_restx/__about__.py
|
||||
vcs = git
|
||||
commit = true
|
||||
tag = true
|
||||
push = true
|
||||
tests = tox -e py38
|
||||
clean =
|
||||
inv clean
|
||||
files =
|
||||
README.rst
|
||||
|
||||
[bump]
|
||||
unsuffix = true
|
||||
|
||||
[prepare]
|
||||
part = patch
|
||||
suffix = dev
|
||||
|
||||
[readthedoc]
|
||||
id = flask-restx
|
||||
|
||||
[replace]
|
||||
dev = ?branch=master
|
||||
stable = ?tag={version}
|
|
@ -0,0 +1,25 @@
|
|||
[run]
|
||||
source = flask_restx
|
||||
branch = True
|
||||
omit =
|
||||
/tests/*
|
||||
|
||||
[report]
|
||||
# Regexes for lines to exclude from consideration
|
||||
exclude_lines =
|
||||
# Have to re-enable the standard pragma
|
||||
pragma: no cover
|
||||
|
||||
# Don't complain about missing debug-only code:
|
||||
def __repr__
|
||||
if self\.debug
|
||||
|
||||
# Don't complain if tests don't hit defensive assertion code:
|
||||
raise AssertionError
|
||||
raise NotImplementedError
|
||||
|
||||
# Don't complain if non-runnable code isn't run:
|
||||
if 0:
|
||||
if __name__ == .__main__.:
|
||||
|
||||
ignore_errors = True
|
|
@ -0,0 +1,7 @@
|
|||
opengnsys-flask-restx (1.3.0) UNRELEASED; urgency=medium
|
||||
|
||||
Initial version
|
||||
*
|
||||
*
|
||||
|
||||
-- Vadim Troshchinskiy <vtroshchinskiy@qindel.com> Tue, 23 Dec 2024 10:47:04 +0000
|
|
@ -0,0 +1,34 @@
|
|||
Source: opengnsys-flask-restx
|
||||
Maintainer: OpenGnsys <opengnsys@opengnsys.org>
|
||||
Section: python
|
||||
Priority: optional
|
||||
Build-Depends: debhelper-compat (= 12),
|
||||
dh-python,
|
||||
libarchive-dev,
|
||||
python3-all,
|
||||
python3-mock,
|
||||
python3-pytest,
|
||||
python3-setuptools,
|
||||
python3-aniso8601,
|
||||
faker,
|
||||
python3-importlib-resources,
|
||||
python3-pytest-flask,
|
||||
python3-pytest-mock,
|
||||
python3-pytest-benchmark
|
||||
Standards-Version: 4.5.0
|
||||
Rules-Requires-Root: no
|
||||
Homepage: https://github.com/vojtechtrefny/pyblkid
|
||||
Vcs-Browser: https://github.com/vojtechtrefny/pyblkid
|
||||
Vcs-Git: https://github.com/vojtechtrefny/pyblkid
|
||||
|
||||
Package: opengnsys-flask-restx
|
||||
Architecture: all
|
||||
Depends: ${lib:Depends}, ${misc:Depends}, ${python3:Depends}
|
||||
Description: Flask-RESTX is a community driven fork of Flask-RESTPlus.
|
||||
Flask-RESTX is an extension for Flask that adds support for quickly building
|
||||
REST APIs. Flask-RESTX encourages best practices with minimal setup.
|
||||
.
|
||||
If you are familiar with Flask, Flask-RESTX should be easy to pick up.
|
||||
It provides a coherent collection of decorators and tools to describe your
|
||||
API and expose its documentation properly using Swagger.
|
||||
.
|
|
@ -0,0 +1,208 @@
|
|||
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Upstream-Name: python-libarchive-c
|
||||
Source: https://github.com/Changaco/python-libarchive-c
|
||||
|
||||
Files: *
|
||||
Copyright: 2014-2018 Changaco <changaco@changaco.oy.lc>
|
||||
License: CC-0
|
||||
|
||||
Files: tests/surrogateescape.py
|
||||
Copyright: 2015 Changaco <changaco@changaco.oy.lc>
|
||||
2011-2013 Victor Stinner <victor.stinner@gmail.com>
|
||||
License: BSD-2-clause or PSF-2
|
||||
|
||||
Files: debian/*
|
||||
Copyright: 2015 Jerémy Bobbio <lunar@debian.org>
|
||||
2019 Mattia Rizzolo <mattia@debian.org>
|
||||
License: permissive
|
||||
Copying and distribution of this package, with or without
|
||||
modification, are permitted in any medium without royalty
|
||||
provided the copyright notice and this notice are
|
||||
preserved.
|
||||
|
||||
License: BSD-2-clause
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
.
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
||||
License: PSF-2
|
||||
1. This LICENSE AGREEMENT is between the Python Software Foundation ("PSF"),
|
||||
and the Individual or Organization ("Licensee") accessing and otherwise using
|
||||
this software ("Python") in source or binary form and its associated
|
||||
documentation.
|
||||
.
|
||||
2. Subject to the terms and conditions of this License Agreement, PSF hereby
|
||||
grants Licensee a nonexclusive, royalty-free, world-wide license to
|
||||
reproduce, analyze, test, perform and/or display publicly, prepare derivative
|
||||
works, distribute, and otherwise use Python alone or in any derivative
|
||||
version, provided, however, that PSF's License Agreement and PSF's notice of
|
||||
copyright, i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 Python
|
||||
Software Foundation; All Rights Reserved" are retained in Python alone or in
|
||||
any derivative version prepared by Licensee.
|
||||
.
|
||||
3. In the event Licensee prepares a derivative work that is based on or
|
||||
incorporates Python or any part thereof, and wants to make the derivative
|
||||
work available to others as provided herein, then Licensee hereby agrees to
|
||||
include in any such work a brief summary of the changes made to Python.
|
||||
.
|
||||
4. PSF is making Python available to Licensee on an "AS IS" basis. PSF MAKES
|
||||
NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT
|
||||
NOT LIMITATION, PSF MAKES NO AND DISCLAIMS ANY REPRESENTATION OR WARRANTY OF
|
||||
MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF
|
||||
PYTHON WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.
|
||||
.
|
||||
5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON FOR ANY
|
||||
INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF
|
||||
MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, OR ANY DERIVATIVE
|
||||
THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
|
||||
.
|
||||
6. This License Agreement will automatically terminate upon a material breach
|
||||
of its terms and conditions.
|
||||
.
|
||||
7. Nothing in this License Agreement shall be deemed to create any
|
||||
relationship of agency, partnership, or joint venture between PSF and
|
||||
Licensee. This License Agreement does not grant permission to use PSF
|
||||
trademarks or trade name in a trademark sense to endorse or promote products
|
||||
or services of Licensee, or any third party.
|
||||
.
|
||||
8. By copying, installing or otherwise using Python, Licensee agrees to be
|
||||
bound by the terms and conditions of this License Agreement.
|
||||
|
||||
License: CC-0
|
||||
Statement of Purpose
|
||||
.
|
||||
The laws of most jurisdictions throughout the world automatically
|
||||
confer exclusive Copyright and Related Rights (defined below) upon
|
||||
the creator and subsequent owner(s) (each and all, an "owner") of an
|
||||
original work of authorship and/or a database (each, a "Work").
|
||||
.
|
||||
Certain owners wish to permanently relinquish those rights to a Work
|
||||
for the purpose of contributing to a commons of creative, cultural
|
||||
and scientific works ("Commons") that the public can reliably and
|
||||
without fear of later claims of infringement build upon, modify,
|
||||
incorporate in other works, reuse and redistribute as freely as
|
||||
possible in any form whatsoever and for any purposes, including
|
||||
without limitation commercial purposes. These owners may contribute
|
||||
to the Commons to promote the ideal of a free culture and the further
|
||||
production of creative, cultural and scientific works, or to gain
|
||||
reputation or greater distribution for their Work in part through the
|
||||
use and efforts of others.
|
||||
.
|
||||
For these and/or other purposes and motivations, and without any
|
||||
expectation of additional consideration or compensation, the person
|
||||
associating CC0 with a Work (the "Affirmer"), to the extent that he
|
||||
or she is an owner of Copyright and Related Rights in the Work,
|
||||
voluntarily elects to apply CC0 to the Work and publicly distribute
|
||||
the Work under its terms, with knowledge of his or her Copyright and
|
||||
Related Rights in the Work and the meaning and intended legal effect
|
||||
of CC0 on those rights.
|
||||
.
|
||||
1. Copyright and Related Rights. A Work made available under CC0 may
|
||||
be protected by copyright and related or neighboring rights
|
||||
("Copyright and Related Rights"). Copyright and Related Rights
|
||||
include, but are not limited to, the following:
|
||||
.
|
||||
i. the right to reproduce, adapt, distribute, perform, display,
|
||||
communicate, and translate a Work;
|
||||
ii. moral rights retained by the original author(s) and/or
|
||||
performer(s);
|
||||
iii. publicity and privacy rights pertaining to a person's image
|
||||
or likeness depicted in a Work;
|
||||
iv. rights protecting against unfair competition in regards to a
|
||||
Work, subject to the limitations in paragraph 4(a), below;
|
||||
v. rights protecting the extraction, dissemination, use and
|
||||
reuse of data in a Work;
|
||||
vi. database rights (such as those arising under Directive
|
||||
96/9/EC of the European Parliament and of the Council of 11
|
||||
March 1996 on the legal protection of databases, and under
|
||||
any national implementation thereof, including any amended or
|
||||
successor version of such directive); and
|
||||
vii. other similar, equivalent or corresponding rights throughout
|
||||
the world based on applicable law or treaty, and any national
|
||||
implementations thereof.
|
||||
.
|
||||
2. Waiver. To the greatest extent permitted by, but not in
|
||||
contravention of, applicable law, Affirmer hereby overtly, fully,
|
||||
permanently, irrevocably and unconditionally waives, abandons, and
|
||||
surrenders all of Affirmer's Copyright and Related Rights and
|
||||
associated claims and causes of action, whether now known or
|
||||
unknown (including existing as well as future claims and causes of
|
||||
action), in the Work (i) in all territories worldwide, (ii) for
|
||||
the maximum duration provided by applicable law or treaty
|
||||
(including future time extensions), (iii) in any current or future
|
||||
medium and for any number of copies, and (iv) for any purpose
|
||||
whatsoever, including without limitation commercial, advertising
|
||||
or promotional purposes (the "Waiver"). Affirmer makes the Waiver
|
||||
for the benefit of each member of the public at large and to the
|
||||
detriment of Affirmer's heirs and successors, fully intending that
|
||||
such Waiver shall not be subject to revocation, rescission,
|
||||
cancellation, termination, or any other legal or equitable action
|
||||
to disrupt the quiet enjoyment of the Work by the public as
|
||||
contemplated by Affirmer's express Statement of Purpose.
|
||||
.
|
||||
3. Public License Fallback. Should any part of the Waiver for any
|
||||
reason be judged legally invalid or ineffective under applicable law,
|
||||
then the Waiver shall be preserved to the maximum extent permitted
|
||||
taking into account Affirmer's express Statement of Purpose. In
|
||||
addition, to the extent the Waiver is so judged Affirmer hereby
|
||||
grants to each affected person a royalty-free, non transferable, non
|
||||
sublicensable, non exclusive, irrevocable and unconditional license
|
||||
to exercise Affirmer's Copyright and Related Rights in the Work (i)
|
||||
in all territories worldwide, (ii) for the maximum duration provided
|
||||
by applicable law or treaty (including future time extensions), (iii)
|
||||
in any current or future medium and for any number of copies, and
|
||||
(iv) for any purpose whatsoever, including without limitation
|
||||
commercial, advertising or promotional purposes (the "License"). The
|
||||
License shall be deemed effective as of the date CC0 was applied by
|
||||
Affirmer to the Work. Should any part of the License for any reason
|
||||
be judged legally invalid or ineffective under applicable law, such
|
||||
partial invalidity or ineffectiveness shall not invalidate the
|
||||
remainder of the License, and in such case Affirmer hereby affirms
|
||||
that he or she will not (i) exercise any of his or her remaining
|
||||
Copyright and Related Rights in the Work or (ii) assert any
|
||||
associated claims and causes of action with respect to the Work, in
|
||||
either case contrary to Affirmer's express Statement of Purpose.
|
||||
.
|
||||
4. Limitations and Disclaimers.
|
||||
.
|
||||
a. No trademark or patent rights held by Affirmer are waived,
|
||||
abandoned, surrendered, licensed or otherwise affected by
|
||||
this document.
|
||||
b. Affirmer offers the Work as-is and makes no representations
|
||||
or warranties of any kind concerning the Work, express,
|
||||
implied, statutory or otherwise, including without limitation
|
||||
warranties of title, merchantability, fitness for a
|
||||
particular purpose, non infringement, or the absence of
|
||||
latent or other defects, accuracy, or the present or absence
|
||||
of errors, whether or not discoverable, all to the greatest
|
||||
extent permissible under applicable law.
|
||||
c. Affirmer disclaims responsibility for clearing rights of
|
||||
other persons that may apply to the Work or any use thereof,
|
||||
including without limitation any person's Copyright and
|
||||
Related Rights in the Work. Further, Affirmer disclaims
|
||||
responsibility for obtaining any necessary consents,
|
||||
permissions or other rights required for any use of the
|
||||
Work.
|
||||
d. Affirmer understands and acknowledges that Creative Commons
|
||||
is not a party to this document and has no duty or obligation
|
||||
with respect to this CC0 or use of the Work.
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/make -f
|
||||
|
||||
export LC_ALL=C.UTF-8
|
||||
export PYBUILD_NAME = flask-restx
|
||||
#export PYBUILD_BEFORE_TEST = cp -av README.rst {build_dir}
|
||||
export PYBUILD_TEST_ARGS = -vv -s
|
||||
#export PYBUILD_AFTER_TEST = rm -v {build_dir}/README.rst
|
||||
# ./usr/lib/python3/dist-packages/libarchive/
|
||||
export PYBUILD_INSTALL_ARGS=--install-lib=/usr/share/opengnsys-modules/python3/dist-packages/
|
||||
%:
|
||||
dh $@ --with python3 --buildsystem=pybuild
|
||||
|
||||
override_dh_gencontrol:
|
||||
dh_gencontrol -- \
|
||||
-Vlib:Depends=$(shell dpkg-query -W -f '$${Depends}' libarchive-dev \
|
||||
| sed -E 's/.*(libarchive[[:alnum:].-]+).*/\1/')
|
||||
|
||||
override_dh_installdocs:
|
||||
# Nothing, we don't want docs
|
||||
|
||||
override_dh_installchangelogs:
|
||||
# Nothing, we don't want the changelog
|
||||
#
|
||||
override_dh_auto_test:
|
||||
# One test is broken, just disable for now
|
|
@ -0,0 +1 @@
|
|||
3.0 (quilt)
|
|
@ -0,0 +1,2 @@
|
|||
Tests: upstream-tests
|
||||
Depends: @, python3-mock, python3-pytest
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
if ! [ -d "$AUTOPKGTEST_TMP" ]; then
|
||||
echo "AUTOPKGTEST_TMP not set." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cp -rv tests "$AUTOPKGTEST_TMP"
|
||||
cd "$AUTOPKGTEST_TMP"
|
||||
mkdir -v libarchive
|
||||
touch README.rst
|
||||
py.test-3 tests -vv -l -r a
|
|
@ -0,0 +1,177 @@
|
|||
# Makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line.
|
||||
SPHINXOPTS =
|
||||
SPHINXBUILD = sphinx-build
|
||||
PAPER =
|
||||
BUILDDIR = _build
|
||||
|
||||
# User-friendly check for sphinx-build
|
||||
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
|
||||
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from https://sphinx-doc.org/)
|
||||
endif
|
||||
|
||||
# Internal variables.
|
||||
PAPEROPT_a4 = -D latex_paper_size=a4
|
||||
PAPEROPT_letter = -D latex_paper_size=letter
|
||||
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
# the i18n builder cannot share the environment and doctrees with the others
|
||||
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
|
||||
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
|
||||
|
||||
help:
|
||||
@echo "Please use \`make <target>' where <target> is one of"
|
||||
@echo " html to make standalone HTML files"
|
||||
@echo " dirhtml to make HTML files named index.html in directories"
|
||||
@echo " singlehtml to make a single large HTML file"
|
||||
@echo " pickle to make pickle files"
|
||||
@echo " json to make JSON files"
|
||||
@echo " htmlhelp to make HTML files and a HTML help project"
|
||||
@echo " qthelp to make HTML files and a qthelp project"
|
||||
@echo " devhelp to make HTML files and a Devhelp project"
|
||||
@echo " epub to make an epub"
|
||||
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
|
||||
@echo " latexpdf to make LaTeX files and run them through pdflatex"
|
||||
@echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
|
||||
@echo " text to make text files"
|
||||
@echo " man to make manual pages"
|
||||
@echo " texinfo to make Texinfo files"
|
||||
@echo " info to make Texinfo files and run them through makeinfo"
|
||||
@echo " gettext to make PO message catalogs"
|
||||
@echo " changes to make an overview of all changed/added/deprecated items"
|
||||
@echo " xml to make Docutils-native XML files"
|
||||
@echo " pseudoxml to make pseudoxml-XML files for display purposes"
|
||||
@echo " linkcheck to check all external links for integrity"
|
||||
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILDDIR)/*
|
||||
|
||||
html:
|
||||
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
|
||||
|
||||
dirhtml:
|
||||
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
|
||||
|
||||
singlehtml:
|
||||
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
|
||||
|
||||
pickle:
|
||||
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
|
||||
@echo
|
||||
@echo "Build finished; now you can process the pickle files."
|
||||
|
||||
json:
|
||||
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
|
||||
@echo
|
||||
@echo "Build finished; now you can process the JSON files."
|
||||
|
||||
htmlhelp:
|
||||
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run HTML Help Workshop with the" \
|
||||
".hhp project file in $(BUILDDIR)/htmlhelp."
|
||||
|
||||
qthelp:
|
||||
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
|
||||
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
|
||||
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Flask-RESTX.qhcp"
|
||||
@echo "To view the help file:"
|
||||
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Flask-RESTX.qhc"
|
||||
|
||||
devhelp:
|
||||
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
|
||||
@echo
|
||||
@echo "Build finished."
|
||||
@echo "To view the help file:"
|
||||
@echo "# mkdir -p $$HOME/.local/share/devhelp/Flask-RESTX"
|
||||
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Flask-RESTX"
|
||||
@echo "# devhelp"
|
||||
|
||||
epub:
|
||||
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
|
||||
@echo
|
||||
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
|
||||
|
||||
latex:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo
|
||||
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
|
||||
@echo "Run \`make' in that directory to run these through (pdf)latex" \
|
||||
"(use \`make latexpdf' here to do that automatically)."
|
||||
|
||||
latexpdf:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo "Running LaTeX files through pdflatex..."
|
||||
$(MAKE) -C $(BUILDDIR)/latex all-pdf
|
||||
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
|
||||
|
||||
latexpdfja:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo "Running LaTeX files through platex and dvipdfmx..."
|
||||
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
|
||||
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
|
||||
|
||||
text:
|
||||
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
|
||||
@echo
|
||||
@echo "Build finished. The text files are in $(BUILDDIR)/text."
|
||||
|
||||
man:
|
||||
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
|
||||
@echo
|
||||
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
|
||||
|
||||
texinfo:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo
|
||||
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
|
||||
@echo "Run \`make' in that directory to run these through makeinfo" \
|
||||
"(use \`make info' here to do that automatically)."
|
||||
|
||||
info:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo "Running Texinfo files through makeinfo..."
|
||||
make -C $(BUILDDIR)/texinfo info
|
||||
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
|
||||
|
||||
gettext:
|
||||
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
|
||||
@echo
|
||||
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
|
||||
|
||||
changes:
|
||||
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
|
||||
@echo
|
||||
@echo "The overview file is in $(BUILDDIR)/changes."
|
||||
|
||||
linkcheck:
|
||||
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
|
||||
@echo
|
||||
@echo "Link check complete; look for any errors in the above output " \
|
||||
"or in $(BUILDDIR)/linkcheck/output.txt."
|
||||
|
||||
doctest:
|
||||
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
|
||||
@echo "Testing of doctests in the sources finished, look at the " \
|
||||
"results in $(BUILDDIR)/doctest/output.txt."
|
||||
|
||||
xml:
|
||||
$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
|
||||
@echo
|
||||
@echo "Build finished. The XML files are in $(BUILDDIR)/xml."
|
||||
|
||||
pseudoxml:
|
||||
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
|
||||
@echo
|
||||
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
|
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 7.4 KiB |
After Width: | Height: | Size: 9.9 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 42 KiB |
After Width: | Height: | Size: 41 KiB |
After Width: | Height: | Size: 128 KiB |
|
@ -0,0 +1,7 @@
|
|||
<!--h3>Links</h3-->
|
||||
{% if theme_badges %}
|
||||
<hr class="badges" />
|
||||
{% for badge, target, alt in theme_badges %}
|
||||
<p class="badge"><a href="{{target}}"><img src="{{badge}}" alt="{{alt}}" /></a></p>
|
||||
{% endfor %}
|
||||
{% endif %}
|
|
@ -0,0 +1,10 @@
|
|||
{% extends "alabaster/layout.html" %}
|
||||
|
||||
{%- block extrahead %}
|
||||
{% if theme_favicons %}
|
||||
{% for size, file in theme_favicons.items() %}
|
||||
<link rel="icon" type="image/png" href="{{ pathto('_static/' ~ file, 1) }}" sizes="{{size}}x{{size}}">
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{{ super() }}
|
||||
{% endblock %}
|
|
@ -0,0 +1,12 @@
|
|||
@import url("alabaster.css");
|
||||
|
||||
.sphinxsidebar p.badge a {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.sphinxsidebar hr.badges {
|
||||
border: 0;
|
||||
border-bottom: 1px dashed #aaa;
|
||||
background: none;
|
||||
/*width: 100%;*/
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
[theme]
|
||||
inherit = alabaster
|
||||
stylesheet = restx.css
|
||||
|
||||
[options]
|
||||
favicons=
|
||||
badges=
|
|
@ -0,0 +1,98 @@
|
|||
.. _api:
|
||||
|
||||
API
|
||||
===
|
||||
|
||||
.. currentmodule:: flask_restx
|
||||
|
||||
Core
|
||||
----
|
||||
|
||||
.. autoclass:: Api
|
||||
:members:
|
||||
:inherited-members:
|
||||
|
||||
.. autoclass:: Namespace
|
||||
:members:
|
||||
|
||||
|
||||
.. autoclass:: Resource
|
||||
:members:
|
||||
:inherited-members:
|
||||
|
||||
|
||||
Models
|
||||
------
|
||||
|
||||
.. autoclass:: flask_restx.Model
|
||||
:members:
|
||||
|
||||
All fields accept a ``required`` boolean and a ``description`` string in ``kwargs``.
|
||||
|
||||
.. automodule:: flask_restx.fields
|
||||
:members:
|
||||
|
||||
|
||||
Serialization
|
||||
-------------
|
||||
.. currentmodule:: flask_restx
|
||||
|
||||
.. autofunction:: marshal
|
||||
|
||||
.. autofunction:: marshal_with
|
||||
|
||||
.. autofunction:: marshal_with_field
|
||||
|
||||
.. autoclass:: flask_restx.mask.Mask
|
||||
:members:
|
||||
|
||||
.. autofunction:: flask_restx.mask.apply
|
||||
|
||||
|
||||
Request parsing
|
||||
---------------
|
||||
|
||||
.. automodule:: flask_restx.reqparse
|
||||
:members:
|
||||
|
||||
Inputs
|
||||
~~~~~~
|
||||
|
||||
.. automodule:: flask_restx.inputs
|
||||
:members:
|
||||
|
||||
|
||||
Errors
|
||||
------
|
||||
|
||||
.. automodule:: flask_restx.errors
|
||||
:members:
|
||||
|
||||
.. autoexception:: flask_restx.fields.MarshallingError
|
||||
|
||||
.. autoexception:: flask_restx.mask.MaskError
|
||||
|
||||
.. autoexception:: flask_restx.mask.ParseError
|
||||
|
||||
|
||||
Schemas
|
||||
-------
|
||||
|
||||
.. automodule:: flask_restx.schemas
|
||||
:members:
|
||||
|
||||
|
||||
Internals
|
||||
---------
|
||||
|
||||
These are internal classes or helpers.
|
||||
Most of the time you shouldn't have to deal directly with them.
|
||||
|
||||
.. autoclass:: flask_restx.api.SwaggerView
|
||||
|
||||
.. autoclass:: flask_restx.swagger.Swagger
|
||||
|
||||
.. autoclass:: flask_restx.postman.PostmanCollectionV1
|
||||
|
||||
.. automodule:: flask_restx.utils
|
||||
:members:
|
|
@ -0,0 +1,342 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Flask-RESTX documentation build configuration file, created by
|
||||
# sphinx-quickstart on Wed Aug 13 17:07:14 2014.
|
||||
#
|
||||
# This file is execfile()d with the current directory set to its
|
||||
# containing dir.
|
||||
#
|
||||
# Note that not all possible configuration values are present in this
|
||||
# autogenerated file.
|
||||
#
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import alabaster
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
sys.path.insert(0, os.path.abspath(".."))
|
||||
|
||||
# -- General configuration ------------------------------------------------
|
||||
|
||||
# If your documentation needs a minimal Sphinx version, state it here.
|
||||
# needs_sphinx = '1.0'
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||
# ones.
|
||||
extensions = [
|
||||
"sphinx.ext.autodoc",
|
||||
"sphinx.ext.viewcode",
|
||||
"sphinx.ext.intersphinx",
|
||||
"sphinx.ext.todo",
|
||||
"sphinx_issues",
|
||||
"alabaster",
|
||||
]
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ["_templates"]
|
||||
|
||||
# The suffix of source filenames.
|
||||
source_suffix = ".rst"
|
||||
|
||||
# The encoding of source files.
|
||||
# source_encoding = 'utf-8-sig'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = "index"
|
||||
|
||||
# General information about the project.
|
||||
project = "Flask-RESTX"
|
||||
copyright = "2020, python-restx Authors"
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
# built documents.
|
||||
#
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = __import__("flask_restx").__version__
|
||||
# The short X.Y version.
|
||||
version = ".".join(release.split(".")[:1])
|
||||
|
||||
# Github repo
|
||||
issues_github_path = "python-restx/flask-restx"
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
# language = None
|
||||
|
||||
# There are two options for replacing |today|: either, you set today to some
|
||||
# non-false value, then it is used:
|
||||
# today = ''
|
||||
# Else, today_fmt is used as the format for a strftime call.
|
||||
# today_fmt = '%B %d, %Y'
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
exclude_patterns = ["_build"]
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all
|
||||
# documents.
|
||||
# default_role = None
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||
# add_function_parentheses = True
|
||||
|
||||
# If true, the current module name will be prepended to all description
|
||||
# unit titles (such as .. function::).
|
||||
# add_module_names = True
|
||||
|
||||
# If true, sectionauthor and moduleauthor directives will be shown in the
|
||||
# output. They are ignored by default.
|
||||
# show_authors = False
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = "sphinx"
|
||||
|
||||
# A list of ignored prefixes for module index sorting.
|
||||
# modindex_common_prefix = []
|
||||
|
||||
# If true, keep warnings as "system message" paragraphs in the built documents.
|
||||
# keep_warnings = False
|
||||
|
||||
|
||||
# -- Options for HTML output ----------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
html_theme = "restx"
|
||||
|
||||
# Theme options are theme-specific and customize the look and feel of a theme
|
||||
# further. For a list of options available for each theme, see the
|
||||
# documentation.
|
||||
html_theme_options = {
|
||||
"logo": "logo-512.png",
|
||||
"logo_name": True,
|
||||
"touch_icon": "apple-180.png",
|
||||
"github_user": "python-restx",
|
||||
"github_repo": "flask-restx",
|
||||
"github_banner": True,
|
||||
"show_related": True,
|
||||
"page_width": "1000px",
|
||||
"sidebar_width": "260px",
|
||||
"favicons": {
|
||||
64: "favicon-64.png",
|
||||
128: "favicon-128.png",
|
||||
196: "favicon-196.png",
|
||||
},
|
||||
"badges": [
|
||||
(
|
||||
# Gitter.im
|
||||
"https://badges.gitter.im/Join%20Chat.svg",
|
||||
"https://gitter.im/python-restx",
|
||||
"Join the chat at https://gitter.im/python-restx",
|
||||
),
|
||||
(
|
||||
# Github Fork
|
||||
"https://img.shields.io/github/forks/python-restx/flask-restx.svg?style=social&label=Fork",
|
||||
"https://github.com/python-restx/flask-restx",
|
||||
"Github repository",
|
||||
),
|
||||
(
|
||||
# Github issues
|
||||
"https://img.shields.io/github/issues-raw/python-restx/flask-restx.svg",
|
||||
"https://github.com/python-restx/flask-restx/issues",
|
||||
"Github repository",
|
||||
),
|
||||
(
|
||||
# License
|
||||
"https://img.shields.io/github/license/python-restx/flask-restx.svg",
|
||||
"https://github.com/python-restx/flask-restx",
|
||||
"License",
|
||||
),
|
||||
(
|
||||
# PyPI
|
||||
"https://img.shields.io/pypi/v/flask-restx.svg",
|
||||
"https://pypi.python.org/pypi/flask-restx",
|
||||
"Latest version on PyPI",
|
||||
),
|
||||
],
|
||||
}
|
||||
|
||||
# Add any paths that contain custom themes here, relative to this directory.
|
||||
html_theme_path = [alabaster.get_path(), "_themes"]
|
||||
|
||||
html_context = {}
|
||||
|
||||
# The name for this set of Sphinx documents. If None, it defaults to
|
||||
# "<project> v<release> documentation".
|
||||
# html_title = None
|
||||
|
||||
# A shorter title for the navigation bar. Default is the same as html_title.
|
||||
# html_short_title = None
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top
|
||||
# of the sidebar.
|
||||
# html_logo = None
|
||||
|
||||
# The name of an image file (within the static path) to use as favicon of the
|
||||
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
|
||||
# pixels large.
|
||||
html_favicon = "_static/favicon.ico"
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ["_static"]
|
||||
|
||||
# Add any extra paths that contain custom files (such as robots.txt or
|
||||
# .htaccess) here, relative to this directory. These files are copied
|
||||
# directly to the root of the documentation.
|
||||
# html_extra_path = []
|
||||
|
||||
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
||||
# using the given strftime format.
|
||||
# html_last_updated_fmt = '%b %d, %Y'
|
||||
|
||||
# If true, SmartyPants will be used to convert quotes and dashes to
|
||||
# typographically correct entities.
|
||||
# html_use_smartypants = True
|
||||
|
||||
# Custom sidebar templates, maps document names to template names.
|
||||
html_sidebars = {
|
||||
"**": [
|
||||
"about.html",
|
||||
"navigation.html",
|
||||
"relations.html",
|
||||
"searchbox.html",
|
||||
"donate.html",
|
||||
"badges.html",
|
||||
]
|
||||
}
|
||||
|
||||
# Additional templates that should be rendered to pages, maps page names to
|
||||
# template names.
|
||||
# html_additional_pages = {}
|
||||
|
||||
# If false, no module index is generated.
|
||||
# html_domain_indices = True
|
||||
|
||||
# If false, no index is generated.
|
||||
# html_use_index = True
|
||||
|
||||
# If true, the index is split into individual pages for each letter.
|
||||
# html_split_index = False
|
||||
|
||||
# If true, links to the reST sources are added to the pages.
|
||||
# html_show_sourcelink = True
|
||||
|
||||
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
|
||||
# html_show_sphinx = True
|
||||
|
||||
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
|
||||
# html_show_copyright = True
|
||||
|
||||
# If true, an OpenSearch description file will be output, and all pages will
|
||||
# contain a <link> tag referring to it. The value of this option must be the
|
||||
# base URL from which the finished HTML is served.
|
||||
# html_use_opensearch = ''
|
||||
|
||||
# This is the file name suffix for HTML files (e.g. ".xhtml").
|
||||
# html_file_suffix = None
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = "Flask-RESTXdoc"
|
||||
|
||||
|
||||
# -- Options for LaTeX output ---------------------------------------------
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
#'papersize': 'letterpaper',
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#'pointsize': '10pt',
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
#'preamble': '',
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title,
|
||||
# author, documentclass [howto, manual, or own class]).
|
||||
latex_documents = [
|
||||
(
|
||||
"index",
|
||||
"Flask-RESTX.tex",
|
||||
"Flask-RESTX Documentation",
|
||||
"python-restx Authors",
|
||||
"manual",
|
||||
),
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
# the title page.
|
||||
# latex_logo = None
|
||||
|
||||
# For "manual" documents, if this is true, then toplevel headings are parts,
|
||||
# not chapters.
|
||||
# latex_use_parts = False
|
||||
|
||||
# If true, show page references after internal links.
|
||||
# latex_show_pagerefs = False
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
# latex_show_urls = False
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
# latex_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
# latex_domain_indices = True
|
||||
|
||||
|
||||
# -- Options for manual page output ---------------------------------------
|
||||
|
||||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
("index", "flask-restx", "Flask-RESTX Documentation", ["python-restx Authors"], 1)
|
||||
]
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
# man_show_urls = False
|
||||
|
||||
|
||||
# -- Options for Texinfo output -------------------------------------------
|
||||
|
||||
# Grouping the document tree into Texinfo files. List of tuples
|
||||
# (source start file, target name, title, author,
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
(
|
||||
"index",
|
||||
"Flask-RESTX",
|
||||
"Flask-RESTX Documentation",
|
||||
"python-restx Authors",
|
||||
"Flask-RESTX",
|
||||
"One line description of project.",
|
||||
"Miscellaneous",
|
||||
),
|
||||
]
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
# texinfo_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
# texinfo_domain_indices = True
|
||||
|
||||
# How to display URL addresses: 'footnote', 'no', or 'inline'.
|
||||
# texinfo_show_urls = 'footnote'
|
||||
|
||||
# If true, do not generate a @detailmenu in the "Top" node's menu.
|
||||
# texinfo_no_detailmenu = False
|
||||
|
||||
|
||||
intersphinx_mapping = {
|
||||
"flask": ("https://flask.palletsprojects.com/", None),
|
||||
"python": ("https://docs.python.org/", None),
|
||||
"werkzeug": ("https://werkzeug.palletsprojects.com/", None),
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
Configuration
|
||||
=============
|
||||
|
||||
Flask-RESTX provides the following `Flask configuration values <https://flask.palletsprojects.com/en/1.1.x/config/#configuration-handling>`_:
|
||||
|
||||
Note: Values with no additional description should be covered in more detail
|
||||
elsewhere in the documentation. If not, please open an issue on GitHub.
|
||||
|
||||
.. py:data:: RESTX_JSON
|
||||
|
||||
Provide global configuration options for JSON serialisation as a :class:`dict`
|
||||
of :func:`json.dumps` keyword arguments.
|
||||
|
||||
.. py:data:: RESTX_VALIDATE
|
||||
|
||||
Whether to enforce payload validation by default when using the
|
||||
``@api.expect()`` decorator. See the `@api.expect()
|
||||
<swagger.html#the-api-expect-decorator>`__ documentation for details.
|
||||
This setting defaults to ``False``.
|
||||
|
||||
.. py:data:: RESTX_MASK_HEADER
|
||||
|
||||
Choose the name of the *Header* that will contain the masks to apply to your
|
||||
answer. See the `Fields masks <mask.html>`__ documentation for details.
|
||||
This setting defaults to ``X-Fields``.
|
||||
|
||||
.. py:data:: RESTX_MASK_SWAGGER
|
||||
|
||||
Whether to enable the mask documentation in your swagger or not. See the
|
||||
`mask usage <mask.html#usage>`__ documentation for details.
|
||||
This setting defaults to ``True``.
|
||||
|
||||
.. py:data:: RESTX_INCLUDE_ALL_MODELS
|
||||
|
||||
This option allows you to include all defined models in the generated Swagger
|
||||
documentation, even if they are not explicitly used in either ``expect`` nor
|
||||
``marshal_with`` decorators.
|
||||
This setting defaults to ``False``.
|
||||
|
||||
.. py:data:: BUNDLE_ERRORS
|
||||
|
||||
Bundle all the validation errors instead of returning only the first one
|
||||
encountered. See the `Error Handling <parsing.html#error-handling>`__ section
|
||||
of the documentation for details.
|
||||
This setting defaults to ``False``.
|
||||
|
||||
.. py:data:: ERROR_404_HELP
|
||||
|
||||
.. py:data:: HTTP_BASIC_AUTH_REALM
|
||||
|
||||
.. py:data:: SWAGGER_VALIDATOR_URL
|
||||
|
||||
.. py:data:: SWAGGER_UI_DOC_EXPANSION
|
||||
|
||||
.. py:data:: SWAGGER_UI_OPERATION_ID
|
||||
|
||||
.. py:data:: SWAGGER_UI_REQUEST_DURATION
|
||||
|
||||
.. py:data:: SWAGGER_UI_OAUTH_APP_NAME
|
||||
|
||||
.. py:data:: SWAGGER_UI_OAUTH_CLIENT_ID
|
||||
|
||||
.. py:data:: SWAGGER_UI_OAUTH_REALM
|
||||
|
||||
.. py:data:: SWAGGER_SUPPORTED_SUBMIT_METHODS
|
|
@ -0,0 +1 @@
|
|||
.. include:: ../CONTRIBUTING.rst
|
|
@ -0,0 +1,227 @@
|
|||
Error handling
|
||||
==============
|
||||
|
||||
.. currentmodule:: flask_restx
|
||||
|
||||
HTTPException handling
|
||||
----------------------
|
||||
|
||||
Werkzeug HTTPException are automatically properly seriliazed
|
||||
reusing the description attribute.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from werkzeug.exceptions import BadRequest
|
||||
raise BadRequest()
|
||||
|
||||
will return a 400 HTTP code and output
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"message": "The browser (or proxy) sent a request that this server could not understand."
|
||||
}
|
||||
|
||||
whereas this:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from werkzeug.exceptions import BadRequest
|
||||
raise BadRequest('My custom message')
|
||||
|
||||
will output
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"message": "My custom message"
|
||||
}
|
||||
|
||||
You can attach extras attributes to the output by providing a data attribute to your exception.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from werkzeug.exceptions import BadRequest
|
||||
e = BadRequest('My custom message')
|
||||
e.data = {'custom': 'value'}
|
||||
raise e
|
||||
|
||||
will output
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"message": "My custom message",
|
||||
"custom": "value"
|
||||
}
|
||||
|
||||
The Flask abort helper
|
||||
----------------------
|
||||
|
||||
The :meth:`abort <werkeug.exceptions.Aborter.__call__>` helper
|
||||
properly wraps errors into a :exc:`~werkzeug.exceptions.HTTPException`
|
||||
so it will have the same behavior.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from flask import abort
|
||||
abort(400)
|
||||
|
||||
will return a 400 HTTP code and output
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"message": "The browser (or proxy) sent a request that this server could not understand."
|
||||
}
|
||||
|
||||
whereas this:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from flask import abort
|
||||
abort(400, 'My custom message')
|
||||
|
||||
will output
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"message": "My custom message"
|
||||
}
|
||||
|
||||
|
||||
The Flask-RESTX abort helper
|
||||
-------------------------------
|
||||
|
||||
The :func:`errors.abort` and the :meth:`Namespace.abort` helpers
|
||||
works like the original Flask :func:`flask.abort`
|
||||
but it will also add the keyword arguments to the response.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from flask_restx import abort
|
||||
abort(400, custom='value')
|
||||
|
||||
will return a 400 HTTP code and output
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"message": "The browser (or proxy) sent a request that this server could not understand.",
|
||||
"custom": "value"
|
||||
}
|
||||
|
||||
whereas this:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from flask import abort
|
||||
abort(400, 'My custom message', custom='value')
|
||||
|
||||
will output
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"message": "My custom message",
|
||||
"custom": "value"
|
||||
}
|
||||
|
||||
|
||||
The ``@api.errorhandler`` decorator
|
||||
-----------------------------------
|
||||
|
||||
The :meth:`@api.errorhandler <Api.errorhandler>` decorator
|
||||
allows you to register a specific handler for a given exception (or any exceptions inherited from it), in the same manner
|
||||
that you can do with Flask/Blueprint :meth:`@errorhandler <flask:flask.Flask.errorhandler>` decorator.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@api.errorhandler(RootException)
|
||||
def handle_root_exception(error):
|
||||
'''Return a custom message and 400 status code'''
|
||||
return {'message': 'What you want'}, 400
|
||||
|
||||
|
||||
@api.errorhandler(CustomException)
|
||||
def handle_custom_exception(error):
|
||||
'''Return a custom message and 400 status code'''
|
||||
return {'message': 'What you want'}, 400
|
||||
|
||||
|
||||
@api.errorhandler(AnotherException)
|
||||
def handle_another_exception(error):
|
||||
'''Return a custom message and 500 status code'''
|
||||
return {'message': error.specific}
|
||||
|
||||
|
||||
@api.errorhandler(FakeException)
|
||||
def handle_fake_exception_with_header(error):
|
||||
'''Return a custom message and 400 status code'''
|
||||
return {'message': error.message}, 400, {'My-Header': 'Value'}
|
||||
|
||||
|
||||
@api.errorhandler(NoResultFound)
|
||||
def handle_no_result_exception(error):
|
||||
'''Return a custom not found error message and 404 status code'''
|
||||
return {'message': error.specific}, 404
|
||||
|
||||
|
||||
.. note ::
|
||||
|
||||
A "NoResultFound" error with description is required by the OpenAPI 2.0 spec. The docstring in the error handle function is output in the swagger.json as the description.
|
||||
|
||||
You can also document the error:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@api.errorhandler(FakeException)
|
||||
@api.marshal_with(error_fields, code=400)
|
||||
@api.header('My-Header', 'Some description')
|
||||
def handle_fake_exception_with_header(error):
|
||||
'''This is a custom error'''
|
||||
return {'message': error.message}, 400, {'My-Header': 'Value'}
|
||||
|
||||
|
||||
@api.route('/test/')
|
||||
class TestResource(Resource):
|
||||
def get(self):
|
||||
'''
|
||||
Do something
|
||||
|
||||
:raises CustomException: In case of something
|
||||
'''
|
||||
pass
|
||||
|
||||
In this example, the ``:raise:`` docstring will be automatically extracted
|
||||
and the response 400 will be documented properly.
|
||||
|
||||
|
||||
It also allows for overriding the default error handler when used without parameter:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@api.errorhandler
|
||||
def default_error_handler(error):
|
||||
'''Default error handler'''
|
||||
return {'message': str(error)}, getattr(error, 'code', 500)
|
||||
|
||||
.. note ::
|
||||
|
||||
Flask-RESTX will return a message in the error response by default.
|
||||
If a custom response is required as an error and the message field is not needed,
|
||||
it can be disabled by setting ``ERROR_INCLUDE_MESSAGE`` to ``False`` in your application config.
|
||||
|
||||
Error handlers can also be registered on namespaces. An error handler registered on a namespace
|
||||
will override one registered on the api.
|
||||
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
ns = Namespace('cats', description='Cats related operations')
|
||||
|
||||
@ns.errorhandler
|
||||
def specific_namespace_error_handler(error):
|
||||
'''Namespace error handler'''
|
||||
return {'message': str(error)}, getattr(error, 'code', 500)
|
|
@ -0,0 +1,108 @@
|
|||
Full example
|
||||
============
|
||||
|
||||
Here is a full example of a `TodoMVC <https://todomvc.com/>`_ API.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from flask import Flask
|
||||
from flask_restx import Api, Resource, fields
|
||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
|
||||
app = Flask(__name__)
|
||||
app.wsgi_app = ProxyFix(app.wsgi_app)
|
||||
api = Api(app, version='1.0', title='TodoMVC API',
|
||||
description='A simple TodoMVC API',
|
||||
)
|
||||
|
||||
ns = api.namespace('todos', description='TODO operations')
|
||||
|
||||
todo = api.model('Todo', {
|
||||
'id': fields.Integer(readonly=True, description='The task unique identifier'),
|
||||
'task': fields.String(required=True, description='The task details')
|
||||
})
|
||||
|
||||
|
||||
class TodoDAO(object):
|
||||
def __init__(self):
|
||||
self.counter = 0
|
||||
self.todos = []
|
||||
|
||||
def get(self, id):
|
||||
for todo in self.todos:
|
||||
if todo['id'] == id:
|
||||
return todo
|
||||
api.abort(404, "Todo {} doesn't exist".format(id))
|
||||
|
||||
def create(self, data):
|
||||
todo = data
|
||||
todo['id'] = self.counter = self.counter + 1
|
||||
self.todos.append(todo)
|
||||
return todo
|
||||
|
||||
def update(self, id, data):
|
||||
todo = self.get(id)
|
||||
todo.update(data)
|
||||
return todo
|
||||
|
||||
def delete(self, id):
|
||||
todo = self.get(id)
|
||||
self.todos.remove(todo)
|
||||
|
||||
|
||||
DAO = TodoDAO()
|
||||
DAO.create({'task': 'Build an API'})
|
||||
DAO.create({'task': '?????'})
|
||||
DAO.create({'task': 'profit!'})
|
||||
|
||||
|
||||
@ns.route('/')
|
||||
class TodoList(Resource):
|
||||
'''Shows a list of all todos, and lets you POST to add new tasks'''
|
||||
@ns.doc('list_todos')
|
||||
@ns.marshal_list_with(todo)
|
||||
def get(self):
|
||||
'''List all tasks'''
|
||||
return DAO.todos
|
||||
|
||||
@ns.doc('create_todo')
|
||||
@ns.expect(todo)
|
||||
@ns.marshal_with(todo, code=201)
|
||||
def post(self):
|
||||
'''Create a new task'''
|
||||
return DAO.create(api.payload), 201
|
||||
|
||||
|
||||
@ns.route('/<int:id>')
|
||||
@ns.response(404, 'Todo not found')
|
||||
@ns.param('id', 'The task identifier')
|
||||
class Todo(Resource):
|
||||
'''Show a single todo item and lets you delete them'''
|
||||
@ns.doc('get_todo')
|
||||
@ns.marshal_with(todo)
|
||||
def get(self, id):
|
||||
'''Fetch a given resource'''
|
||||
return DAO.get(id)
|
||||
|
||||
@ns.doc('delete_todo')
|
||||
@ns.response(204, 'Todo deleted')
|
||||
def delete(self, id):
|
||||
'''Delete a task given its identifier'''
|
||||
DAO.delete(id)
|
||||
return '', 204
|
||||
|
||||
@ns.expect(todo)
|
||||
@ns.marshal_with(todo)
|
||||
def put(self, id):
|
||||
'''Update a task given its identifier'''
|
||||
return DAO.update(id, api.payload)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
|
||||
|
||||
|
||||
You can find other examples in the `github repository examples folder`_.
|
||||
|
||||
.. _github repository examples folder: https://github.com/python-restx/flask-restx/tree/master/examples
|
|
@ -0,0 +1,103 @@
|
|||
.. Flask-RESTX documentation master file, created by
|
||||
sphinx-quickstart on Wed Aug 13 17:07:14 2014.
|
||||
You can adapt this file completely to your liking, but it should at least
|
||||
contain the root `toctree` directive.
|
||||
|
||||
Welcome to Flask-RESTX's documentation!
|
||||
=======================================
|
||||
|
||||
Flask-RESTX is an extension for Flask that adds support for quickly building REST APIs.
|
||||
Flask-RESTX encourages best practices with minimal setup.
|
||||
If you are familiar with Flask, Flask-RESTX should be easy to pick up.
|
||||
It provides a coherent collection of decorators and tools to describe your API
|
||||
and expose its documentation properly (using Swagger).
|
||||
|
||||
Flask-RESTX is a community driven fork of `Flask-RESTPlus
|
||||
<https://github.com/noirbizarre/flask-restplus>`_
|
||||
|
||||
|
||||
Why did we fork?
|
||||
================
|
||||
|
||||
The community has decided to fork the project due to lack of response from the
|
||||
original author @noirbizarre. We have been discussing this eventuality for
|
||||
`a long time <https://github.com/noirbizarre/flask-restplus/issues/593>`_.
|
||||
|
||||
Things evolved a bit since that discussion and a few of us have been granted
|
||||
maintainers access to the github project, but only the original author has
|
||||
access rights on the PyPi project. As such, we been unable to make any actual
|
||||
releases. To prevent this project from dying out, we have forked it to continue
|
||||
development and to support our users.
|
||||
|
||||
|
||||
Compatibility
|
||||
=============
|
||||
|
||||
Flask-RESTX requires Python 3.8+.
|
||||
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
You can install Flask-RESTX with pip:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ pip install flask-restx
|
||||
|
||||
or with easy_install:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ easy_install flask-restx
|
||||
|
||||
|
||||
Documentation
|
||||
=============
|
||||
|
||||
This part of the documentation will show you how to get started in using
|
||||
Flask-RESTX with Flask.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
installation
|
||||
quickstart
|
||||
marshalling
|
||||
parsing
|
||||
errors
|
||||
mask
|
||||
swagger
|
||||
logging
|
||||
postman
|
||||
scaling
|
||||
example
|
||||
configuration
|
||||
|
||||
|
||||
API Reference
|
||||
-------------
|
||||
|
||||
If you are looking for information on a specific function, class or
|
||||
method, this part of the documentation is for you.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
api
|
||||
|
||||
Additional Notes
|
||||
----------------
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
contributing
|
||||
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`modindex`
|
||||
* :ref:`search`
|
|
@ -0,0 +1,24 @@
|
|||
.. _installation:
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
Install Flask-RESTX with ``pip``:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
pip install flask-restx
|
||||
|
||||
|
||||
The development version can be downloaded from
|
||||
`GitHub <https://github.com/python-restx/flask-restx>`_.
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
git clone https://github.com/python-restx/flask-restx.git
|
||||
cd flask-restx
|
||||
pip install -e .[dev,test]
|
||||
|
||||
|
||||
Flask-RESTX requires Python version 3.8+.
|
||||
It's also working with PyPy and PyPy3.
|
|
@ -0,0 +1,103 @@
|
|||
Logging
|
||||
===============
|
||||
|
||||
Flask-RESTX extends `Flask's logging <https://flask.palletsprojects.com/en/1.1.x/logging/>`_
|
||||
by providing each ``API`` and ``Namespace`` it's own standard Python :class:`logging.Logger` instance.
|
||||
This allows separation of logging on a per namespace basis to allow more fine-grained detail and configuration.
|
||||
|
||||
By default, these loggers inherit configuration from the Flask application object logger.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import logging
|
||||
|
||||
import flask
|
||||
|
||||
from flask_restx import Api, Resource
|
||||
|
||||
# configure root logger
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
app = flask.Flask(__name__)
|
||||
|
||||
api = Api(app)
|
||||
|
||||
|
||||
# each of these loggers uses configuration from app.logger
|
||||
ns1 = api.namespace('api/v1', description='test')
|
||||
ns2 = api.namespace('api/v2', description='test')
|
||||
|
||||
|
||||
@ns1.route('/my-resource')
|
||||
class MyResource(Resource):
|
||||
def get(self):
|
||||
# will log
|
||||
ns1.logger.info("hello from ns1")
|
||||
return {"message": "hello"}
|
||||
|
||||
|
||||
@ns2.route('/my-resource')
|
||||
class MyNewResource(Resource):
|
||||
def get(self):
|
||||
# won't log due to INFO log level from app.logger
|
||||
ns2.logger.debug("hello from ns2")
|
||||
return {"message": "hello"}
|
||||
|
||||
|
||||
Loggers can be configured individually to override the configuration from the Flask
|
||||
application object logger. In the above example, ``ns2`` log level can be set to
|
||||
``DEBUG`` individually:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# ns1 will have log level INFO from app.logger
|
||||
ns1 = api.namespace('api/v1', description='test')
|
||||
|
||||
# ns2 will have log level DEBUG
|
||||
ns2 = api.namespace('api/v2', description='test')
|
||||
ns2.logger.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
@ns1.route('/my-resource')
|
||||
class MyResource(Resource):
|
||||
def get(self):
|
||||
# will log
|
||||
ns1.logger.info("hello from ns1")
|
||||
return {"message": "hello"}
|
||||
|
||||
|
||||
@ns2.route('/my-resource')
|
||||
class MyNewResource(Resource):
|
||||
def get(self):
|
||||
# will log
|
||||
ns2.logger.debug("hello from ns2")
|
||||
return {"message": "hello"}
|
||||
|
||||
|
||||
Adding additional handlers:
|
||||
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# configure a file handler for ns1 only
|
||||
ns1 = api.namespace('api/v1')
|
||||
fh = logging.FileHandler("v1.log")
|
||||
ns1.logger.addHandler(fh)
|
||||
|
||||
ns2 = api.namespace('api/v2')
|
||||
|
||||
|
||||
@ns1.route('/my-resource')
|
||||
class MyResource(Resource):
|
||||
def get(self):
|
||||
# will log to *both* v1.log file and app.logger handlers
|
||||
ns1.logger.info("hello from ns1")
|
||||
return {"message": "hello"}
|
||||
|
||||
|
||||
@ns2.route('/my-resource')
|
||||
class MyNewResource(Resource):
|
||||
def get(self):
|
||||
# will log to *only* app.logger handlers
|
||||
ns2.logger.info("hello from ns2")
|
||||
return {"message": "hello"}
|