From ec33fbca6498d7e5214be186644829da0cbe4a08 Mon Sep 17 00:00:00 2001 From: Seth Wang Date: Thu, 21 Apr 2022 17:16:44 +0800 Subject: [PATCH 1/2] 1. Replace setup.py by pyproject 2. Use format.sh --- .github/workflows/python-package.yml | 4 +- .gitignore | 6 +++ believe/__init__.py | 5 ++- believe/dict_matcher.py | 55 +++++++++++++++++++++------- believe/error.py | 24 ++++++------ believe/internal.py | 27 +++++++------- believe/list_matcher.py | 40 +++++++++++++++----- believe/number_matcher.py | 31 +++++++++++----- believe/other_matcher.py | 15 ++++---- believe/str_matcher.py | 43 +++++++++++++--------- format.sh | 7 ++++ pyproject.toml | 38 +++++++++++++++++++ setup.py | 29 --------------- 13 files changed, 209 insertions(+), 115 deletions(-) create mode 100755 format.sh create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index f84166b..a48b4ba 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -25,9 +25,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - python -m pip install --upgrade pip - pip install pytest pytest-cov coverage-lcov - pip install -e . + pip install -e ".[test]" - name: Test with pytest run: | pytest --junitxml=junit_report.xml --cov=believe tests diff --git a/.gitignore b/.gitignore index b6e4761..f4545dd 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,9 @@ dmypy.json # Pyre type checker .pyre/ + +# customized +.direnv +.envrc +junit_report.xml +lcov.info \ No newline at end of file diff --git a/believe/__init__.py b/believe/__init__.py index 78089fc..cc0f25d 100644 --- a/believe/__init__.py +++ b/believe/__init__.py @@ -28,7 +28,10 @@ from .str_matcher import AnySHA1 # Put all Matcher into BelieveMixin -class BelieveMixin(object): pass +class BelieveMixin(object): + pass + + for c, cls in dict(locals()).items(): try: if issubclass(cls, BelieveBase) and cls != BelieveBase: diff --git a/believe/dict_matcher.py b/believe/dict_matcher.py index 6da2d71..21aa021 100644 --- a/believe/dict_matcher.py +++ b/believe/dict_matcher.py @@ -1,17 +1,17 @@ -import json import typing from .internal import BelieveBase from .internal import validate from .internal import NO_CHECK + class Dict(BelieveBase): - def __init__(self, dict_obj: typing.Dict): + def __init__(self, dict_obj: typing.Dict) -> None: assert isinstance(dict_obj, dict) super().__init__(dict_obj) self.__dict_obj = dict_obj - def validate(self, rhs, e_path=""): + def validate(self, rhs: typing.Dict, e_path: str = "") -> None: if not isinstance(rhs, dict): self.raise_validate_error(rhs, e_path=e_path, e_msg="not_dict") @@ -19,49 +19,78 @@ def validate(self, rhs, e_path=""): for k, v in self.__dict_obj.items(): if not isinstance(v, Optional): if k not in rhs: - self.raise_validate_error(rhs, e_path=e_path, e_msg=f'missing_required_field: {k}') + self.raise_validate_error( + rhs, e_path=e_path, e_msg=f"missing_required_field: {k}" + ) # validate field value for k, v in rhs.items(): if k in self.__dict_obj: validate(self.__dict_obj[k], v, "%s.%s" % (e_path, k)) else: - self.raise_validate_error(rhs, e_path=e_path, e_msg="unknown_field", e_unsafe_msg=f'unknown_field: {k}') + self.raise_validate_error( + rhs, + e_path=e_path, + e_msg="unknown_field", + e_unsafe_msg=f"unknown_field: {k}", + ) class DictOf(BelieveBase): - def __init__(self, key: typing.Any, value: typing.Any, n_item: int = NO_CHECK, min_item: int = NO_CHECK, max_item: int = NO_CHECK): + def __init__( + self, + key: typing.Any, + value: typing.Any, + n_item: int = NO_CHECK, + min_item: int = NO_CHECK, + max_item: int = NO_CHECK, + ) -> None: assert n_item == NO_CHECK or isinstance(n_item, int) assert min_item == NO_CHECK or isinstance(min_item, int) assert max_item == NO_CHECK or isinstance(max_item, int) - super().__init__(key, value, n_item=n_item, min_item=min_item, max_item=max_item) + super().__init__( + key, value, n_item=n_item, min_item=min_item, max_item=max_item + ) self.__key = key self.__value = value self.__n_item = n_item self.__min_item = min_item self.__max_item = max_item - def validate(self, rhs, e_path=""): + def validate(self, rhs: Dict, e_path: str = "") -> None: if not isinstance(rhs, dict): self.raise_validate_error(rhs, e_path=e_path, e_msg="not_dict") if self.__n_item != NO_CHECK: if not len(rhs) == self.__n_item: - self.raise_validate_error(rhs, e_path=e_path, e_msg=f'mismatch_item_count: {len(rhs)} != {self.__n_item}') + self.raise_validate_error( + rhs, + e_path=e_path, + e_msg=f"mismatch_item_count: {len(rhs)} != {self.__n_item}", + ) if self.__min_item != NO_CHECK: if len(rhs) < self.__min_item: - self.raise_validate_error(rhs, e_path=e_path, e_msg=f'too_few_items: {len(rhs)} < {self.__min_item}') + self.raise_validate_error( + rhs, + e_path=e_path, + e_msg=f"too_few_items: {len(rhs)} < {self.__min_item}", + ) if self.__max_item != NO_CHECK: if len(rhs) > self.__max_item: - self.raise_validate_error(rhs, e_path=e_path, e_msg=f'too_many_items: {len(rhs)} > {self.__max_item}') + self.raise_validate_error( + rhs, + e_path=e_path, + e_msg=f"too_many_items: {len(rhs)} > {self.__max_item}", + ) for k, v in rhs.items(): validate(self.__key, k, "%s.%s" % (e_path, k)) validate(self.__value, v, "%s.%s" % (e_path, k)) + class Optional(BelieveBase): - def __init__(self, value: typing.Any): + def __init__(self, value: typing.Any) -> None: super().__init__(value) self.__value = value - def validate(self, rhs: typing.Any, e_path: str = ""): + def validate(self, rhs: typing.Any, e_path: str = "") -> None: validate(rhs, self.__value, e_path=e_path) diff --git a/believe/error.py b/believe/error.py index 8edb472..82832eb 100644 --- a/believe/error.py +++ b/believe/error.py @@ -1,31 +1,29 @@ - from typing import Any, List class ValidateError(Exception): - def __init__(self, v1: Any, v2: Any, **kwargs: Any): + def __init__(self, v1: Any, v2: Any, **kwargs: Any) -> None: self.v1 = repr(v1) self.v2 = repr(v2) self.kwargs = kwargs - def kwargs_to_string(self, fields: List[str], with_v2: bool): + def kwargs_to_string(self, fields: List[str], with_v2: bool) -> str: result = [] for k in fields: if self.kwargs.get(k): - if k == 'e_path': - result.append(f'[{k}=${self.kwargs[k]}]') + if k == "e_path": + result.append(f"[{k}=${self.kwargs[k]}]") else: - result.append(f'[{k}={self.kwargs[k]}]') + result.append(f"[{k}={self.kwargs[k]}]") if with_v2: - result.append(f'{self.v2} != {self.v1}') + result.append(f"{self.v2} != {self.v1}") return " ".join(result) - def xss_unsafe_message(self): - return self.kwargs_to_string(['e_path', 'e_msg', 'e_unsafe_msg'], True) + def xss_unsafe_message(self) -> str: + return self.kwargs_to_string(["e_path", "e_msg", "e_unsafe_msg"], True) - def xss_safe_message(self): - return self.kwargs_to_string(['e_path', 'e_msg'], False) + def xss_safe_message(self) -> str: + return self.kwargs_to_string(["e_path", "e_msg"], False) - def __str__(self): + def __str__(self) -> str: return self.xss_unsafe_message() - diff --git a/believe/internal.py b/believe/internal.py index 3340a1a..f703022 100644 --- a/believe/internal.py +++ b/believe/internal.py @@ -7,48 +7,49 @@ # We use Ellipsis to differentiate if caller assign non-default value for kwargs NO_CHECK = USE_DEFAULT = Ellipsis + class BelieveBase(abc.ABC): - def __init__(self, *args: Any, **kwargs: Any): - self.__arg_str = self.init_arg_str(*args, **kwargs) + def __init__(self, *args: Any, **kwargs: Any) -> None: + self.__arg_str = self.__init_arg_str(*args, **kwargs) - def __ne__(self, rhs: Any): + def __ne__(self, rhs: Any) -> bool: return not self.__eq__(rhs) - def __eq__(self, rhs: Any): + def __eq__(self, rhs: Any) -> bool: try: self.validate(rhs) return True except ValidateError: return False - def __str__(self): + def __str__(self) -> str: return "%s(%s)" % (self.__class__.__name__, self.__arg_str) - def __repr__(self): + def __repr__(self) -> str: return self.__str__() - def to_str(self, val: Any) -> str: + def __to_str(self, val: Any) -> str: if inspect.isclass(val) and hasattr(val, "__name__"): return val.__name__ else: return str(val) - def init_arg_str(self, *args: Any, **kwargs: Any): + def __init_arg_str(self, *args: Any, **kwargs: Any) -> str: list_of_arg = list(args) for k, v in kwargs.items(): - if v != Ellipsis: # only show overwritten kwargs + if v != Ellipsis: # only show overwritten kwargs list_of_arg.append("%s=%s" % (k, v)) - return ", ".join([self.to_str(i) for i in list_of_arg]) + return ", ".join([self.__to_str(i) for i in list_of_arg]) - def raise_validate_error(self, rhs: Any, **kwargs: Any): + def raise_validate_error(self, rhs: Any, **kwargs: Any) -> None: raise ValidateError(self, rhs, **kwargs) @abc.abstractmethod - def validate(self, rhs: Any, e_path: str = ""): + def validate(self, rhs: Any, e_path: str = "") -> None: raise NotImplemented() -def validate(v1: Any, v2: Any, e_path: str = ""): +def validate(v1: Any, v2: Any, e_path: str = "") -> None: if isinstance(v1, BelieveBase): v1.validate(v2, e_path=e_path) elif isinstance(v2, BelieveBase): diff --git a/believe/list_matcher.py b/believe/list_matcher.py index 3e821b3..84995e3 100644 --- a/believe/list_matcher.py +++ b/believe/list_matcher.py @@ -6,11 +6,11 @@ class OneOf(BelieveBase): - def __init__(self, *candidates: Any): + def __init__(self, *candidates: Any) -> None: super().__init__(*candidates) self.__candidates = candidates - def validate(self, rhs: Any, e_path: str = ""): + def validate(self, rhs: Any, e_path: str = "") -> None: for i in self.__candidates: if i == rhs: return @@ -18,13 +18,13 @@ def validate(self, rhs: Any, e_path: str = ""): class AnyOrder(BelieveBase): - def __init__(self, list_obj: List): + def __init__(self, list_obj: List) -> None: assert isinstance(list_obj, list) super().__init__(list_obj) self.__list_obj = list_obj - def validate(self, rhs: List[Any], e_path: str = ""): + def validate(self, rhs: List[Any], e_path: str = "") -> None: if not isinstance(rhs, list): self.raise_validate_error(rhs, e_path=e_path) if len(rhs) != len(self.__list_obj): @@ -32,12 +32,20 @@ def validate(self, rhs: List[Any], e_path: str = ""): list_obj = self.__list_obj[:] for idx, i in enumerate(rhs): if not i in list_obj: - self.raise_validate_error(rhs, e_path=e_path, e_msg=f'item_not_found_at_index: {idx}') + self.raise_validate_error( + rhs, e_path=e_path, e_msg=f"item_not_found_at_index: {idx}" + ) list_obj.remove(i) class ListOf(BelieveBase): - def __init__(self, one_item: Any, n_item: int = NO_CHECK, min_item: int = NO_CHECK, max_item: int = NO_CHECK): + def __init__( + self, + one_item: Any, + n_item: int = NO_CHECK, + min_item: int = NO_CHECK, + max_item: int = NO_CHECK, + ) -> None: assert n_item == NO_CHECK or isinstance(n_item, int) assert min_item == NO_CHECK or isinstance(min_item, int) assert max_item == NO_CHECK or isinstance(max_item, int) @@ -49,17 +57,29 @@ def __init__(self, one_item: Any, n_item: int = NO_CHECK, min_item: int = NO_CHE self.__min_item = min_item self.__max_item = max_item - def validate(self, rhs: List, e_path: str = ""): + def validate(self, rhs: List, e_path: str = "") -> None: if not isinstance(rhs, list): self.raise_validate_error(rhs, e_path=e_path, e_msg="not_list") if self.__n_item != NO_CHECK: if not len(rhs) == self.__n_item: - self.raise_validate_error(rhs, e_path=e_path, e_msg=f'mismatch_item_count: {len(rhs)} != {self.__n_item}') + self.raise_validate_error( + rhs, + e_path=e_path, + e_msg=f"mismatch_item_count: {len(rhs)} != {self.__n_item}", + ) if self.__min_item != NO_CHECK: if len(rhs) < self.__min_item: - self.raise_validate_error(rhs, e_path=e_path, e_msg=f'too_few_items: {len(rhs)} < {self.__min_item}') + self.raise_validate_error( + rhs, + e_path=e_path, + e_msg=f"too_few_items: {len(rhs)} < {self.__min_item}", + ) if self.__max_item != NO_CHECK: if len(rhs) > self.__max_item: - self.raise_validate_error(rhs, e_path=e_path, e_msg=f'too_many_items: {len(rhs)} > {self.__max_item}') + self.raise_validate_error( + rhs, + e_path=e_path, + e_msg=f"too_many_items: {len(rhs)} > {self.__max_item}", + ) for idx, val in enumerate(rhs): validate(self.__one_item, val, "%s.%s" % (e_path, str(idx))) diff --git a/believe/number_matcher.py b/believe/number_matcher.py index c4bcc99..ea07c73 100644 --- a/believe/number_matcher.py +++ b/believe/number_matcher.py @@ -4,7 +4,9 @@ class Almost(BelieveBase): - def __init__(self, ts: Union[int, float], ts_range: Union[int, float] = USE_DEFAULT): + def __init__( + self, ts: Union[int, float], ts_range: Union[int, float] = USE_DEFAULT + ) -> None: assert isinstance(ts, (int, float)) assert ts_range == USE_DEFAULT or isinstance(ts_range, (int, float)) super().__init__(ts, ts_range=ts_range) @@ -15,12 +17,13 @@ def __init__(self, ts: Union[int, float], ts_range: Union[int, float] = USE_DEFA def validate(self, rhs: Union[int, float], e_path: str = ""): if not isinstance(rhs, (int, float)): - self.raise_validate_error(rhs, e_path=e_path, e_msg=f'not_int_or_float') + self.raise_validate_error(rhs, e_path=e_path, e_msg=f"not_int_or_float") if not self.__ts - self.__ts_range <= rhs <= self.__ts + self.__ts_range: - self.raise_validate_error(rhs, e_path=e_path, e_msg=f'not_in_range') + self.raise_validate_error(rhs, e_path=e_path, e_msg=f"not_in_range") + class AnyInt(BelieveBase): - def __init__(self, min_value: int = NO_CHECK, max_value: int = NO_CHECK): + def __init__(self, min_value: int = NO_CHECK, max_value: int = NO_CHECK) -> None: assert min_value == NO_CHECK or isinstance(min_value, int) assert max_value == NO_CHECK or isinstance(max_value, int) super().__init__(min_value=min_value, max_value=max_value) @@ -31,13 +34,19 @@ def validate(self, rhs: int, e_path: str = ""): if not isinstance(rhs, int): self.raise_validate_error(rhs, e_path=e_path) if self.__min_value != NO_CHECK and self.__min_value > rhs: - self.raise_validate_error(rhs, e_path=e_path, e_msg=f'value_too_small: {rhs} < {self.__min_value}') + self.raise_validate_error( + rhs, e_path=e_path, e_msg=f"value_too_small: {rhs} < {self.__min_value}" + ) if self.__max_value != NO_CHECK and self.__max_value < rhs: - self.raise_validate_error(rhs, e_path=e_path, e_msg=f'value_too_large: {rhs} > {self.__max_value}') + self.raise_validate_error( + rhs, e_path=e_path, e_msg=f"value_too_large: {rhs} > {self.__max_value}" + ) class AnyFloat(BelieveBase): - def __init__(self, min_value: float = NO_CHECK, max_value: float = NO_CHECK): + def __init__( + self, min_value: float = NO_CHECK, max_value: float = NO_CHECK + ) -> None: assert min_value == NO_CHECK or isinstance(min_value, float) assert max_value == NO_CHECK or isinstance(max_value, float) super().__init__(min_value=min_value, max_value=max_value) @@ -48,6 +57,10 @@ def validate(self, rhs: float, e_path: str = ""): if not isinstance(rhs, float): self.raise_validate_error(rhs, e_path=e_path) if self.__min_value != NO_CHECK and self.__min_value > rhs: - self.raise_validate_error(rhs, e_path=e_path, e_msg=f'value_too_small: {rhs} < {self.__min_value}') + self.raise_validate_error( + rhs, e_path=e_path, e_msg=f"value_too_small: {rhs} < {self.__min_value}" + ) if self.__max_value != NO_CHECK and self.__max_value < rhs: - self.raise_validate_error(rhs, e_path=e_path, e_msg=f'value_too_large: {rhs} > {self.__max_value}') + self.raise_validate_error( + rhs, e_path=e_path, e_msg=f"value_too_large: {rhs} > {self.__max_value}" + ) diff --git a/believe/other_matcher.py b/believe/other_matcher.py index 48ecb68..f38e709 100644 --- a/believe/other_matcher.py +++ b/believe/other_matcher.py @@ -1,12 +1,13 @@ from .internal import BelieveBase -from typing import Any, Union +from typing import Any + class Nullable(BelieveBase): - def __init__(self, obj: Any): + def __init__(self, obj: Any) -> None: super().__init__(obj) self.__obj = obj - def validate(self, rhs: Any, e_path: str = ""): + def validate(self, rhs: Any, e_path: str = "") -> None: if rhs is None: return if self.__obj != rhs: @@ -14,24 +15,24 @@ def validate(self, rhs: Any, e_path: str = ""): class Not(BelieveBase): - def __init__(self, obj: Any): + def __init__(self, obj: Any) -> None: super().__init__(obj) self.__obj = obj - def validate(self, rhs: Any, e_path: str = ""): + def validate(self, rhs: Any, e_path: str = "") -> None: if self.__obj == rhs: self.raise_validate_error(rhs, e_path=e_path, e_msg="invalid_param") class Any(BelieveBase): - def __init__(self, *type_classes: type): + def __init__(self, *type_classes: type) -> None: for type_class in type_classes: assert isinstance(type_class, type) super().__init__(*type_classes) self.__type_classes = type_classes - def validate(self, rhs: Any, e_path: str = ""): + def validate(self, rhs: Any, e_path: str = "") -> None: if not self.__type_classes: return if not isinstance(rhs, self.__type_classes): diff --git a/believe/str_matcher.py b/believe/str_matcher.py index 0135e76..8d81b67 100644 --- a/believe/str_matcher.py +++ b/believe/str_matcher.py @@ -7,7 +7,7 @@ class AnyStr(BelieveBase): - def __init__(self, min_len: int = NO_CHECK, max_len: int = NO_CHECK): + def __init__(self, min_len: int = NO_CHECK, max_len: int = NO_CHECK) -> None: assert min_len == NO_CHECK or isinstance(min_len, int) assert max_len == NO_CHECK or isinstance(max_len, int) @@ -15,17 +15,25 @@ def __init__(self, min_len: int = NO_CHECK, max_len: int = NO_CHECK): self.__min_len = min_len self.__max_len = max_len - def validate(self, rhs: str, e_path: str = ""): + def validate(self, rhs: str, e_path: str = "") -> None: if not isinstance(rhs, str): self.raise_validate_error(rhs, e_path=e_path, e_msg="not_string") if self.__min_len != NO_CHECK and len(rhs) < self.__min_len: - self.raise_validate_error(rhs, e_path=e_path, e_msg=f'string_too_short: {len(rhs)} < {self.__min_len}') + self.raise_validate_error( + rhs, + e_path=e_path, + e_msg=f"string_too_short: {len(rhs)} < {self.__min_len}", + ) if self.__max_len != NO_CHECK and len(rhs) > self.__max_len: - self.raise_validate_error(rhs, e_path=e_path, e_msg=f'string_too_long: {len(rhs)} > {self.__max_len}') + self.raise_validate_error( + rhs, + e_path=e_path, + e_msg=f"string_too_long: {len(rhs)} > {self.__max_len}", + ) class AnyIntStr(BelieveBase): - def validate(self, rhs: str, e_path: str = ""): + def validate(self, rhs: str, e_path: str = "") -> None: if not isinstance(rhs, str): self.raise_validate_error(rhs, e_path=e_path, e_msg="not_string") @@ -36,7 +44,7 @@ def validate(self, rhs: str, e_path: str = ""): class AnyUUID(BelieveBase): - def validate(self, rhs: str, e_path: str = ""): + def validate(self, rhs: str, e_path: str = "") -> None: if not isinstance(rhs, str) or len(rhs) != 36: self.raise_validate_error(rhs, e_path=e_path, e_msg="invalid_uuid") try: @@ -46,10 +54,10 @@ def validate(self, rhs: str, e_path: str = ""): class AnyIPV4(BelieveBase): - def validate(self, rhs: str, e_path: str = ""): + def validate(self, rhs: str, e_path: str = "") -> None: if not isinstance(rhs, str): self.raise_validate_error(rhs, e_path=e_path, e_msg="invalid_ipv4") - tokens = rhs.split('.') + tokens = rhs.split(".") if len(tokens) != 4: self.raise_validate_error(rhs, e_path=e_path, e_msg="invalid_ipv4") for token in tokens: @@ -62,7 +70,7 @@ def validate(self, rhs: str, e_path: str = ""): class AnySHA1(BelieveBase): - def validate(self, rhs: str, e_path: str = ""): + def validate(self, rhs: str, e_path: str = "") -> None: if not isinstance(rhs, str): self.raise_validate_error(rhs, e_path=e_path, e_msg="invalid_sha1") if len(rhs) != 40: @@ -74,12 +82,12 @@ def validate(self, rhs: str, e_path: str = ""): class AnyJsonStr(BelieveBase): - def __init__(self, json_obj: Union[Dict, List]): + def __init__(self, json_obj: Union[Dict, List]) -> None: assert isinstance(json_obj, (dict, list)) super().__init__(json_obj) self.__json_obj = json_obj - def validate(self, rhs: str, e_path: str = ""): + def validate(self, rhs: str, e_path: str = "") -> None: if not isinstance(rhs, str): self.raise_validate_error(rhs, e_path=e_path, e_msg="not_string") try: @@ -91,20 +99,20 @@ def validate(self, rhs: str, e_path: str = ""): class AnyUrl(BelieveBase): - def __init__(self, url: str): + def __init__(self, url: str) -> None: super().__init__(url) self.__parsed_url = urlparse(url) - def _normalize_query(self, query: str): + def _normalize_query(self, query: str) -> str: return "&".join(sorted(query.split("&"))) - def _default_port(self, scheme: str): + def _default_port(self, scheme: str) -> int: if scheme == "http": return 80 elif scheme == "https": return 443 - def validate(self, rhs: str, e_path: str = ""): + def validate(self, rhs: str, e_path: str = "") -> None: if not isinstance(rhs, str): self.raise_validate_error(rhs, e_path=e_path, e_msg="not_string") @@ -130,6 +138,7 @@ def validate(self, rhs: str, e_path: str = ""): if self.__parsed_url.path != o.path: self.raise_validate_error(rhs, e_path=e_path, e_msg="mismatch_path") - if self._normalize_query(self.__parsed_url.query) != self._normalize_query(o.query): + if self._normalize_query(self.__parsed_url.query) != self._normalize_query( + o.query + ): self.raise_validate_error(rhs, e_path=e_path, e_msg="mismatch_query") - diff --git a/format.sh b/format.sh new file mode 100755 index 0000000..bf801c5 --- /dev/null +++ b/format.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +FORMAT_DIR=believe + +autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place "${FORMAT_DIR}" --exclude=__init__.py +black "${FORMAT_DIR}" +isort "${FORMAT_DIR}" \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d049d4b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,38 @@ +[build-system] +requires = ["flit"] +build-backend = "flit.buildapi" + +[project] +name = "believe" +authors = [{name = "Seth Wang", email = "pkyosx@gmail.com"}] +readme = "README.md" +license = {file = "LICENSE"} +classifiers = [ + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + ] +description = "A easy to use validator for json content" +description-file = "README.md" +requires-python = '>=3.8' +dynamic = ["version"] +keywords = ["json", "validate", "validator"] + +[project.urls] +Home = "https://github.com/pkyosx/believe" + + +[project.optional-dependencies] +test = [ + "pytest", + "pytest-cov", + "coverage-lcov", +] + +[tool.isort] +profile = "black" +src_paths = ["believe"] +force_single_line = true \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index 0933b36..0000000 --- a/setup.py +++ /dev/null @@ -1,29 +0,0 @@ -import os -import believe -from setuptools import find_packages, setup - -# read the contents of your README file -this_directory = os.path.abspath(os.path.dirname(__file__)) -with open(os.path.join(this_directory, 'README.md'), encoding='utf-8') as f: - long_description = f.read() - -if __name__ == '__main__': - setup( - name='believe', - version=believe.__version__, - description='A easy to use validator for json content', - long_description=long_description, - long_description_content_type='text/markdown', - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent" - ], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers - python_requires='>=3.6', - keywords=['json', 'validate', 'validator'], - author='Seth Wang', - author_email='pkyosx@gmail.com', - url='https://github.com/pkyosx/believe', - packages=find_packages(exclude=["ez_setup", "examples", "*.tests", "*.tests.*", "tests.*", "tests"]), - include_package_data=True, - ) From 8673b130f42b088f74fe7c58a8b0a7b0ffd60f13 Mon Sep 17 00:00:00 2001 From: Seth Wang Date: Thu, 21 Apr 2022 17:52:27 +0800 Subject: [PATCH 2/2] bump version --- .github/workflows/python-package.yml | 1 + .github/workflows/python-publish.yml | 9 ++++----- believe/__init__.py | 2 +- publish.sh | 6 ------ pyproject.toml | 4 +++- 5 files changed, 9 insertions(+), 13 deletions(-) delete mode 100755 publish.sh diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index a48b4ba..300b101 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -25,6 +25,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | + python -m pip install --upgrade pip pip install -e ".[test]" - name: Test with pytest run: | diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 4e1ef42..c4c82ca 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -21,11 +21,10 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools wheel twine + pip install -e ".[publish]" - name: Build and publish env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + FLIT_USERNAME: ${{ secrets.PYPI_USERNAME }} + FLIT_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | - python setup.py sdist bdist_wheel - twine upload dist/* + flit publish diff --git a/believe/__init__.py b/believe/__init__.py index cc0f25d..d21ab4f 100644 --- a/believe/__init__.py +++ b/believe/__init__.py @@ -39,4 +39,4 @@ class BelieveMixin(object): except TypeError: pass -__version__ = "1.0.11" +__version__ = "1.0.12" diff --git a/publish.sh b/publish.sh deleted file mode 100755 index 3e5ff5d..0000000 --- a/publish.sh +++ /dev/null @@ -1,6 +0,0 @@ -pip3 install setuptools wheel twine -pushd src -rm -rf dist/ -python3 setup.py sdist bdist_wheel -python3 -m twine upload dist/* -popd \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index d049d4b..6ebe15d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,6 @@ classifiers = [ "Programming Language :: Python :: 3.10", ] description = "A easy to use validator for json content" -description-file = "README.md" requires-python = '>=3.8' dynamic = ["version"] keywords = ["json", "validate", "validator"] @@ -31,6 +30,9 @@ test = [ "pytest-cov", "coverage-lcov", ] +publish = [ + "flit" +] [tool.isort] profile = "black"