executablebooks / meta

A community dedicated to supporting tools for technical and scientific communication and interactive computing
https://executablebooks.org
128 stars 164 forks source link

Handling resource compilation in sphinx extensions (SCSS,JS,TS)) #137

Open chrisjsewell opened 3 years ago

chrisjsewell commented 3 years ago

Originally posted by @chrisjsewell in https://github.com/executablebooks/sphinx-panels/pull/32#issuecomment-692871773 (also discussed in executablebooks/sphinx-panels#31)

just to finish my thoughts here, basically as you say each option seems to have an annoying tradeoff. Putting aside JavaScript compilation for now, my ideal goals are:

pradyunsg commented 3 years ago

Assuming we provide wheels, treating SCSS as a "compilable" artifact should satisfy these. We'd need $compiler-toolchain if we ever go source/git-repo -> installed (instead of wheel -> installed) tho.

chrisjsewell commented 3 years ago

Could you expand on this a bit. What's the physical setup you envisage for the repo/workflow?

chrisjsewell commented 3 years ago

Is there a way to hook into setuptools/distutils etc, to run arbitrary pre-build code (to create the compiled CSS files)? It looks like you can maybe use the cmdclass option in setuptools.setup, but I couldn't find any good documentation on it that wasn't specifically for compiling C extensions.

akhmerov commented 3 years ago

Is there a way to hook into setuptools/distutils etc, to run arbitrary pre-build code (to create the compiled CSS files)?

Yep! Check this out: https://gitlab.kwant-project.org/kwant/mumpy/-/blob/master/setup.py we render a jinja template to generate a cython file, which we cythonize to C.

chrisjsewell commented 3 years ago

Ah brilliant thanks @akhmerov, have you found any drawbacks/gotchas with this approach?

akhmerov commented 3 years ago

The setuptools part never gave any trouble. Obviously your build env needs to have all the tooling, but the rest is smooth sailing. e.g. pip only ever sees the built files

pradyunsg commented 3 years ago

@akhmerov made my entire long-form comment redundant (that I was writing) because I came up with the same approach as mumpy is already using. :)

chrisjsewell commented 3 years ago

perfect ok ta, I can give a go at setting this up for sphinx-panels. If that goes well can then try rolling out to sphinx-book-theme, which is a little trickier, because you also want to replace the CSS file name in theme.conf, etc

pradyunsg commented 3 years ago

Consider making it a separate package that we could depend on at build-time?

chrisjsewell commented 3 years ago

Yeh quite possibly. For simplicity, I'm initially just going to put all the code in sphinx-panels. Then we can look to extract the repo independent stuff into a separate package.

pradyunsg commented 3 years ago

One fun thing to note here -- we would want to check what is available in the ReadTheDocs build environments; I'm not sure they ship with npm and friends, and that'd be a -ve for this approach. :(