def set_version(context: Context, version=None, bump=False):
    """
    Updates the version of MTP-common
    """
    if bump and version:
        raise TaskError('You cannot bump and set a specific version')
    if bump:
        from mtp_common import VERSION

        version = list(VERSION)
        version[-1] += 1
    else:
        try:
            version = list(map(int, version.split('.')))
            assert len(version) == 3
        except (AttributeError, ValueError, AssertionError):
            raise TaskError('Version must be in the form N.N.N')

    dotted_version = '.'.join(map(str, version))
    replacements = [
        (r'^VERSION =.*$',
         'VERSION = (%s)' % ', '.join(map(str, version)),
         'mtp_common/__init__.py'),
        (r'^  "version":.*$',
         '  "version": "%s",' % dotted_version,
         'package.json'),
    ]
    for search, replacement, path in replacements:
        with open(os.path.join(os.path.dirname(__file__), path)) as f:
            content = f.read()
        content = re.sub(search, replacement, content, flags=re.MULTILINE)
        with open(os.path.join(os.path.dirname(__file__), path), 'w') as f:
            f.write(content)
    context.debug('Updated version to %s' % dotted_version)
def bundle_javascript(context: Context):
    """
    Copies javascript sources
    No compilation is necessary
    """
    rsync_flags = '-avz' if context.verbosity == 2 else '-az'
    context.shell('rsync %s %s %s/' % (rsync_flags, context.app.javascript_source_path, context.app.asset_build_path))
Exemple #3
0
def bundle_javascript(context: Context):
    """
    Copies javascript sources
    No compilation is necessary
    """
    rsync_flags = '-avz' if context.verbosity == 2 else '-az'
    context.shell('rsync %s %s %s/' %
                  (rsync_flags, context.app.javascript_source_path,
                   context.app.asset_build_path))
def start(context: Context, port=8000, test_mode=False):
    """
    Starts a development server with test data
    """
    if not test_mode:
        super_task = context.overidden_tasks[0]
        return super_task(context=context, port=port)
    context.setup_django()
    return call_command('testserver', 'initial_groups', 'test_prisons', addrport='0:%s' % port, interactive=False)
Exemple #5
0
def start(context: Context, port=8000, test_mode=False):
    """
    Starts a development server with test data
    """
    if not test_mode:
        super_task = context.overidden_tasks[0]
        return super_task(context=context, port=port)
    context.setup_django()
    return call_command('testserver',
                        'initial_groups',
                        'test_prisons',
                        addrport='0:%s' % port,
                        interactive=False)
def docs(context: Context):
    """
    Generates static documentation
    """
    try:
        from sphinx.application import Sphinx
    except ImportError:
        context.pip_command('install', 'Sphinx')
        from sphinx.application import Sphinx

    context.shell('cp', 'README.rst', 'docs/README.rst')
    app = Sphinx('docs', 'docs', 'docs/build', 'docs/build/.doctrees', buildername='html', parallel=True,
                 verbosity=context.verbosity)
    app.build()
Exemple #7
0
def clean(context: Context, delete_dependencies: bool = False):
    """
    Deletes build outputs
    """
    paths = ['nosetests.xml']
    context.shell('rm -rf %s' % paths_for_shell(paths))
    context.shell('find %s -name "*.pyc" -or -name __pycache__ -delete' % context.app.django_app_name)

    if delete_dependencies:
        context.info('Cleaning app %s dependencies' % context.app.name)
        paths = ['venv']
        context.shell('rm -rf %s' % paths_for_shell(paths))
def clean(context: Context, delete_dependencies: bool = False):
    """
    Deletes build outputs
    """
    paths = ['docs/build', 'build', 'dist', '.eggs'] + glob.glob('*.egg-info')
    context.shell('rm -rf %s' % paths_for_shell(paths))
    context.shell('find %s -name "*.pyc" -or -name __pycache__ -delete' % context.app.django_app_name)

    if delete_dependencies:
        context.info('Cleaning local %s dependencies' % context.app.name)
        paths = ['venv']
        context.shell('rm -rf %s' % paths_for_shell(paths))
Exemple #9
0
def test(context: Context, functional_tests=False):
    """
    Tests the app
    """
    environment = {'IGNORE_LOCAL_SETTINGS': 'True'}
    if functional_tests:
        environment.update({
            'RUN_FUNCTIONAL_TESTS': '1',
            'OAUTHLIB_INSECURE_TRANSPORT': '1',
        })
    return context.shell('nosetests', environment=environment)
def python_dependencies(context: Context, extras=None):
    """
    Updates python dependencies
    """
    with mock.patch('setuptools.setup'):
        from setup import install_requires, extras_require

        requirements = install_requires.copy()
        if extras:
            requirements.extend(extras_require[extras])
    return context.pip_command('install', *requirements)
Exemple #11
0
def migrate(context: Context):
    """
    Migrates the database models
    Use `./manage.py migrate` for fine-grained options
    """
    context.management_command('migrate', interactive=False)
def migrate(context: Context):
    """
    Migrates the database models
    Use `./manage.py migrate` for fine-grained options
    """
    context.management_command('migrate', interactive=False)
def upload(context: Context):
    """
    Builds and uploads MTP-common to pypi
    """
    return context.shell(sys.executable, 'setup.py', 'sdist', 'bdist_wheel', 'upload')