Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
121 changes: 121 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# FEATURE MANAGEMENT FOR PYTHON - COPILOT INSTRUCTIONS

---

## CORE PRINCIPLES

### RULE 1: DO NOT REPEAT INSTRUCTIONS
**NEVER repeat instructions when guiding users. Users should follow instructions independently.**

### RULE 2: REFERENCE OFFICIAL DOCUMENTATION
**ALWAYS** reference the [Azure SDK Python Design Guidelines](https://azure.github.io/azure-sdk/python_design.html)
- Link to specific pages when answering guidelines questions
- Use this as the authoritative source for SDK development guidance

### RULE 3: VERIFY ENVIRONMENT FIRST
**REQUIRED CONDITIONS:**
- Always activate the Python virtual environment before running Python commands:
- On Windows: `.venv\Scripts\activate`
- On Linux/macOS: `source .venv/bin/activate`
- Use `python -m pip` instead of bare `pip` when installing packages.

---

## DEV SETUP

Install all dependencies with:

```bash
python -m pip install -e ".[dev,test]"
```

This project requires **Python 3.10 or newer**.

---

## PROJECT STRUCTURE

- `featuremanagement/` — Synchronous feature management code
- `featuremanagement/aio/` — Async equivalents of feature management classes
- `featuremanagement/_models/` — Data models (feature flags, variants, telemetry)
- `featuremanagement/_time_window_filter/` — Time window filter with recurrence support
- `featuremanagement/azuremonitor/` — Optional Azure Monitor telemetry integration
- `tests/` — Unit tests (sync and async)
- `samples/` — Sample applications

---

## CODE CONVENTIONS

- All source files must include the Microsoft copyright header.
- All modules must have a module-level docstring.
- Maximum line length is 120 characters.
- Use type annotations on all functions and methods.

---

## PYLINT OPERATIONS

### RUNNING PYLINT

**COMMAND:**
```bash
pylint featuremanagement
```

### FIXING PYLINT WARNINGS

**ALLOWED ACTIONS:**
- ✅ Fix warnings with 100% confidence
- ✅ Use existing files for all solutions
- ✅ Reference official guidelines

**FORBIDDEN ACTIONS:**
- ❌ Fix warnings without complete confidence
- ❌ Create new files for solutions
- ❌ Import non-existent modules
- ❌ Add new dependencies/imports
- ❌ Make unnecessary large changes
- ❌ Change code style without reason
- ❌ Delete code without clear justification

---

## MYPY OPERATIONS

### RUNNING MYPY

**COMMAND:**
```bash
mypy featuremanagement
```

The project uses `strict = True` in `mypy.ini`.

---

## CODE FORMATTING

### RUNNING BLACK

**COMMAND:**
```bash
black featuremanagement
```

Line length is configured to 120 in `pyproject.toml`.

---

## TESTING

### RUNNING TESTS

**COMMAND:**
```bash
pytest tests
```

- Sync tests are in `tests/test_*.py`
- Async tests use `pytest-asyncio` and are in files ending with `_async.py`
- Run tests with: `pytest tests`
7 changes: 3 additions & 4 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r dev_requirements.txt
pip install .
python -m pip install ".[dev]"
- name: Analysing the code with pylint
run: |
pylint featuremanagement
Expand All @@ -30,9 +29,9 @@ jobs:
uses: streetsidesoftware/cspell-action@v6.8.0
- name: Test with pytest
run: |
pip install -r tests/requirements.txt
python -m pip install ".[test]"
pytest tests --doctest-modules --cov-report=xml --cov-report=html
- name: Analysing the samples with pylint
run: |
pip install -r samples/requirements.txt
python -m pip install -r samples/requirements.txt
pylint --disable=missing-function-docstring,missing-class-docstring samples tests
6 changes: 0 additions & 6 deletions MANIFEST.in

This file was deleted.

2 changes: 1 addition & 1 deletion cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ignorePaths:
- '.*'
- 'build'
- 'docs'
- 'dev_requirements.txt'
- 'node_modules'
- '*.egg-info'
- '*.ini'
- '*.toml'
Expand Down
12 changes: 0 additions & 12 deletions dev_requirements.txt

This file was deleted.

2 changes: 2 additions & 0 deletions featuremanagement/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Feature management library for Python."""

from ._featuremanager import FeatureManager
from ._featurefilters import FeatureFilter
from ._defaultfilters import TimeWindowFilter, TargetingFilter
Expand Down
2 changes: 2 additions & 0 deletions featuremanagement/_defaultfilters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Built-in feature filter implementations."""

import logging
import hashlib
from datetime import datetime, timezone
Expand Down
2 changes: 2 additions & 0 deletions featuremanagement/_featurefilters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Base class for feature filters."""

from abc import ABC, abstractmethod
from typing import Mapping, Callable, Any, Optional

Expand Down
2 changes: 2 additions & 0 deletions featuremanagement/_featuremanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Synchronous feature manager implementation."""

import logging
from typing import cast, overload, Any, Optional, Dict, Mapping, List, Tuple
from ._defaultfilters import TimeWindowFilter, TargetingFilter
Expand Down
2 changes: 2 additions & 0 deletions featuremanagement/_featuremanagerbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Base class for feature manager implementations."""

import hashlib
import logging
from abc import ABC
Expand Down
2 changes: 2 additions & 0 deletions featuremanagement/_models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Data models for feature management."""

from ._feature_flag import FeatureFlag
from ._variant import Variant
from ._evaluation_event import EvaluationEvent
Expand Down
2 changes: 2 additions & 0 deletions featuremanagement/_models/_allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Allocation model for feature variant assignment."""

from typing import cast, List, Optional, Mapping, Dict, Any, Union
from dataclasses import dataclass
from ._constants import DEFAULT_WHEN_ENABLED, DEFAULT_WHEN_DISABLED, USER, GROUP, PERCENTILE, SEED
Expand Down
1 change: 1 addition & 0 deletions featuremanagement/_models/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Constants used by feature management models."""

# Feature Flag
FEATURE_FLAG_ID = "id"
Expand Down
2 changes: 2 additions & 0 deletions featuremanagement/_models/_evaluation_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Evaluation event model for feature flag telemetry."""

from dataclasses import dataclass
from typing import Optional
from ._feature_flag import FeatureFlag
Expand Down
2 changes: 2 additions & 0 deletions featuremanagement/_models/_feature_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Feature flag condition models."""

from collections.abc import Mapping
from typing import Any, Dict, List
from ._constants import (
Expand Down
2 changes: 2 additions & 0 deletions featuremanagement/_models/_feature_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Feature flag model."""

from typing import cast, List, Union, Optional, Mapping, Any
from ._feature_conditions import FeatureConditions
from ._allocation import Allocation
Expand Down
1 change: 1 addition & 0 deletions featuremanagement/_models/_targeting_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""Targeting context model for user and group targeting."""

from typing import NamedTuple, List

Expand Down
2 changes: 2 additions & 0 deletions featuremanagement/_models/_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Telemetry metadata model."""

from typing import Dict
from dataclasses import dataclass, field

Expand Down
2 changes: 2 additions & 0 deletions featuremanagement/_models/_variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Variant model representing a feature flag variant."""

from typing import Any


Expand Down
2 changes: 2 additions & 0 deletions featuremanagement/_models/_variant_assignment_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Enum for variant assignment reasons."""

from enum import Enum


Expand Down
2 changes: 2 additions & 0 deletions featuremanagement/_models/_variant_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Variant reference model."""

from dataclasses import dataclass
from typing import Optional, Mapping, Any
from ._constants import VARIANT_REFERENCE_NAME, CONFIGURATION_VALUE, STATUS_OVERRIDE
Expand Down
2 changes: 2 additions & 0 deletions featuremanagement/_time_window_filter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Time window filter with recurrence support."""

from ._recurrence_evaluator import is_match
from ._models import Recurrence, TimeWindowFilterSettings

Expand Down
2 changes: 2 additions & 0 deletions featuremanagement/_time_window_filter/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Data models for the time window filter."""

from enum import Enum
from typing import Dict, Any, Optional, List
from datetime import datetime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Recurrence evaluation logic for the time window filter."""

from datetime import datetime, timedelta
from typing import Optional
from ._models import RecurrencePatternType, RecurrenceRangeType, TimeWindowFilterSettings, OccurrenceInfo, Recurrence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Validation logic for recurrence settings."""

from datetime import datetime, timedelta
from typing import List
from ._models import RecurrencePatternType, RecurrenceRangeType, Recurrence, RecurrencePattern, RecurrenceRange
Expand Down
1 change: 1 addition & 0 deletions featuremanagement/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Package version."""

VERSION = "2.1.0"
2 changes: 2 additions & 0 deletions featuremanagement/aio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Async feature management support."""

from ._featuremanager import FeatureManager
from ._featurefilters import FeatureFilter
from ._defaultfilters import TimeWindowFilter, TargetingFilter
Expand Down
2 changes: 2 additions & 0 deletions featuremanagement/aio/_defaultfilters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Built-in async feature filter implementations."""

from typing import Mapping, Any
from ._featurefilters import FeatureFilter
from .._defaultfilters import (
Expand Down
2 changes: 2 additions & 0 deletions featuremanagement/aio/_featurefilters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Base class for async feature filters."""

from abc import ABC, abstractmethod
from typing import Mapping, Callable, Any, Optional

Expand Down
2 changes: 2 additions & 0 deletions featuremanagement/aio/_featuremanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Async feature manager implementation."""

import inspect
import logging
from typing import cast, overload, Any, Optional, Dict, Mapping, List, Tuple
Expand Down
Loading