pax_global_header 0000666 0000000 0000000 00000000064 14766650302 0014523 g ustar 00root root 0000000 0000000 52 comment=13cc60c15e6a1efac98ba567283a129c4b7af61d
django-yarnpkg-6.1.3/ 0000775 0000000 0000000 00000000000 14766650302 0014445 5 ustar 00root root 0000000 0000000 django-yarnpkg-6.1.3/.coveragerc 0000664 0000000 0000000 00000000040 14766650302 0016560 0 ustar 00root root 0000000 0000000 [run]
include = django_yarnpkg*
django-yarnpkg-6.1.3/.gitignore 0000664 0000000 0000000 00000000641 14766650302 0016436 0 ustar 00root root 0000000 0000000 # Numerous always-ignore extensions
*.diff
*.err
*.orig
*.log
*.rej
*.swo
*.swp
*.vi
*~
*.sass-cache
*.egg-info/
*.db
*.log
*.pyc
build/
src/
# OS or Editor folders
.DS_Store
._*
Thumbs.db
.cache
.project
.settings
.tmproj
nbproject
*.sublime-project
*.sublime-workspace
*.mo
.idea
django_bower.egg-info
example/db
example/components/*
example/static/*
!example/components/.gitkeep
!example/static/.gitkeep
dist/
django-yarnpkg-6.1.3/.gitlab-ci.yml 0000664 0000000 0000000 00000000577 14766650302 0017112 0 ustar 00root root 0000000 0000000 test:
image: python:3.9-buster
before_script:
- apt-get update -y -qq && apt-get install -y -qq yarnpkg
- pip install -q Django
- pip install .
- pip install -r requirements_dev.txt
- pip install pep8
script:
- mkdir -p /tmp/test_root/
- export TEST_PROJECT_ROOT=/tmp/test_root/
- coverage run runtests.py test django_yarnpkg && coverage report
django-yarnpkg-6.1.3/CHANGELOG.rst 0000664 0000000 0000000 00000003647 14766650302 0016500 0 ustar 00root root 0000000 0000000 Version 6.1.3 (2025-03-19)
=====================================================
* Fix compatibility with Python 3.13 by dropping usage of distutils.
Version 6.1.2 (2024-02-10)
=====================================================
* Explicitly set nodeLinker config to fix compatibility with Yarn 4.x
Version 6.1.1 (2024-02-09)
=====================================================
* Fix compatibility with Yarn 4.x
* Drop usage of six
Version 6.1.0 (2023-02-19)
=====================================================
* Pass on yarn's exit code
Version 6.0.3 (2022-11-01)
=====================================================
* Fix compatibility with Django 4.1
* Pass all arguments of yarn commands to yarn
* [Dev] Fix tests
Version 6.0.2 (2022-09-05)
=====================================================
* Fix yarnpkg call for non-install commands
Version 6.0.1 (2020-01-03)
=====================================================
* Prefer the yarnpkg command over yarn if installed due to naming conflict
on Debian
Version 6.0 (2019-12-07)
=====================================================
* Fork and port to yarnpkg
Version 4.8 (2013-10-02)
=====================================================
* Support of bower arguments in bower_install
Version 4.7 (2013-09-01)
======================================================
* Bower 1.2 support.
* Better code coverage.
Version 4.6 (2013-08-11)
======================================================
* Add bower 1.1 support.
* Add django 1.6 support.
* Remove dev dependencies from setup.py.
Version 4.5 (2013-07-30)
======================================================
* Remove bower < 1.0 support.
Version 4.4 (2013-07-30)
======================================================
* Add bower >= 1.0 support.
* Fix freeze packages from git.
Version 4.3 (2013-07-16)
======================================================
* Add bower 0.10 support.
* Add python 3.3 support.
django-yarnpkg-6.1.3/LICENSE 0000664 0000000 0000000 00000026125 14766650302 0015460 0 ustar 00root root 0000000 0000000 Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2020 AlekSIS / Libraries
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
django-yarnpkg-6.1.3/README.rst 0000664 0000000 0000000 00000004005 14766650302 0016133 0 ustar 00root root 0000000 0000000 Django-yarnpkg
==============
Easy way to use `yarnpkg `_ with your `Django `_ project.
This is a fork of `django-bower ` by Vladimir Iakovlev.
Read full documentation on `read-the-docs `_.
Installation
------------
Install django-yarnpkg package:
.. code-block:: bash
pip install django-yarnpkg
Add django-bower to `INSTALLED_APPS` in your settings:
.. code-block:: python
'django_yarnpkg',
Add staticfinder to `STATICFILES_FINDERS`:
.. code-block:: python
'django_yarnpkg.finders.NodeModulesFinder',
Specify path to components root (you need to use an absolute path):
.. code-block:: python
NODE_MODULES_ROOT = os.path.join(BASE_DIR, 'node_modules')
If you need, you can manually set the path to yarnpkg:
.. code-block:: python
YARN_PATH = '/usr/bin/yarnpkg'
You can see an example settings file in `example project `_.
Usage
-----
Specify `YARN_INSTALLED_APPS` in settings, like:
.. code-block:: python
YARN_INSTALLED_APPS = (
'bootstrap@^4.4.1',
'underscore@^1.6.1',
)
Download yarn packages with the management command:
.. code-block:: bash
./manage.py yarn install
Add scripts in the template, like:
.. code-block:: html+django
{% load static %}
In production you need to call `yarnpkg install` before `collectstatic`:
.. code-block:: bash
./manage.py yarn install
./manage.py collectstatic
If you need to pass arguments to yarnpkg, like `--flat`, use:
.. code-block:: bash
./manage.py yarn install -- --flat
You can call yarnpkg commands like `info` and `update` with:
.. code-block:: bash
./manage.py yarn info backbone
./manage.py yarn update
Python 3 support
----------------
django-yarnpkg supports python 3.3+
django-yarnpkg-6.1.3/django_yarnpkg/ 0000775 0000000 0000000 00000000000 14766650302 0017442 5 ustar 00root root 0000000 0000000 django-yarnpkg-6.1.3/django_yarnpkg/__init__.py 0000664 0000000 0000000 00000000000 14766650302 0021541 0 ustar 00root root 0000000 0000000 django-yarnpkg-6.1.3/django_yarnpkg/conf.py 0000664 0000000 0000000 00000000563 14766650302 0020745 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
from shutil import which
import os
import sys
from django.conf import settings
__all__ = ['NODE_MODULES_ROOT', 'YARN_PATH']
NODE_MODULES_ROOT = getattr(settings, 'NODE_MODULES_ROOT', os.path.abspath(os.path.dirname(__name__)))
default_yarn_path = which('yarnpkg') or which('yarn')
YARN_PATH = getattr(settings, 'YARN_PATH', default_yarn_path)
django-yarnpkg-6.1.3/django_yarnpkg/context_processors.py 0000664 0000000 0000000 00000001410 14766650302 0023756 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
import os.path
import json
from django.conf import settings
from django.utils.datastructures import OrderedSet
def read_files():
for component in settings.YARN_INSTALLED_APPS:
component = component.split('#')[0]
try:
with open(os.path.join(
settings.NODE_MODULES_ROOT,
'node_modules',
component,
'package.json')) as package_json:
files = json.load(bower_json).get('files')
for f in files:
yield '%s/%s' % (component, f)
except FileNotFoundError:
continue
def node_modules(request):
return {
'node_modules': OrderedSet([f for f in read_files()]),
}
django-yarnpkg-6.1.3/django_yarnpkg/exceptions.py 0000664 0000000 0000000 00000000437 14766650302 0022201 0 ustar 00root root 0000000 0000000 from django.core.management.base import CommandError
class YarnNotInstalled(CommandError):
"""Custom command error"""
def __init__(self):
super(YarnNotInstalled, self).__init__(
"Yarn not installed, read instruction here - https://yarnpkg.com/",
)
django-yarnpkg-6.1.3/django_yarnpkg/finders.py 0000664 0000000 0000000 00000002037 14766650302 0021450 0 ustar 00root root 0000000 0000000 try:
from collections import OrderedDict
except ImportError:
from ordereddict import OrderedDict
from django.contrib.staticfiles.finders import FileSystemFinder
from django.core.files.storage import FileSystemStorage
from . import conf
import os
class NodeModulesFinder(FileSystemFinder):
"""Find static files installed with yarnpkg"""
def __init__(self, apps=None, *args, **kwargs):
self.locations = []
self.storages = OrderedDict()
root = self._get_node_modules_location()
if root is not None:
prefix = ''
self.locations.append((prefix, root))
filesystem_storage = FileSystemStorage(location=root)
filesystem_storage.prefix = prefix
self.storages[root] = filesystem_storage
def _get_node_modules_location(self):
"""
Return the node modules location, or None if one does not exist.
"""
path = os.path.join(conf.NODE_MODULES_ROOT, 'node_modules')
if os.path.exists(path):
return path
django-yarnpkg-6.1.3/django_yarnpkg/management/ 0000775 0000000 0000000 00000000000 14766650302 0021556 5 ustar 00root root 0000000 0000000 django-yarnpkg-6.1.3/django_yarnpkg/management/__init__.py 0000664 0000000 0000000 00000000000 14766650302 0023655 0 ustar 00root root 0000000 0000000 django-yarnpkg-6.1.3/django_yarnpkg/management/base.py 0000664 0000000 0000000 00000001471 14766650302 0023045 0 ustar 00root root 0000000 0000000 from pprint import pformat
from django.core.management.base import BaseCommand
from django.conf import settings
from ..yarn import yarn_adapter
from ..exceptions import YarnNotInstalled
class BaseYarnCommand(BaseCommand):
"""Base management command with yarn support"""
requires_system_checks = []
# add fake .options_list for Django>=1.10
if not hasattr(BaseCommand, 'option_list'):
option_list = ()
def handle(self, *args, **options):
self._check_yarn_exists()
yarn_adapter.create_node_modules_root()
def _check_yarn_exists(self):
"""Check yarn exists or raise exception"""
if not yarn_adapter.is_yarn_exists():
raise YarnNotInstalled()
def _install(self, args):
return yarn_adapter.install(settings.YARN_INSTALLED_APPS, *args)
django-yarnpkg-6.1.3/django_yarnpkg/management/commands/ 0000775 0000000 0000000 00000000000 14766650302 0023357 5 ustar 00root root 0000000 0000000 django-yarnpkg-6.1.3/django_yarnpkg/management/commands/__init__.py 0000664 0000000 0000000 00000000000 14766650302 0025456 0 ustar 00root root 0000000 0000000 django-yarnpkg-6.1.3/django_yarnpkg/management/commands/yarn.py 0000664 0000000 0000000 00000001407 14766650302 0024704 0 ustar 00root root 0000000 0000000 import sys
from ...yarn import yarn_adapter
from ..base import BaseYarnCommand
from argparse import REMAINDER
class Command(BaseYarnCommand):
args = 'command'
help = 'Call yarn in node modules root ({0}).'.format(
yarn_adapter._node_modules_root)
def add_arguments(self, parser):
parser.add_argument('command', nargs=REMAINDER)
def handle(self, *args, **options):
super(Command, self).handle(*args, **options)
args = args or tuple(options.pop('command'))
if self._is_single_command('install', args):
ret = self._install([])
else:
ret = yarn_adapter.call_yarn(args)
sys.exit(ret)
def _is_single_command(self, name, args):
return len(args) == 1 and args[0] == name
django-yarnpkg-6.1.3/django_yarnpkg/management/commands/yarn_install.py 0000664 0000000 0000000 00000000447 14766650302 0026435 0 ustar 00root root 0000000 0000000 import sys
from optparse import make_option
from ..base import BaseYarnCommand
class Command(BaseYarnCommand):
help = 'Install yarn apps'
def handle(self, *args, **options):
super(Command, self).handle(*args, **options)
ret = self._install(args)
sys.exit(ret)
django-yarnpkg-6.1.3/django_yarnpkg/models.py 0000664 0000000 0000000 00000000000 14766650302 0021265 0 ustar 00root root 0000000 0000000 django-yarnpkg-6.1.3/django_yarnpkg/shortcuts.py 0000664 0000000 0000000 00000000454 14766650302 0022055 0 ustar 00root root 0000000 0000000 import os, sys
def is_executable(path):
"""Check file is executable"""
if sys.platform == 'win32':
executable = os.access(path, os.X_OK) or path.lower().endswith(".cmd")
return os.path.isfile(path) and executable
return os.path.isfile(path) and os.access(path, os.X_OK)
django-yarnpkg-6.1.3/django_yarnpkg/templatetags/ 0000775 0000000 0000000 00000000000 14766650302 0022134 5 ustar 00root root 0000000 0000000 django-yarnpkg-6.1.3/django_yarnpkg/templatetags/__init__.py 0000664 0000000 0000000 00000000030 14766650302 0024236 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
django-yarnpkg-6.1.3/django_yarnpkg/templatetags/yarn.py 0000664 0000000 0000000 00000002255 14766650302 0023463 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os.path
from django import template
from django.templatetags import static
register = template.Library()
style_template = template.Template(
"""{% for filename in files %}
{% endfor %}"""
)
script_template = template.Template(
"""{% for filename in files %}
{% endfor %}"""
)
def tags(context, args, type):
components = (
[arg for arg in args if arg in context['node_modules']]
if args else context['node_modules']
)
files = []
for component in components:
files.append(component)
context['node_modules'].remove(component)
return {'files': [
static.static(f)
for f in files
if os.path.splitext(f)[1][1:] == type
]}
@register.inclusion_tag(style_template, takes_context=True)
def yarn_styles(context, *args):
return tags(context, args, 'css')
@register.inclusion_tag(script_template, takes_context=True)
def yarn_scripts(context, *args):
return tags(context, args, 'js')
django-yarnpkg-6.1.3/django_yarnpkg/test_settings.py 0000664 0000000 0000000 00000001440 14766650302 0022712 0 ustar 00root root 0000000 0000000 import os
TEST_PROJECT_ROOT = os.path.abspath(
os.environ.get('TEST_PROJECT_ROOT', '/tmp/'),
)
BASE_DIR = TEST_PROJECT_ROOT
NODE_MODULES_ROOT = os.path.join(TEST_PROJECT_ROOT, 'node_modules')
STATIC_ROOT = os.path.join(TEST_PROJECT_ROOT, 'yarnpkg_static')
STATIC_URL = '/static/'
YARN_INSTALLED_APPS = (
'jquery#1.9',
'underscore',
)
SECRET_KEY = 'iamdjangoyarnpkg'
INSTALLED_APPS = (
'django_yarnpkg',
)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {},
},
]
django-yarnpkg-6.1.3/django_yarnpkg/tests/ 0000775 0000000 0000000 00000000000 14766650302 0020604 5 ustar 00root root 0000000 0000000 django-yarnpkg-6.1.3/django_yarnpkg/tests/__init__.py 0000664 0000000 0000000 00000000065 14766650302 0022716 0 ustar 00root root 0000000 0000000 from .test_yarn import *
from .test_finders import *
django-yarnpkg-6.1.3/django_yarnpkg/tests/base.py 0000664 0000000 0000000 00000002075 14766650302 0022074 0 ustar 00root root 0000000 0000000 from django.conf import settings
from django.test import TestCase
from django.test.utils import override_settings
from ..yarn import yarn_adapter
import os
import shutil
try:
TEST_NODE_MODULES_ROOT = os.path.join(
settings.TEST_PROJECT_ROOT, 'node_modules',
)
except AttributeError:
TEST_NODE_MODULES_ROOT = '/tmp/node_modules/'
@override_settings(NODE_MODULES_ROOT=TEST_NODE_MODULES_ROOT)
class BaseYarnCase(TestCase):
"""Base bower test case"""
def setUp(self):
yarn_adapter.create_node_modules_root()
def tearDown(self):
self._remove_node_modules_root()
def _remove_node_modules_root(self):
"""Remove node_modules root if exists"""
if os.path.exists(TEST_NODE_MODULES_ROOT):
shutil.rmtree(TEST_NODE_MODULES_ROOT)
def assertCountEqual(self, *args, **kwargs):
"""Add python 2 support"""
if hasattr(self, 'assertItemsEqual'):
return self.assertItemsEqual(*args, **kwargs)
else:
return super(BaseYarnCase, self).assertCountEqual(*args, **kwargs)
django-yarnpkg-6.1.3/django_yarnpkg/tests/test_finders.py 0000664 0000000 0000000 00000005676 14766650302 0023665 0 ustar 00root root 0000000 0000000 from django.core.files.storage import FileSystemStorage
from django.test import TestCase
from ..yarn import yarn_adapter
from ..finders import NodeModulesFinder
from .. import conf
from .base import BaseYarnCase
import os
import os.path
import shutil
class _MakeDirsTestCase(TestCase):
"""
Helper to create and clean up test directories.
"""
def setUp(self):
super(_MakeDirsTestCase, self).setUp()
self.created = []
def tearDown(self):
super(_MakeDirsTestCase, self).tearDown()
for name in self.created:
if os.path.exists(name):
shutil.rmtree(name)
def makedirs(self, name):
"""
Wrap os.makedirs() to delete the created directory on teardown.
"""
os.makedirs(name)
self.created.append(name)
class SimpleNodeModulesFinderCase(_MakeDirsTestCase):
"""
Simple YarnFinder tests, without any packages installed.
"""
def test_list_nonexistent(self):
"""
When no Yarn folder exists, just gracefully find nothing.
"""
finder = NodeModulesFinder()
self.assertEqual(finder.locations, [])
self.assertEqual(finder.storages, {})
def test_list_existent(self, leaf_name='node_modules'):
"""
If 'node_modules' exists, use it to to find files.
"""
root = os.path.join(conf.NODE_MODULES_ROOT, leaf_name)
self.makedirs(root)
finder = NodeModulesFinder()
self.assertEqual(finder.locations, [('', root)])
self.assertEqual(set(finder.storages.keys()), set([root]))
storage = finder.storages[root]
self.assertIsInstance(storage, FileSystemStorage)
self.assertEqual(storage.prefix, '')
self.assertEqual(storage.location, root)
def test_list_old_path(self):
"""
If only the old 'node_modules' folder exists, use it instead.
"""
self.test_list_existent(leaf_name='node_modules')
def test_list_both(self):
"""
If both folders exist, only 'yarn_node_modules' should be used.
"""
self.test_list_existent(leaf_name='node_modules')
class NodeModulesFinderCase(BaseYarnCase):
"""Test finding installed with yarn files"""
def setUp(self):
super(NodeModulesFinderCase, self).setUp()
yarn_adapter.install(['jquery@1.9'])
self.finder = NodeModulesFinder()
def test_find(self):
"""Test staticfinder find"""
test_path = os.path.join('jquery', 'jquery.min.js')
path = self.finder.find(test_path)
self.assertEqual(path, os.path.join(
conf.NODE_MODULES_ROOT, 'node_modules', test_path,
))
def test_list(self):
"""Test staticfinder list"""
test_path = os.path.join('jquery', 'jquery.min.js')
result = self.finder.list([])
matched = [
part for part in result if part[0] == test_path
]
self.assertEqual(len(matched), 1)
django-yarnpkg-6.1.3/django_yarnpkg/tests/test_yarn.py 0000664 0000000 0000000 00000007575 14766650302 0023204 0 ustar 00root root 0000000 0000000 from django.core.management import call_command
from django.conf import settings
from django.test import TestCase
from io import StringIO
from mock import MagicMock
from ..yarn import yarn_adapter, YarnAdapter
from .. import conf
from .base import BaseYarnCase, TEST_NODE_MODULES_ROOT
import os
import shutil
class YarnAdapterCase(TestCase):
"""
YarnAdapter regression tests.
"""
def test_create_node_modules_root_subdirs(self):
"""
create_node_modules_root() creates missing intermediate directories.
"""
if os.path.exists(TEST_NODE_MODULES_ROOT):
shutil.rmtree(TEST_NODE_MODULES_ROOT)
subdir = os.path.join(TEST_NODE_MODULES_ROOT, 'sub', 'dir')
adapter = YarnAdapter(conf.YARN_PATH, subdir)
adapter.create_node_modules_root()
self.assertTrue(os.path.exists(subdir))
shutil.rmtree(TEST_NODE_MODULES_ROOT)
class YarnInstallCase(BaseYarnCase):
"""Test case for yarn_install management command"""
def setUp(self):
super(YarnInstallCase, self).setUp()
self.apps = settings.YARN_INSTALLED_APPS
self._original_install = yarn_adapter.install
yarn_adapter.install = MagicMock()
def tearDown(self):
super(YarnInstallCase, self).tearDown()
yarn_adapter.install = self._original_install
def test_create_node_modules_root(self):
"""Test create node_modules root"""
self._remove_node_modules_root()
call_command('yarn_install')
self.assertTrue(os.path.exists(TEST_NODE_MODULES_ROOT))
def test_install(self):
"""Test install yarn packages"""
call_command('yarn_install')
yarn_adapter.install.assert_called_once_with(self.apps)
class YarnExistsCase(BaseYarnCase):
"""
Test yarn exists checker.
This case need yarn to be installed.
"""
def setUp(self):
super(YarnExistsCase, self).setUp()
self._original_exists = yarn_adapter.is_yarn_exists
def tearDown(self):
super(YarnExistsCase, self).tearDown()
yarn_adapter.is_yarn_exists = self._original_exists
def test_if_exists(self):
"""Test if yarn exists"""
self.assertTrue(yarn_adapter.is_yarn_exists())
def test_if_not_exists(self):
"""Test if yarn not exists"""
adapter = YarnAdapter('/not/exists/path', TEST_NODE_MODULES_ROOT)
self.assertFalse(adapter.is_yarn_exists())
def _mock_exists_check(self):
"""Make exists check return false"""
yarn_adapter.is_yarn_exists = MagicMock()
yarn_adapter.is_yarn_exists.return_value = False
class YarnCommandCase(BaseYarnCase):
"""Test case for ./manage.py yarn something command"""
def setUp(self):
super(YarnCommandCase, self).setUp()
self.apps = settings.YARN_INSTALLED_APPS
self._mock_yarn_adapter()
def _mock_yarn_adapter(self):
self._original_install = yarn_adapter.install
yarn_adapter.install = MagicMock()
self._orig_call = yarn_adapter.call_yarn
yarn_adapter.call_yarn = MagicMock()
def tearDown(self):
super(YarnCommandCase, self).tearDown()
yarn_adapter.install = self._original_install
yarn_adapter.call_yarn = self._orig_call
def test_install_without_params(self):
"""Test that yarn install without param identical
with yarn_install
"""
call_command('yarn', 'install')
yarn_adapter.install.assert_called_once_with(
self.apps)
def test_install_with_params(self):
"""Test yarn install """
call_command('yarn', 'install', 'jquery')
yarn_adapter.call_yarn.assert_called_once_with(
('install', 'jquery'))
def test_call_to_yarn(self):
"""Test simple call to yarn"""
call_command('yarn', 'update')
yarn_adapter.call_yarn.assert_called_once_with(
('update',))
django-yarnpkg-6.1.3/django_yarnpkg/yarn.py 0000664 0000000 0000000 00000003564 14766650302 0020775 0 ustar 00root root 0000000 0000000 from . import conf, shortcuts, exceptions
from shutil import which
import os
import subprocess
import sys
import json
class YarnAdapter(object):
"""Adapter for working with yarnpkg"""
def __init__(self, yarn_path, node_modules_root):
self._yarn_path = yarn_path
self._node_modules_root = node_modules_root
def is_yarn_exists(self):
"""Check is bower exists"""
if shortcuts.is_executable(self._yarn_path)\
or which(self._yarn_path):
return True
else:
return False
def create_node_modules_root(self):
"""Create node modules root if need"""
if not os.path.exists(self._node_modules_root):
os.makedirs(self._node_modules_root)
def call_yarn(self, args):
"""Call yarn with a list of args"""
proc = subprocess.Popen(
[self._yarn_path] + list(args),
cwd=self._node_modules_root)
return proc.wait()
def install(self, packages, *options):
"""Install packages from yarn"""
self.call_yarn(["init", "--yes"])
self.call_yarn(["config", "set", "nodeLinker", "node-modules"])
return self.call_yarn(['add'] + list(options) + list(packages))
def _accumulate_dependencies(self, data):
"""Accumulate dependencies"""
for name, version in data['dependencies'].items():
if version:
full_name = '{0}@{1}'.format(name, version)
else:
full_name = name
self._packages.append(full_name)
self._accumulate_dependencies(params)
def _parse_package_names(self, output):
"""Get package names in yarn"""
data = json.loads(output)
self._packages = []
self._accumulate_dependencies(data)
return self._packages
yarn_adapter = YarnAdapter(conf.YARN_PATH, conf.NODE_MODULES_ROOT)
django-yarnpkg-6.1.3/docs/ 0000775 0000000 0000000 00000000000 14766650302 0015375 5 ustar 00root root 0000000 0000000 django-yarnpkg-6.1.3/docs/Makefile 0000664 0000000 0000000 00000012734 14766650302 0017044 0 ustar 00root root 0000000 0000000 # Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
help:
@echo "Please use \`make ' where is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " gettext to make PO message catalogs"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
clean:
-rm -rf $(BUILDDIR)/*
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/django-yarnpkg.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/django-yarnpkg.qhc"
devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/django-yarnpkg"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/django-yarnpkg"
@echo "# devhelp"
epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."
latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."
man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
texinfo:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."
info:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
gettext:
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
django-yarnpkg-6.1.3/docs/conf.py 0000664 0000000 0000000 00000017232 14766650302 0016701 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
#
# django-yarnpkg documentation build configuration file, created by
# sphinx-quickstart on Tue Jul 16 16:38:23 2013.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = []
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'django-yarnpkg'
copyright = u'2013, Vladimir Iakovlev; 2019, Dominik George'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '6.0'
# The full version, including alpha/beta/rc tags.
release = '6.0'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# " v documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'django-yarnpkgdoc'
# -- Options for LaTeX output --------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'django-yarnpkg.tex', u'django-yarnpkg Documentation',
u'Vladimir Iakovlev', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'django-yarnpkg', u'django-yarnpkg Documentation',
[u'Vladimir Iakovlev'], 1)
]
# If true, show URL addresses after external links.
#man_show_urls = False
# -- Options for Texinfo output ------------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'django-yarnpkg', u'django-yarnpkg Documentation',
u'Vladimir Iakovlev', 'django-yarnpkg', 'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
django-yarnpkg-6.1.3/docs/example.rst 0000664 0000000 0000000 00000000434 14766650302 0017563 0 ustar 00root root 0000000 0000000 ***************
Example project
***************
For running example project you need to change dir to `example`.
Prepare project with:
.. code-block:: bash
./manage.py syncdb
./manage.py yarn install
And run project with:
.. code-block:: bash
./manage.py runserver
django-yarnpkg-6.1.3/docs/index.rst 0000664 0000000 0000000 00000002276 14766650302 0017245 0 ustar 00root root 0000000 0000000 .. django-yarnpkg documentation master file, created by
sphinx-quickstart on Tue Jul 16 16:38:23 2013.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to django-yarnpkg's documentation!
========================================
Easy way to use `Yarn `_ with your `django `_ project.
Yarn is a package manager for the web. It offers a generic, unopinionated solution to the problem of front-end package management, while exposing the package dependency model via an API that can be consumed by a more opinionated build stack. There are no system wide dependencies, no dependencies are shared between different apps, and the dependency tree is flat.
Yarn runs over Git, and is package-agnostic. A packaged module can be made up of any type of asset, and use any type of transport (e.g., AMD, CommonJS, etc.).
Contents:
.. toctree::
:maxdepth: 2
installation
usage
tests
example
`Visit django-yarnpkg EduGit page. `_
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
django-yarnpkg-6.1.3/docs/installation.rst 0000664 0000000 0000000 00000004565 14766650302 0020642 0 ustar 00root root 0000000 0000000 ************
Installation
************
Install `Yarn `_ from npm:
.. code-block:: bash
npm install -g yarn
And django-yarnpkg package:
.. code-block:: bash
pip install django-yarnpkg
Add django-bower to `INSTALLED_APPS` in your settings:
.. code-block:: python
'django_yarnpkg',
Add staticfinder to `STATICFILES_FINDERS`:
.. code-block:: python
'django_yarnpkg.finders.NodeModulesFinder',
Specify path to node modules root (you need to use absolute path):
.. code-block:: python
NODE_MODULES_ROOT = '/PROJECT_ROOT/node_modules/'
If you need, you can manually set path to yarn
.. code-block:: python
YARN_PATH = '/usr/bin/yarnpkg'
Example settings file with django-yarnpkg:
.. code-block:: python
:linenos:
import os
PROJECT_ROOT = os.path.abspath(
os.path.join(os.path.dirname(__file__), ".."),
)
DEBUG = True
TEMPLATE_DEBUG = DEBUG
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'db',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
STATIC_URL = '/static/'
NODE_MODULES_ROOT = os.path.join(PROJECT_ROOT, 'node_modules')
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django_yarnpkg.finders.NodeModulesFinder',
)
SECRET_KEY = 'g^i##va1ewa5d-rw-mevzvx2^udt63@!xu$-&di^19t)5rbm!5'
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'example.urls'
WSGI_APPLICATION = 'example.wsgi.application'
TEMPLATE_DIRS = (
os.path.join(PROJECT_ROOT, 'templates'),
)
INSTALLED_APPS = (
'django.contrib.staticfiles',
'django_yarnpkg',
)
YARN_INSTALLED_APPS = (
'jquery',
'underscore',
)
django-yarnpkg-6.1.3/docs/tests.rst 0000664 0000000 0000000 00000000767 14766650302 0017303 0 ustar 00root root 0000000 0000000 *************
Running tests
*************
For running tests you need to install `django-yarnpkg` in development mode with:
.. code-block:: bash
python setup.py develop
Install dev requirements:
.. code-block:: bash
pip install -r requirements_dev.txt
Now you can run tests with:
.. code-block:: bash
django-admin.py test --settings=django_yarnpkg.test_settings django_yarnpkg
You can change test project root with `TEST_PROJECT_ROOT` environment variable. By default it is `/tmp`.
django-yarnpkg-6.1.3/docs/usage.rst 0000664 0000000 0000000 00000001533 14766650302 0017235 0 ustar 00root root 0000000 0000000 *****
Usage
*****
Specify `YARN_INSTALLED_APPS` in settings, like:
.. code-block:: python
YARN_INSTALLED_APPS = (
'jquery#1.9',
'underscore',
)
Download yarn packages with management command:
.. code-block:: bash
./manage.py yarn install
Add scripts in template, like:
.. code-block:: html+django
{% load static %}
In production you need to call `yarn install` before `collectstatic`:
.. code-block:: bash
./manage.py yarn install
./manage.py collectstatic
If you need to pass arguments to yarn, like `--flat`, use:
.. code-block:: bash
./manage.py yarn install -- --flat
You can call yarn commands like `info` and `update` with:
.. code-block:: bash
./manage.py yarn info backbone
./manage.py yarn update
django-yarnpkg-6.1.3/example/ 0000775 0000000 0000000 00000000000 14766650302 0016100 5 ustar 00root root 0000000 0000000 django-yarnpkg-6.1.3/example/example/ 0000775 0000000 0000000 00000000000 14766650302 0017533 5 ustar 00root root 0000000 0000000 django-yarnpkg-6.1.3/example/example/__init__.py 0000664 0000000 0000000 00000000000 14766650302 0021632 0 ustar 00root root 0000000 0000000 django-yarnpkg-6.1.3/example/example/settings.py 0000664 0000000 0000000 00000002650 14766650302 0021750 0 ustar 00root root 0000000 0000000 import os
PROJECT_ROOT = os.path.abspath(
os.path.join(os.path.dirname(__file__), ".."),
)
DEBUG = True
TEMPLATE_DEBUG = DEBUG
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'db',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
STATIC_URL = '/static/'
NODE_MODULES_ROOT = os.path.join(PROJECT_ROOT, 'node_modules')
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django_yarnpkg.finders.NodeModulesFinder',
)
SECRET_KEY = 'g^i##va1ewa5d-rw-mevzvx2^udt63@!xu$-&di^19t)5rbm!5'
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'example.urls'
WSGI_APPLICATION = 'example.wsgi.application'
TEMPLATE_DIRS = (
os.path.join(PROJECT_ROOT, 'templates'),
)
INSTALLED_APPS = (
'django.contrib.staticfiles',
'django_yarnpkg',
)
YARN_INSTALLED_APPS = (
'jquery',
'underscore',
)
django-yarnpkg-6.1.3/example/example/urls.py 0000664 0000000 0000000 00000000277 14766650302 0021100 0 ustar 00root root 0000000 0000000 from django.conf.urls import patterns, url
from django.views.generic import TemplateView
urlpatterns = patterns(
'',
url(r'^$', TemplateView.as_view(template_name='index.html')),
)
django-yarnpkg-6.1.3/example/example/wsgi.py 0000664 0000000 0000000 00000002616 14766650302 0021063 0 ustar 00root root 0000000 0000000 """
WSGI config for example project.
This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.
Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.
"""
import os
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "example.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
django-yarnpkg-6.1.3/example/manage.py 0000775 0000000 0000000 00000000372 14766650302 0017707 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
django-yarnpkg-6.1.3/example/node_modules/ 0000775 0000000 0000000 00000000000 14766650302 0020555 5 ustar 00root root 0000000 0000000 django-yarnpkg-6.1.3/example/node_modules/.gitkeep 0000664 0000000 0000000 00000000000 14766650302 0022174 0 ustar 00root root 0000000 0000000 django-yarnpkg-6.1.3/example/static/ 0000775 0000000 0000000 00000000000 14766650302 0017367 5 ustar 00root root 0000000 0000000 django-yarnpkg-6.1.3/example/static/.gitkeep 0000664 0000000 0000000 00000000000 14766650302 0021006 0 ustar 00root root 0000000 0000000 django-yarnpkg-6.1.3/example/templates/ 0000775 0000000 0000000 00000000000 14766650302 0020076 5 ustar 00root root 0000000 0000000 django-yarnpkg-6.1.3/example/templates/index.html 0000664 0000000 0000000 00000001021 14766650302 0022065 0 ustar 00root root 0000000 0000000
{% load static %}
django-yarnpkg demo
django-yarnpkg-6.1.3/renovate.json 0000664 0000000 0000000 00000000003 14766650302 0017154 0 ustar 00root root 0000000 0000000 {}
django-yarnpkg-6.1.3/requirements_dev.txt 0000664 0000000 0000000 00000000016 14766650302 0020564 0 ustar 00root root 0000000 0000000 mock
coverage
django-yarnpkg-6.1.3/runtests.py 0000664 0000000 0000000 00000000425 14766650302 0016707 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault(
"DJANGO_SETTINGS_MODULE", 'django_yarnpkg.test_settings',
)
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
django-yarnpkg-6.1.3/setup.py 0000664 0000000 0000000 00000001422 14766650302 0016156 0 ustar 00root root 0000000 0000000 from setuptools import setup, find_packages
version = '6.1.3'
setup(
name='django-yarnpkg',
version=version,
description="Integrate django with yarnpkg",
long_description=open('README.rst').read(),
classifiers=[
'Framework :: Django',
'Programming Language :: JavaScript',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
],
keywords='',
author='Dominik George',
author_email='nik@naturalnet.de',
url='https://edugit.org/AlekSIS/libs/django-yarnpkg',
license='Apache-2.0',
packages=find_packages(exclude=['example']),
include_package_data=True,
zip_safe=True,
install_requires=[
'django',
],
entry_points="""
# -*- Entry points: -*-
""",
)