==> ./contents <== ==> ./setup.cfg <== # flake8 doesn't support pyproject.toml yet: # https://github.com/PyCQA/flake8/issues/234 [flake8] exclude = setup.py,venv,build,dist max-line-length = 88 ==> ./.gitignore <== # Python __pycache__/ # Files created by this set up: venv/ build/ dist/ *.egg-info/ .pytest_cache/ .mypy_cache/ ==> ./Makefile <== all: run clean: rm -rf venv build dist .pytest_cache .mypy_cache *.egg-info venv: python3 -m venv venv && \ venv/bin/pip install --upgrade pip setuptools && \ venv/bin/pip install --editable ".[dev]" run: venv venv/bin/flask --app scipaperloader --debug run format: venv venv/bin/black . && venv/bin/isort . format-check: venv venv/bin/black --check . && venv/bin/isort --check . lint: venv venv/bin/flake8 . mypy: venv venv/bin/mypy test: venv venv/bin/pytest dist: venv format-check lint mypy test venv/bin/pip wheel --wheel-dir dist --no-deps . ==> ./pyproject.toml <== [build-system] requires = ["setuptools"] build-backend = "setuptools.build_meta" [project] name = "scipaperloader" version = "1.0.0" requires-python = ">=3.8.1,<4" dependencies = [ "Flask>=3.0.2,<4", ] [project.optional-dependencies] dev = [ "pytest>=8,<9", "flake8>=7,<8", "black>=24.2.0,<25", "isort>=5.13.1,<6", "mypy>=1.8.0,<2", ] [tool.setuptools.package-data] "*" = ["**/static/**/*", "**/templates/**/*"] [tool.pytest.ini_options] testpaths = ["tests"] [tool.black] line-length = 88 [tool.isort] profile = "black" [tool.mypy] ignore_missing_imports = true files = "scipaperloader,tests" ==> ./tests/test_scipaperloader.py <== import pytest from scipaperloader import create_app @pytest.fixture def app(): app = create_app({"TESTING": True}) # set up here yield app # tear down here @pytest.fixture def client(app): return app.test_client() def test_index(client): response = client.get("/") assert b"It works!" in response.data ==> ./scipaperloader/templates/index.html <== SciPaperLoader

It works!

Next steps

The development environment is now set up and you can start coding! Check out the README.md for the development environment usage.

If you are new to Flask, both Quickstart and Tutorial are great resources to get up and running quickly.

Check out Flask documentation for more patterns such as using SQL DB or Mongo DB, making a single-page application and many more features.

When you are ready to deploy, you may want to consider these:

