fmtr.tools 1.3.38__py3-none-any.whl → 1.3.40__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fmtr.tools might be problematic. Click here for more details.

@@ -1,3 +1,4 @@
1
+ from google.auth.transport.requests import Request
1
2
  from google.oauth2.credentials import Credentials
2
3
  from google_auth_oauthlib.flow import InstalledAppFlow
3
4
  from googleapiclient.discovery import build
@@ -20,8 +21,12 @@ class Authenticator:
20
21
 
21
22
  @classmethod
22
23
  def auth(cls):
23
- msg = f'Doing auth for service {cls.SERVICE} ({cls.VERSION})...'
24
- logger.info(msg)
24
+ """
25
+
26
+ Do initial authentication or refresh token if expired.
27
+
28
+ """
29
+ logger.info(f'Doing auth for service {cls.SERVICE} ({cls.VERSION})...')
25
30
 
26
31
  PATH_CREDS = cls.PATH / 'credentials.json'
27
32
  PATH_TOKEN = cls.PATH / f'{cls.SERVICE}.json'
@@ -29,9 +34,15 @@ class Authenticator:
29
34
  if PATH_TOKEN.exists():
30
35
  data_token = PATH_TOKEN.read_json()
31
36
  credentials = Credentials.from_authorized_user_info(data_token, cls.SCOPES)
37
+ if credentials.expired:
38
+ with logger.span(f'Credentials expired for {cls.SERVICE}. Will refresh...'):
39
+ logger.warning(f'{cls.SERVICE}. {PATH_CREDS.exists()=} {PATH_TOKEN.exists()=} {credentials.valid=} {credentials.expired=} {credentials.expiry=}')
40
+ credentials.refresh(Request())
41
+ PATH_TOKEN.write_text(credentials.to_json())
32
42
  else:
33
43
  flow = InstalledAppFlow.from_client_secrets_file(PATH_CREDS, cls.SCOPES)
44
+ flow.authorization_url(prompt='consent', access_type='offline')
34
45
  credentials = flow.run_local_server(open_browser=False, port=cls.PORT)
35
46
  PATH_TOKEN.write_text(credentials.to_json())
36
- service = build(cls.SERVICE, cls.VERSION, credentials=credentials)
37
- return service
47
+
48
+ return build(cls.SERVICE, cls.VERSION, credentials=credentials)
@@ -3,5 +3,6 @@ from fmtr.tools.import_tools import MissingExtraMockModule
3
3
  try:
4
4
  from fmtr.tools.interface_tools.interface_tools import Interface, update, progress
5
5
  from fmtr.tools.interface_tools import controls
6
+ from fmtr.tools.interface_tools.context import Context
6
7
  except ImportError as exception:
7
8
  Interface = update = progress = controls = MissingExtraMockModule('interface', exception)
@@ -0,0 +1,12 @@
1
+ from flet.core.page import Page
2
+
3
+ from fmtr.tools.data_modelling_tools import Base, MixinArbitraryTypes
4
+
5
+
6
+ class Context(Base, MixinArbitraryTypes):
7
+ """
8
+
9
+ Base context class
10
+
11
+ """
12
+ page: Page
@@ -1,12 +1,13 @@
1
- from functools import cached_property
2
-
3
1
  import flet as ft
4
2
  from flet.core.types import AppView
5
3
  from flet.core.view import View
4
+ from functools import cached_property
5
+ from typing import TypeVar, Generic, Type
6
6
 
7
7
  from fmtr.tools import environment_tools
8
8
  from fmtr.tools.constants import Constants
9
9
  from fmtr.tools.function_tools import MethodDecorator
10
+ from fmtr.tools.interface_tools.context import Context
10
11
  from fmtr.tools.logging_tools import logger
11
12
 
12
13
 
@@ -55,9 +56,10 @@ class progress(update):
55
56
  super().stop(instance)
56
57
 
57
58
 
59
+ T = TypeVar('T', bound=Context)
58
60
 
59
61
 
