Skip to content

Commit

Permalink
Merge branch '1.0.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
metatoaster committed May 24, 2018
2 parents 6af6349 + bbdf647 commit e7379ed
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 43 deletions.
18 changes: 9 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ matrix:
include:
- language: python
python: 2.7
env: TRAVIS_NODE_VERSION=4.6
env: TRAVIS_NODE_VERSION=4.9
- language: python
python: 3.3
env: TRAVIS_NODE_VERSION=4.8
env: TRAVIS_NODE_VERSION=6.12
- language: python
python: 3.4
env: TRAVIS_NODE_VERSION=6.12
env: TRAVIS_NODE_VERSION=6.14
- language: python
python: 3.5
env: TRAVIS_NODE_VERSION=6.12
env: TRAVIS_NODE_VERSION=8.9
- language: python
python: 3.6
env: TRAVIS_NODE_VERSION=8.9
env: TRAVIS_NODE_VERSION=8.11
- language: python
python: 3.7-dev
env: TRAVIS_NODE_VERSION=9
env: TRAVIS_NODE_VERSION=10
- language: python
python: pypy
env: TRAVIS_NODE_VERSION=4.8
Expand All @@ -32,15 +32,15 @@ matrix:
env: TRAVIS_NODE_VERSION=6.12
# test different versions of Node.js on osx
- language: node_js
node_js: 4.8
node_js: 4.9
os: osx
env: TRAVIS_PYTHON_VERSION=3.4.5
- language: node_js
node_js: 6.12
node_js: 6.14
os: osx
env: TRAVIS_PYTHON_VERSION=3.5.3
- language: node_js
node_js: 8.9
node_js: 8.11
os: osx
env: TRAVIS_PYTHON_VERSION=3.6.0

Expand Down
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

1.0.2 (2018-05-24)
------------------

- Provide a builder that will generate an artifact with the supported
optimize flags enabled. [
`#3 <https://github.com/calmjs/calmjs.webpack/issues/3>`_
]

1.0.1 (2018-05-03)
------------------

Expand Down
70 changes: 43 additions & 27 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
calmjs.webpack
==============

Package for extending the the `Calmjs framework`_ to support the usage
of |webpack|_ for the generation of deployable artifacts from
JavaScript source code provided by Python packages in conjunction with
standard JavaScript or `Node.js`_
similar package repositories.
Provide the integration of |webpack|_ into a Python environment through
the `Calmjs framework`_ to facilitate the usage of JavaScript sources
included with Python packages in conjunction with Node.js packages
sourced from |npm|_ or similar package repositories, for the declaration
and production of prebuilt JavaScript artifacts with |webpack| in a
manner that allow reuse and extension by Python packages' dependants.

.. image:: https://travis-ci.org/calmjs/calmjs.webpack.svg?branch=master
:target: https://travis-ci.org/calmjs/calmjs.webpack
Expand All @@ -19,7 +20,7 @@ similar package repositories.
.. |calmjs.dev| replace:: ``calmjs.dev``
.. |calmjs.parse| replace:: ``calmjs.parse``
.. |calmjs.webpack| replace:: ``calmjs.webpack``
.. |karma| replace:: ``npm``
.. |karma| replace:: ``karma``
.. |npm| replace:: ``npm``
.. |webpack| replace:: ``webpack``
.. _Calmjs framework: https://pypi.python.org/pypi/calmjs
Expand All @@ -38,7 +39,8 @@ ultimately rely on some form of JavaScript. This is especially true if
associated functionalities are sourced from `Node.js`_ based package
management systems such as |npm|_. However, backend languages that
offer their own package management system typically lack comprehensive
integration with |npm| by default.
integration with |npm|, or integration is tightly coupled with whatever
framework that is not reusable in a more generalized manner.

A common way to address this issue is that a package may be forced to be
split into two, or at the very least a completely separate deployment
Expand Down Expand Up @@ -94,8 +96,8 @@ compilation target, with the final deployable artifact(s) being produced
through |webpack| from the |webpack|_ package.

