Skip to content

Commit

Permalink
fix: restrict python version and update cattrs version restriction (#949
Browse files Browse the repository at this point in the history
)

* unpin cattrs version, restrict python to <=3.9.9

* restrict cattrs to >= 1.3


* ci: specify 3.9.9 for GHA

* fix: seems like cattrs changed how enums are destructured

Co-authored-by: Joel Dodge <joeldodge@google.com>
Co-authored-by: John Kaster <kaster@google.com>
  • Loading branch information
3 people authored Jan 22, 2022
1 parent fa44a8a commit ba28ac6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.9.9
- run: pip install -e .
- run: pip install mypy types-requests
- run: mypy looker_sdk/
Expand All @@ -57,7 +57,7 @@ jobs:
- macos
- windows
python-version:
- '3.9'
- '3.9.9'
include:
- python-version: '3.6'
os: ubuntu
Expand Down Expand Up @@ -179,7 +179,7 @@ jobs:
pip install tox
- name: Determine credentials version
# Prior to 21_18, each version had different credentials and a
# Prior to 21_18, each version had different credentials and a
# different secret. 21_20 and later all use the same credentials
# as 21_18. The parse_version.sh script parses the version and
# yields 21_12, 21_14, 21_16 etc for those versions but 21_18 for
Expand Down Expand Up @@ -220,7 +220,7 @@ jobs:

- uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.9.9
- name: Twine upload check
run: |
pip install wheel twine
Expand Down
1 change: 1 addition & 0 deletions python/.python-version
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
3.9.9
3.9.0
3.8.2
3.7.6
Expand Down
6 changes: 4 additions & 2 deletions python/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pytest = "*"
ptpython = "*"
ipython = "*"
mypy = "*"
types-requests = "*"
pytest-cov = "*"
black = "*"
flake8 = "*"
Expand All @@ -26,11 +27,12 @@ tox-pyenv = "*"
[packages]
requests = "*"
attrs = "*"
cattrs = "==1.1.2"
cattrs = ">=1.3"
python-dateutil = "*"

[requires]
python_full_version = "3.8.2"
# pin python at 3.9.9 due to https://github.com/looker-open-source/sdk-codegen/issues/944
python_full_version = "3.9.9"

[pipenv]
# for `black`
Expand Down
10 changes: 8 additions & 2 deletions python/looker_sdk/rtl/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ def unstructure_hook(api_model):
del data[key]
elif value == model.EXPLICIT_NULL:
data[key] = None
# bug here: in the unittests cattrs unstructures this correctly
# as an enum calling .value but in the integration tests we see
# it doesn't for WriteCreateQueryTask.result_format for some reason
# Haven't been able to debug it fully, so catching and processing
# it here.
elif isinstance(value, enum.Enum):
data[key] = value.value
for reserved in keyword.kwlist:
if f"{reserved}_" in data:
data[reserved] = data.pop(f"{reserved}_")
Expand All @@ -153,7 +160,6 @@ def datetime_structure_hook(
) -> datetime.datetime:
return parser.isoparse(d)


else:

def datetime_structure_hook(
Expand All @@ -165,4 +171,4 @@ def datetime_structure_hook(
converter31.register_structure_hook(datetime.datetime, datetime_structure_hook)
converter40.register_structure_hook(datetime.datetime, datetime_structure_hook)
cattr.register_unstructure_hook(model.Model, unstructure_hook) # type: ignore
cattr.register_unstructure_hook(datetime.datetime, lambda dt: dt.strftime(DATETIME_FMT))
cattr.register_unstructure_hook(datetime.datetime, lambda dt: dt.strftime(DATETIME_FMT)) # type: ignore
5 changes: 3 additions & 2 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"python-dateutil;python_version<'3.7'",
# Python 3.7+
"attrs >= 20.1.0;python_version>='3.7'",
"cattrs == 1.1.2;python_version>='3.7'",
"cattrs >= 1.3;python_version>='3.7'",
"typing-extensions;python_version<'3.8'",
]

Expand All @@ -54,7 +54,8 @@
name=NAME,
package_data={"looker_sdk": ["py.typed", "looker_sdk/looker-sample.ini"]},
packages=find_packages(),
python_requires="~=3.6",
# restrict python to <=3.9.9 due to https://github.com/looker-open-source/sdk-codegen/issues/944
python_requires=">=3.6, <=3.9.9",
url="https://pypi.python.org/pypi/looker_sdk",
version=VERSION,
)

0 comments on commit ba28ac6

Please sign in to comment.