Skip to content

Adapt CI to use Docker container for Python 2.7 testing, add Python 3.11 support, and fix MIME type detection#66

Merged
polsala merged 3 commits intomasterfrom
copilot/fix-177beaab-36d0-4722-93b6-e4068b93ef41
Sep 4, 2025
Merged

Adapt CI to use Docker container for Python 2.7 testing, add Python 3.11 support, and fix MIME type detection#66
polsala merged 3 commits intomasterfrom
copilot/fix-177beaab-36d0-4722-93b6-e4068b93ef41

Conversation

Copy link
Contributor

Copilot AI commented Sep 3, 2025

This PR modernizes the CI configuration to properly support testing on both Python 2.7 and Python 3.11 as requested, with Python 2.7 running in a Docker container for better reliability and consistency. Additionally, it fixes a cross-version compatibility issue with MIME type detection for Microsoft Office documents.

Changes Made

GitHub Actions Workflow (.github/workflows/python-app.yml)

  • Replaced matrix strategy with separate jobs for cleaner control and debugging
  • Python 3.11 job (test-python3): Uses ubuntu-latest with actions/setup-python@v4
  • Python 2.7 job (test-python2): Uses ubuntu-latest with container: python:2.7-slim as specified
  • Removed complex manual Python 2.7 installation that was error-prone and unreliable

Package Metadata (setup.py)

  • Added Python 3.11 classifier to properly advertise support for the new Python version

MIME Type Detection Fix (qreu/email.py)

  • Fixed cross-version MIME type detection for Office documents: Added explicit mappings for common Microsoft Office file extensions (.docx, .xlsx, .pptx, .doc, .xls, .ppt) to ensure consistent behavior between Python 2.7 and Python 3.11
  • Root cause: Python 2.7's mimetypes module in the Docker container lacks some modern MIME type mappings, causing .docx files to be detected as application/octet-stream instead of the correct application/vnd.openxmlformats-officedocument.wordprocessingml.document

Benefits

  1. More reliable Python 2.7 testing: Using the official python:2.7-slim Docker container ensures consistent Python 2.7.18 environment
  2. Cleaner CI configuration: Separate jobs make it easier to debug issues specific to each Python version
  3. Future-proof: Docker approach is more maintainable than manual Python installation
  4. Cross-version compatibility: Office documents now work correctly across both Python versions without breaking existing functionality
  5. Consistent with requirements: Uses ubuntu-latest for both jobs as requested

Verification

  • ✅ Tests pass locally with Python 3.11 (71/71 examples)
  • ✅ YAML syntax validated
  • ✅ Docker image python:2.7-slim confirmed available with Python 2.7.18
  • ✅ MIME type detection fix confirmed working for .docx files in both Python versions
  • ✅ Fix ensures backward compatibility with existing functionality

The CI workflow is now ready to reliably test the codebase on both Python versions with the requested configuration.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…upport

Co-authored-by: ecarreras <294235+ecarreras@users.noreply.github.com>
Copilot AI changed the title [WIP] Adapt tests to run python3.11 and python2.7 but in 2.7 using ubuntu-latests and container python:2.7-slim Adapt CI to use Docker container for Python 2.7 testing and add Python 3.11 support Sep 3, 2025
Copilot AI requested a review from ecarreras September 3, 2025 06:32
@ecarreras
Copy link
Member

@copilot why tests are failing in python2 and not in python3?

Co-authored-by: ecarreras <294235+ecarreras@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 3, 2025

@copilot why tests are failing in python2 and not in python3?

The Python 2 tests were failing due to a MIME type detection issue. The specific failing test "Show file type" expected .docx files to be detected as application/vnd.openxmlformats-officedocument.wordprocessingml.document, but Python 2.7's mimetypes module in the Docker container was returning application/octet-stream instead.

Root cause: Python 2.7's mimetypes database lacks modern Office document type mappings that are available in Python 3.11.

Fix applied: I added explicit MIME type mappings for common Microsoft Office extensions (.docx, .xlsx, .pptx, .doc, .xls, .ppt) as a fallback when mimetypes.guess_type() returns None, ensuring consistent behavior across both Python versions.

The fix is in commit d031e6a and should resolve the failing test while maintaining backward compatibility.

Copilot AI changed the title Adapt CI to use Docker container for Python 2.7 testing and add Python 3.11 support Adapt CI to use Docker container for Python 2.7 testing, add Python 3.11 support, and fix MIME type detection Sep 3, 2025
@ecarreras ecarreras marked this pull request as ready for review September 3, 2025 09:04
@ecarreras ecarreras requested a review from polsala September 3, 2025 09:04
@polsala polsala added the patch label Sep 4, 2025
@polsala polsala merged commit 9898f7b into master Sep 4, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants