#204 Add a tasks.py for Invoke
Closed 7 years ago by atelic. Opened 7 years ago by atelic.
atelic/fedora-hubs feature/tasks.py  into  develop

Add a tasks.py for invoke
Eric Barbour • 7 years ago  
file modified
+1
@@ -9,6 +9,7 @@ 

  fmn.rules

  gunicorn

  html5lib

+ invoke>=0.13

  munch

  psycopg2

  pytz

file added
+145
@@ -0,0 +1,145 @@ 

+ #!/usr/bin/env python

+ 

+ from invoke import run, task

+ 

+ 

+ @task(aliases=['a'])

+ def assets(ctx, watch=False):

+     cmd = './node_modules/.bin/webpack'

+     if watch:

+         cmd += ' -w'

+     run(cmd, echo=True)

+ 

+ 

+ @task(aliases=['c'])

+ def clean(ctx):

+     cmd = 'find . -name "*.pyc" -delete'

+     run(cmd, echo=True)

+ 

+ 

+ @task

+ def credentials(ctx):

+     content = """config = {

+     # Put your FAS credentials here...

+     # but leave them commented out.  Note that, if you leave your fas

+     # credentials out, some widgets won't be as accurate as they could be..

+     # but it also makes the app faster than it would otherwise be (which is

+     # nice for development).

+     #'fas_credentials': {

+     #    'username': 'YOUR_FAS_USERNAME',

+     #    'password': 'YOUR_FAS_PASSWORD',

+     #},

+ 

+     # Go and generate a token for this here:

+     # https://github.com/settings/tokens

+     'github.oauth_token': 'YOUR_GITHUB_TOKEN',

+ }"""

+     run('touch fedmsg.d/credentials.py', echo=True)

+     print('Writing credential template')

+     print(content)

+     with open('fedmsg.d/credentials.py', 'w') as fp:

+         fp.write(content)

+ 

+ 

+ @task(aliases=['flake8'])

+ def flake(ctx):

+     run('flake8 .', echo=True)

+ 

+ 

+ @task

+ def populate(ctx):

+     run('python populate.py', echo=True)

+ 

+ 

+ @task(aliases=['rdb'])

+ def restart_db(ctx, serve=False):

+     cmd = 'rm /var/tmp/hubs.db;\

+            rm /var/tmp/fedora-hubs-cache.db;\

+            PYTHONPATH=. python populate.py;'

+ 

+     if serve:

+         cmd += 'gunicorn -w 8 -t 240 --log-config logging.ini hubs.app:app'

+ 

+     run(cmd, echo=True)

+ 

+ 

+ @task(aliases=['req'])

+ def requirements(ctx, test=False):

+     run('pip install -r requirements.txt', echo=True)

+     if test:

+         run('pip install -r test-requirements.txt', echo=True)

+ 

+ 

+ @task(aliases=['s', 'serve'])

+ def server(ctx, gunicorn=False, log=False):

+     cmd = ''

+     if gunicorn:

+         cmd = 'gunicorn -w 8 -t 240 --log-config logging.ini hubs.app:app'

+     else:

+         cmd = 'python runserver.py'

+ 

+     if log:

+         cmd += ' >>log 2>&1'

+     run(cmd, echo=True)

+ 

+ 

+ @task

+ def shell(ctx):

+     '''

+     required:

+         pip install ipython

+     '''

+     import requests

+     import fedmsg.config

+     import fedmsg.meta

+ 

+     import hubs.models

+     import hubs.widgets.base

+ 

+     from hubs.app import app

+     fedmsg_config = fedmsg.config.load_config()

+     fedmsg.meta.make_processors(**fedmsg_config)

+ 

+     session = hubs.models.init(fedmsg_config['hubs.sqlalchemy.uri'])

+ 

+     context = {

+         'requests': requests,

+         'fedmsg_config': fedmsg_config,

+         'session': session,

+         'models': hubs.models,

+         'widgets.base': hubs.widgets.base,

+         'app': app

+     }

+ 

+     try:

+         try:

+             # 0.10.x

+             from IPython.Shell import IPShellEmbed

+             ipshell = IPShellEmbed()

+             ipshell(global_ns={}, local_ns=context)

+         except ImportError:

+             # 0.12+

+             from IPython import embed

+             embed(user_ns=context)

+         return

+     except ImportError:

+         pass

+ 

+ 

+ @task

+ def stream(ctx):

+     cmd = 'python ev-server/hubs-stream-server.py'

+     run(cmd, echo=True)

+ 

+ 

+ @task(aliases=['t', 'tests'])

+ def test(ctx, coverage=False):

+     cmd = 'PYTHON_PATH=. nosetests '

+     if coverage:

+         cmd += '--with-coverage --cover-erase --cover-package=hubs --cover-html'

+     run(cmd, echo=True)

+ 

+ 

+ @task(default=True)

+ def usage(ctx):

+     run('invoke --list')

Invoke is a task running tool that makes development tasks easier to run. This adds a bunch of common tasks for developing on hubs and decreases typing.

Examples:

$ inv server # runs python runserver.py

$ inv req # runs pip install -r requirements.txt

$ inv req --test # runs ^ plus pip install -r test-requrements.txt

seems to me that this does the same things than what we have (so nothing new) and adds a new dependency.

Not sure I'm entirely fan of it

Pull-Request has been closed by atelic

7 years ago
Metadata