Commit Graph
21 Commits
Author SHA1 Message Date
David Landa Marban 1fd280c68d Removing trailing spaces and adding eol at eof 2025-10-02 10:22:55 +02:00
Håkon Hægland bd402ee230 Fix auto-detection by not setting PYTHON_VERSIONS when not specified
The auto-detection wasn't working because the
CLI was always setting PYTHON_VERSIONS environment variable to all supported
versions when --python-versions was not provided.

Changes:
- click_helpers.py: Return None instead of all versions when option not provided
- helpers.py: Only set PYTHON_VERSIONS env var when explicitly specified
- main.py: Update type hints to allow None for python_versions parameter

Now the flow works correctly:
1. No --python-versions CLI option -> python_versions = None
2. None passed to Docker -> no PYTHON_VERSIONS env var set
3. Container auto-detects installed versions using pyenv
4. Tests run only on detected versions
2025-09-23 12:42:48 +02:00
Håkon Hægland 85344a3998 Auto-detect installed Python versions at runtime
When no --python-versions is specified at
runtime, auto-detect which Python versions are actually installed in the
container instead of defaulting to all versions from python_versions.json.

This resolves the issue where:
1. Building with --python-versions=3.12 installs only Python 3.12
2. Running without --python-versions would try to test all versions from JSON
3. Tests would fail for non-installed versions (3.8, 3.9, 3.10, 3.11, 3.13)

Now the runtime logic:
1. Uses `pyenv versions --bare` to detect installed versions
2. Maps full versions (3.12.9) to short versions (3.12)
3. Uses detected versions as default for testing
4. Falls back to JSON versions if detection fails

Example behavior:
- Build: --python-versions=3.12 (installs only 3.12.9)
- Runtime: auto-detects 3.12, tests only that version
- Explicit: --python-versions=3.11,3.12 still works as before
2025-09-23 11:46:27 +02:00
Håkon Hægland 412773785e Remove references to original behavior 2025-09-23 09:23:58 +02:00
Håkon Hægland f355be1c65 Add debugging documentation for Docker wheel testing
Adds detailed documentation covering all debugging features implemented
in recent commits:

python/docker/test_wheels/scripts/README.md:
- New "Debugging" section with complete workflow examples
- Python version selection for faster builds (--python-versions)
- Focused test selection for isolation (--test-cases-common/simulators)
- Continue-on-error mode for comprehensive failure analysis
- Docker-specific debugging strategies
- Updated CLI option documentation

python/docker/README.md:
- Added debugging section reference with feature highlights
- Links to detailed debugging documentation
2025-09-23 08:31:34 +02:00
Håkon Hægland ac20e8ed87 Add --stop-on-error option for Docker wheel testing
Adds a new CLI option to control test execution behavior when failures occur:
- Without --stop-on-error (default): Continue running all tests even if some fail
- With --stop-on-error: Stop execution on first test failure (previous behavior)

This enables comprehensive debugging by running both opm-common and omp-simulators
tests in a single run, showing all failures at once rather than stopping at the first one.

Changes:
- Add --stop-on-error flag to run-docker-image command
- Pass STOP_ON_ERROR environment variable to Docker container
- Update entrypoint.py to handle continue-on-error behavior
- Modify test functions to check return codes and continue when appropriate
- Maintain backward compatibility with existing error handling
2025-09-23 08:13:53 +02:00
Håkon Hægland ddf2e3d338 Add Python version selection to Docker image builds
This enhancement allows specifying which Python versions to install during
Docker image builds, significantly reducing build times when only testing
specific Python versions during debugging.

Changes:
- Add --python-versions option to build-docker-image command
- Pass BUILD_PYTHON_VERSIONS build argument to Docker
- Update install_python_versions.py to respect BUILD_PYTHON_VERSIONS env var
- Validate requested versions against supported versions in python_versions.json
- Maintain backward compatibility (installs all versions if not specified)

Usage examples:
  # Build with only Python 3.12 (much faster for debugging)
  opm-wheels build-docker-image --docker-os="ubuntu-24.04" --python-versions="3.12"

  # Build with multiple specific versions
  omp-wheels build-docker-image --python-versions="3.11,3.12"

  # Build with all versions (original behavior)
  opm-wheels build-docker-image