60
- class Interface(ft.Column):
62
+ class Interface(Generic[T], ft.Column):
61
63
  """
62
64
 
63
65
  Simple interface base class.
@@ -72,12 +74,15 @@ class Interface(ft.Column):
72
74
  ROUTE_ROOT = '/'
73
75
  SCROLL = ft.ScrollMode.AUTO
74
76
 
75
- def __init__(self, *args, **kwargs):
77
+ TypeContext: Type[T] = Context
78
+
79
+ def __init__(self, context: T, *args, **kwargs):
76
80
  """
77
81
 
78
82
  Instantiate and apply interface config
79
83
 
80
84
  """
85
+ self.context = context
81
86
  super().__init__(*args, **kwargs, scroll=self.SCROLL)
82
87
 
83
88
  @classmethod
@@ -88,9 +93,11 @@ class Interface(ft.Column):
88
93
 
89
94
  """
90
95
  if not page.on_route_change:
96
+ page.title = cls.TITLE
91
97
  page.theme = cls.get_theme()
92
98
  page.views.clear()
93
- self = cls()
99
+ context = cls.TypeContext(page=page)
100
+ self = cls(context)
94
101
  view = self.view
95
102
  if not view:
96
103
  view = self
fmtr/tools/version CHANGED
@@ -1 +1 @@
1
- 1.3.38
1
+ 1.3.40
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fmtr.tools
3
- Version: 1.3.38
3
+ Version: 1.3.40
4
4
  Summary: Collection of high-level tools to simplify everyday development tasks, with a focus on AI/ML
5
5
  Home-page: https://github.com/fmtr/fmtr.tools
6
6
  Author: Frontmatter
@@ -133,62 +133,62 @@ Requires-Dist: logfire[httpx]; extra == "webhook"
133
133
  Provides-Extra: browsers
134
134
  Requires-Dist: playwright; extra == "browsers"
135
135
  Provides-Extra: all
136
- Requires-Dist: flet-video; extra == "all"
137
- Requires-Dist: google-auth; extra == "all"
136
+ Requires-Dist: contexttimer; extra == "all"
137
+ Requires-Dist: flet[all]; extra == "all"
138
+ Requires-Dist: torchaudio; extra == "all"
139
+ Requires-Dist: yamlscript; extra == "all"
140
+ Requires-Dist: filetype; extra == "all"
138
141
  Requires-Dist: logfire[httpx]; extra == "all"
139
- Requires-Dist: pymupdf4llm; extra == "all"
142
+ Requires-Dist: transformers[sentencepiece]; extra == "all"
143
+ Requires-Dist: google-auth-httplib2; extra == "all"
144
+ Requires-Dist: diskcache; extra == "all"
145
+ Requires-Dist: appdirs; extra == "all"
146
+ Requires-Dist: faker; extra == "all"
140
147
  Requires-Dist: deepmerge; extra == "all"
141
148
  Requires-Dist: pydantic-ai[logfire,openai]; extra == "all"
142
- Requires-Dist: Unidecode; extra == "all"
143
- Requires-Dist: semver; extra == "all"
144
- Requires-Dist: diskcache; extra == "all"
145
- Requires-Dist: pandas; extra == "all"
146
- Requires-Dist: pydevd-pycharm~=251.25410.159; extra == "all"
147
- Requires-Dist: ollama; extra == "all"
148
- Requires-Dist: peft; extra == "all"
149
- Requires-Dist: playwright; extra == "all"
150
- Requires-Dist: html2text; extra == "all"
149
+ Requires-Dist: openai; extra == "all"
150
+ Requires-Dist: distributed; extra == "all"
151
+ Requires-Dist: httpx; extra == "all"
152
+ Requires-Dist: dask[bag]; extra == "all"
153
+ Requires-Dist: tokenizers; extra == "all"
154
+ Requires-Dist: docker; extra == "all"
151
155
  Requires-Dist: sentence_transformers; extra == "all"