==> ./scipaperloader/__pycache__/views.cpython-313.pyc <== zghSSKJr SSKJr SSKJr \"S\5r\RS5S5rg)) Blueprint) current_app)render_templateroot/cV[RRS5 [S5$)Nzsample messagez index.html)apploggerwarningr5/home/michaelb/scipaperloader/scipaperloader/views.pyindexrs JJ'( < ((r N) flaskrrr r__name__bprouterr r rrs6$!vx #))r ==> ./scipaperloader/__pycache__/logging.cpython-313.pyc <== zg SSKrSSKrSrSrg)Ncn[R"SS5R5nUS:H=(d US:H$)N FLASK_DEBUGtrue1)osgetenvlower)flags 7/home/michaelb/scipaperloader/scipaperloader/logging.py _is_debugr s. 99]B ' - - /D 6> (TS[(c Sn[RRSSSU00SSSSS.0[5(aS OS S/S .S S .5 g)Nz6[%(asctime)s] %(levelname)s in %(module)s: %(message)sdefaultformatwsgizlogging.StreamHandlerzext://sys.stdout)classstream formatterDEBUGINFO)levelhandlersF)version formattersrrootdisable_existing_loggers)loggingconfig dictConfigr )msg_fmts r init_loggingr# sgFG NNg 40!*%.KKV#H).% r)logging.configrrr r#rr r&s ) r ==> ./scipaperloader/__pycache__/__init__.cpython-313.pyc <== zg:SSKrSSKJr SSKJr SSKJr SSjrg)N)Flask)views) init_loggingc[5 [[5nURR S5 URR 5 UbURR U5 UR[R5 U$)Nzscipaperloader.defaults) rr__name__config from_objectfrom_prefixed_env from_mappingregister_blueprintrbp)config_overridesapps 8/home/michaelb/scipaperloader/scipaperloader/__init__.py create_appr scN /CJJ45JJ  "#  01588$ J)N) logging.configloggingflaskrscipaperloaderrscipaperloader.loggingrrrrrs / r ==> ./scipaperloader/__pycache__/defaults.cpython-313.pyc <== zgLSrg)FN)DEBUG8/home/michaelb/scipaperloader/scipaperloader/defaults.pyrs  r ==> ./scipaperloader/defaults.py <== DEBUG = False # make sure DEBUG is off unless enabled explicitly otherwise ==> ./scipaperloader/__init__.py <== import logging.config from flask import Flask from scipaperloader import views from scipaperloader.logging import init_logging def create_app(config_overrides=None): init_logging() # should be configured before any access to app.logger app = Flask(__name__) app.config.from_object("scipaperloader.defaults") app.config.from_prefixed_env() if config_overrides is not None: app.config.from_mapping(config_overrides) app.register_blueprint(views.bp) return app ==> ./scipaperloader/views.py <== from flask import Blueprint from flask import current_app as app from flask import render_template bp = Blueprint("root", __name__) @bp.route("/") def index(): app.logger.warning("sample message") return render_template("index.html") ==> ./scipaperloader/logging.py <== import logging.config import os # Since logging is initialized before the application, can't use # app.debug here, relying on FLASK_DEBUG env var only. def _is_debug(): flag = os.getenv("FLASK_DEBUG", "").lower() return flag == "true" or flag == "1" def init_logging(): msg_fmt = "[%(asctime)s] %(levelname)s in %(module)s: %(message)s" logging.config.dictConfig( { "version": 1, "formatters": { "default": { "format": msg_fmt, } }, "handlers": { "wsgi": { "class": "logging.StreamHandler", "stream": "ext://sys.stdout", "formatter": "default", } }, "root": { "level": "DEBUG" if _is_debug() else "INFO", "handlers": ["wsgi"], }, "disable_existing_loggers": False, } ) ==> ./scipaperloader/static/styles.css <== .message { padding: 10px; font-size: 1.3em; font-family: Arial, sans-serif; } ==> ./setup.py <== # This project uses pyproject.toml for all configuration. # This file is for compatibility only. # See https://setuptools.pypa.io/en/latest/userguide/quickstart.html#development-mode from setuptools import setup setup() ==> ./README.md <== # SciPaperLoader SciPaperLoader description ## Quick Start Run the application: make run And open it in the browser at [http://localhost:5000/](http://localhost:5000/) ## Prerequisites Python >=3.8 ## Development environment - `make venv`: creates a virtualenv with dependencies and this application installed in [development mode](http://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode) - `make run`: runs a development server in debug mode (changes in source code are reloaded automatically) - `make format`: reformats code - `make lint`: runs flake8 - `make mypy`: runs type checks by mypy - `make test`: runs tests (see also: [Testing Flask Applications](https://flask.palletsprojects.com/en/3.0.x/testing/)) - `make dist`: creates a wheel distribution (will run tests first) - `make clean`: removes virtualenv and build artifacts - add application dependencies in `pyproject.toml` under `project.dependencies`; add development dependencies under `project.optional-dependencies.*`; run `make clean && make venv` to reinstall the environment ## Configuration Default configuration is loaded from `scipaperloader.defaults` and can be overriden by environment variables with a `FLASK_` prefix. See [Configuring from Environment Variables](https://flask.palletsprojects.com/en/3.0.x/config/#configuring-from-environment-variables). Consider using [dotenv](https://flask.palletsprojects.com/en/3.0.x/cli/#environment-variables-from-dotenv). ## Deployment See [Deploying to Production](https://flask.palletsprojects.com/en/3.0.x/deploying/). You may use the distribution (`make dist`) to publish it to a package index, deliver to your server, or copy in your `Dockerfile`, and insall it with `pip`. You must set a [SECRET_KEY](https://flask.palletsprojects.com/en/3.0.x/tutorial/deploy/#configure-the-secret-key) in production to a secret and stable value.