refactor code layout, move config to .env, add pyproject.toml
This commit is contained in:
parent
b874b989bf
commit
71f7bd1a3b
51 changed files with 64 additions and 41 deletions
7
.gitignore
vendored
7
.gitignore
vendored
|
|
@ -4,8 +4,8 @@ __pycache__/
|
||||||
uploads/
|
uploads/
|
||||||
*.pyc
|
*.pyc
|
||||||
**~
|
**~
|
||||||
**/.*.swp
|
.*.swp
|
||||||
**/__pycache__/
|
__pycache__/
|
||||||
venv
|
venv
|
||||||
.env
|
.env
|
||||||
.venv
|
.venv
|
||||||
|
|
@ -15,3 +15,6 @@ conf/
|
||||||
config/
|
config/
|
||||||
\#*\#
|
\#*\#
|
||||||
.\#*
|
.\#*
|
||||||
|
node_modules/
|
||||||
|
alembic.ini
|
||||||
|
**.egg-info
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## 0.9-dev
|
## 0.10.0
|
||||||
|
+ Codebase refactor (with breaking changes!)
|
||||||
|
+ Move ALL config to .env (config.py is NO MORE supported)
|
||||||
|
+ Config SITE_NAME replaced with APP_NAME
|
||||||
|
|
||||||
|
## 0.9.0
|
||||||
|
|
||||||
* Website redesign: added some material icons, implemented via a `inline_svg` function, injected by default in templates and defined in `utils.py`.
|
* Website redesign: added some material icons, implemented via a `inline_svg` function, injected by default in templates and defined in `utils.py`.
|
||||||
* Added positive feedback mechanism: now you can +1 a message. So, `score_message_add` and `score_message_remove` API endpoints were added, and `MessageUpvote` table was created.
|
* Added positive feedback mechanism: now you can +1 a message. So, `score_message_add` and `score_message_remove` API endpoints were added, and `MessageUpvote` table was created.
|
||||||
|
|
@ -26,7 +31,7 @@
|
||||||
* Changed default `robots.txt`, adding report and admin-related lines.
|
* Changed default `robots.txt`, adding report and admin-related lines.
|
||||||
* Released official [Android client](https://github.com/sakuragasaki46/coriplusapp/releases/tag/v0.8.0).
|
* Released official [Android client](https://github.com/sakuragasaki46/coriplusapp/releases/tag/v0.8.0).
|
||||||
|
|
||||||
## 0.7.1-dev
|
## 0.7.1
|
||||||
|
|
||||||
* Adding `messages_count`, `followers_count` and `following_count` to `profile_info` API endpoint (forgot to release).
|
* Adding `messages_count`, `followers_count` and `following_count` to `profile_info` API endpoint (forgot to release).
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
DEBUG = True
|
|
||||||
SECRET_KEY = 'hin6bab8ge25*r=x&+5$0kn=-#log$pt^#@vrqjld!^2ci@g*b'
|
|
||||||
SITE_NAME = 'Cori+'
|
|
||||||
21
pyproject.toml
Normal file
21
pyproject.toml
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
[project]
|
||||||
|
name = "sakuragasaki46_coriplus"
|
||||||
|
authors = [
|
||||||
|
{ name = "Sakuragasaki46" }
|
||||||
|
]
|
||||||
|
dynamic = ["version"]
|
||||||
|
dependencies = [
|
||||||
|
"Python-Dotenv>=1.0.0",
|
||||||
|
"Flask",
|
||||||
|
"Flask-Login",
|
||||||
|
"Peewee"
|
||||||
|
]
|
||||||
|
requires-python = ">=3.10"
|
||||||
|
classifiers = [
|
||||||
|
"Private :: X"
|
||||||
|
]
|
||||||
|
|
||||||
|
[tool.setuptools.dynamic]
|
||||||
|
version = { attr = "coriplus.__version__" }
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import sys
|
|
||||||
sys.path.insert(0, '../..')
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument('-p', '--port', type=int, default=5000,
|
|
||||||
help='An alternative port where to run the server.')
|
|
||||||
|
|
||||||
from app import app, create_tables
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
args = parser.parse_args()
|
|
||||||
create_tables()
|
|
||||||
app.run(port=args.port)
|
|
||||||
|
|
@ -16,24 +16,31 @@ For other, see `app.utils`.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from flask import (
|
from flask import (
|
||||||
Flask, abort, flash, g, jsonify, redirect, render_template, request,
|
Flask, g, jsonify, render_template, request,
|
||||||
send_from_directory, session, url_for, __version__ as flask_version)
|
send_from_directory, __version__ as flask_version)
|
||||||
import hashlib
|
import os, sys
|
||||||
import datetime, time, re, os, sys, string, json, html
|
|
||||||
from functools import wraps
|
|
||||||
from flask_login import LoginManager
|
from flask_login import LoginManager
|
||||||
|
import dotenv
|
||||||
|
import logging
|
||||||
|
|
||||||
__version__ = '0.9.0'
|
__version__ = '0.10.0-dev44'
|
||||||
|
|
||||||
# we want to support Python 3 only.
|
# we want to support Python 3.10+ only.
|
||||||
# Python 2 has too many caveats.
|
# Python 2 has too many caveats.
|
||||||
if sys.version_info[0] < 3:
|
# Python <=3.9 has harder type support.
|
||||||
raise RuntimeError('Python 3 required')
|
if sys.version_info[0:2] < (3, 10):
|
||||||
|
raise RuntimeError('Python 3.10+ required')
|
||||||
|
|
||||||
os.chdir(os.path.dirname(os.path.dirname(__file__)))
|
BASEDIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
|
||||||
|
os.chdir(BASEDIR)
|
||||||
|
|
||||||
|
dotenv.load_dotenv()
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.from_pyfile('../config.py')
|
app.secret_key = os.environ['SECRET_KEY']
|
||||||
|
|
||||||
login_manager = LoginManager(app)
|
login_manager = LoginManager(app)
|
||||||
|
|
||||||
|
|
@ -53,7 +60,7 @@ def before_request():
|
||||||
try:
|
try:
|
||||||
g.db.connect()
|
g.db.connect()
|
||||||
except OperationalError:
|
except OperationalError:
|
||||||
sys.stderr.write('database connected twice.\n')
|
logger.error('database connected twice.\n')
|
||||||
|
|
||||||
@app.after_request
|
@app.after_request
|
||||||
def after_request(response):
|
def after_request(response):
|
||||||
|
|
@ -63,7 +70,7 @@ def after_request(response):
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
def _inject_variables():
|
def _inject_variables():
|
||||||
return {
|
return {
|
||||||
'site_name': app.config['SITE_NAME'],
|
'site_name': os.environ.get('APP_NAME', 'Cori+'),
|
||||||
'locations': locations,
|
'locations': locations,
|
||||||
'inline_svg': inline_svg
|
'inline_svg': inline_svg
|
||||||
}
|
}
|
||||||
|
|
@ -78,11 +85,11 @@ def error_404(body):
|
||||||
|
|
||||||
@app.route('/favicon.ico')
|
@app.route('/favicon.ico')
|
||||||
def favicon_ico():
|
def favicon_ico():
|
||||||
return send_from_directory(os.getcwd(), 'favicon.ico')
|
return send_from_directory(BASEDIR, 'src/favicon.ico')
|
||||||
|
|
||||||
@app.route('/robots.txt')
|
@app.route('/robots.txt')
|
||||||
def robots_txt():
|
def robots_txt():
|
||||||
return send_from_directory(os.getcwd(), 'robots.txt')
|
return send_from_directory(BASEDIR, 'src/robots.txt')
|
||||||
|
|
||||||
@app.route('/uploads/<id>.<type>')
|
@app.route('/uploads/<id>.<type>')
|
||||||
def uploads(id, type='jpg'):
|
def uploads(id, type='jpg'):
|
||||||
|
|
@ -7,6 +7,9 @@ from .models import User, UserProfile, Message, Upload, Relationship, Notificati
|
||||||
MSGPRV_PUBLIC, MSGPRV_UNLISTED, MSGPRV_FRIENDS, MSGPRV_ONLYME, UPLOAD_DIRECTORY
|
MSGPRV_PUBLIC, MSGPRV_UNLISTED, MSGPRV_FRIENDS, MSGPRV_ONLYME, UPLOAD_DIRECTORY
|
||||||
from .utils import check_access_token, Visibility, push_notification, unpush_notification, \
|
from .utils import check_access_token, Visibility, push_notification, unpush_notification, \
|
||||||
create_mentions, is_username, generate_access_token, pwdhash
|
create_mentions, is_username, generate_access_token, pwdhash
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
bp = Blueprint('api', __name__, url_prefix='/api/V1')
|
bp = Blueprint('api', __name__, url_prefix='/api/V1')
|
||||||
|
|
||||||
|
|
@ -16,7 +19,7 @@ def get_message_info(message):
|
||||||
except IndexError:
|
except IndexError:
|
||||||
media = None
|
media = None
|
||||||
if media:
|
if media:
|
||||||
print(media)
|
logger.debug(media)
|
||||||
return {
|
return {
|
||||||
'id': message.id,
|
'id': message.id,
|
||||||
'user': {
|
'user': {
|
||||||
|
|
@ -122,7 +125,7 @@ def create2(self):
|
||||||
privacy=privacy)
|
privacy=privacy)
|
||||||
file = request.files.get('file')
|
file = request.files.get('file')
|
||||||
if file:
|
if file:
|
||||||
print('Uploading', file.filename)
|
logger.info('Uploading', file.filename)
|
||||||
ext = file.filename.split('.')[-1]
|
ext = file.filename.split('.')[-1]
|
||||||
upload = Upload.create(
|
upload = Upload.create(
|
||||||
type=ext,
|
type=ext,
|
||||||
|
|
@ -9,6 +9,9 @@ from sys import version as python_version
|
||||||
from flask import Blueprint, abort, flash, redirect, render_template, request, url_for, __version__ as flask_version
|
from flask import Blueprint, abort, flash, redirect, render_template, request, url_for, __version__ as flask_version
|
||||||
from flask_login import login_required, login_user, logout_user
|
from flask_login import login_required, login_user, logout_user
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
bp = Blueprint('website', __name__)
|
bp = Blueprint('website', __name__)
|
||||||
|
|
||||||
|
|
@ -181,7 +184,7 @@ def create():
|
||||||
privacy=privacy)
|
privacy=privacy)
|
||||||
file = request.files.get('file')
|
file = request.files.get('file')
|
||||||
if file:
|
if file:
|
||||||
print('Uploading', file.filename)
|
logger.info('Uploading', file.filename)
|
||||||
ext = file.filename.split('.')[-1]
|
ext = file.filename.split('.')[-1]
|
||||||
upload = Upload.create(
|
upload = Upload.create(
|
||||||
type=ext,
|
type=ext,
|
||||||
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Loading…
Add table
Add a link
Reference in a new issue