Benefits:
- Reduces build time from ~7 minutes to ~2 minutes for single Python version
- Enables faster iteration during debugging of Docker-specific issues
- Particularly valuable when combined with --test-cases-* for focused testing
2025-09-23 07:06:24 +02:00
Håkon Hægland 0b8926c475 Add focused test selection for Docker wheel testing
This enhancement adds the ability to run specific test cases in the Docker
testing infrastructure, enabling more focused debugging and faster iteration
when investigating test failures.

Changes:
- Add --test-cases-common and --test-cases-simulators CLI options to opm-wheels
- Pass test selection as environment variables to Docker container
- Update entrypoint.py to support selective test execution:
  * Run only opm-common tests when --test-cases-common is specified
  * Run only opm-simulators tests when --test-cases-simulators is specified
  * Maintain backward compatibility (run all tests if no selection specified)
- Support both host-tests-dir and cloned repo testing modes

Usage examples:
  # Run only esmry tests from opm-common
  opm-wheels run-docker-image --test-cases-common=esmry

  # Run only basic tests from opm-simulators
  opm-wheels run-docker-image --test-cases-simulators=basic

  # Run specific tests from both suites
  opm-wheels run-docker-image --test-cases-common=esmry --test-cases-simulators=mpi

This enables efficient debugging of Docker-specific test failures by isolating
problematic test cases without running the full test suite.
2025-09-23 06:48:20 +02:00
Arne Morten Kvarving 26660b6640 python packaging: update to use python_simulator_modules target 2025-09-17 14:53:52 +02:00
Arne Morten Kvarving b44692349e python packaging: enable LTO 2025-09-15 09:53:25 +02:00
Håkon Hægland 53270c95b6 docker: clean pip usage and drop pytest-runner
- Export PIP_ROOT_USER_ACTION=ignore to silence root-user warning in manylinux.
- Remove pytest-runner from build-time pip installs; no longer needed after
  removing setup_requires.
2025-09-12 17:57:33 +02:00
Håkon Hægland 31716f2cef docker/python: switch to PEP 517 builds via python -m build
- Replace direct setup.py invocations with: python -m build --sdist --wheel
- Add comments explaining motivation (setuptools deprecations, build isolation)
  and why we drop explicit --plat-name/--python-tag (auditwheel/env handles).
- Ensure the build frontend is present per-interpreter by installing 'build'.

Also add build-backend to pyproject.toml with notes and TODO for full modernization.
2025-09-12 16:00:57 +02:00
Håkon Hægland d5664a5f1c python/docker(test_wheels): prefer hyphenated OS names; accept colon input
- Default --docker-os to ubuntu-22.04
- Normalize input (: -> -) for paths/tags
- Fallback to legacy directories pre-rename
- Update docs with Windows compatibility note
2025-09-12 13:08:40 +02:00
Håkon Hægland bd69d21af8 docker(test_wheels): rename dockerfiles dirs to hyphen (Windows checkout fix)
- debian:11    -> debian-11
- ubuntu:22.04 -> ubuntu-22.04
- ubuntu:24.04 -> ubuntu-24.04

CLI accepts colon or hyphen; code now canonicalizes to hyphen.
2025-09-12 13:06:41 +02:00
Håkon Hægland 922e0c0522 Copy host dir files to container to avoid conflict.
Copy host directory files from opm-simulators/python and
opm-common/python to container to avoid conflict with
opm-simulators/python/opm/ and opm-common/python/opm/ folders when
running "python -m unittest discover" from the python directories.
An alternative would be to rename the opm directories in the host.
2025-09-04 17:15:11 +02:00
Håkon Hægland 9167a35ae4 Add option to use opm python tests folders from host
This will help avoid rebuilding the test containers each time
the host data changes.
2025-09-04 13:25:57 +02:00
Håkon Hægland ec56668d8b Fix path lookup for python_versions.json file 2025-09-04 11:58:17 +02:00
Håkon Hægland 4bc25047c2 Trim white space at EOL 2025-09-04 11:24:05 +02:00
Håkon Hægland be8039a0a8 Add support for version_tag
Add support for adding a version tag to the generated wheels
2025-08-28 11:37:56 +02:00
Håkon Hægland 158ddddca0 Replace head with merge
Don't encourage building PR branches directly
2025-08-28 11:25:25 +02:00
Håkon Hægland 6e2503cac8 Major Python Docker Build System Restructure and Enhancement
Reorganize Python folder: separate Docker/PyPI from CMake/PyBind11 workflows
and implement comprehensive build automation

