From 8f6ebb18e821f3b100a8ee12516754d8f16f1ec1 Mon Sep 17 00:00:00 2001 From: Joseph Weston <joseph.weston08@gmail.com> Date: Tue, 16 Jan 2018 14:35:28 +0100 Subject: [PATCH] set up packaging + webpack and rename 'server' to 'zesje' Rename required to get the package name correct --- .gitignore | 2 +- setup.py | 37 +++++++++++++++++++++++++++++++++++ webpack.config.js | 2 +- {server => zesje}/__init__.py | 5 ++++- {server => zesje}/__main__.py | 2 +- {server => zesje}/api.py | 0 {server => zesje}/db.py | 0 7 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 setup.py rename {server => zesje}/__init__.py (59%) rename {server => zesje}/__main__.py (75%) rename {server => zesje}/api.py (100%) rename {server => zesje}/db.py (100%) diff --git a/.gitignore b/.gitignore index 88b0b9f8f..486844185 100644 --- a/.gitignore +++ b/.gitignore @@ -64,7 +64,7 @@ yarn.lock .next # webpack output -dist/ +server/static/ # IPython temporary files .ipynb_checkpoints/ diff --git a/setup.py b/setup.py new file mode 100644 index 000000000..7b7f1b053 --- /dev/null +++ b/setup.py @@ -0,0 +1,37 @@ +from setuptools import setup, find_packages +from distutils.command.build import build +from setuptools.command.sdist import sdist + + +def webpack(): + import subprocess + subprocess.check_call(['npm', 'install']) + subprocess.check_call(['./node_modules/.bin/webpack']) + + +class Build(build): + def run(self): + webpack() + super().run() + + +class Sdist(sdist): + def run(self): + webpack() + super().run() + + +setup( + name="zesje", + version="0.1", + url="http://gitlab.kwant-project,org/zesje/zesje", + description="", + author="Zesje authors", + author_email="anton.akhmerov@tudelft.nl", + packages=find_packages('.'), + cmdclass={'build': Build, + 'sdist': Sdist, + }, + package_data={'zesje': ['static/*']}, + include_package_data=True, +) diff --git a/webpack.config.js b/webpack.config.js index c55990bb4..44f730044 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -13,7 +13,7 @@ const HtmlWebpackPluginConfig = new HtmlWebpackPlugin({ module.exports = { entry: './client/index.js', output: { - path: path.resolve('dist'), + path: path.resolve('zesje/static'), filename: 'index_bundle.js' }, module: { diff --git a/server/__init__.py b/zesje/__init__.py similarity index 59% rename from server/__init__.py rename to zesje/__init__.py index 9c85b604e..ee839b034 100644 --- a/server/__init__.py +++ b/zesje/__init__.py @@ -1,8 +1,11 @@ +from os import path +from os.path import abspath, dirname from flask import Flask from . import db, api -app = Flask('zesje', static_folder='dist') +app = Flask(__name__, + static_folder=path.join(abspath(dirname(__file__)), 'static')) db.use_db() app.register_blueprint(api.app, url_prefix='/api') diff --git a/server/__main__.py b/zesje/__main__.py similarity index 75% rename from server/__main__.py rename to zesje/__main__.py index f43d14dc8..232d4dc7d 100644 --- a/server/__main__.py +++ b/zesje/__main__.py @@ -2,5 +2,5 @@ import sys import os sys.path.append(os.getcwd()) -from server import app +from zesje import app app.run(debug=True) diff --git a/server/api.py b/zesje/api.py similarity index 100% rename from server/api.py rename to zesje/api.py diff --git a/server/db.py b/zesje/db.py similarity index 100% rename from server/db.py rename to zesje/db.py -- GitLab