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
5 changes: 3 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[run]
omit =
omit =
switcher_client/lib/utils/timed_match/worker.py
switcher_client/version.py
switcher_client/lib/compat.py,
switcher_client/version.py,
*/tests/*
*/test_*

Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ jobs:

- name: Lint
run: pipenv run python -m pylint switcher_client

- name: Test
run: pipenv run pytest -v --cov=./switcher_client --cov-report xml --cov-config=.coveragerc

- name: SonarCloud Scan
uses: sonarsource/sonarqube-scan-action@v7.0.0
uses: sonarsource/sonarqube-scan-action@v7.1.0
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: env.SONAR_TOKEN != ''
Expand Down Expand Up @@ -62,8 +62,5 @@ jobs:
pip install pipenv
pipenv install --dev

- name: Lint
run: pipenv run python -m pylint switcher_client

- name: Test
run: pipenv run pytest -v
2 changes: 1 addition & 1 deletion .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: pipenv run pytest -v --cov=./switcher_client --cov-report xml

- name: SonarCloud Scan
uses: sonarsource/sonarqube-scan-action@v7.0.0
uses: sonarsource/sonarqube-scan-action@v7.1.0
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: env.SONAR_TOKEN != ''
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ on:
description: 'Operating System (ubuntu-20.04, ubuntu-latest, windows-latest)'
required: true
default: 'ubuntu-latest'
skip-lint:
description: 'Skip linting step'
required: false
default: 'false'

jobs:
build-test:
Expand All @@ -35,7 +39,8 @@ jobs:
pipenv install --dev

- name: Lint
if: ${{ github.event.inputs.skip-lint != 'true' }}
run: pipenv run python -m pylint switcher_client

- name: Test
run: pipenv run pytest -v
4 changes: 3 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ name = "pypi"

[packages]
httpx = {extras = ["http2"], version = "==0.28.1"}
typing-extensions = {version = "==4.15.0", markers = "python_version <= '3.12'"}

[dev-packages]
exceptiongroup = "*"
tomli = "*"
pylint = "==4.0.5"
pytest = "==9.0.3"
pytest-cov = "==7.1.0"
pytest-httpx = "==0.36.2"
python-dotenv = "==1.2.2"
typing-extensions = "4.15.0"
switcher-client = {file = ".", editable = true}
82 changes: 72 additions & 10 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ A Python SDK for Switcher API

[![Master CI](https://github.com/switcherapi/switcher-client-py/actions/workflows/master.yml/badge.svg)](https://github.com/switcherapi/switcher-client-py/actions/workflows/master.yml)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=switcherapi_switcher-client-py&metric=alert_status)](https://sonarcloud.io/dashboard?id=switcherapi_switcher-client-py)
[![Known Vulnerabilities](https://snyk.io/test/github/switcherapi/switcher-client-py/badge.svg)](https://snyk.io/test/github/switcherapi/switcher-client-py)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Slack: Switcher-HQ](https://img.shields.io/badge/slack-@switcher/hq-blue.svg?logo=slack)](https://switcher-hq.slack.com/)

Expand Down Expand Up @@ -165,7 +164,7 @@ switcher = Client.get_switcher()

- **ReDoS Protection**: Built-in ReDoS attack prevention with regex safety features
- **Time Limits**: Configurable timeouts prevent long-running regex operations
- **Certificate Support**: Use custom certificates for secure API connections
- **Certificate Support**: Use custom certificates for secure API connections

## Usage Examples

Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ build-backend = "setuptools.build_meta"
name = "switcher_client"
description = "Switcher Client SDK for Python"
dynamic = ["version", "readme"]
dependencies = ["httpx[http2]>=0.28.1"]
dependencies = [
"httpx[http2]>=0.28.1",
"typing_extensions>=4.0; python_version <= '3.12'",
]
authors = [{name='Roger Floriano (petruki)', email='switcher.project@gmail.com'}]
license = "MIT"
license-files = ["LICENSE"]
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ sonar.sources=switcher_client
sonar.tests=tests
sonar.python.coverage.reportPaths=coverage.xml
sonar.python.version=3.14
sonar.exclusions=**/tests/**,**/switcher_client/version.py,**/switcher_client/lib/utils/timed_match/worker.py,**/switcher_client/lib/utils/timed_match/__init__.py
sonar.exclusions=**/tests/**,**/switcher_client/version.py,**/switcher_client/lib/utils/timed_match/worker.py,**/switcher_client/lib/utils/timed_match/__init__.py,**/switcher_client/lib/compat.py
4 changes: 2 additions & 2 deletions switcher_client/errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class RemoteCriteriaError(RemoteError):
class RemoteSwitcherError(RemoteError):
""" Raised when there is a switcher error with the remote service """
def __init__(self, not_found: list):
super().__init__(f'{', '.join(not_found)} not found')
super().__init__(f'{", ".join(not_found)} not found')

class LocalSwitcherError(Exception):
""" Raised when there is a switcher error with the local service """
def __init__(self, not_found: list):
self.message = f'{', '.join(not_found)} not found'
self.message = f'{", ".join(not_found)} not found'
super().__init__(self.message)

class LocalCriteriaError(Exception):
Expand Down
8 changes: 8 additions & 0 deletions switcher_client/lib/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import sys

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self

__all__ = ['Self']
5 changes: 3 additions & 2 deletions switcher_client/switcher_data.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# pylint: disable=redefined-builtin
from dataclasses import dataclass
import json

from dataclasses import dataclass
from datetime import datetime
from abc import ABCMeta
from typing import Optional, Self, Union
from typing import Optional, Union

from switcher_client.lib.compat import Self
from switcher_client.lib.utils import get
from switcher_client.lib.globals.global_context import Context
from switcher_client.lib.snapshot import StrategiesType
Expand Down