While the input source files made available through Python packages
could be written in any format as understood by webpack,
currently only standard ES5 is understood. The reason for this is that
could be written in any format as understood by webpack, currently only
standard ES5 is properly processed. The reason for this is that
|calmjs.parse|_, the parser library that |calmjs.webpack| make use for
the parsing of JavaScript, currently only understand ES5, and is used
for extracting all the import statements to create the dynamic Calmjs
Expand Down Expand Up @@ -141,7 +143,7 @@ although PyPy3-2.4 should work, however there may be difficulties due to
new versions of dependencies rejecting older versions of Python.

To install |calmjs.webpack| into a given Python environment, it may be
installed via the git repo through this command:
installed directly from PyPI with the following command:

.. code:: sh
Expand Down Expand Up @@ -263,7 +265,7 @@ shells this may be executed instead from within that directory:
$ CALMJS_TEST_ENV=. python -m unittest calmjs.webpack.tests.make_suite
Do note that if the |calmjs.dev| package is unavailable, a number of
tests relating to integration with ``karma`` will be skipped. To avoid
tests relating to integration with |karma| will be skipped. To avoid
this, either install |calmjs.dev| manually, or install |calmjs.webpack|
using its extras dependencies declaration like so:

Expand Down Expand Up @@ -294,8 +296,8 @@ Python packages`__.
.. __: https://pypi.python.org/pypi/calmjs/#export-javascript-code-from-python-packages


Declaring JavaScript exports for Python
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Declaring JavaScript exports for the Python package
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

JavaScript code embedded within a Python package can be exposed to the
Calmjs framework through the ``calmjs.module`` registry. For example,
Expand All @@ -322,8 +324,9 @@ The following is am example for packages that have nested submodules
While the import locations declared looks exactly like a Python module
(as per the rules of a Python entry point), the ``calmjs.module``
registry will present them using the CommonJS/ES6 style import paths
(i.e. ``'example/lib'`` and ``'example/app'``), so users of that need
those JavaScript modules to be sure they ``require`` those strings.
(i.e. ``'example/lib'`` and ``'example/app'``). Thus users that wish
to import those specific JavaScript modules will then ``require`` the
required modules prefixed by those strings.

Please also note that the default source extractor will extract all
JavaScript files within those directories. Finally, as a consequence of
Expand Down Expand Up @@ -586,23 +589,31 @@ specifying an entry in the ``calmjs.artifacts`` registry, with the key
being the filename of the artifact and the value being the import
location to a builder. A default builder function provided at
``calmjs.webpack.artifact:complete_webpack`` will enable the generation
of a complete webpack artifact for the Python package. For example:
of a complete webpack artifact for the Python package. The builder
``calmjs.webpack.artifact:optimize_webpack`` will do the same, but with
the optimize options enabled (currently only the minimize output is
supported).

For example, a configuration that contains both forms might look like
so:

.. code:: ini
[calmjs.artifacts]
example.webpack.js = calmjs.webpack.artifact:complete_webpack
Once those entry points are installed, running ``calmjs artifact build
example.package`` will make use of the webpack toolchain and build the
artifact at ``example.webpack.js`` inside the ``calmjs_artifacts``
directory within the metadata directory for ``example.package``.
Alternatively, for solution more integrated with ``setuptools``, the
``setup`` function in ``setup.py`` should also enable the
``build_calmjs_artifacts`` flag such that ``setup.py build`` will also
trigger the building process. This is useful for automatically
generating and including the artifact as part of the wheel building
process. Consider this ``setup.py``:
example.webpack.min.js = calmjs.webpack.artifact:optimize_webpack
Once those entry points are added to ``setup.py`` and the package
metadata is regenerated using ``setup.py egg_info``, running ``calmjs
artifact build example.package`` will make use of the webpack toolchain
and build the artifact at ``example.webpack.js`` inside the
``calmjs_artifacts`` directory within the package metadata directory for
``example.package``. Alternatively, for solution more integrated with
``setuptools``, the ``setup`` function in ``setup.py`` should also
enable the ``build_calmjs_artifacts`` flag such that ``setup.py build``
will also trigger the building process. This is useful for
automatically generating and including the artifact as part of the wheel
building process. Consider this ``setup.py``:

.. code:: Python
Expand All @@ -617,6 +628,7 @@ process. Consider this ``setup.py``:
[calmjs.artifacts]
example.webpack.js = calmjs.webpack.artifact:complete_webpack
example.webpack.min.js = calmjs.webpack.artifact:optimize_webpack
""",
)
Expand Down Expand Up @@ -655,6 +667,10 @@ that were declared in ``calmjs.artifacts``.
[calmjs.artifacts.tests]
example.webpack.js = calmjs.webpack.artifact:test_complete_webpack
example.webpack.min.js = calmjs.webpack.artifact:test_complete_webpack
Note that the same ``test_complete_webpack`` test builder will be able
to test the optimize_webpack artifact also.


Troubleshooting
Expand Down
10 changes: 5 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
environment:
matrix:
- PYTHON: "C:\\Python27"
nodejs_version: "4.8"
nodejs_version: "6.14"
- PYTHON: "C:\\Python33"
nodejs_version: "6.12"
nodejs_version: "8.10"
- PYTHON: "C:\\Python34"
nodejs_version: "6.12"
nodejs_version: "6"
- PYTHON: "C:\\Python35"
nodejs_version: "8.9"
nodejs_version: "8"
- PYTHON: "C:\\Python36"
nodejs_version: "9"
nodejs_version: "10"

install:
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
Expand Down
13 changes: 13 additions & 0 deletions src/calmjs/webpack/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,16 @@ def test_complete_webpack(package_names, export_target):
)
spec.advise(SETUP, webpack_advice, spec)
return KarmaToolchain(), spec


def optimize_webpack(package_names, export_target):
"""
Return the toolchain and a spec that when executed together, will
result in a complete artifact using the provided package names onto
the export_target, with the optimize options enabled.
"""

return default_toolchain, create_spec(
package_names, export_target,
webpack_optimize_minimize=True,
)
5 changes: 5 additions & 0 deletions src/calmjs/webpack/testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,13 @@ def cls_setup_webpack_example_package(cls):
('entry_points.txt', (
'[calmjs.artifacts]\n'
'ex.webpack.js = calmjs.webpack.artifact:complete_webpack\n'
'ex.webpack.min.js = calmjs.webpack.artifact:optimize_webpack\n'
'[calmjs.artifacts.tests]\n'
'ex.webpack.js = calmjs.webpack.artifact:test_complete_webpack\n'
# no separate builder for testing optimize_webpack as there
# should be no difference.
'ex.webpack.min.js = calmjs.webpack.artifact:test_complete_webpack'
'\n'
'[%s]\n'
'example.package = example.package\n'
'[%s.tests]\n'
Expand Down
25 changes: 23 additions & 2 deletions src/calmjs/webpack/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,13 +1287,34 @@ def test_prebuilts(self):

def test_calmjs_artifact_package_generation(self):
utils.stub_stdouts(self)
registry = get_registry('calmjs.artifacts')
builders = sorted(
registry.iter_builders_for('example.package'),
key=lambda builder: str(builder[0])
)

self.assertEqual(2, len(builders))

with self.assertRaises(SystemExit) as e:
runtime.main(['artifact', 'build', 'example.package'])

self.assertEqual(e.exception.args[0], 0)
registry = get_registry('calmjs.artifacts')
for e, t, spec in registry.iter_builders_for('example.package'):

for e, t, spec in builders:
self.assertTrue(exists(spec['export_target']))

with open(builders[0][2]['export_target']) as fd:
# ex.webpack.js
self.assertIn('webpackUniversalModuleDefinition', fd.readline())
# there are more lines.
self.assertNotEqual('', fd.readline())

with open(builders[1][2]['export_target']) as fd:
# ex.webpack.min.js
self.assertNotIn('webpackUniversalModuleDefinition', fd.readline())
# assume no source map? the entire thing is one line
self.assertEqual('', fd.readline())


@unittest.skipIf(karma is None, 'calmjs.dev or its karma module not available')
class KarmatoolchainIntegrationTestCase(unittest.TestCase):
Expand Down

0 comments on commit e7379ed

Please sign in to comment.