Skip to content

Commit

Permalink
refactor(python): remove deprecated Python 2 code (openfga#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamzeh authored Mar 7, 2024
2 parents 161c953 + d9f506c commit 50e73d9
Show file tree
Hide file tree
Showing 63 changed files with 807 additions and 933 deletions.
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,12 @@ build-client-python:
make run-in-docker sdk_language=python image=busybox:${BUSYBOX_DOCKER_TAG} command="/bin/sh -c 'patch -p1 /module/openfga_sdk/api/open_fga_api.py /config/clients/python/patches/open_fga_api.py.patch'"
make run-in-docker sdk_language=python image=busybox:${BUSYBOX_DOCKER_TAG} command="/bin/sh -c 'patch -p1 /module/openfga_sdk/sync/open_fga_api.py /config/clients/python/patches/open_fga_api_sync.py.patch'"
make run-in-docker sdk_language=python image=busybox:${BUSYBOX_DOCKER_TAG} command="/bin/sh -c 'patch -p1 /module/docs/OpenFgaApi.md /config/clients/python/patches/OpenFgaApi.md.patch'"
make run-in-docker sdk_language=python image=python:${PYTHON_DOCKER_TAG} command="/bin/sh -c 'python -m pip install pycodestyle==2.10.0 autopep8==2.0.2; autopep8 --in-place --ignore E402 --recursive openfga_sdk; autopep8 --in-place --recursive test'"
make run-in-docker sdk_language=python image=python:${PYTHON_DOCKER_TAG} command="/bin/sh -c 'python -m pip install pyupgrade==3.15.1 isort==5.13.2 black==24.2.0 autoflake==2.3.0; pyupgrade \`find . -name *.py -type f\` --py310-plus --keep-runtime-typing; isort . --profile black; black .; autoflake --exclude=__init__.py --in-place --remove-unused-variables --remove-all-unused-imports -r .'"
make run-in-docker sdk_language=python image=python:${PYTHON_DOCKER_TAG} command="/bin/sh -c 'pip install setuptools wheel && python setup.py sdist bdist_wheel'"

.PHONY: test-client-python
test-client-python: build-client-python
make run-in-docker sdk_language=python image=python:${PYTHON_DOCKER_TAG} command="/bin/sh -c 'python -m pip install -r test-requirements.txt; python -m unittest test/*'"
make run-in-docker sdk_language=python image=python:${PYTHON_DOCKER_TAG} command="/bin/sh -c 'python -m pip install -r test-requirements.txt; python -m flake8 --ignore F401,E402,E501,W504 openfga_sdk'"
# Need to ignore E402 (import order) to avoid circular dependency
make run-in-docker sdk_language=python image=python:${PYTHON_DOCKER_TAG} command="/bin/sh -c 'python -m pip install -r test-requirements.txt; python -m flake8 --ignore E501 test'"
make run-in-docker sdk_language=python image=python:${PYTHON_DOCKER_TAG} command="/bin/sh -c 'python -m pip install -r test-requirements.txt; pytest; flake8 . --count --show-source --statistics'"

### Java
.PHONY: tag-client-java
Expand Down
46 changes: 23 additions & 23 deletions config/clients/python/patches/open_fga_api.py.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
@@ -193,13 +193,15 @@
_request_auth=local_var_params.get('_request_auth'),
_oauth2_client=self._oauth2_client))
- async def create_store(self, **kwargs): # noqa: E501
+ async def create_store(self, body, **kwargs): # noqa: E501
"""Create a store # noqa: E501
Create a unique OpenFGA store which will be used to store authorization models and relationship tuples. # noqa: E501

- async def create_store(self, **kwargs):
+ async def create_store(self, body, **kwargs):
"""Create a store

Create a unique OpenFGA store which will be used to store authorization models and relationship tuples.

- >>> thread = await api.create_store()
+ >>> thread = await api.create_store(body)

+ :param body: (required)
+ :type body: CreateStoreRequest
:param async_req: Whether to execute the request asynchronously.
Expand All @@ -21,36 +21,36 @@
@@ -216,15 +218,17 @@
:rtype: CreateStoreResponse
"""
kwargs['_return_http_data_only'] = True
- return await (self.create_store_with_http_info(**kwargs)) # noqa: E501
+ return await (self.create_store_with_http_info(body, **kwargs)) # noqa: E501
- async def create_store_with_http_info(self, **kwargs): # noqa: E501
+ async def create_store_with_http_info(self, body, **kwargs): # noqa: E501
"""Create a store # noqa: E501
Create a unique OpenFGA store which will be used to store authorization models and relationship tuples. # noqa: E501
kwargs["_return_http_data_only"] = True
- return await self.create_store_with_http_info(**kwargs)
+ return await self.create_store_with_http_info(body, **kwargs)