This commit represents a comprehensive restructuring and enhancement of the
OPM Python build system, addressing maintainability, consistency, and
usability issues through architectural improvements and automation.

FILES CHANGED
=============

Refactored:
- python/Dockerfile -> python/docker/Dockerfile
- python/generate-pypi-package.sh -> python/docker/scripts/generate-pypi-package.sh
- python/setup-docker-image.sh -> python/docker/scripts/setup-docker-image.sh
- python/build-deps.sh -> python/docker/scripts/build-boost.sh
- python/build-deps.sh -> python/docker/scripts/build-dune.sh

Added (24 files):
- python/docker/python_versions.json (single source of truth)
- python/docker/scripts/sync_versions.sh
- python/docker/scripts/read_python_config.py
- python/docker/run-docker-build.sh
- python/docker/README.md
- python/docker/test_wheels/* (complete testing framework)

Modified:
- python/setup.py.in
- .gitignore

MAJOR CHANGES
=============

Architecture Restructure
------------------------
- Separated build workflows: Clearly distinguished Docker/PyPI wheel
  generation from CMake/PyBind11 compilation
- Moved Docker-specific files: Relocated docker build system to
  appropriate locations
- Streamlined organization: Created logical separation between different
  build contexts

Single Source of Truth Configuration
-------------------------------------
- Centralized Python version management: Created python_versions.json as
  authoritative configuration
- Automated synchronization: Built sync_versions.sh script to maintain
  consistency across all components
- Dynamic configuration: Components now read from JSON rather than
  hardcoded values

Enhanced Docker Build System
----------------------------
- Multi-OS support: Added Ubuntu 22.04, Ubuntu 24.04, and Debian 11
  Dockerfiles
- Improved caching: Split dependencies into separate Docker layers for
  better build performance
- Fixed PyPI wheel generation: Added LD_LIBRARY_PATH setup for proper
  library bundling, corrected auditwheel wheel copying from wheelhouse/
  instead of dist/
- Optimized Docker layer structure: Delayed source code copying until
  final stage, preventing dependency rebuilds on source changes and
  reducing iteration time from 30+ to <5 minutes during development

Build Automation & Tooling
--------------------------
- Comprehensive wheel testing: Created opm-wheels CLI tool for building
  and testing Docker images
- Automated validation: Integrated Python version validation and error
  handling
- Enhanced scripts: Improved generate-pypi-package.sh with better error
  handling and version management

Testing Framework
-----------------
- Docker-based testing: Complete framework for testing wheels across
  multiple Python versions and OS configurations
- Automated validation: Wheel installation and import testing with
  comprehensive error reporting
- Multi-version support: Parallel testing across Python 3.8-3.13
- Platform verification: Validates manylinux wheels install and function
  correctly across Ubuntu 22.04/24.04 and Debian 11

Documentation & Usability
-------------------------
- Comprehensive maintenance guides: Detailed instructions for
  adding/removing Python versions
- Clear workflows: Step-by-step procedures for build system maintenance
- Improved CLI experience: Better error messages, path handling, and
  user guidance
- Updated documentation: Enhanced README files with practical examples
  and troubleshooting

IMPACT
======

This restructure transforms the Python build system from a collection of
loosely coupled scripts into a cohesive, maintainable, and reliable build
automation system. The single source of truth configuration eliminates the
primary source of maintenance overhead, while the enhanced testing
framework provides confidence in the quality of generated wheels.

The changes enable the OPM project to more easily support new Python
versions, maintain consistency across platforms, and provide a better
developer experience for both maintainers and users.
2025-08-28 07:24:46 +02:00