From 32c77deee18ace5bb26fb0cf4c86ed0446fcd142 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Thu, 16 Feb 2017 21:40:27 +0100 Subject: [PATCH] Some changes to the installation scripts These changes are necessary for the packaged version of the application (pip install wger). Among other things and (hopefully!) to make the installation more robust, all commands are routed through the 'wger' entry point, and calling 'invoke' on its own has been deprecated. Sadly, we had to revive an ugly hack that changes the sys path, but hopefully this doesn't cause any problems. --- .bowerrc | 4 -- README.rst | 8 ++-- docs/changelog.rst | 8 ++++ docs/commands.rst | 24 +++++----- docs/development.rst | 2 +- docs/production.rst | 2 +- extras/docker/apache/Dockerfile | 5 +- extras/docker/development-fedora/Dockerfile | 15 ++++-- extras/docker/development/Dockerfile | 16 +++++-- manage.py | 2 +- setup.py | 2 +- wger/.bowerrc | 4 ++ wger/__main__.py | 3 ++ package.json => wger/package.json | 0 tasks.py => wger/tasks.py | 52 ++++++++++++--------- 15 files changed, 92 insertions(+), 55 deletions(-) delete mode 100644 .bowerrc create mode 100644 wger/.bowerrc rename package.json => wger/package.json (100%) rename tasks.py => wger/tasks.py (91%) diff --git a/.bowerrc b/.bowerrc deleted file mode 100644 index e798057df..000000000 --- a/.bowerrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "directory" : "wger/core/static/bower_components", - "interactive": false -} diff --git a/README.rst b/README.rst index 7c7f286fd..e0efc9bfc 100644 --- a/README.rst +++ b/README.rst @@ -69,7 +69,7 @@ Then install the python packages from pypi in the virtualenv:: $ invoke create_settings \ --settings-path /home/wger/wger/settings.py \ --database-path /home/wger/wger/database.sqlite - $ invoke bootstrap_wger \ + $ invoke bootstrap \ --settings-path /home/wger/wger/settings.py \ --no-start-server $ python manage.py runserver @@ -130,7 +130,7 @@ Stable version (from PyPI) :: - $ wger bootstrap_wger + $ wger bootstrap 3) Log in as: **admin**, password **admin** @@ -144,13 +144,13 @@ The available options for the ``wger`` command (if installed from PyPI) or ``:: - bootstrap_wger Performs all steps necessary to bootstrap the application + bootstrap Performs all steps necessary to bootstrap the application config_location Returns the default location for the settings file and the data folder create_or_reset_admin Creates an admin user or resets the password for an existing one create_settings Creates a local settings file load_fixtures Loads all fixtures migrate_db Run all database migrations - start_wger Start the application using django's built in webserver + start Start the application using django's built in webserver Contact ======= diff --git a/docs/changelog.rst b/docs/changelog.rst index 9477f7699..a5e6e0877 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -5,6 +5,14 @@ Changelog -------------------- **2016-XX-XX** +.. warning :: + There have been some changes to the installation procedure. Calling 'invoke' + on its own has been deprecated, you should use the 'wger' command (which + accepts the same options). Also some of these commands have been renamed: + + * ``start_wger`` to ``wger`` + * ``bootstrap_wger`` ``bootstrap`` + Upgrade steps from 1.7: * Django update to 1.9: ``pip install -r requirements.txt`` diff --git a/docs/commands.rst b/docs/commands.rst index 2f0958dae..bda86bb25 100644 --- a/docs/commands.rst +++ b/docs/commands.rst @@ -24,17 +24,17 @@ in this manual. You can get a list of all available commands with ``invoke --list`` or ``wger``. While you can do this from any folder in the application, some of them (e.g. -``start_wger``) might only work from the root folder:: +``start``) might only work from the root folder:: Available tasks: - bootstrap_wger Performs all steps necessary to bootstrap the application + bootstrap Performs all steps necessary to bootstrap the application config_location Returns the default location for the settings file and the data folder create_or_reset_admin Creates an admin user or resets the password for an existing one create_settings Creates a local settings file load_fixtures Loads all fixtures migrate_db Run all database migrations - start_wger Start the application using django's built in webserver + start Start the application using django's built in webserver You can also get help on a specific command with ``invoke --help ``. @@ -43,21 +43,21 @@ You can also get help on a specific command with ``invoke --help ``. settings file to use for the operation. If you use it, it is recommended to use absolute paths, for example:: - invoke bootstrap_wger --settings-path /path/to/development/wger/settings-test.py + invoke bootstrap --settings-path /path/to/development/wger/settings-test.py -Bootstrap wger -~~~~~~~~~~~~~~ +Bootstrap +~~~~~~~~~ -Command: **bootstrap_wger** +Command: **bootstrap** This command bootstraps the application: it creates a settings file, initialises a sqlite database, loads all necessary fixtures for the application to work and creates a default administrator user. While it can also work with e.g. a postgreSQL database, you will need to create it yourself:: - invoke bootstrap_wger + invoke bootstrap The most usual use-case is creating the settings file and the sqlite database to their default locations, but you can set your own paths if you want e.g. start @@ -65,7 +65,7 @@ developing on a branch that is going to change the database schema. Usage:: - Usage: inv[oke] [--core-opts] bootstrap_wger [--options] [other tasks here ...] + Usage: inv[oke] [--core-opts] bootstrap [--options] [other tasks here ...] Docstring: Performs all steps necessary to bootstrap the application @@ -81,11 +81,11 @@ Usage:: Start wger ~~~~~~~~~~ -Command: **start_wger** +Command: **start** Starts an already installed application:: - invoke start_wger + invoke start Please note that this is simply a comfort function and does not use any *magic*, it simply calls django's development server and (optionally) opens a browser @@ -94,7 +94,7 @@ is probably better. Usage:: - Usage: inv[oke] [--core-opts] start_wger [--options] [other tasks here ...] + Usage: inv[oke] [--core-opts] start [--options] [other tasks here ...] Docstring: Start the application using django's built in webserver diff --git a/docs/development.rst b/docs/development.rst index d90672964..1c37ad27b 100644 --- a/docs/development.rst +++ b/docs/development.rst @@ -48,7 +48,7 @@ To install the server:: $ invoke create_settings \ --settings-path /home/wger/wger/settings.py \ --database-path /home/wger/wger/database.sqlite - $ invoke bootstrap_wger \ + $ invoke bootstrap \ --settings-path /home/wger/wger/settings.py \ --no-start-server diff --git a/docs/production.rst b/docs/production.rst index 49c791f8c..6859526de 100644 --- a/docs/production.rst +++ b/docs/production.rst @@ -126,7 +126,7 @@ for the engine). Also set ``MEDIA_ROOT`` to ``/home/wger/media`` and Run the installation script, this will download some CSS and JS libraries and load all initial data:: - invoke bootstrap_wger --settings-path /path/to/settings.py --no-start-server + invoke bootstrap --settings-path /path/to/settings.py --no-start-server Collect all static resources:: diff --git a/extras/docker/apache/Dockerfile b/extras/docker/apache/Dockerfile index 2321e2ca2..c9254ab4a 100644 --- a/extras/docker/apache/Dockerfile +++ b/extras/docker/apache/Dockerfile @@ -29,10 +29,11 @@ RUN virtualenv --python python3 /home/wger/venv RUN . /home/wger/venv/bin/activate \ && pip install --upgrade pip \ && pip install -r requirements.txt \ - && invoke create_settings \ + && python setup.py develop \ + && wger create_settings \ --settings-path /home/wger/src/settings.py \ --database-path /home/wger/db/database.sqlite \ - && invoke bootstrap_wger \ + && wger bootstrap \ --settings-path /home/wger/src/settings.py \ --no-start-server diff --git a/extras/docker/development-fedora/Dockerfile b/extras/docker/development-fedora/Dockerfile index 6902a15ca..ce8e4bae7 100644 --- a/extras/docker/development-fedora/Dockerfile +++ b/extras/docker/development-fedora/Dockerfile @@ -17,6 +17,12 @@ RUN dnf update;\ nodejs npm libjpeg-turbo-devel zlib-devel git \ tmux sudo redhat-rpm-config gcc python-imaging +# Set locale to UTF8, otherwise problems with the encoding can occur +RUN locale-gen en_US.UTF-8 +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 + # Add wger user RUN adduser wger RUN echo "wger ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/wger @@ -32,10 +38,11 @@ RUN virtualenv --python python3 /home/wger/venv RUN . /home/wger/venv/bin/activate \ && pip install --upgrade pip \ && pip install -r requirements_devel.txt \ - && invoke create_settings \ + && python setup.py develop \ + && wger create_settings \ --settings-path /home/wger/src/settings.py \ --database-path /home/wger/db/database.sqlite \ - && invoke bootstrap_wger \ + && wger bootstrap \ --settings-path /home/wger/src/settings.py \ --no-start-server @@ -45,9 +52,11 @@ RUN . /home/wger/venv/bin/activate \ # to delete the node_modules folder and install everything again # -> https://github.com/npm/npm/issues/9863 # -> https://github.com/npm/npm/issues/13306 -RUN rm -r node_modules \ +RUN cd wger \ + && rm -r node_modules \ && npm install bower \ && npm install \ + && cd .. \ && mkdir ~/media \ && sed -i "/^MEDIA_ROOT/c\MEDIA_ROOT='\/home\/wger\/media'" settings.py \ && . /home/wger/venv/bin/activate \ diff --git a/extras/docker/development/Dockerfile b/extras/docker/development/Dockerfile index 73a83300c..46ea2406f 100644 --- a/extras/docker/development/Dockerfile +++ b/extras/docker/development/Dockerfile @@ -15,6 +15,13 @@ FROM wger/base MAINTAINER Roland Geider EXPOSE 8000 +# Set locale to UTF8, otherwise problems with the encoding can occur +RUN locale-gen en_US.UTF-8 +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 + + # Install dependencies RUN apt-get install -y vim tmux sqlite3 @@ -27,10 +34,11 @@ RUN virtualenv --python python3 /home/wger/venv RUN . /home/wger/venv/bin/activate \ && pip install --upgrade pip \ && pip install -r requirements_devel.txt \ - && invoke create_settings \ + && python setup.py develop \ + && wger create_settings \ --settings-path /home/wger/src/settings.py \ --database-path /home/wger/db/database.sqlite \ - && invoke bootstrap_wger \ + && wger bootstrap \ --settings-path /home/wger/src/settings.py \ --no-start-server @@ -40,9 +48,11 @@ RUN . /home/wger/venv/bin/activate \ # to delete the node_modules folder and install everything again # -> https://github.com/npm/npm/issues/9863 # -> https://github.com/npm/npm/issues/13306 -RUN rm -r node_modules \ +RUN cd wger \ + && rm -r node_modules \ && npm install bower \ && npm install \ + && cd .. \ && mkdir ~/media \ && sed -i "/^MEDIA_ROOT/c\MEDIA_ROOT='\/home\/wger\/media'" settings.py \ && . /home/wger/venv/bin/activate \ diff --git a/manage.py b/manage.py index 2f6e4057b..d5c1c05be 100644 --- a/manage.py +++ b/manage.py @@ -3,7 +3,7 @@ import sys from django.core.management import execute_from_command_line -from tasks import ( +from wger.tasks import ( setup_django_environment, get_user_config_path ) diff --git a/setup.py b/setup.py index 1c10d52a7..0c95f7884 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ from setuptools import ( from wger import get_version -with open('README.rst') as readme: +with open('README.rst', encoding='utf-8') as readme: long_description = readme.read() with open('requirements.txt') as requirements_production: diff --git a/wger/.bowerrc b/wger/.bowerrc new file mode 100644 index 000000000..6b111d1bc --- /dev/null +++ b/wger/.bowerrc @@ -0,0 +1,4 @@ +{ + "directory" : "core/static/bower_components", + "interactive": false +} diff --git a/wger/__main__.py b/wger/__main__.py index 63620b38e..1b36fcb76 100644 --- a/wger/__main__.py +++ b/wger/__main__.py @@ -28,6 +28,9 @@ invoke_cmd = 'invoke ' def main(): + # Change the working directory so that invoke can find the tasks fiel + os.chdir(os.path.dirname(os.path.abspath(__file__))) + args = sys.argv[1:] if len(args): run(invoke_cmd + ' '.join(args), pty=True) diff --git a/package.json b/wger/package.json similarity index 100% rename from package.json rename to wger/package.json diff --git a/tasks.py b/wger/tasks.py similarity index 91% rename from tasks.py rename to wger/tasks.py index a96f064d3..b2a37f7a6 100644 --- a/tasks.py +++ b/wger/tasks.py @@ -16,6 +16,17 @@ import sys + +# +# This is an ugly and terrible hack, please don't do this! +# +# The reason we do this is that during django's setup later in this script, it +# tries to load the standard library's "mail" module which collides with our +# (perhaps unluckily named) app with the same name. Since this script is only +# used for installation and does not depend on anything from wger proper, it +# is kind of OK to change the system path. +sys.path = sys.path[1:] + import time import logging import threading @@ -40,7 +51,7 @@ logger = logging.getLogger(__name__) 'browser': 'Whether to open the application in a browser window. Default: false', 'settings-path': 'Path to settings file (absolute path recommended). Leave empty for default', 'extra-args': 'Additional arguments to pass to the builtin server. Pass as string: "--arg1 --arg2=value". Default: none'}) -def start_wger(context, address='localhost', port=8000, browser=False, settings_path=None, extra_args=''): +def start(context, address='localhost', port=8000, browser=False, settings_path=None, extra_args=''): ''' Start the application using django's built in webserver ''' @@ -64,13 +75,13 @@ def start_wger(context, address='localhost', port=8000, browser=False, settings_ 'port': 'Port to use. Default: 8000', 'browser': 'Whether to open the application in a browser window. Default: false', 'start-server': 'Whether to start the development server. Default: true'}) -def bootstrap_wger(context, - settings_path=None, - database_path=None, - address='localhost', - port=8000, - browser=False, - start_server=True): +def bootstrap(context, + settings_path=None, + database_path=None, + address='localhost', + port=8000, + browser=False, + start_server=True): ''' Performs all steps necessary to bootstrap the application ''' @@ -99,15 +110,14 @@ def bootstrap_wger(context, create_or_reset_admin(context, settings_path=settings_path) # Download JS libraries with bower - os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'wger')) - context.run('npm install bower') os.chdir(os.path.dirname(os.path.abspath(__file__))) + context.run('npm install bower') call_command('bower', 'install') # Start the webserver if start_server: print('*** Bootstraping complete, starting application') - start_wger(address=address, port=port, browser=browser, settings_path=settings_path) + start(context, address=address, port=port, browser=browser, settings_path=settings_path) @task(help={'settings-path': 'Path to settings file (absolute path recommended). Leave empty for default', @@ -135,7 +145,7 @@ def create_settings(context, settings_path=None, database_path=None, url=None, d url = 'http://localhost:8000' # Fill in the config file template - settings_template = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'wger', 'settings.tpl') + settings_template = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'settings.tpl') with open(settings_template, 'r') as settings_file: settings_content = settings_file.read() @@ -198,11 +208,9 @@ def create_or_reset_admin(context, settings_path=None): except User.DoesNotExist: print("*** Created default admin user") - # os.chdir(os.path.dirname(inspect.stack()[0][1])) - # current_dir = os.path.join(os.getcwd(), 'wger') current_dir = os.path.dirname(os.path.abspath(__file__)) + path = os.path.join(current_dir, 'core', 'fixtures/') - path = os.path.join(current_dir, 'wger', 'core', 'fixtures/') call_command("loaddata", path + "users.json") @@ -228,16 +236,14 @@ def load_fixtures(context, settings_path=None): setup_django_environment(settings_path) - # os.chdir(os.path.dirname(inspect.stack()[0][1])) - # current_dir = os.path.join(os.getcwd(), 'wger') current_dir = os.path.dirname(os.path.abspath(__file__)) # Gym - path = os.path.join(current_dir, 'wger', 'gym', 'fixtures/') + path = os.path.join(current_dir, 'gym', 'fixtures/') call_command("loaddata", path + "gym.json") # Core - path = os.path.join(current_dir, 'wger', 'core', 'fixtures/') + path = os.path.join(current_dir, 'core', 'fixtures/') call_command("loaddata", path + "languages.json") call_command("loaddata", path + "groups.json") call_command("loaddata", path + "users.json") @@ -247,7 +253,7 @@ def load_fixtures(context, settings_path=None): call_command("loaddata", path + "setting_weight_units.json") # Config - path = os.path.join(current_dir, 'wger', 'config', 'fixtures/') + path = os.path.join(current_dir, 'config', 'fixtures/') call_command("loaddata", path + "language_config.json") call_command("loaddata", path + "gym_config.json") @@ -255,20 +261,20 @@ def load_fixtures(context, settings_path=None): # path = os.path.join(current_dir, 'manager', 'fixtures/') # Exercises - path = os.path.join(current_dir, 'wger', 'exercises', 'fixtures/') + path = os.path.join(current_dir, 'exercises', 'fixtures/') call_command("loaddata", path + "equipment.json") call_command("loaddata", path + "muscles.json") call_command("loaddata", path + "categories.json") call_command("loaddata", path + "exercises.json") # Nutrition - path = os.path.join(current_dir, 'wger', 'nutrition', 'fixtures/') + path = os.path.join(current_dir, 'nutrition', 'fixtures/') call_command("loaddata", path + "ingredients.json") call_command("loaddata", path + "weight_units.json") call_command("loaddata", path + "ingredient_units.json") # Gym - path = os.path.join(current_dir, 'wger', 'gym', 'fixtures/') + path = os.path.join(current_dir, 'gym', 'fixtures/') call_command("loaddata", path + "gym.json") call_command("loaddata", path + "gym-config.json") call_command("loaddata", path + "gym-adminconfig.json")