- async def create_store_with_http_info(self, **kwargs):
+ async def create_store_with_http_info(self, body, **kwargs):
"""Create a store

Create a unique OpenFGA store which will be used to store authorization models and relationship tuples.

- >>> thread = api.create_store_with_http_info()
+ >>> thread = api.create_store_with_http_info(body)

+ :param body: (required)
+ :type body: CreateStoreRequest
:param async_req: Whether to execute the request asynchronously.
:type async_req: bool, optional
:param _return_http_data_only: response data without head status code
@@ -253,6 +257,8 @@

all_params = [

+ 'body'
+
]
all_params.extend(
[
@@ -312,7 +318,7 @@
}

return await (self.api_client.call_api(
- '/stores'.replace('{store_id}', store_id), 'POST',
+ '/stores', 'POST',
Expand All @@ -59,7 +59,7 @@
header_params,
@@ -998,7 +1004,7 @@
}

return await (self.api_client.call_api(
- '/stores'.replace('{store_id}', store_id), 'GET',
+ '/stores', 'GET',
Expand Down
46 changes: 23 additions & 23 deletions config/clients/python/patches/open_fga_api_sync.py.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
@@ -193,13 +193,15 @@
_request_auth=local_var_params.get('_request_auth'),
_oauth2_client=self._oauth2_client)
- def create_store(self, **kwargs): # noqa: E501
+ def create_store(self, body, **kwargs): # noqa: E501
"""Create a store # noqa: E501
Create a unique OpenFGA store which will be used to store authorization models and relationship tuples. # noqa: E501

- def create_store(self, **kwargs):
+ def create_store(self, body, **kwargs):
"""Create a store

Create a unique OpenFGA store which will be used to store authorization models and relationship tuples.

- >>> thread = api.create_store()
+ >>> thread = api.create_store(body)

+ :param body: (required)
+ :type body: CreateStoreRequest
:param async_req: Whether to execute the request asynchronously.
Expand All @@ -21,36 +21,36 @@
@@ -216,15 +218,17 @@
:rtype: CreateStoreResponse
"""
kwargs['_return_http_data_only'] = True
- return self.create_store_with_http_info(**kwargs) # noqa: E501
+ return self.create_store_with_http_info(body, **kwargs) # noqa: E501
- def create_store_with_http_info(self, **kwargs): # noqa: E501
+ def create_store_with_http_info(self, body, **kwargs): # noqa: E501
"""Create a store # noqa: E501
Create a unique OpenFGA store which will be used to store authorization models and relationship tuples. # noqa: E501
kwargs["_return_http_data_only"] = True
- return self.create_store_with_http_info(**kwargs)
+ return self.create_store_with_http_info(body, **kwargs)

- def create_store_with_http_info(self, **kwargs):
+ def create_store_with_http_info(self, body, **kwargs):
"""Create a store

Create a unique OpenFGA store which will be used to store authorization models and relationship tuples.

- >>> thread = api.create_store_with_http_info()
+ >>> thread = api.create_store_with_http_info(body)

+ :param body: (required)
+ :type body: CreateStoreRequest
:param async_req: Whether to execute the request asynchronously.
:type async_req: bool, optional
:param _return_http_data_only: response data without head status code
@@ -253,6 +257,8 @@

