From ae496abf9a45327c1d0b9b08dafeb1334c9711f46262d4d3fe27b067f09563e9 Mon Sep 17 00:00:00 2001 From: Matej Cepl Date: Thu, 14 Apr 2022 20:31:15 +0000 Subject: [PATCH] Accepting request 970240 from home:bnavigator:branches:devel:languages:python Always check your metadata!!! - Update optional runtime and buildtime requirements * 0.13 replaced deprecated ouauth2client with newer oauthlib. * 0.11 replaced toml with qtoml (unavailabe in TW) OBS-URL: https://build.opensuse.org/request/show/970240 OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-dictknife?expand=0&rev=6 --- dictknife-omit-oauth2client.patch | 287 ++++++++++++++++++++++++++++++ python-dictknife.changes | 7 + python-dictknife.spec | 11 +- 3 files changed, 300 insertions(+), 5 deletions(-) create mode 100644 dictknife-omit-oauth2client.patch diff --git a/dictknife-omit-oauth2client.patch b/dictknife-omit-oauth2client.patch new file mode 100644 index 0000000..3e86648 --- /dev/null +++ b/dictknife-omit-oauth2client.patch @@ -0,0 +1,287 @@ +From ddb8ceb4eff72fea9b5220f2ac0cb5150630fe6c Mon Sep 17 00:00:00 2001 +From: podhmo +Date: Wed, 8 Jan 2020 06:25:38 +0900 +Subject: [PATCH 1/3] refactor: black + +--- + dictknife/loading/_gsuite.py | 44 ++++++++++++++++++++++++------------ + 1 file changed, 30 insertions(+), 14 deletions(-) + +diff --git a/dictknife/loading/_gsuite.py b/dictknife/loading/_gsuite.py +index e272b3c..024ec6f 100644 +--- a/dictknife/loading/_gsuite.py ++++ b/dictknife/loading/_gsuite.py +@@ -10,6 +10,7 @@ + from oauth2client.client import OAuth2Credentials + from dictknife.langhelpers import reify + from googleapiclient.discovery_cache.base import Cache ++ + # from googleapiclient.discovery_cache import LOGGER as noisy_logger + # # supress stderr message of 'ImportError: file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth' # noqa + # noisy_logger.setLevel(logging.ERROR) # noqa +@@ -26,8 +27,8 @@ + # 'https://www.googleapis.com/auth/drive.readonly' + # 'https://www.googleapis.com/auth/spreadsheets' + # 'https://www.googleapis.com/auth/spreadsheets.readonly' +-SCOPE = 'https://www.googleapis.com/auth/spreadsheets' +-SCOPE_READONLY = 'https://www.googleapis.com/auth/spreadsheets.readonly' ++SCOPE = "https://www.googleapis.com/auth/spreadsheets" ++SCOPE_READONLY = "https://www.googleapis.com/auth/spreadsheets.readonly" + + + def get_credentials( +@@ -52,7 +53,9 @@ def get_credentials( + logger.info("credentials are invalid (or not found). %s", cache_path) + logger.debug("see: %s", config_path) + flow = client.flow_from_clientsecrets(config_path, scopes) +- flags = tools.argparser.parse_args(["--logging_level=DEBUG", "--noauth_local_webserver"]) ++ flags = tools.argparser.parse_args( ++ ["--logging_level=DEBUG", "--noauth_local_webserver"] ++ ) + credentials = tools.run_flow(flow, store, flags=flags) + return credentials + +@@ -66,21 +69,31 @@ def get_credentials_failback_webbrowser( + ) -> OAuth2Credentials: + if scopes is None: + import webbrowser ++ + url = "https://developers.google.com/identity/protocols/googlescopes" + print( +- "please passing scopes: (e.g. 'https://www.googleapis.com/auth/spreadsheets.readonly')\nopening {}...". +- format(url), +- file=sys.stderr ++ "please passing scopes: (e.g. 'https://www.googleapis.com/auth/spreadsheets.readonly')\nopening {}...".format( ++ url ++ ), ++ file=sys.stderr, + ) + webbrowser.open(url, new=1, autoraise=True) + sys.exit(1) + while True: + try: +- return get_credentials(config_path, scopes=scopes, cache_path=cache_path, logger=logger) ++ return get_credentials( ++ config_path, scopes=scopes, cache_path=cache_path, logger=logger ++ ) + except InvalidClientSecretsError: + import webbrowser ++ + url = "https://console.cloud.google.com/apis/credentials" +- print("please save credentials.json at {!r}.".format(config_path), file=sys.stderr) ++ print( ++ "please save credentials.json at {!r} (OAuth 2.0 client ID)".format( ++ config_path ++ ), ++ file=sys.stderr, ++ ) + webbrowser.open(url, new=1, autoraise=True) + input("saved? (if saved, please typing enter key)") + +@@ -137,7 +150,7 @@ def service(self): + need_save = self.cache.is_empty + credentials = self.get_credentials(self.config_path, scopes=self.scopes) + service = googleapiclient.discovery.build( +- 'sheets', 'v4', http=credentials.authorize(self.http), cache=self.cache ++ "sheets", "v4", http=credentials.authorize(self.http), cache=self.cache + ) + if need_save: + self._save_cache(self.cache) +@@ -157,13 +170,16 @@ def load_sheet(self, guessed, *, with_header=True): + return [ + { + "title": sheet["properties"]["title"], +- **sheet["properties"]["gridProperties"] +- } for sheet in result.get("sheets") or [] ++ **sheet["properties"]["gridProperties"], ++ } ++ for sheet in result.get("sheets") or [] + ] + +- result = resource.values().get( +- spreadsheetId=guessed.spreadsheet_id, range=range_value +- ).execute() ++ result = ( ++ resource.values() ++ .get(spreadsheetId=guessed.spreadsheet_id, range=range_value) ++ .execute() ++ ) + values = result.get("values") + if not with_header: + return values + +From e1859e3460e35ff2420db5ef0cd5ab20cdf0eb4e Mon Sep 17 00:00:00 2001 +From: podhmo +Date: Wed, 8 Jan 2020 07:11:39 +0900 +Subject: [PATCH 2/3] fix: use google_auth_oauthlib + +--- + dictknife/loading/_gsuite.py | 73 +++++++++++++++++++++--------------- + 1 file changed, 43 insertions(+), 30 deletions(-) + +diff --git a/dictknife/loading/_gsuite.py b/dictknife/loading/_gsuite.py +index 024ec6f..81df050 100644 +--- a/dictknife/loading/_gsuite.py ++++ b/dictknife/loading/_gsuite.py +@@ -3,12 +3,10 @@ + import os.path + import logging + import pickle +-import httplib2 +-from oauth2client import file, client +-from oauth2client import tools +-from oauth2client.clientsecrets import InvalidClientSecretsError +-from oauth2client.client import OAuth2Credentials ++from google_auth_oauthlib import flow ++from google.oauth2.credentials import Credentials + from dictknife.langhelpers import reify ++ + from googleapiclient.discovery_cache.base import Cache + + # from googleapiclient.discovery_cache import LOGGER as noisy_logger +@@ -18,7 +16,7 @@ + + logger = logging.getLogger(__name__) + +-DEFAULT_CREDENTIALS_PATH = "~/.config/dictknife/credentials.json" ++DEFAULT_CREDENTIALS_PATH = "~/.config/dictknife/google-client-secrets.json" + DEFAULT_DISCOVERY_CACHE_PATH = "~/.config/dictknife/discovery.pickle" + + # Authorize using one of the following scopes: +@@ -36,28 +34,45 @@ def get_credentials( + *, + cache_path: t.Optional[str] = None, + scopes: t.Sequence[str], +- logger: t.Any = logger +-) -> OAuth2Credentials: ++ logger: t.Any = logger, ++ launch_browser: bool = True, ++) -> Credentials: + config_path = os.path.expanduser(config_path) + if cache_path is None: +- cache_path = os.path.join(os.path.dirname(config_path), "token.json") ++ cache_path = os.path.join( ++ os.path.dirname(config_path), "google-token.json" ++ ) + cache_path = os.path.expanduser(cache_path) + + os.makedirs(os.path.dirname(config_path), exist_ok=True) + + logger.debug("see: %s", cache_path) +- store = file.Storage(cache_path) +- credentials = store.get() +- +- if not credentials or credentials.invalid: +- logger.info("credentials are invalid (or not found). %s", cache_path) +- logger.debug("see: %s", config_path) +- flow = client.flow_from_clientsecrets(config_path, scopes) +- flags = tools.argparser.parse_args( +- ["--logging_level=DEBUG", "--noauth_local_webserver"] +- ) +- credentials = tools.run_flow(flow, store, flags=flags) +- return credentials ++ try: ++ credentials = Credentials.from_authorized_user_file(cache_path, scopes=scopes) ++ if credentials.valid: ++ return credentials ++ ++ # todo: refresh token ++ from google.auth.transport.requests import Request ++ ++ credentials.refresh(Request()) # xxx ++ if credentials.valid: ++ return credentials ++ except FileNotFoundError: ++ pass ++ ++ logger.info("credentials are invalid (or not found). %s", cache_path) ++ logger.debug("see: %s", config_path) ++ appflow = flow.InstalledAppFlow.from_client_secrets_file(config_path, scopes=scopes) ++ ++ if launch_browser: ++ appflow.run_local_server() ++ else: ++ appflow.run_console() ++ ++ with open(cache_path, "w") as wf: ++ wf.write(appflow.credentials.to_json()) ++ return appflow.credentials + + + def get_credentials_failback_webbrowser( +@@ -65,8 +80,8 @@ def get_credentials_failback_webbrowser( + *, + cache_path: t.Optional[str] = None, + scopes: t.Optional[t.Sequence[str]] = None, +- logger: t.Any = logger +-) -> OAuth2Credentials: ++ logger: t.Any = logger, ++) -> Credentials: + if scopes is None: + import webbrowser + +@@ -84,14 +99,13 @@ def get_credentials_failback_webbrowser( + return get_credentials( + config_path, scopes=scopes, cache_path=cache_path, logger=logger + ) +- except InvalidClientSecretsError: ++ except (FileNotFoundError, ValueError) as e: ++ logger.warn("excpetion %r", e) + import webbrowser + + url = "https://console.cloud.google.com/apis/credentials" + print( +- "please save credentials.json at {!r} (OAuth 2.0 client ID)".format( +- config_path +- ), ++ "please save fileat {!r} (OAuth 2.0 client ID)".format(config_path), + file=sys.stderr, + ) + webbrowser.open(url, new=1, autoraise=True) +@@ -129,13 +143,12 @@ def __init__( + discovery_cache_path=DEFAULT_DISCOVERY_CACHE_PATH, + scopes=[SCOPE], + get_credentials=get_credentials_failback_webbrowser, +- http=None ++ http=None, + ): + self.config_path = os.path.expanduser(config_path) + self.discovery_cache_path = os.path.expanduser(discovery_cache_path) + self.scopes = scopes + self.get_credentials = get_credentials +- self.http = http or httplib2.Http() + + @reify + def cache(self): +@@ -150,7 +163,7 @@ def service(self): + need_save = self.cache.is_empty + credentials = self.get_credentials(self.config_path, scopes=self.scopes) + service = googleapiclient.discovery.build( +- "sheets", "v4", http=credentials.authorize(self.http), cache=self.cache ++ "sheets", "v4", credentials=credentials, cache=self.cache + ) + if need_save: + self._save_cache(self.cache) + +From 391c0690011aee72b0ad259d7fe77521da9f9a8c Mon Sep 17 00:00:00 2001 +From: podhmo +Date: Wed, 8 Jan 2020 07:18:40 +0900 +Subject: [PATCH 3/3] chore: update setup.py + +--- + setup.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/setup.py b/setup.py +index 976a9f5..3f91710 100644 +--- a/setup.py ++++ b/setup.py +@@ -37,7 +37,7 @@ + "docs": ["sphinx", "recommonmark", "sphinx_rtd_theme"], + "load": ["PyYAML", "qtoml"], + "command": ["PyYAML", "magicalimport", "prestring"], +- "spreadsheet": ["google-api-python-client", "oauth2client"], ++ "spreadsheet": ["google-api-python-client", "google-auth-oauthlib"], + }, + tests_require=[], + test_suite="dictknife.tests", diff --git a/python-dictknife.changes b/python-dictknife.changes index aa3d50c..07713b3 100644 --- a/python-dictknife.changes +++ b/python-dictknife.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Thu Apr 14 19:15:20 UTC 2022 - Ben Greiner + +- Update optional runtime and buildtime requirements + * 0.13 replaced deprecated ouauth2client with newer oauthlib. + * 0.11 replaced toml with qtoml (unavailabe in TW) + ------------------------------------------------------------------- Thu Feb 3 01:38:47 UTC 2022 - Steve Kowalik diff --git a/python-dictknife.spec b/python-dictknife.spec index e899db9..521f382 100644 --- a/python-dictknife.spec +++ b/python-dictknife.spec @@ -28,24 +28,24 @@ Source: https://github.com/podhmo/dictknife/archive/%{version}.tar.gz#/d Patch0: support-python-310.patch BuildRequires: %{python_module PyYAML} BuildRequires: %{python_module google-api-python-client} +BuildRequires: %{python_module google-auth-oauthlib} BuildRequires: %{python_module jsonpatch} BuildRequires: %{python_module magicalimport} -BuildRequires: %{python_module oauth2client} BuildRequires: %{python_module prestring} BuildRequires: %{python_module pytest} BuildRequires: %{python_module setuptools} -BuildRequires: %{python_module toml} BuildRequires: fdupes BuildRequires: python-rpm-macros Requires(post): update-alternatives Requires(postun):update-alternatives Suggests: python-PyYAML Suggests: python-google-api-python-client +Suggests: python-google-auth-oauthlib Suggests: python-jsonpatch Suggests: python-magicalimport -Suggests: python-oauth2client Suggests: python-prestring -Suggests: python-toml +# Not available +Suggests: python-qtoml BuildArch: noarch %python_subpackages @@ -88,6 +88,7 @@ JSON pointer syntax. %python_alternative %{_bindir}/dictknife %python_alternative %{_bindir}/jsonknife %python_alternative %{_bindir}/swaggerknife -%{python_sitelib}/* +%{python_sitelib}/dictknife +%{python_sitelib}/dictknife-%{version}*-info %changelog