Skip to content

Conversation

@ianhelle
Copy link
Contributor

@ianhelle ianhelle commented Dec 9, 2025

PR #867: MSticpy 3.0 and Python 3.13 Support

Important

Major Version Release - This PR introduces breaking changes. Review the migration guide before upgrading.

Version
Python
Status

📋 Overview

Major version release modernizing the codebase with Python 3.13 support, development tooling improvements, and removal of deprecated features.


🎯 Key Changes

🐍 Python Version Support

  • Dropped: Python 3.8 and 3.9
  • Added: Python 3.13
  • Minimum: Python 3.10+
Updated CI Matrix
matrix:
  python-version: ["3.10", "3.11", "3.12", "3.13"]

🛠️ Development Workflow Modernization

Migrated to Ruff

Replaced multiple tools (black, flake8, isort) with unified ruff for linting and formatting:

# pyproject.toml
[tool.ruff]
line-length = 95
target-version = "py310"

[tool.ruff.lint]
select = ["E", "W", "F", "I", "D", "UP", "B", "C4", "PL"]
ignore = ["E401", "E501", "W503", "D212", "D203", "D417"]

Changes:

  • ✅ Updated .pre-commit-config.yaml and GitHub Actions workflows
  • ✅ Removed obsolete dev dependencies
  • ✅ Increased pylint max line length: 90 → 110 characters

Removed dependencies:

- black>=20.8b1
- flake8>=3.8.4
- isort>=5.10.1
- pydocstyle>=6.0.0
- pep8-naming>=0.10.0

🗑️ Deprecated Features Removed

Warning

The following features have been completely removed in v3.0

KqlMagic Integration

  • Removed all KqlMagic imports and environment variable handling
  • Cleaned up msticpy/__init__.py KqlMagic configuration
  • Removed from requirements: KqlmagicCustom[jupyter-extended]

AI Agents Modules

- msticpy/aiagents/config_utils.py
- msticpy/aiagents/mp_docs_rag_magic.py

Legacy Query Drivers

  • Removed test_kql_driver.py (254 lines)
  • Removed test_kusto_driver.py (372 lines)
  • Cleaned up legacy driver tests

Deprecated Pandas Accessors

# ❌ Old (removed)
df.mp_timeline.plot()
df.mp_process_tree.plot()
df.mp_whois.lookup()

# ✅ New (use these)
df.mp_plot.timeline()
df.mp_plot.process_tree()
df.mp.whois()

📦 Dependencies & Configuration

Package Change Impact
importlib-resources Removed (Python ≤3.8) Cleanup
mo-sql-parsing 2.x11.x ⚠️ Breaking
ipython Now >=7.23.1 (unified) Cleanup

Documentation Updates

  • 📝 "Azure Sentinel" → "Microsoft Sentinel" (branding update)
  • 📝 Updated README.md with Python 3.10+ requirement
  • 📝 Removed outdated badge references

💻 Code Quality Improvements

Type Hints Modernization
# Before
from typing import Union, Optional, List, Dict

def foo(x: Optional[str]) -> Union[List[str], Dict[str, str]]:
    pass

# After  
def foo(x: str | None) -> list[str] | dict[str, str]:
    pass
Import Modernization
# Before
from typing import Iterable, Iterator

# After
from collections.abc import Iterable, Iterator

Additional improvements:

  • 🔧 Applied Ruff formatting across 350+ files
  • 🧪 Added pytest filter warnings for deprecated patterns
  • 🐛 Fixed timezone warnings (datetime.utcnow()datetime.now(timezone.utc))

🔧 CI/CD Updates

# GitHub Actions improvements
- name: Free Disk Space
  run: # Added disk cleanup steps
  
- name: Setup Python
  with:
    python-version: ["3.10", "3.11", "3.12", "3.13"]

- name: Ruff Check
  run: ruff check msticpy --ignore PLW0603

Simplified workflows:

  • ❌ Removed: black, flake8, pydocstyle steps
  • ✅ Added: Unified ruff check and ruff format

⚠️ Breaking Changes

Users upgrading to v3.0 should note:

  1. Python 3.8/3.9 no longer supported - Upgrade to Python 3.10+
  2. KqlMagic functionality removed - No direct replacement
  3. Legacy pandas accessors deprecated - Use new mp_plot and mp accessors
  4. mo-sql-parsing v2 → v11 - SQL parsing behavior may differ
  5. Removed AI agents experimental features - Code removed entirely

🚀 Migration Guide

Step 1: Upgrade Python

# Check current version
python --version

# Upgrade to 3.10 or later
conda create -n msticpy-3.0 python=3.10
conda activate msticpy-3.0

Step 2: Update Code

Replace deprecated accessor methods:

# Timeline plotting
df.mp_timeline.plot(...)           # ❌ Old
df.mp_plot.timeline(...)           # ✅ New

