Skip to content

Commit

Permalink
[http-client-python] Fix ci to make sure generated SDK code pass lint…
Browse files Browse the repository at this point in the history
… check (#4648)

fix #4570

---------

Co-authored-by: iscai-msft <[email protected]>
  • Loading branch information
msyyc and iscai-msft authored Oct 10, 2024
1 parent 09317da commit ba1becb
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 9 deletions.
6 changes: 6 additions & 0 deletions packages/http-client-python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log - @typespec/http-client-python

## X.X.X

### Bug Fixes

- Fix CI to make sure generated SDK pass necessary check

## 0.2.0

### Bug Fixes
Expand Down
4 changes: 4 additions & 0 deletions packages/http-client-python/eng/scripts/ci/run_pyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ def _single_dir_pyright(mod):


if __name__ == "__main__":
if os.name == "nt":
# Before https://github.com/microsoft/typespec/issues/4667 fixed, skip running PyRight on Windows
logging.info("Skip running PyRight on Windows for now")
sys.exit(0)
run_check("pyright", _single_dir_pyright, "PyRight")
2 changes: 1 addition & 1 deletion packages/http-client-python/eng/scripts/ci/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ def run_check(name, call_back, log_info):
response = call_back(dirs[0])
if not response:
logging.error("%s fails", log_info)
exit(0)
exit(1)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% set async_class = "Async" if async_mode else "" %}
{% macro escape_str(s) %}'{{ s|replace("'", "\\'") }}'{% endmacro %}
{% set kwargs_declaration = "**kwargs: Any" %}
{% set extend_all = "__all__.extend([p for p in _patch_all if p not in __all__])" %}
{% set extend_all = "__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore" %}
{% macro patch_imports(try_except=False) %}
{% set indentation = " " if try_except else "" %}
{% if try_except %}
Expand All @@ -16,4 +16,4 @@ try:
except ImportError:
_patch_all = []
{% endif %}
from ._patch import patch_sdk as _patch_sdk{% endmacro %}
from ._patch import patch_sdk as _patch_sdk{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
{% for param_signature in serializer.init_line(model) %}
{{ param_signature }}
{% endfor %}
):
) -> None:
...

@overload
def __init__(self, mapping: Mapping[str, Any]):
def __init__(self, mapping: Mapping[str, Any]) -> None:
"""
:param mapping: raw JSON to initialize the model.
:type mapping: Mapping[str, Any]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ except ImportError: # Python 2.7
:param datetime.timedelta offset: offset in timedelta format
"""

def __init__(self, offset):
def __init__(self, offset) -> None:
self.__offset = offset

def utcoffset(self, dt):
Expand Down Expand Up @@ -598,7 +598,7 @@ class Serializer(object): # pylint: disable=too-many-public-methods
"multiple": lambda x, y: x % y != 0,
}

def __init__(self, classes: Optional[Mapping[str, type]] = None):
def __init__(self, classes: Optional[Mapping[str, type]] = None) -> None:
self.serialize_type = {
"iso-8601": Serializer.serialize_iso,
"rfc-1123": Serializer.serialize_rfc,
Expand Down Expand Up @@ -1452,7 +1452,7 @@ class Deserializer(object):

valid_date = re.compile(r"\d{4}[-]\d{2}[-]\d{2}T\d{2}:\d{2}:\d{2}\.?\d*Z?[-+]?[\d{2}]?:?[\d{2}]?")

def __init__(self, classes: Optional[Mapping[str, type]] = None):
def __init__(self, classes: Optional[Mapping[str, type]] = None) -> None:
self.deserialize_type = {
"iso-8601": Deserializer.deserialize_iso,
"rfc-1123": Deserializer.deserialize_rfc,
Expand Down
2 changes: 1 addition & 1 deletion packages/http-client-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"node": ">=18.0.0"
},
"scripts": {
"clean": "rimraf ./dist ./temp ./**/test/**/generated/ ./venv",
"clean": "rimraf ./dist ./temp ./emitter/temp ./generator/test/azure/generated ./generator/test/unbranded/generated ./venv",
"build": "tsc -p ./emitter/tsconfig.build.json",
"watch": "tsc -p ./emitter/tsconfig.build.json --watch",
"lint": "eslint . --max-warnings=0",
Expand Down

0 comments on commit ba1becb

Please sign in to comment.