hosted-flasks 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ # Hosted Flasks
2
+
3
+ > serve flask apps side by side
4
+
5
+ [![Latest Version on PyPI](https://img.shields.io/pypi/v/hosted-flasks.svg)](https://pypi.python.org/pypi/hosted-flasks/)
6
+ [![Supported Implementations](https://img.shields.io/pypi/pyversions/hosted-flasks.svg)](https://pypi.python.org/pypi/hosted-flasks/)
7
+ ![Build Status](https://github.com/christophevg/hosted-flasks/actions/workflows/test.yaml/badge.svg)
8
+ [![Documentation Status](https://readthedocs.org/projects/hosted-flasks/badge/?version=latest)](https://hosted-flasks.readthedocs.io/en/latest/?badge=latest)
9
+ [![Coverage Status](https://coveralls.io/repos/github/christophevg/hosted-flasks/badge.svg?branch=master)](https://coveralls.io/github/christophevg/hosted-flasks?branch=master)
10
+ [![Built with PyPi Template](https://img.shields.io/badge/PyPi_Template-v0.5.0-blue.svg)](https://github.com/christophevg/pypi-template)
11
+
12
+
13
+
14
+ ## Documentation
15
+
16
+ Visit [Read the Docs](https://hosted-flasks.readthedocs.org) for the full documentation, including overviews and several examples.
17
+
18
+
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2024 Christophe VG
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ include .github/README.md
2
+ global-exclude __pycache__
3
+ global-exclude *.py[co]
@@ -0,0 +1,36 @@
1
+ Metadata-Version: 2.1
2
+ Name: hosted-flasks
3
+ Version: 0.0.1
4
+ Summary: serve flask apps side by side
5
+ Home-page: https://github.com/christophevg/hosted-flasks
6
+ Author: Christophe VG
7
+ License: MIT
8
+ Description: # Hosted Flasks
9
+
10
+ > serve flask apps side by side
11
+
12
+ [![Latest Version on PyPI](https://img.shields.io/pypi/v/hosted-flasks.svg)](https://pypi.python.org/pypi/hosted-flasks/)
13
+ [![Supported Implementations](https://img.shields.io/pypi/pyversions/hosted-flasks.svg)](https://pypi.python.org/pypi/hosted-flasks/)
14
+ ![Build Status](https://github.com/christophevg/hosted-flasks/actions/workflows/test.yaml/badge.svg)
15
+ [![Documentation Status](https://readthedocs.org/projects/hosted-flasks/badge/?version=latest)](https://hosted-flasks.readthedocs.io/en/latest/?badge=latest)
16
+ [![Coverage Status](https://coveralls.io/repos/github/christophevg/hosted-flasks/badge.svg?branch=master)](https://coveralls.io/github/christophevg/hosted-flasks?branch=master)
17
+ [![Built with PyPi Template](https://img.shields.io/badge/PyPi_Template-v0.5.0-blue.svg)](https://github.com/christophevg/pypi-template)
18
+
19
+
20
+
21
+ ## Documentation
22
+
23
+ Visit [Read the Docs](https://hosted-flasks.readthedocs.org) for the full documentation, including overviews and several examples.
24
+
25
+
26
+
27
+ Keywords: multiple flask apps
28
+ Platform: UNKNOWN
29
+ Classifier: Programming Language :: Python :: 3.8
30
+ Classifier: Programming Language :: Python :: 3.9
31
+ Classifier: Programming Language :: Python :: 3.10
32
+ Classifier: Programming Language :: Python :: 3.11
33
+ Classifier: Environment :: Web Environment
34
+ Classifier: Intended Audience :: Developers
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Description-Content-Type: text/markdown
File without changes
@@ -0,0 +1,36 @@
1
+ # Configuration file for the Sphinx documentation builder.
2
+ #
3
+ # For the full list of built-in configuration values, see the documentation:
4
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html
5
+
6
+ # -- Project information -----------------------------------------------------
7
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
8
+
9
+ project = u'Hosted Flasks'
10
+ copyright = u'2024-2024, Christophe VG'
11
+ author = u'Christophe VG'
12
+
13
+ # -- General configuration ---------------------------------------------------
14
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
15
+
16
+ extensions = ["myst_parser", "autodoc2"]
17
+
18
+ templates_path = ["_templates"]
19
+ exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
20
+
21
+ autodoc2_render_plugin = "myst"
22
+
23
+ autodoc2_packages = [
24
+ {
25
+ "path": "../hosted_flasks",
26
+ "exclude_dirs" : [ "templates" ],
27
+ "auto_mode": False
28
+ }
29
+ ]
30
+
31
+ # -- Options for HTML output -------------------------------------------------
32
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
33
+
34
+ html_theme = 'sphinx_rtd_theme'
35
+
36
+ html_static_path = ["_static"]
@@ -0,0 +1 @@
1
+ __version__ = "0.0.1"
@@ -0,0 +1,6 @@
1
+ import json
2
+
3
+ from hosted_flasks import scanner
4
+ from hosted_flasks import server
5
+
6
+ print(json.dumps(scanner.find_apps(server.APPS_FOLDER), indent=2, default=str))
@@ -0,0 +1,23 @@
1
+ import logging
2
+
3
+ import os
4
+
5
+ from pathlib import Path
6
+
7
+ from flask import Flask, render_template
8
+
9
+ logger = logging.getLogger(__name__)
10
+
11
+ TEMPLATE_FOLDER = os.environ.get(
12
+ "HOSTED_FLASKS_TEMPLATE_FOLDER",
13
+ Path(__file__).resolve().parent / "templates"
14
+ )
15
+ logger.info(f"using template_folder: {TEMPLATE_FOLDER}")
16
+
17
+ app = Flask("hosted-flasks", template_folder=TEMPLATE_FOLDER)
18
+
19
+ apps = {}
20
+
21
+ @app.route("/")
22
+ def show_frontpage():
23
+ return render_template("frontpage.html", apps=apps)
@@ -0,0 +1,15 @@
1
+ import logging
2
+
3
+ import os
4
+
5
+ # setup logging to stdout
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+ LOG_LEVEL = os.environ.get("LOG_LEVEL") or "INFO"
10
+ FORMAT = "[%(name)s] [%(levelname)s] %(message)s"
11
+ DATEFMT = "%Y-%m-%d %H:%M:%S %z"
12
+
13
+ logging.basicConfig(level=LOG_LEVEL, format=FORMAT, datefmt=DATEFMT)
14
+ formatter = logging.Formatter(FORMAT, DATEFMT)
15
+ logging.getLogger().handlers[0].setFormatter(formatter)
@@ -0,0 +1,31 @@
1
+ import logging
2
+
3
+ from pathlib import Path
4
+ import importlib.util
5
+ import sys
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+ def find_apps(apps_folder):
10
+ """
11
+ given a folder, finds all Flask apps and returns them as a dict with keys
12
+ path-name and value the flask app
13
+ """
14
+ logger.info(f"loading apps from: {apps_folder}")
15
+ apps = {}
16
+ for folder in Path(apps_folder).iterdir():
17
+ if folder.is_dir():
18
+ logger.info(f"loading {folder.name}")
19
+ try:
20
+ spec = importlib.util.spec_from_file_location(folder.name, folder / "__init__.py")
21
+ mod = importlib.util.module_from_spec(spec)
22
+ sys.modules[folder.name] = mod
23
+ spec.loader.exec_module(mod)
24
+ app = getattr(mod, "app")
25
+ app_name = str(folder.name)
26
+ apps[f"/{app_name}"] = app
27
+ except FileNotFoundError:
28
+ pass
29
+ except AttributeError:
30
+ logger.warning(f"'{folder.name}' doesn't provide 'app'")
31
+ return apps
@@ -0,0 +1,21 @@
1
+ import logging
2
+ import os
3
+
4
+ from werkzeug.middleware.dispatcher import DispatcherMiddleware
5
+
6
+ import hosted_flasks.log_setup #noqa
7
+
8
+ from hosted_flasks import scanner
9
+ from hosted_flasks import frontpage
10
+
11
+ logger = logging.getLogger(__name__)
12
+
13
+ # load modules/apps dynamically
14
+
15
+ APPS_FOLDER = os.environ.get("HOSTED_FLASKS_APPS_FOLDER", "apps")
16
+ apps = scanner.find_apps(APPS_FOLDER)
17
+ frontpage.apps = apps
18
+
19
+ # combine the apps with the frontpage
20
+
21
+ app = DispatcherMiddleware(frontpage.app, apps)
@@ -0,0 +1,36 @@
1
+ Metadata-Version: 2.1
2
+ Name: hosted-flasks
3
+ Version: 0.0.1
4
+ Summary: serve flask apps side by side
5
+ Home-page: https://github.com/christophevg/hosted-flasks
6
+ Author: Christophe VG
7
+ License: MIT
8
+ Description: # Hosted Flasks
9
+
10
+ > serve flask apps side by side
11
+
12
+ [![Latest Version on PyPI](https://img.shields.io/pypi/v/hosted-flasks.svg)](https://pypi.python.org/pypi/hosted-flasks/)
13
+ [![Supported Implementations](https://img.shields.io/pypi/pyversions/hosted-flasks.svg)](https://pypi.python.org/pypi/hosted-flasks/)
14
+ ![Build Status](https://github.com/christophevg/hosted-flasks/actions/workflows/test.yaml/badge.svg)
15
+ [![Documentation Status](https://readthedocs.org/projects/hosted-flasks/badge/?version=latest)](https://hosted-flasks.readthedocs.io/en/latest/?badge=latest)
16
+ [![Coverage Status](https://coveralls.io/repos/github/christophevg/hosted-flasks/badge.svg?branch=master)](https://coveralls.io/github/christophevg/hosted-flasks?branch=master)
17
+ [![Built with PyPi Template](https://img.shields.io/badge/PyPi_Template-v0.5.0-blue.svg)](https://github.com/christophevg/pypi-template)
18
+
19
+
20
+
21
+ ## Documentation
22
+
23
+ Visit [Read the Docs](https://hosted-flasks.readthedocs.org) for the full documentation, including overviews and several examples.
24
+
25
+
26
+
27
+ Keywords: multiple flask apps
28
+ Platform: UNKNOWN
29
+ Classifier: Programming Language :: Python :: 3.8
30
+ Classifier: Programming Language :: Python :: 3.9
31
+ Classifier: Programming Language :: Python :: 3.10
32
+ Classifier: Programming Language :: Python :: 3.11
33
+ Classifier: Environment :: Web Environment
34
+ Classifier: Intended Audience :: Developers
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Description-Content-Type: text/markdown
@@ -0,0 +1,19 @@
1
+ LICENSE.txt
2
+ MANIFEST.in
3
+ setup.py
4
+ .github/README.md
5
+ docs/__init__.py
6
+ docs/conf.py
7
+ hosted_flasks/__init__.py
8
+ hosted_flasks/__main__.py
9
+ hosted_flasks/frontpage.py
10
+ hosted_flasks/log_setup.py
11
+ hosted_flasks/scanner.py
12
+ hosted_flasks/server.py
13
+ hosted_flasks.egg-info/PKG-INFO
14
+ hosted_flasks.egg-info/SOURCES.txt
15
+ hosted_flasks.egg-info/dependency_links.txt
16
+ hosted_flasks.egg-info/requires.txt
17
+ hosted_flasks.egg-info/top_level.txt
18
+ tests/__init__.py
19
+ tests/test_example.py
@@ -0,0 +1,3 @@
1
+ docs
2
+ hosted_flasks
3
+ tests
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,64 @@
1
+ import os
2
+ import re
3
+ import setuptools
4
+
5
+ NAME = "hosted-flasks"
6
+ AUTHOR = "Christophe VG"
7
+ AUTHOR_EMAIL = "contact@christophe.vg"
8
+ DESCRIPTION = "serve flask apps side by side"
9
+ LICENSE = "MIT"
10
+ KEYWORDS = "multiple flask apps"
11
+ URL = "https://github.com/christophevg/" + NAME
12
+ README = ".github/README.md"
13
+ CLASSIFIERS = [
14
+ "Programming Language :: Python :: 3.8",
15
+ "Programming Language :: Python :: 3.9",
16
+ "Programming Language :: Python :: 3.10",
17
+ "Programming Language :: Python :: 3.11",
18
+ "Environment :: Web Environment",
19
+ "Intended Audience :: Developers",
20
+ "License :: OSI Approved :: MIT License",
21
+
22
+ ]
23
+ INSTALL_REQUIRES = [
24
+ "Flask",
25
+
26
+ ]
27
+ ENTRY_POINTS = {
28
+
29
+ }
30
+ SCRIPTS = [
31
+
32
+ ]
33
+
34
+ HERE = os.path.dirname(__file__)
35
+
36
+ def read(file):
37
+ with open(os.path.join(HERE, file), "r") as fh:
38
+ return fh.read()
39
+
40
+ VERSION = re.search(
41
+ r'__version__ = [\'"]([^\'"]*)[\'"]',
42
+ read(NAME.replace("-", "_") + "/__init__.py")
43
+ ).group(1)
44
+
45
+ LONG_DESCRIPTION = read(README)
46
+
47
+ if __name__ == "__main__":
48
+ setuptools.setup(
49
+ name=NAME,
50
+ version=VERSION,
51
+ packages=setuptools.find_packages(),
52
+ author=AUTHOR,
53
+ description=DESCRIPTION,
54
+ long_description=LONG_DESCRIPTION,
55
+ long_description_content_type="text/markdown",
56
+ license=LICENSE,
57
+ keywords=KEYWORDS,
58
+ url=URL,
59
+ classifiers=CLASSIFIERS,
60
+ install_requires=INSTALL_REQUIRES,
61
+ entry_points=ENTRY_POINTS,
62
+ scripts=SCRIPTS,
63
+ include_package_data=True
64
+ )
File without changes
@@ -0,0 +1,37 @@
1
+ from hosted_flasks.scanner import find_apps
2
+
3
+ def test_app_detection(tmp_path):
4
+ assert find_apps(tmp_path) == {}
5
+ # create 2 miminal apps
6
+ for app_name in [ "app_1", "app_2" ]:
7
+ folder = tmp_path / app_name
8
+ folder.mkdir()
9
+ init = folder / "__init__.py"
10
+ init.write_text("""
11
+ from flask import Flask
12
+
13
+ app = Flask(__name__)
14
+
15
+ @app.route("/")
16
+ def hello_world():
17
+ return "Hello World"
18
+ """)
19
+ apps = find_apps(tmp_path)
20
+ assert len(apps) == 2
21
+ assert list(apps.keys()) == [ "/app_1", "/app_2" ]
22
+
23
+ # add dummy folder / coverage of FileNotFound
24
+ dummy = tmp_path / "dummy"
25
+ dummy.mkdir()
26
+
27
+ apps = find_apps(tmp_path)
28
+ assert len(apps) == 2
29
+ assert list(apps.keys()) == [ "/app_1", "/app_2" ]
30
+
31
+ # add empty __init__.py / coverage of AttributeError
32
+ init = dummy / "__init__.py"
33
+ init.write_text("# nothing here")
34
+
35
+ apps = find_apps(tmp_path)
36
+ assert len(apps) == 2
37
+ assert list(apps.keys()) == [ "/app_1", "/app_2" ]