# Process tree
df.mp_process_tree.plot(...)       # ❌ Old  
df.mp_plot.process_tree(...)       # ✅ New

# WHOIS lookups
df.mp_whois.lookup(...)            # ❌ Old
df.mp.whois(...)                   # ✅ New

Step 3: Update Dependencies

# Upgrade msticpy
pip install --upgrade msticpy==3.0.0.pre1

# Review pinned dependencies
pip list | grep mo-sql-parsing

📊 Statistics

  • Files Changed: ~350+
  • Lines Added: ~15,000+
  • Lines Removed: ~10,000+
  • Test Coverage: All checks passing ✅
  • Reviewers: @ryan-detect-dot-dev (Approved)

📚 Related Links


Reviewer Comments

@ryan-detect-dot-dev:

Only minor questions, otherwise LGTM

Resolved discussions:

  • Line length alignment between ruff and pylint
  • Python 3.8 dependency cleanup
  • Target Python version for Ruff configuration

Tip

Status: Open | All checks passing
Ready to merge pending final approval

ianhelle and others added 30 commits October 16, 2025 11:42
- Updating pyautogen dependencies for Python 3.13
Also excluding some test functions for linux
- implementing ruff as primary linter
- updating type annotations to modern format
…e/py313-cleanup-2025-12-08

# Conflicts:
#	msticpy/aiagents/rag_agents.py
#	msticpy/data/sql_to_kql.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…e/py313-cleanup-2025-12-08

# Conflicts:
#	msticpy/analysis/outliers.py
#	msticpy/init/azure_ml_tools.py
- also removing unneeded dependencies
- cleaning up unit tests
- removing build for Python 3.8 and 3.9
- setting version to 3.0.0.pre1
@ianhelle ianhelle changed the title Ianhelle/py313 cleanup 2025 12 08 Ianhelle/msticpy 3.0 - 2025 12 08 Dec 15, 2025
…/py313-cleanup-2025-12-08

# Conflicts:
#	.github/workflows/python-package.yml
#	conda/conda-reqs-pip.txt
#	msticpy/aiagents/mp_docs_rag_magic.py
#	msticpy/aiagents/rag_agents.py
#	msticpy/analysis/outliers.py
#	msticpy/context/tiproviders/pulsedive.py
#	msticpy/data/drivers/kql_driver.py
#	requirements-all.txt
#	setup.py
#	tests/aiagents/test_rag_agents.py
@ianhelle ianhelle changed the title Ianhelle/msticpy 3.0 - 2025 12 08 Ianhelle/msticpy 3.0/Python 3.13 Dec 15, 2025
@ianhelle ianhelle changed the title Ianhelle/msticpy 3.0/Python 3.13 Ianhelle/msticpy 3.0 and Python 3.13 Dec 15, 2025
Copy link
Collaborator

@ryan-detect-dot-dev ryan-detect-dot-dev left a comment

Choose a reason for hiding this comment

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

Only minor questions, otherwise LGTM

## Overview
This commit represents a major modernization effort for MSticPy 3.0, dropping support for Python 3.8 and 3.9 to leverage modern Python features and clean up technical debt.

## Breaking Changes

### Python Version Requirements
- **Minimum Python version raised from 3.8 to 3.10**
- Updated in `setup.cfg`: `python_requires = >=3.10`
- Updated build target in `pyproject.toml`: `target-version = "py310"`
- Removed Python version-specific conditionals from requirements files

### Dependency Cleanup
- Removed `importlib-resources` (only needed for Python ≤3.8)
- Simplified `ipython` dependency (removed version-specific conditionals)
- Removed outdated conditional dependencies from:
  - `requirements.txt`
  - `requirements-all.txt`
  - `conda/conda-reqs-pip.txt`
  - `conda/conda-reqs-dev.txt`

## Code Quality Improvements

### Type Hint Modernization
- Replaced legacy `typing.Union` with modern `|` union syntax (PEP 604)
- Replaced `typing.Optional` with `| None` where appropriate
- Updated type hints across 300+ files for improved readability

### Code Style and Linting
- Updated `.pylintrc`: max line length reduced from 110 to 95 characters
- Enhanced `pyproject.toml` with comprehensive Ruff configuration:
  - Line length: 95 characters (consistent with pylint)
  - Target version: Python 3.10
  - Enabled rule sets: pycodestyle, pyflakes, isort, pydocstyle, pyupgrade, flake8-bugbear
  - Configured numpy-style docstring convention
- Updated `.pre-commit-config.yaml` with modern linting tools

## Deprecated Code Removal

### AI Agents Module
Removed entire `msticpy/aiagents/` module (deprecated functionality):
- `config_utils.py`
- `mp_docs_rag_magic.py`
- `rag_agents.py`
- Associated test file `tests/aiagents/test_rag_agents.py`

