CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-sphinx-rtd-theme

Read the Docs theme for Sphinx documentation with responsive design and interactive navigation

Overview
Eval results
Files

build-system.mddocs/

Build System Integration

Asset compilation and translation management system with webpack integration, custom setup.py commands, and npm script integration for theme development and distribution.

Python Build Commands

Custom distutils commands available via python setup.py <command> for theme development and asset management.

WebpackBuildCommand

class WebpackBuildCommand(distutils.cmd.Command):
    """
    Generate static assets via webpack production build.
    
    Command: python setup.py build_assets
    
    Actions:
    - Runs npm install to ensure dependencies
    - Executes webpack production build via webpack.prod.js
    - Skips build in CI and TOX environments
    
    Environment Detection:
    - Skips if 'CI' environment variable is set
    - Skips if 'TOX_ENV_NAME' environment variable is set
    """

Usage:

# Build production assets
python setup.py build_assets

# Equivalent npm command
npm run build

WebpackDevelopCommand

class WebpackDevelopCommand(distutils.cmd.Command):
    """
    Run webpack development server with live reloading.
    
    Command: python setup.py watch
    
    Actions:
    - Starts webpack-dev-server with hot module replacement
    - Opens browser automatically
    - Uses webpack.dev.js configuration
    - Provides live reloading for development
    """

Usage:

# Start development server
python setup.py watch

# Equivalent npm command  
npm run dev

Translation Management

UpdateTranslationsCommand

class UpdateTranslationsCommand(distutils.cmd.Command):
    """
    Run complete localization workflow.
    
    Command: python setup.py update_translations
    
    Sub-commands (executed in order):
    1. extract_messages - Extract translatable strings
    2. update_catalog - Update existing translation files
    3. transifex - Push/pull translations from Transifex
    4. compile_catalog - Compile .po files to .mo files
    """

TransifexCommand

class TransifexCommand(distutils.cmd.Command):
    """
    Update translation files through Transifex service.
    
    Command: python setup.py transifex
    
    Actions:
    - Pushes source strings to Transifex (tx push --source)
    - Pulls reviewed translations (tx pull --mode onlyreviewed -f -a)
    
    Requirements:
    - transifex-client package installed
    - Transifex project configured
    """

NPM Scripts Integration

Package.json scripts for frontend development workflow:

Development Script

{
  "scripts": {
    "dev": "webpack-dev-server --open --config webpack.dev.js"
  }
}

Starts development server with:

  • Live reloading for SCSS/JS changes
  • Automatic browser opening
  • Hot module replacement
  • Source maps for debugging

Production Build Script

{
  "scripts": {
    "build": "webpack --config webpack.prod.js"
  }
}

Creates optimized production assets:

  • Minified CSS and JavaScript
  • Optimized images and fonts
  • Asset fingerprinting for caching
  • Compressed file sizes

Pre-installation Script

{
  "scripts": {
    "preinstall": "bin/preinstall.js"
  }
}

Runs automatically before npm install to handle environment-specific setup requirements.

Webpack Configuration

Development Configuration (webpack.dev.js)

// Development-specific webpack settings
module.exports = {
  mode: 'development',
  devtool: 'eval-source-map',
  devServer: {
    contentBase: './sphinx_rtd_theme/static',
    hot: true,
    open: true
  },
  // SCSS compilation with source maps
  // Live reloading for template changes
  // Unminified output for debugging
}

Production Configuration (webpack.prod.js)

// Production-specific webpack settings  
module.exports = {
  mode: 'production',
  optimization: {
    minimizer: [
      new OptimizeCSSAssetsPlugin(),
      new UglifyJsPlugin()
    ]
  },
  // SCSS compilation and minification
  // Asset optimization and compression
  // File fingerprinting for cache busting
}

Common Configuration (webpack.common.js)

// Shared webpack configuration
module.exports = {
  entry: './src/theme.js',
  output: {
    path: path.resolve(__dirname, 'sphinx_rtd_theme/static'),
    filename: 'js/theme.js'
  },
  module: {
    rules: [
      // SCSS processing
      // JavaScript compilation  
      // Font and image handling
      // CSS extraction
    ]
  }
}

