Skip to content

Commit d2b4843

Browse files
authored
Restructure modules (#3)
restructure-modules: Rename src module to open_feature Signed-off-by: Andrew Helsby <[email protected]>
1 parent 0b30681 commit d2b4843

24 files changed

+263
-66
lines changed

.flake8

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[flake8]
2-
max-line-length = 88
2+
max-line-length = 88
3+
exclude = .venv/*,venv/*,.git,__pycache__

.github/workflows/build.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
name: Test
7+
8+
on:
9+
push:
10+
branches:
11+
- '*'
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
container: [ "python:3.8", "python:3.9", "python:3.10" ]
19+
container:
20+
image: ${{ matrix.container }}
21+
22+
steps:
23+
- uses: actions/checkout@v2
24+
25+
- name: Cache virtualenvironment
26+
uses: actions/cache@v2
27+
with:
28+
path: ~/.venv
29+
key: ${{ hashFiles('requirements.txt', 'requirements-dev.txt') }}
30+
31+
- name: Upgrade pip
32+
run: pip install --upgrade pip
33+
34+
- name: Create and activate Virtualenv
35+
run: |
36+
pip install virtualenv
37+
[ ! -d ".venv" ] && virtualenv .venv
38+
. .venv/bin/activate
39+
40+
- name: Install dependencies
41+
run: pip install -r requirements-dev.txt
42+
43+
- name: Run black formatter check
44+
run: black --check .
45+
46+
- name: Run flake8 formatter check
47+
run: flake8 .
48+
49+
- name: Run isort formatter check
50+
run: isort .
51+
52+
- name: Test with pytest
53+
run: pytest
File renamed without changes.
File renamed without changes.

open_feature/exception/exceptions.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
from open_feature.flag_evaluation.error_code import ErrorCode
2+
3+
4+
class OpenFeatureError(Exception):
5+
"""
6+
A generic open feature exception, this exception should not be raised. Instead
7+
the more specific exceptions extending this one should be used.
8+
"""
9+
10+
def __init__(self, error_message: str = None, error_code: ErrorCode = None):
11+
"""
12+
Constructor for the generic OpenFeatureError.
13+
@param error_message: a string message representing why the error has been
14+
raised
15+
@param error_code: the ErrorCode string enum value for the type of error
16+
@return: the generic OpenFeatureError exception
17+
"""
18+
self.error_message = error_message
19+
self.error_code = error_code
20+
21+
22+
class FlagNotFoundError(OpenFeatureError):
23+
"""
24+
This exception should be raised when the provider cannot find a flag with the
25+
key provided by the user.
26+
"""
27+
28+
def __init__(self, error_message: str = None):
29+
"""
30+
Constructor for the FlagNotFoundError. The error code for
31+
this type of exception is ErrorCode.FLAG_NOT_FOUND.
32+
@param error_message: a string message representing why the error has been
33+
raised
34+
@return: the generic FlagNotFoundError exception
35+
"""
36+
super().__init__(error_message, ErrorCode.FLAG_NOT_FOUND)
37+
38+
39+
class GeneralError(OpenFeatureError):
40+
"""
41+
This exception should be raised when the for an exception within the open
42+
feature python sdk.
43+
"""
44+
45+
def __init__(self, error_message: str = None):
46+
"""
47+
Constructor for the GeneralError. The error code for this type of exception
48+
is ErrorCode.GENERAL.
49+
@param error_message: a string message representing why the error has been
50+
raised
51+
@return: the generic GeneralError exception
52+
"""
53+
super().__init__(error_message, ErrorCode.GENERAL)
54+
55+
56+
class ParseError(OpenFeatureError):
57+
"""
58+
This exception should be raised when the flag returned by the provider cannot
59+
be parsed into a FlagEvaluationDetails object.
60+
"""
61+
62+
def __init__(self, error_message: str = None):
63+
"""
64+
Constructor for the ParseError. The error code for this type of exception
65+
is ErrorCode.PARSE_ERROR.
66+
@param error_message: a string message representing why the error has been
67+
raised
68+
@return: the generic ParseError exception
69+
"""
70+
super().__init__(error_message, ErrorCode.PARSE_ERROR)
71+
72+
73+
class TypeMismatchError(OpenFeatureError):
74+
"""
75+
This exception should be raised when the flag returned by the provider does
76+
not match the type requested by the user.
77+
"""
78+
79+
def __init__(self, error_message: str = None):
80+
"""
81+
Constructor for the TypeMismatchError. The error code for this type of
82+
exception is ErrorCode.TYPE_MISMATCH.
83+
@param error_message: a string message representing why the error has been
84+
raised
85+
@return: the generic TypeMismatchError exception
86+
"""
87+
super().__init__(error_message, ErrorCode.TYPE_MISMATCH)

src/flag_evaluation/flag_evaluation_details.py renamed to open_feature/flag_evaluation/flag_evaluation_details.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from src.flag_evaluation.error_code import ErrorCode
2-
from src.flag_evaluation.reason import Reason
1+
from open_feature.flag_evaluation.error_code import ErrorCode
2+
from open_feature.flag_evaluation.reason import Reason
33

44

55
class FlagEvaluationDetails:

0 commit comments

Comments
 (0)