all_params = [

+ 'body'
+
]
all_params.extend(
[
@@ -312,7 +318,7 @@
}

return self.api_client.call_api(
- '/stores'.replace('{store_id}', store_id), 'POST',
+ '/stores', 'POST',
Expand All @@ -59,7 +59,7 @@
header_params,
@@ -998,7 +1004,7 @@
}

return self.api_client.call_api(
- '/stores'.replace('{store_id}', store_id), 'GET',
+ '/stores', 'GET',
Expand Down
18 changes: 7 additions & 11 deletions config/clients/python/template/.github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,17 @@ jobs:
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache: "pip"
cache-dependency-path: |
**/setup.cfg
**/requirements*.txt
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r test-requirements.txt
python -m pip install -r test-requirements.txt
- name: Test
run: python -m unittest test/*
- name: Flake8 on SDK
run: python -m flake8 --ignore F401,E402,E501,W504 openfga_sdk
- name: Flake8 on unit test
run: python -m flake8 --ignore E501 test
run: python -m pytest
- name: Flake8
run: flake8 . --count --show-source --statistics

publish:
runs-on: ubuntu-latest
Expand All @@ -55,14 +52,13 @@ jobs:
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: "3.10"
cache: 'pip'
cache: "pip"
cache-dependency-path: |
**/setup.cfg
**/requirements*.txt
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r test-requirements.txt
python -m pip install -r test-requirements.txt
- name: Build package
run: |
Expand Down
48 changes: 10 additions & 38 deletions config/clients/python/template/NOTICE_details.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Revision ID: 36bd43e0361ceff7245afbcd5d24c4760dac4d71
- pytest-cov (2.8.1) [MIT]
- python-dateutil (2.8.2) [Multi-license: Apache-2.0 OR BSD-3-Clause]
- setuptools (66.0.0) [MIT, MPL-2.0, GPL-3.0-only, BSD-3-Clause, Apache-2.0, Python-2.0]
- six (1.16.0) [MIT]
- urllib3 (1.26.14) [MIT, Apache-2.0, Python-2.0]


Expand Down Expand Up @@ -435,33 +434,6 @@ Permission to use, copy, modify, and distribute this software and its documentat
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.


--------------------------------------------------------------------------------
Package Title: six (1.16.0)
--------------------------------------------------------------------------------

* Declared Licenses *
MIT

Copyright (c) 2010-2020 Benjamin Peterson

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



--------------------------------------------------------------------------------
Package Title: urllib3 (1.26.14)
Expand Down Expand Up @@ -599,25 +571,25 @@ Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.

"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.

"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.

"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.

"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.

"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.

"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.

"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).

"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.

"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."

"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{docPrefix}}{{apiDocPath}}{{classname}}.md#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}}
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
The code in this repo was auto generated by [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) from a template based on the [python legacy template](https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/python-legacy), licensed under the [Apache License 2.0](https://github.com/OpenAPITools/openapi-generator/blob/master/LICENSE).
The code in this repo was auto generated by [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) from a template based on the [python legacy template](https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/python-legacy), licensed under the [Apache License 2.0](https://github.com/OpenAPITools/openapi-generator/blob/master/LICENSE).
5 changes: 1 addition & 4 deletions config/clients/python/template/__init__api.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
# flake8: noqa

# import apis into api package
{{#apiInfo}}{{#apis}}from {{apiPackage}}.{{classFilename}} import {{classname}}
{{/apis}}{{/apiInfo}}
{{/apis}}{{/apiInfo}}
5 changes: 0 additions & 5 deletions config/clients/python/template/__init__model.mustache
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# coding: utf-8

# flake8: noqa
{{>partial_header}}

# import models into model package
{{#models}}{{#model}}from {{modelPackage}}.{{classFilename}} import {{classname}}{{/model}}
{{/models}}
10 changes: 2 additions & 8 deletions config/clients/python/template/__init__package.mustache
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
# coding: utf-8

# flake8: noqa

{{>partial_header}}

__version__ = "{{packageVersion}}"

from {{packageName}}.client.client import OpenFgaClient
from {{packageName}}.client.configuration import ClientConfiguration

# import apis into sdk package
{{#apiInfo}}{{#apis}}from {{apiPackage}}.{{classFilename}} import {{classname}}
{{/apis}}{{/apiInfo}}
# import ApiClient
from {{packageName}}.api_client import ApiClient
from {{packageName}}.configuration import Configuration

from {{packageName}}.exceptions import OpenApiException
from {{packageName}}.exceptions import FgaValidationException
from {{packageName}}.exceptions import ApiValueError
from {{packageName}}.exceptions import ApiKeyError
from {{packageName}}.exceptions import ApiAttributeError
from {{packageName}}.exceptions import ApiException
# import models into sdk package

{{#models}}{{#model}}from {{modelPackage}}.{{classFilename}} import {{classname}}
{{/model}}{{/models}}
{{#recursionLimit}}
Expand Down
3 changes: 0 additions & 3 deletions config/clients/python/template/__init__sync.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# coding: utf-8

# flake8: noqa
{{>partial_header}}

from {{packageName}}.sync.client.client import OpenFgaClient
Expand Down
3 changes: 0 additions & 3 deletions config/clients/python/template/__init__sync_client.mustache
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
# coding: utf-8

# flake8: noqa
{{>partial_header}}
Loading

0 comments on commit 50e73d9

Please sign in to comment.