Asset Pipeline

Source Files

// Source structure
src/
├── theme.js          // Main JavaScript entry point
├── sass/            // SCSS stylesheets  
│   ├── theme.scss   // Main stylesheet
│   └── _*.scss      // Partials and components
└── fonts/           // Font assets

Compiled Output

// Output structure in sphinx_rtd_theme/static/
static/
├── css/
│   ├── theme.css    // Compiled and minified CSS
│   └── fonts/       // Web font files
└── js/
    └── theme.js     // Compiled and minified JavaScript

Build Dependencies

NPM Development Dependencies

{
  "devDependencies": {
    "webpack": "^4.46.0",
    "webpack-cli": "^3.3.12", 
    "webpack-dev-server": "^3.11.2",
    "webpack-merge": "^4.2.1",
    "node-sass": "^4.14.1",
    "sass-loader": "^7.3.0",
    "css-loader": "^3.6.0",
    "mini-css-extract-plugin": "^0.6.0",
    "optimize-css-assets-webpack-plugin": "^5.0.4",
    "font-awesome": "^4.7.0",
    "jquery": "^3.6.0"
  }
}

Python Development Dependencies

# setup.cfg [options.extras_require]
dev = [
    "transifex-client",  # Translation management
    "bump2version",      # Version bumping
    "wheel",            # Package building
    "twine"             # Package publishing
]

Translation Workflow

Babel Configuration

# babel.cfg - Translation extraction configuration
[python: **.py]
[jinja2: **/templates/**.html]
encoding = utf-8

Message Extraction

# setup.cfg - Babel extraction settings
[extract_messages]
mapping_file = babel.cfg
output_file = sphinx_rtd_theme/locale/sphinx.pot
keywords = _ l_ lazy_gettext
add_comments = Translators:

Catalog Management

# setup.cfg - Translation catalog settings
[update_catalog]
domain = sphinx
input_file = sphinx_rtd_theme/locale/sphinx.pot
output_dir = sphinx_rtd_theme/locale/

[compile_catalog]
domain = sphinx
directory = sphinx_rtd_theme/locale/

Usage Examples

Development Workflow

# Set up development environment
npm install
pip install -e .[dev]

# Start development server
python setup.py watch
# OR
npm run dev

# Build production assets
python setup.py build_assets
# OR  
npm run build

Translation Management

# Extract translatable strings
python setup.py extract_messages

# Update translation files
python setup.py update_catalog

# Sync with Transifex
python setup.py transifex

# Compile translations
python setup.py compile_catalog

# Complete translation workflow
python setup.py update_translations

CI/CD Integration

# In CI environment (NODE_ENV=production, CI=true)
# Assets are built automatically during package installation
pip install sphinx-rtd-theme

# Manual asset building disabled in CI
python setup.py build_assets  # Skipped due to CI environment

Custom Build Integration

# Custom setup.py extension
from sphinx_rtd_theme.setup import WebpackBuildCommand

class CustomBuildCommand(WebpackBuildCommand):
    def run(self):
        # Custom pre-build steps
        super().run()
        # Custom post-build steps
        
setup(
    cmdclass={
        'build_assets': CustomBuildCommand,
    }
)

Package Distribution

Static Asset Inclusion

# setup.cfg - Package data inclusion
[options.package_data]
sphinx_rtd_theme = [
    "theme.conf",
    "*.html", 
    "static/css/*.css",
    "static/css/fonts/*.*",
    "static/js/*.js"
]

MANIFEST.in

# Include additional files in source distribution
include *.rst *.txt *.yml *.yaml *.json
include babel.cfg
include webpack*.js
recursive-include sphinx_rtd_theme/locale *.po *.pot
recursive-include src *.js *.scss

Install with Tessl CLI

npx tessl i tessl/pypi-sphinx-rtd-theme

docs

build-system.md

index.md

javascript-navigation.md

python-extension.md

theme-configuration.md

tile.json