Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG - Fix i18n files and compilation for distribution #2042

Merged
merged 17 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add comments to webpack
  • Loading branch information
trallard committed Nov 18, 2024
commit ed1decbf4cea3604ed2a738ddee6c7c40b59580e
38 changes: 17 additions & 21 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ permissions:

jobs:
# calls our general CI workflow (tests, build docs, etc.)
# tests:
# uses: ./.github/workflows/CI.yml
# # needed for the coverage action
# permissions:
# contents: write
# pull-requests: write
tests:
uses: ./.github/workflows/CI.yml
# needed for the coverage action
permissions:
contents: write
pull-requests: write

build-package:
name: "Build & verify PST package"
# needs: [tests] # require tests to pass before deploy runs
needs: [tests] # require tests to pass before deploy runs
runs-on: ubuntu-latest
steps:
- name: "Checkout repository 🛎"
Expand All @@ -39,10 +39,6 @@ jobs:
python-version: "3.9"
pandoc: "False"

- name: "Compile localization"
run:
tox run -e i18n-compile

- name: "Build and inspect package 📦"
uses: hynek/build-and-inspect-python-package@v2
id: baipp
Expand All @@ -65,14 +61,14 @@ jobs:
run: |
tar xvf dist/*.tar.gz --strip-components=1

# - name: "Publish PST package to PyPI 🚀"
# uses: pypa/gh-action-pypi-publish@release/v1
# # only publish if this is a published release by pydata
# if: github.repository_owner == 'pydata' && github.event_name == 'release' && github.event.action == 'published'
- name: "Publish PST package to PyPI 🚀"
uses: pypa/gh-action-pypi-publish@release/v1
# only publish if this is a published release by pydata
if: github.repository_owner == 'pydata' && github.event_name == 'release' && github.event.action == 'published'

# - name: "Publish PST package to scientific-python-nightly-wheels 🚀"
# uses: scientific-python/upload-nightly-action@82396a2ed4269ba06c6b2988bb4fd568ef3c3d6b # 0.6.1
# with:
# artifacts_path: dist
# anaconda_nightly_upload_token: ${{ secrets.ANACONDA_ORG_UPLOAD_TOKEN }}
# if: github.repository_owner == 'pydata' && github.event_name == 'schedule'
- name: "Publish PST package to scientific-python-nightly-wheels 🚀"
uses: scientific-python/upload-nightly-action@82396a2ed4269ba06c6b2988bb4fd568ef3c3d6b # 0.6.1
with:
artifacts_path: dist
anaconda_nightly_upload_token: ${{ secrets.ANACONDA_ORG_UPLOAD_TOKEN }}
if: github.repository_owner == 'pydata' && github.event_name == 'schedule'
11 changes: 3 additions & 8 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,16 @@ const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const dedent = require("dedent");
const { Compilation } = require("webpack");
const { exec } = require("child_process");

/*******************************************************************************
* Paths for various assets (sources and destinations)
*/

const scriptPath = resolve(__dirname, "src/pydata_sphinx_theme/assets/scripts");
const staticPath = resolve(__dirname, "src/pydata_sphinx_theme/theme/pydata_sphinx_theme/static");
const { exec } = require("child_process");
const localePath = resolve(__dirname, "src/pydata_sphinx_theme/locale");


/*******************************************************************************
* Compile our translation files
*/
// exec(`pybabel compile -d ${localePath} -D sphinx`);

/*******************************************************************************
* functions to load the assets in the html head
* the css, and js (preload/scripts) are digested for cache busting
Expand Down Expand Up @@ -180,7 +174,8 @@ var config = {
};

module.exports = (env, argv) => {
if (argv.mode === 'development') {
// since STB isolates the build, we need to compile the translations here for releases
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide a link in this code comment to more info? What does it mean that STB isolates the build?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Under the hood stb uses build for perform stb package (which in turn calls python -m build).
build builds the package in an isolated env to create the source distribution (https://build.pypa.io/en/stable/)

That means, when compiling assets from tox (or even doing npm run build during development or in our CI) it would result in something like

# note I added a simple console print to demonstrate
Webpack is building the theme in my-local-dir/pydata-sphinx-theme/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/static
Locale will be located in my-local-dir/pydata-sphinx-theme/src/pydata_sphinx_theme/locale

When calling via stb package or python -m build (which is what we do to build the dist) this is instead

Webpack is building the theme in /private/var/folders/6p/062gm41556s5p63x1555cjzw0000gn/T/build-via-sdist-rmc_7ti7/pydata_sphinx_theme-0.16.1.dev0/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/static
Locale will be located in /private/var/folders/6p/062gm41556s5p63x1555cjzw0000gn/T/build-via-sdist-rmc_7ti7/pydata_sphinx_theme-0.16.1.dev0/src/pydata_sphinx_theme/locale

so if you compile the translation files first with tox run -e i18n-compile then the compiled .mo will not be included in the distribution files by default (this isolation helps to avoid unwanted files and what not to be added to the distribution packages afterall)

if (argv.mode === 'production') {
exec(`pybabel compile -d ${localePath} -D sphinx`, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
Expand Down