Giter Club home page Giter Club logo

django-gulp's Introduction

django-gulp

django-gulp overrides ./manage.py runserver and ./manage.py collectstatic so that they also run your gulp tasks.

I've used this in conjunction with watchify and livereload in gulp, so that my simple unadorned runserver automatically watches and compiles new JavaScript files with browserify and live reloads new CSS that's been automatically compiled from SASS.

Installation

Add "django_gulp" to your INSTALLED_APPS setting like this, making sure that it comes before django.contrib.staticfiles (or other apps that override runserver or collectstatic in the list if they're listed):

INSTALLED_APPS = (
    'django_gulp',
    ...
)

Now when you run ./manage.py runserver or ./manage.py collectstatic your gulp tasks will run as well!

Settings

GULP_CWD defaults to the current working directory. Override it if your gulpfile.js does not reside within the Django project's toplevel directory.

GULP_PRODUCTION_COMMAND defaults to gulp build --production. GULP_DEVELOP_COMMAND defaults to gulp. Note that when specifying this setting manually, GULP_CWD is ignored.

Heroku

django-gulp works on Heroku! You'll just need to use buildpack-multi and make sure your .buildpacks file looks like this:

https://github.com/heroku/heroku-buildpack-nodejs.git
https://github.com/heroku/heroku-buildpack-python.git

To use buildback-multi set your configuration like so:

$ heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-multi.git

Example output

$ ./manage.py runserver
>>> Starting gulp
>>> gulp process on pid 47863
Performing system checks...

System check identified no issues.
May 04, 2015 - 18:27:52
Django version 1.8.1, using settings 'example.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[18:27:53] Using gulpfile ~/p/example/gulpfile.js
[18:27:53] Starting 'bower-install'...
[18:27:54] Using cwd:  /Users/beau/p/example
[18:27:54] Using bower dir:  static/vendor
[18:27:54] Starting 'sass'...
[18:27:54] Starting 'watch'...
[18:27:54] Finished 'watch' after 19 ms
[18:27:54] Starting 'watchify'...
[18:28:08] Watching files required by bundle-about.js
[18:28:08] Bundling bundle-about.js...
[18:28:08] Watching files required by bundle-accounts-login.js
[18:28:08] Bundling bundle-accounts-login.js...
[18:28:08] Watching files required by bundle-accounts-signup.js
[18:28:08] Bundling bundle-accounts-signup.js...
[18:28:08] Watching files required by bundle-activities.js
[18:28:08] Bundling bundle-activities.js...
[18:28:08] Finished 'watchify' after 14 s
[18:28:09] Finished 'sass' after 15 s
^C>>> Closing gulp process
$ ./manage.py collectstatic
[18:32:54] Using gulpfile ~/p/example/gulpfile.js
[18:32:54] Starting 'bower-install'...
[18:32:55] Using cwd:  /Users/beau/p/example
[18:32:55] Using bower dir:  static/vendor
[18:32:55] Starting 'sass'...
[18:32:56] Starting 'browserify'...
[18:33:05] Bundling bundle-about.js...
[18:33:05] Bundling bundle-accounts-login.js...
[18:33:05] Bundling bundle-accounts-signup.js...
[18:33:05] Bundling bundle-activities.js...
[18:33:05] Finished 'browserify' after 9.39 s
[18:33:08] Finished 'sass' after 13 s
[18:33:14] Finished 'bower-install' after 19 s
[18:33:14] Starting 'bower-main-files'...
[18:33:14] Starting 'bower-detritus'...
[18:33:14] Finished 'bower-main-files' after 104 ms
[18:33:14] Finished 'bower-detritus' after 507 ms
[18:33:14] Starting 'bower'...
[18:33:14] Finished 'bower' after 18 ฮผs
[18:33:14] Starting 'build'...
[18:33:14] Finished 'build' after 5 ฮผs

You have requested to collect static files at the destination
location as specified in your settings:

    /Users/beau/p/example/static-files

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes
Copying '/Users/beau/p/example/build/js/bundle-about.js'
Copying '/Users/beau/p/example/build/js/bundle-about.map.json'
Copying '/Users/beau/p/example/build/js/bundle-accounts-login.js'
Copying '/Users/beau/p/example/build/js/bundle-accounts-login.map.json'
Copying '/Users/beau/p/example/build/js/bundle-accounts-signup.js'
Copying '/Users/beau/p/example/build/js/bundle-accounts-signup.map.json'
Copying '/Users/beau/p/example/build/js/bundle-activities.js'
Copying '/Users/beau/p/example/build/js/bundle-activities.map.json'

django-gulp's People

Contributors

beaugunderson avatar czlee avatar danpalmer avatar gegenschall avatar joshblum avatar theunraveler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-gulp's Issues

Can't get app to load

jimbo@mako:~/dev$ mkvirtualenv -p /usr/bin/python3.4 gulptest
Running virtualenv with interpreter /usr/bin/python3.4
Using base prefix '/usr'
New python executable in gulptest/bin/python3.4
Also creating executable in gulptest/bin/python
Installing setuptools, pip, wheel...done.
(gulptest)jimbo@mako:~/dev$ pip install django django-gulp
Collecting django
  Using cached Django-1.8.6-py2.py3-none-any.whl
Collecting django-gulp
  Using cached django_gulp-2.1.1-py2.py3-none-any.whl
Collecting psutil==2.2.1 (from django-gulp)
Collecting futures==2.2.0 (from django-gulp)
  Using cached futures-2.2.0-py2.py3-none-any.whl
Collecting ansicolors==1.0.2 (from django-gulp)
Collecting env-tools==2.0 (from django-gulp)
  Using cached env_tools-2.0.0-py2.py3-none-any.whl
Collecting tini>=3.0.0 (from env-tools==2.0->django-gulp)
  Using cached tini-3.0.1-py2.py3-none-any.whl
Collecting six>=1.9.0 (from tini>=3.0.0->env-tools==2.0->django-gulp)
  Using cached six-1.10.0-py2.py3-none-any.whl
Collecting configparser>=3.5.0b2 (from tini>=3.0.0->env-tools==2.0->django-gulp)
Installing collected packages: django, psutil, futures, ansicolors, six, configparser, tini, env-tools, django-gulp
Successfully installed ansicolors-1.0.2 configparser-3.5.0b2 django-1.8.6 django-gulp-2.1.1 env-tools-2.0.0 futures-2.2.0 psutil-2.2.1 six-1.10.0 tini-3.0.1
(gulptest)jimbo@mako:~/dev$ django-admin startproject gulptest
(gulptest)jimbo@mako:~/dev$ cd gulptest
(gulptest)jimbo@mako:~/dev/gulptest$ npm install gulp
npm WARN engine [email protected]: wanted: {"node":">=0.12.0"} (current: {"node":"0.10.25","npm":"1.4.21"})
[email protected] node_modules/gulp
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
โ”œโ”€โ”€ [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
โ””โ”€โ”€ [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
(gulptest)jimbo@mako:~/dev/gulptest$ echo "INSTALLED_APPS += ('django_gulp',)" >> gulptest/settings.py
(gulptest)jimbo@mako:~/dev/gulptest$ echo "var gulp = require('gulp'); gulp.task('default', function() { console.log('Gulp is working') });" > gulpfile.js
(gulptest)jimbo@mako:~/dev/gulptest$ gulp
[06:49:10] Using gulpfile ~/dev/gulptest/gulpfile.js
[06:49:10] Starting 'default'...
Gulp is working
[06:49:10] Finished 'default' after 95 ฮผs
(gulptest)jimbo@mako:~/dev/gulptest$ ./manage.py migrate
Operations to perform:
  Synchronize unmigrated apps: staticfiles, django_gulp, messages
  Apply all migrations: contenttypes, admin, auth, sessions
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
  Installing custom SQL...
Running migrations:
  Rendering model states... DONE
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying sessions.0001_initial... OK
(gulptest)jimbo@mako:~/dev/gulptest$ ./manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
November 16, 2015 - 06:49:17
Django version 1.8.6, using settings 'gulptest.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

I've spent a bit of time trying to work out why this wasn't loading in my existing project, and eventually decided to just see if I could get it working in an empty project. These are the steps I've taken.

When I try and inspect manually in the shell, everything seems fine:

C(gulptest)jimbo@mako:~/dev/gulptest$ ./manage.py shell
Python 3.4.3 (default, Mar 26 2015, 22:03:40)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.conf import settings
>>> print(settings.INSTALLED_APPS)
('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_gulp')
>>> from django_gulp.management.commands import runserver
>>> print(runserver)
<module 'django_gulp.management.commands.runserver' from '/home/jimbo/.virtualenvs/gulptest/lib/python3.4/site-packages/django_gulp/management/commands/runserver.py'>

... but on runserver, nothing gulp-related happens.

I tried cloning the repo and putting the django_gulp folder into my project directly - it seems that django_gulp/__init__.py executes, but django_gulp/management/__init.py__ does not (I put print statements in them)

Do you have any ideas what might be going on? Have you encountered this?

Install futures only in python2

Hi,

I'm using django-gulp in python 3.

It works well but I'm having some interaction-problems.

django-pipeline imports 'concurrent.future' and in some cases 'futures' raises a exception in python2 way that it is not supported in python3 (two exceptions without brackets).

django-gulp gave me no problem with python3 but the fact that 'futures' is also installed in python3 makes some packages use the installed 'futures' instead of the standard library.

It would be nice to make the 'futures' installation depending on the python version.

Thanks.

Django extensions incompatibility

Hello,

I'm using extensively django-extensions for development, and especially ./manage.py runserver_plus command, that allows me to make posrmortem debugging, which for me is essential. However, I cannot get django-gulp to initiate my gulpfile.js with runserver_plus. In runs correctly with Django's simple runserver, though.

Is there any workaround to use django-gulp with django-extenstions?

Python 3: Error in invoking subprocess.Popen with stream wrapper

I'm running Python 3.6.3 and trying to just django_gulp 3.0.0.

$ python manage.py runserver
>>> Starting gulp
<class 'django.core.management.base.OutputWrapper'> <class 'django.core.management.base.OutputWrapper'>
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/rzg/Projects/2017/10/cocktails-ii/.direnv/python-3.6.3/lib/python3.6/site-packages/django_gulp/management/commands/runserver.py", line 112, in start_gulp
    stderr=self.stderr)
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 667, in __init__
    errread, errwrite) = self._get_handles(stdin, stdout, stderr)
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1184, in _get_handles
    c2pwrite = stdout.fileno()
io.UnsupportedOperation: fileno

>>> Killing pid 36211
>>> Exiting

What seems to be happening is that start_gulp calls subprocess.Popen and passes self.stdout, which is an instance of django.core.management.base.OutputWrapper. This class in turn wraps a _io.TextIOWrapper, which does not necessarily have an associated file descriptor number.

Doesn't work with ManifestStaticFilesStorage

Didn't test any other storage backends.

Would be nice if this was supported, but if it's not going to happen it would also be nice to document that it doesn't work, and perhaps suggest an alternative.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.