152
- Requires-Dist: pydantic; extra == "all"
153
- Requires-Dist: sre_yield; extra == "all"
154
- Requires-Dist: tabulate; extra == "all"
155
- Requires-Dist: appdirs; extra == "all"
156
- Requires-Dist: bokeh; extra == "all"
156
+ Requires-Dist: tinynetrc; extra == "all"
157
+ Requires-Dist: google-api-python-client; extra == "all"
157
158
  Requires-Dist: dnspython[doh]; extra == "all"
158
- Requires-Dist: yamlscript; extra == "all"
159
- Requires-Dist: logfire[fastapi]; extra == "all"
160
- Requires-Dist: regex; extra == "all"
161
159
  Requires-Dist: fastapi; extra == "all"
162
- Requires-Dist: torchaudio; extra == "all"
160
+ Requires-Dist: uvicorn[standard]; extra == "all"
161
+ Requires-Dist: html2text; extra == "all"
162
+ Requires-Dist: ollama; extra == "all"
163
163
  Requires-Dist: pytest-cov; extra == "all"
164
- Requires-Dist: flet[all]; extra == "all"
165
- Requires-Dist: google-auth-oauthlib; extra == "all"
166
164
  Requires-Dist: pymupdf; extra == "all"
167
- Requires-Dist: torchvision; extra == "all"
168
- Requires-Dist: google-api-python-client; extra == "all"
169
- Requires-Dist: uvicorn[standard]; extra == "all"
170
- Requires-Dist: tokenizers; extra == "all"
171
- Requires-Dist: logfire; extra == "all"
165
+ Requires-Dist: json_repair; extra == "all"
166
+ Requires-Dist: logfire[fastapi]; extra == "all"
167
+ Requires-Dist: tabulate; extra == "all"
172
168
  Requires-Dist: cachetools; extra == "all"
173
- Requires-Dist: distributed; extra == "all"
169
+ Requires-Dist: semver; extra == "all"
170
+ Requires-Dist: huggingface_hub; extra == "all"
174
171
  Requires-Dist: openpyxl; extra == "all"
172
+ Requires-Dist: pydevd-pycharm~=251.25410.159; extra == "all"
173
+ Requires-Dist: pymupdf4llm; extra == "all"
174
+ Requires-Dist: playwright; extra == "all"
175
+ Requires-Dist: sre_yield; extra == "all"
176
+ Requires-Dist: flet-webview; extra == "all"
177
+ Requires-Dist: google-auth-oauthlib; extra == "all"
178
+ Requires-Dist: Unidecode; extra == "all"
175
179
  Requires-Dist: setuptools; extra == "all"
176
- Requires-Dist: huggingface_hub; extra == "all"
180
+ Requires-Dist: google-auth; extra == "all"
181
+ Requires-Dist: pyyaml; extra == "all"
182
+ Requires-Dist: pydantic; extra == "all"
183
+ Requires-Dist: pandas; extra == "all"
184
+ Requires-Dist: regex; extra == "all"
185
+ Requires-Dist: logfire; extra == "all"
186
+ Requires-Dist: peft; extra == "all"
177
187
  Requires-Dist: pydantic-settings; extra == "all"
178
- Requires-Dist: httpx; extra == "all"
179
- Requires-Dist: json_repair; extra == "all"
180
188
  Requires-Dist: httpx_retries; extra == "all"
181
- Requires-Dist: filetype; extra == "all"
182
- Requires-Dist: faker; extra == "all"
183
- Requires-Dist: docker; extra == "all"
184
- Requires-Dist: contexttimer; extra == "all"
185
- Requires-Dist: google-auth-httplib2; extra == "all"
186
- Requires-Dist: openai; extra == "all"
187
- Requires-Dist: transformers[sentencepiece]; extra == "all"
188
- Requires-Dist: dask[bag]; extra == "all"
189
- Requires-Dist: flet-webview; extra == "all"
190
- Requires-Dist: tinynetrc; extra == "all"
191
- Requires-Dist: pyyaml; extra == "all"
189
+ Requires-Dist: flet-video; extra == "all"
190
+ Requires-Dist: bokeh; extra == "all"
191
+ Requires-Dist: torchvision; extra == "all"
192
192
  Dynamic: author
193
193
  Dynamic: author-email
194
194
  Dynamic: description
@@ -12,7 +12,7 @@ fmtr/tools/debugging_tools.py,sha256=_xzqS0V5BpL8d06j-jVQjGgI7T020QsqVXKAKMz7Du8
12
12
  fmtr/tools/docker_tools.py,sha256=rdaZje2xhlmnfQqZnR7IHgRdWncTLjrJcViUTt5oEwk,617
13
13
  fmtr/tools/environment_tools.py,sha256=43uqfj1G1bNX0IwKz-NKbu3AbFYSdbBuGN9rlThe030,1845
14
14
  fmtr/tools/function_tools.py,sha256=O1K8HwftXfzrBblNZrj-BhWNbr4poJghrXNr2mFcylI,2831
15
- fmtr/tools/google_api_tools.py,sha256=owWE0GlnJjmVbXus8ENxT2PH7Fnd3m_r-14xyR7lAnA,1107
15
+ fmtr/tools/google_api_tools.py,sha256=QUungBoj5SCaBQnMjn9QpXtWmdNCplbw8ZPK9LXi77U,1691
16
16
  fmtr/tools/hash_tools.py,sha256=tr4HXpeT6rRrDk6TvMlRPUSrLRRaov96y128OI2tzsc,729
17
17
  fmtr/tools/hfh_tools.py,sha256=DCDIWuWlhtmIGCtp9cLcOTTEw_4yN_NocLX8w5NZsbk,2384
18
18
  fmtr/tools/html_tools.py,sha256=0nN8Nz5HtG9bXyApYfHSKEivLlxjsm3Gn6Mg2TK0brI,394
@@ -45,7 +45,7 @@ fmtr/tools/tabular_tools.py,sha256=tpIpZzYku1HcJrHZJL6BC39LmN3WUWVhFbK2N7nDVmE,1
45
45
  fmtr/tools/tokenization_tools.py,sha256=me-IBzSLyNYejLybwjO9CNB6Mj2NYfKPaOVThXyaGNg,4268
46
46
  fmtr/tools/tools.py,sha256=CAsApa1YwVdNE6H66Vjivs_mXYvOas3rh7fPELAnTpk,795
47
47
  fmtr/tools/unicode_tools.py,sha256=yS_9wpu8ogNoiIL7s1G_8bETFFO_YQlo4LNPv1NLDeY,52
48
- fmtr/tools/version,sha256=CUhoLtYuOkZkXro_emKCgxROYC4p3ceZxrtbyGlGwQw,6
48
+ fmtr/tools/version,sha256=509ysBiNGW5G48sMKppbTs43JeWeaLLb02lbfZjkc48,6
49
49
  fmtr/tools/webhook_tools.py,sha256=q3pVJ1NCem2SrMuFcLxiWd7DibFs7Q-uGtojfXd3Qcg,380
50
50
  fmtr/tools/yaml_tools.py,sha256=Bhhyd6GQVKO72Lp8ky7bAUjIB_65Hdh0Q45SKIEe6S8,1901
51
51
  fmtr/tools/ai_tools/__init__.py,sha256=JZrLuOFNV1A3wvJgonxOgz_4WS-7MfCuowGWA5uYCjs,372
@@ -62,9 +62,10 @@ fmtr/tools/entrypoints/ep_test.py,sha256=B8HfWISfSgw_xVX475CbJGh_QnpOe9MH65H8qGj
62
62
  fmtr/tools/entrypoints/install_yamlscript.py,sha256=D9-QET4uPkwMvOBQJAgzn1fYb7Z7VAgZzFdHSAXc3Qc,116
63
63
  fmtr/tools/entrypoints/remote_debug_test.py,sha256=wmKg9o2pQq7eqeHmaO8oviujNgtnsCVEXOdXLIcQWs4,123
64
64
  fmtr/tools/entrypoints/shell_debug.py,sha256=0No3tAg9Ri4_vvSlQCUtAY-11HR0nE45i0VVtiAViwY,106
