From e2a173d3930e59f764366e76a6632ebc922d5d6e Mon Sep 17 00:00:00 2001 From: Anthony Johnson Date: Fri, 26 Jul 2019 17:14:36 -0600 Subject: [PATCH 1/7] Add webpack commands into setup.py This is a POC that shows building webpack through standard `setup.py` commands. Any call to `setup.py build` or `bdist` or `sdist` will trigger a Webpack build of the assets first. A non-zero exit code will halt the process. Also, moved the `npm run dev` command, which here is `python setup.py watch`, though there is perhaps something better here. There is already `python setup.py develop`, which has a separate function, so I don't want to collide there. Example output here: https://gist.github.com/agjohnson/cdaab364fe598daa7f3bef750cfb84dd Refs #797 --- docs/contributing.rst | 8 +++++--- setup.py | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/docs/contributing.rst b/docs/contributing.rst index a151f7a0..971e6ca0 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -94,9 +94,11 @@ To release a new version of the theme, core team will take the following steps: (with regards to alpha release and development versions). The version increment should reflect these releases and any potentially breaking changes. #. Update the changelog (``docs/changelog.rst``) with the version information. -#. Run ``npm run build`` to rebuild all the theme assets. -#. Run ``python setup.py update_translations`` to compile new translation files and update Transifex -#. Commit that change. +#. Run ``python setup.py update_translations`` to compile new translation files + and update Transifex. +#. Run ``python setup.py build`` to rebuild all the theme assets and the Python + package. +#. Commit these changes. #. Tag the release in git: ``git tag $NEW_VERSION``. #. Push the tag to GitHub: ``git push --tags origin``. #. Upload the package to PyPI: diff --git a/setup.py b/setup.py index c937eacd..0818f0c5 100644 --- a/setup.py +++ b/setup.py @@ -7,10 +7,39 @@ import subprocess import distutils.cmd +import setuptools.command.build_py from io import open from setuptools import setup +class WebpackBuildCommand(setuptools.command.build_py.build_py): + + """Prefix Python build with Webpack asset build""" + + def run(self): + subprocess.run(['webpack', '--config', 'webpack.prod.js'], check=True) + super().run() + + +class WebpackDevelopCommand(distutils.cmd.Command): + + description = "Run Webpack dev server" + + user_options = [] + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + subprocess.run( + ["webpack-dev-server", "--open", "--config", "webpack.dev.js"], + check=True + ) + + class UpdateTranslationsCommand(distutils.cmd.Command): description = "Run all localization commands" @@ -47,8 +76,8 @@ class TransifexCommand(distutils.cmd.Command): pass def run(self): - subprocess.run(['tx', 'push', '--source']) - subprocess.run(['tx', 'pull']) + subprocess.run(['tx', 'push', '--source'], check=True) + subprocess.run(['tx', 'pull'], check=True) setup( @@ -63,6 +92,8 @@ setup( cmdclass={ 'update_translations': UpdateTranslationsCommand, 'transifex': TransifexCommand, + 'build_py': WebpackBuildCommand, + 'watch': WebpackDevelopCommand, }, zip_safe=False, packages=['sphinx_rtd_theme'], From 46722499622d839e76e090f75280eb00de62cce6 Mon Sep 17 00:00:00 2001 From: Anthony Johnson Date: Mon, 29 Jul 2019 10:56:44 -0600 Subject: [PATCH 2/7] Fix webpack command to run in CI --- setup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0818f0c5..2693a7b1 100644 --- a/setup.py +++ b/setup.py @@ -5,6 +5,7 @@ """ +import os import subprocess import distutils.cmd import setuptools.command.build_py @@ -17,7 +18,8 @@ class WebpackBuildCommand(setuptools.command.build_py.build_py): """Prefix Python build with Webpack asset build""" def run(self): - subprocess.run(['webpack', '--config', 'webpack.prod.js'], check=True) + if not 'CI' in os.environ: + subprocess.run(['webpack', '--config', 'webpack.prod.js'], check=True) super().run() From af521d644dced902112294e9e53e71320c51b20f Mon Sep 17 00:00:00 2001 From: Anthony Johnson Date: Mon, 29 Jul 2019 11:04:41 -0600 Subject: [PATCH 3/7] Make super() py2/3 compat --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2693a7b1..4acce80f 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ class WebpackBuildCommand(setuptools.command.build_py.build_py): def run(self): if not 'CI' in os.environ: subprocess.run(['webpack', '--config', 'webpack.prod.js'], check=True) - super().run() + super(WebpackBuildCommand, self).run() class WebpackDevelopCommand(distutils.cmd.Command): From 00cc82c2f2ae69088edb115d3f458c253deca652 Mon Sep 17 00:00:00 2001 From: Anthony Johnson Date: Mon, 29 Jul 2019 11:10:31 -0600 Subject: [PATCH 4/7] Not an object class anyways, drop super --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 4acce80f..5951c330 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ class WebpackBuildCommand(setuptools.command.build_py.build_py): def run(self): if not 'CI' in os.environ: subprocess.run(['webpack', '--config', 'webpack.prod.js'], check=True) - super(WebpackBuildCommand, self).run() + WebpackBuildCommand.run(self) class WebpackDevelopCommand(distutils.cmd.Command): From 28ca8458a331be9b68a8830d3474a6af308c6c96 Mon Sep 17 00:00:00 2001 From: Anthony Johnson Date: Mon, 29 Jul 2019 11:29:49 -0600 Subject: [PATCH 5/7] Old classes are The Worst --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5951c330..cd03a162 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ class WebpackBuildCommand(setuptools.command.build_py.build_py): def run(self): if not 'CI' in os.environ: subprocess.run(['webpack', '--config', 'webpack.prod.js'], check=True) - WebpackBuildCommand.run(self) + setuptools.command.build_py.build_py.run(self) class WebpackDevelopCommand(distutils.cmd.Command): From 04f5c9281c140850e372eb3f93dab79e8c5dad6f Mon Sep 17 00:00:00 2001 From: Anthony Date: Thu, 22 Aug 2019 12:33:05 -0600 Subject: [PATCH 6/7] Update setup.py Co-Authored-By: Jesse Tan --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index cd03a162..5221ec0b 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ class WebpackBuildCommand(setuptools.command.build_py.build_py): def run(self): if not 'CI' in os.environ: - subprocess.run(['webpack', '--config', 'webpack.prod.js'], check=True) + subprocess.run(['node_modules/.bin/webpack', '--config', 'webpack.prod.js'], check=True) setuptools.command.build_py.build_py.run(self) From 9fee2a2585c90002aec6c0ca6ac38bb50fc3e3dd Mon Sep 17 00:00:00 2001 From: Anthony Date: Thu, 22 Aug 2019 12:33:15 -0600 Subject: [PATCH 7/7] Update setup.py Co-Authored-By: Jesse Tan --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5221ec0b..dd6a1494 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ class WebpackDevelopCommand(distutils.cmd.Command): def run(self): subprocess.run( - ["webpack-dev-server", "--open", "--config", "webpack.dev.js"], + ["node_modules/.bin/webpack-dev-server", "--open", "--config", "webpack.dev.js"], check=True )