### Legacy Data Drivers
Removed deprecated and obsolete driver files:
- `msticpy/data/drivers/kql_driver.py` (587 lines removed)
- `msticpy/data/drivers/kusto_driver.py` (296 lines removed)
- Associated test files:
  - `tests/data/drivers/test_kql_driver.py`
  - `tests/data/drivers/test_kusto_driver.py`

### Deprecated Aliases and Shims
Removed compatibility shims and deprecated module aliases:
- `msticpy/common/azure_auth.py`
- `msticpy/data/azure/` directory (legacy Azure modules)
- `msticpy/data/azure_blob_storage.py`
- `msticpy/data/azure_data.py`
- `msticpy/data/azure_sentinel.py`
- `msticpy/data/data_providers.py`
- `msticpy/data/query_container.py`
- `msticpy/data/query_defns.py`
- `msticpy/datamodel/pivot.py`
- Entire `msticpy/nbtools/` compatibility layer
- Entire `msticpy/sectools/` compatibility layer (450+ lines removed)

### Visualization Cleanup
- Removed `msticpy/vis/morph_charts.py` (162 lines)
- Removed `msticpy/vis/timeline_pd_accessor.py` (266 lines)
- Removed associated test file `tests/vis/test_morph_charts.py`

## Enhanced Functionality

### SQL to KQL Improvements
- Significantly enhanced `msticpy/data/sql_to_kql.py` (139 lines modified)
- Expanded test coverage in `tests/data/test_sql_to_kql.py` (300+ lines added)
- Better handling of SQL parsing edge cases

### Azure ML and Synapse Tools
- Modernized `msticpy/init/azure_ml_tools.py` (115 lines cleaned)
- Updated `msticpy/init/azure_synapse_tools.py` for Python 3.10+

### Data Processing
- Streamlined `msticpy/data/data_obfus.py` (95 lines removed)
- Enhanced process tree builders with modern type hints

## Testing and CI/CD

### GitHub Workflows
- Updated `.github/workflows/python-package.yml` (38 modifications)
- Removed `.github/workflows/codeql.yml` (92 lines removed - outdated configuration)

### Test Suite Updates
- Removed tests for deprecated modules
- Updated test fixtures and utilities in `tests/unit_test_lib.py`
- Fixed compatibility issues in pivot tests

## Documentation
- Updated `README.md` with current Python version requirements
- Added comprehensive API documentation for new Prisma Cloud driver
- Updated Sphinx configuration in `docs/source/conf.py`

## Statistics
- **343 files changed**
- **1,490 insertions(+)**
- **5,606 deletions(-)**
- **Net reduction: 4,116 lines of code removed**

## Migration Notes
For users upgrading to MSticPy 3.0:

1. **Python Version**: Ensure you're using Python 3.10 or later
2. **Removed Modules**: The following deprecated modules have been removed:
   - `msticpy.aiagents.*`
   - `msticpy.sectools.*` (use `msticpy.transform.*` and `msticpy.analysis.*`)
   - `msticpy.nbtools.*` (use `msticpy.vis.*` and `msticpy.init.*`)
   - Legacy Azure module aliases (use `msticpy.data.storage.*` and `msticpy.context.azure.*`)
3. **Dependencies**: The package now has fewer dependencies due to Python 3.10+ baseline
4. **Type Hints**: Code using MSticPy's type hints may benefit from better IDE support with modern union syntax

## Related
- PR #867: MSticPy 3.0 and Python 3.13 Support
- Branch: `ianhelle/py313-cleanup-2025-12-08`
- Replace legacy typing imports (Union, Optional, List, Dict, etc.) with modern syntax
- Convert Optional[X] to X | None (PEP 604)
- Convert Union[X, Y] to X | Y (PEP 604)
- Convert typing.List/Dict/Set/Tuple to list/dict/set/tuple (PEP 585)
- Convert isinstance() tuple checks to use | syntax where safe
- Remove unused typing imports and fix duplicate import
- Auto-format all code with ruff format
- All ruff checks pass

Files affected: 200+ files across msticpy codebase
Total fixes: 1800+ type hint modernizations

Note: Some lines exceed 95 char limit (pylint C0301) - will address separately
When removing the duplicate import 'from collections.abc import Iterable as C_Iterable',
I forgot to update code that was still using C_Iterable. Changed to use Iterable directly.

Fixes test_context_provider[ServiceNow] failure.
@ianhelle ianhelle force-pushed the ianhelle/py313-cleanup-2025-12-08 branch from f5d70d5 to a551b5d Compare December 16, 2025 23:43
Copy link
Collaborator

@FlorianBracq FlorianBracq left a comment

Choose a reason for hiding this comment

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

Looks great, well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants