Skip to content

Commit

Permalink
make dist -> for release
Browse files Browse the repository at this point in the history
Add extras to make it releasable
  • Loading branch information
yitsushi committed Jan 1, 2019
1 parent f203375 commit 477fdc6
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -4,7 +4,8 @@ __pycache__
.coverage
pip-selfcheck.json
.Python
example_service.egg-info
*.egg-info
dist/
docs/build/
src
bin
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Expand Up @@ -5,7 +5,7 @@ PYTHON = $(BIN)/python

INSTALL = $(BIN)/pip install --no-deps

.PHONY: all test docs build_extras
.PHONY: all test docs build_extras dist build

all: build

Expand All @@ -26,4 +26,8 @@ test: build test_dependencies
$(BIN)/tox

run:
FLASK_APP=example_service bin/flask run
FLASK_APP=example_service bin/flask run

dist:
$(INSTALL) wheel
$(PYTHON) setup.py sdist bdist_wheel
4 changes: 3 additions & 1 deletion example_service/__init__.py
@@ -1 +1,3 @@
from example_service.app import app # NOQA
# from example_service.app import app # NOQA

__version__ = '0.1'
24 changes: 17 additions & 7 deletions example_service/app.py
Expand Up @@ -3,12 +3,22 @@
from konfig import Config
from example_service.endpoints import blueprints

settings = os.path.join(os.path.dirname(__file__), 'settings.ini')
settings = os.environ.get('FLASK_SETTINGS', settings)

app = Flask(__name__)
app.config_file = Config(settings)
app.config.update(app.config_file.get_map('flask'))
def create():
settings = os.path.join(os.path.dirname(__file__), 'settings.ini')
settings = os.environ.get('FLASK_SETTINGS', settings)

for blueprint in blueprints:
app.register_blueprint(blueprint['pkg'], url_prefix=blueprint['prefix'])
app = Flask(__name__)
app.config_file = Config(settings)
app.config.update(app.config_file.get_map('flask'))

for blueprint in blueprints:
app.register_blueprint(blueprint['pkg'],
url_prefix=blueprint['prefix'])

return app


if __name__ == '__main__':
app = create()
app.run()
39 changes: 39 additions & 0 deletions example_service/run.py
@@ -0,0 +1,39 @@
import argparse
import sys
import os
import signal
from .app import create


def _quit(signal, frame):
print('Shutting down!')
sys.exit(0)


def main(args=sys.argv[1:]):
parser = argparse.ArgumentParser(description='Service Example')
parser.add_argument('--config-file', help='Config file',
type=str, default=None)
args = parser.parse_args(args=args)

if args.config_file is not None:
os.environ.set('FLASK_SETTINGS', args.config_file)

app = create()

host = app.config.get('host', '0.0.0.0')
host = os.environ.get('HOST', host)

port = app.config.get('port', 5000)
port = os.environ.get('PORT', port)

debug = app.config.get('DEBUG', False)

signal.signal(signal.SIGINT, _quit)
signal.signal(signal.SIGTERM, _quit)

app.run(debug=debug, host=host, port=port)


if __name__ == "__main__":
main()
10 changes: 7 additions & 3 deletions setup.py
@@ -1,5 +1,5 @@
from setuptools import setup, find_packages

from example_service import __version__

def requirements():
with open('requirements.txt') as f:
Expand All @@ -8,8 +8,12 @@ def requirements():


setup(name='example_service',
version="0.1",
version=__version__,
packages=find_packages(),
zip_safe=False,
include_package_data=True,
install_requires=requirements())
install_requires=requirements(),
entry_points="""
[console_scripts]
example-service = example_service.run:main
""")
5 changes: 3 additions & 2 deletions tests/endpoints/test_main.py
@@ -1,10 +1,11 @@
import os
import unittest
from example_service import app
from example_service.app import create


class TestMain(unittest.TestCase):
def setUp(self):
app = create()
app.config['TESTING'] = True
app.config['WTF_CSRF_ENABLED'] = False
app.config['DEBUG'] = False
Expand All @@ -26,4 +27,4 @@ def test_index(self):


if __name__ == "__main__":
unittest.main()
unittest.main()

0 comments on commit 477fdc6

Please sign in to comment.