65
- fmtr/tools/interface_tools/__init__.py,sha256=nODVT7v657onpmak7qbW4P8NoW2HQqyeEDUSx5pZAFg,331
65
+ fmtr/tools/interface_tools/__init__.py,sha256=hgierRDkJDXrYkPM4z-m44aL7OMS8DKNKJzaXayBmw4,390
66
+ fmtr/tools/interface_tools/context.py,sha256=vTrHwat2s71HCZZySerIlkvhVeeDzyuAWeY4puLVqSY,203
66
67
  fmtr/tools/interface_tools/controls.py,sha256=oOl0_sZB8fkvYB-9A5yjArfQmFQLMCsVGgRNrJAFJm4,332
67
- fmtr/tools/interface_tools/interface_tools.py,sha256=a7WRwf8TKek8ML08ANfkncLfoMHWk5b_929bFf3Y6cQ,3577
68
+ fmtr/tools/interface_tools/interface_tools.py,sha256=y1Lnphbc00kBjP4GyR5YPtMevUS9BR1weex-J3qEw5A,3887
68
69
  fmtr/tools/path_tools/__init__.py,sha256=v5CpmzXq5Ii90FtcmxAJKiLxmguZMrPnQ_HdT872Np0,443
69
70
  fmtr/tools/path_tools/app_path_tools.py,sha256=JrJvtTDd_gkCKcZtBCDTMktsM77PZwGV_hzQX0g5GU8,1722
70
71
  fmtr/tools/path_tools/path_tools.py,sha256=eh30PpmH0wopy0wNWuPT84cmXY1EvqsTSDT7AV_GPOY,8034
@@ -81,9 +82,9 @@ fmtr/tools/tests/test_path.py,sha256=AkZQa6_8BQ-VaCyL_J-iKmdf2ZaM-xFYR37Kun3k4_g
81
82
  fmtr/tools/tests/test_yaml.py,sha256=jc0TwwKu9eC0LvFGNMERdgBue591xwLxYXFbtsRwXVM,287
82
83
  fmtr/tools/version_tools/__init__.py,sha256=pg4iLtmIr5HtyEW_j0fMFoIdzqi_w9xH8-grQaXLB28,318
83
84
  fmtr/tools/version_tools/version_tools.py,sha256=Hcc6yferZS1hHbugRTdiHhSNmXEEG0hjCiTTXKna-YY,1127
84
- fmtr_tools-1.3.38.dist-info/licenses/LICENSE,sha256=FW9aa6vVN5IjRQWLT43hs4_koYSmpcbIovlKeAJ0_cI,10757
85
- fmtr_tools-1.3.38.dist-info/METADATA,sha256=fNG_O_TGAtpbSYUjS7nn5eGE150AOSNECmadWbN73Gs,16259
86
- fmtr_tools-1.3.38.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
87
- fmtr_tools-1.3.38.dist-info/entry_points.txt,sha256=h-r__Xh5njtFqreMLg6cGuTFS4Qh-QqJPU1HB-_BS-Q,357
88
- fmtr_tools-1.3.38.dist-info/top_level.txt,sha256=LXem9xCgNOD72tE2gRKESdiQTL902mfFkwWb6-dlwEE,5
89
- fmtr_tools-1.3.38.dist-info/RECORD,,
85
+ fmtr_tools-1.3.40.dist-info/licenses/LICENSE,sha256=FW9aa6vVN5IjRQWLT43hs4_koYSmpcbIovlKeAJ0_cI,10757
86
+ fmtr_tools-1.3.40.dist-info/METADATA,sha256=m6rHbc4NRBpELpK60mCP5SB9qOwm-EolTfaKyKKCMRQ,16259
87
+ fmtr_tools-1.3.40.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
88
+ fmtr_tools-1.3.40.dist-info/entry_points.txt,sha256=h-r__Xh5njtFqreMLg6cGuTFS4Qh-QqJPU1HB-_BS-Q,357
89
+ fmtr_tools-1.3.40.dist-info/top_level.txt,sha256=LXem9xCgNOD72tE2gRKESdiQTL902mfFkwWb6-dlwEE,5
90
+ fmtr_tools-1.3.40.dist-info/RECORD,,