This repository has been archived by the owner on Jan 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'multi_platform_imp_runserver' into dev
- Loading branch information
Showing
4 changed files
with
206 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,5 @@ venv/ | |
arborist-settings.json | ||
*.pyc | ||
dist/ | ||
*.egg-info/ | ||
*.egg* | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,31 @@ | ||
#!/usr/bin/env python | ||
from arborist import app | ||
import socket | ||
import argparse | ||
import webbrowser | ||
|
||
parser = argparse.ArgumentParser(description='Launch the Arborist') | ||
parser.add_argument('--debug', action="store_true", default=False, help="Run in debug mode") | ||
parser.add_argument('--port', type=int, | ||
help="Set port to try to listen to. By default the OS is asked what port to use.") | ||
args = parser.parse_args() | ||
|
||
app.run(debug=args.debug) | ||
|
||
def get_open_port(): | ||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
s.bind(('', 0)) | ||
s.listen(1) | ||
port = s.getsockname()[1] | ||
s.close() | ||
return port | ||
|
||
if not args.port: | ||
port = get_open_port() | ||
else: | ||
port = args.port | ||
|
||
if not args.debug: | ||
running_on = 'http://localhost:{}'.format(port) | ||
webbrowser.open(running_on, new=0, autoraise=True) | ||
|
||
app.run(debug=args.debug, port=port) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,141 @@ | ||
""" | ||
Setuptools and py2app/py2exe build script for transmart-arborist. | ||
To install dependencies for your machine: | ||
Usage: | ||
python setup.py install | ||
To build a packaged executable: | ||
Usage (Mac OS X): | ||
python setup.py py2app | ||
Usage (Windows): | ||
python setup.py py2exe | ||
""" | ||
|
||
import sys | ||
import os | ||
import glob | ||
from setuptools import setup, find_packages | ||
|
||
mainscript = 'runserver.py' | ||
extra_options = {} | ||
# Which directories to take all normal files from, these have to be specified explicitely. | ||
patterns = [ | ||
'static/*', | ||
'templates/*', | ||
'static/img/*', | ||
'static/img/message/*', | ||
'static/img/tree/*', | ||
'static/jstree/*', | ||
'static/jstree/dist/*', | ||
'static/jstree/dist/themes/*', | ||
'static/jstree/dist/themes/default/*', | ||
'static/jstree/dist/themes/default-dark/*', | ||
] | ||
|
||
|
||
def find_data_files(source, target, patterns): | ||
"""Locates the specified data-files and returns the matches | ||
in a data_files compatible format. | ||
source is the root of the source data tree. | ||
Use '' or '.' for current directory. | ||
target is the root of the target data tree. | ||
Use '' or '.' for the distribution directory. | ||
patterns is a sequence of glob-patterns for the | ||
files you want to copy. | ||
""" | ||
if glob.has_magic(source) or glob.has_magic(target): | ||
raise ValueError("Magic not allowed in src, target") | ||
ret = {} | ||
for pattern in patterns: | ||
pattern = os.path.join(source, pattern) | ||
for filename in glob.glob(pattern): | ||
if os.path.isfile(filename): | ||
targetpath = os.path.join(target, os.path.relpath(filename, source)) | ||
path = os.path.dirname(targetpath) | ||
ret.setdefault(path, []).append(filename) | ||
return sorted(ret.items()) | ||
|
||
|
||
def osx_app_build_options(): | ||
""" | ||
Collects additional requirements for building a MacOSX packaged executable. Only works on | ||
OS X and must have py2app manually installed. | ||
""" | ||
data_files = find_data_files(source=os.getcwd() + '/arborist', | ||
target='', | ||
patterns=patterns) | ||
py2app_options = {'argv_emulation': True, | ||
'packages': ['jinja2', | ||
'flask', | ||
'email', | ||
], | ||
'includes': ['os', | ||
'flask', | ||
'sys', | ||
], | ||
'excludes': ['mime'], | ||
} | ||
|
||
extra_options = dict(setup_requires=['py2app'], | ||
app=[mainscript], | ||
options={'py2app': py2app_options}, | ||
data_files=data_files, | ||
) | ||
return extra_options | ||
|
||
|
||
def win32_exe_build_options(): | ||
""" | ||
This collects additional requirements for building a Windows executable. | ||
only works when running from Windows and having manually | ||
installed the py2exe package. | ||
""" | ||
import py2exe | ||
data_files = find_data_files(source=os.getcwd() + r'/arborist', | ||
target='', | ||
patterns=patterns) | ||
py2exe_options = {'packages': ['werkzeug', | ||
'email.mime', | ||
'jinja2', | ||
], | ||
'includes': ['os', | ||
'flask', | ||
'sys', | ||
'jinja2.ext', | ||
], | ||
} | ||
|
||
extra_options = dict(setup_requires=['py2exe'], | ||
console=[mainscript], | ||
options={'py2exe': py2exe_options}, | ||
data_files=data_files, | ||
) | ||
return extra_options | ||
|
||
|
||
if sys.platform == 'darwin' and 'py2app' in sys.argv: | ||
extra_options = osx_app_build_options() | ||
|
||
|
||
elif sys.platform == 'win32' and 'py2exe' in sys.argv: | ||
extra_options = win32_exe_build_options() | ||
|
||
|
||
setup( | ||
name='tranSMART Arborist', | ||
version='1.3', | ||
description='Graphical tool to help you prepare your data for loading into the tranSMART data warehouse', | ||
url='https://github.com/thehyve/transmart-arborist', | ||
author='Ward Weistra', | ||
author='Ward Weistra and Jochem Bijlard', | ||
author_email='[email protected]', | ||
license='GNU General Public License V3', | ||
packages=find_packages(), | ||
include_package_data=True, | ||
zip_safe=False, | ||
install_requires=['Flask'], | ||
scripts=['runserver.py'] | ||
scripts=[mainscript], | ||
**extra_options | ||
) |