utils-mystuff 1.0.1__tar.gz → 1.2.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: utils-mystuff
3
- Version: 1.0.1
3
+ Version: 1.2.0
4
4
  Summary: Package with various utilities i.e. VB regex translation, CLI logging, file handling, basic GUI wrapper ...
5
5
  Project-URL: Documentation, https://dornech.github.io/utils-mystuff
6
6
  Project-URL: Source, https://github.com/dornech/utils-mystuff
@@ -10,22 +10,21 @@ Author-email: dornech <dornech@gmx.de>
10
10
  License: GPL-3.0-only
11
11
  License-File: AUTHORS.md
12
12
  License-File: LICENSE.txt
13
- Keywords: CLI logging,GUI wrapper,RegEx conversion,command line interface,file handling,logging,regular expression
13
+ Keywords: CLI logging,GUI wrapper,RegEx conversion,command line interface,config file reader,config parser,file handling,logger creartion,logging,regular expression
14
14
  Classifier: Programming Language :: Python
15
- Classifier: Programming Language :: Python :: 3.9
16
- Classifier: Programming Language :: Python :: 3.10
17
15
  Classifier: Programming Language :: Python :: 3.11
18
16
  Classifier: Programming Language :: Python :: 3.12
19
17
  Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
20
19
  Classifier: Programming Language :: Python :: Implementation :: CPython
21
- Requires-Python: >=3.9
20
+ Requires-Python: >=3.11
22
21
  Requires-Dist: easygui
23
22
  Requires-Dist: freesimplegui
23
+ Requires-Dist: hatchling
24
24
  Requires-Dist: pymsgbox
25
25
  Requires-Dist: python-dateutil
26
26
  Requires-Dist: pytz
27
- Provides-Extra: python39
28
- Requires-Dist: typing-extensions; extra == 'python39'
27
+ Requires-Dist: utils-mystuff
29
28
  Description-Content-Type: text/markdown
30
29
 
31
30
  # Personal utilities package for Python
@@ -15,14 +15,15 @@ build-backend = "hatchling.build"
15
15
  name = "utils-mystuff"
16
16
  description = "Package with various utilities i.e. VB regex translation, CLI logging, file handling, basic GUI wrapper ..."
17
17
  readme = "README.md"
18
- requires-python = ">=3.9"
18
+ requires-python = ">=3.11"
19
19
  # only license identifier from https://spdx.org/licenses/ are allowed
20
20
  license = { text = "GPL-3.0-only" }
21
21
  # keywords for easier look-up on PyPI
22
22
  keywords = [
23
23
  "RegEx conversion", "regular expression",
24
- "command line interface", "CLI logging", "logging",
25
- "GUI wrapper", "file handling"
24
+ "command line interface", "CLI logging", "logging", "logger creartion",
25
+ "config file reader", "config parser",
26
+ "GUI wrapper", "file handling",
26
27
  ]
27
28
  authors = [
28
29
  { name = "dornech", email = "dornech@gmx.de" },
@@ -30,27 +31,26 @@ authors = [
30
31
  # options under https://pypi.org/classifiers/
31
32
  classifiers = [
32
33
  "Programming Language :: Python",
33
- "Programming Language :: Python :: 3.9",
34
- "Programming Language :: Python :: 3.10",
35
34
  "Programming Language :: Python :: 3.11",
36
35
  "Programming Language :: Python :: 3.12",
37
36
  "Programming Language :: Python :: 3.13",
37
+ "Programming Language :: Python :: 3.14",
38
38
  "Programming Language :: Python :: Implementation :: CPython",
39
39
  ]
40
40
  # direct dependencies of this package, installed when users `pip install utils-mystuff` later.
41
41
  dependencies = [
42
42
  "easygui",
43
- "freesimplegui",
44
- "python_dateutil",
43
+ "FreeSimpleGUI",
44
+ "hatchling",
45
+ "python-dateutil",
45
46
  "pytz",
46
- "pymsgbox"
47
+ "pymsgbox",
48
+ "utils-mystuff",
47
49
  ]
48
50
  dynamic = ["version"]
49
51
 
50
52
  [project.optional-dependencies]
51
- python39 = [
52
- "typing-extensions",
53
- ]
53
+ # n. a.
54
54
 
55
55
  [project.scripts]
56
56
  # n. a.
@@ -93,7 +93,7 @@ exclude = [
93
93
  [tool.commitizen]
94
94
  name = "cz_customize"
95
95
  version_scheme = "pep440"
96
- version = "1.0.1"
96
+ version = "1.2.0"
97
97
  version_files = ["pyproject.toml:version"]
98
98
  tag_format = "v$version"
99
99
  # retry_after_failure = false
@@ -120,8 +120,8 @@ bump_map = {"feat" = "MINOR", "fix" = "PATCH", "BREAKING CHANGE" = "MAJOR"}
120
120
  # with Initial Commit in changelog
121
121
  commit_parser ="^(?P<change_type>[Ii]nitial [Cc]ommit|feat|fix|refactor|perf|docs|style|test|chore|build|ci|revert|BREAKING CHANGE)(\\((?P<scope>[^)]+)\\))?(:\\s(?P<message>.*))?"
122
122
  changelog_pattern = "^([Ii]nitial [Cc]ommit|feat|fix|docs|style|refactor|perf|test|chore|build|ci|revert|BREAKING CHANGE).*"
123
- change_type_map = { feat = "Features", fix = "Bug fixes", refactor = "Refactoring", perf = "performance improvements", docs = "Documentation", style = "Code style", test = "Testing", chore = "Chores", build = "Build system", ci = "Continuous Integration" }
124
- change_type_order = ["BREAKING CHANGE", "feat", "fix", "refactor", "perf", "docs", "style", "test", "chore", "build", "ci"]
123
+ change_type_map = { feat = "Features", fix = "Bug fixes", refactor = "Code refactoring", perf = "Performance improvements", docs = "Documentation", style = "Code style", test = "Testing", chore = "Chores", build = "Build system", ci = "Continuous Integration" }
124
+ change_type_order = ["BREAKING CHANGE", "Features", "Bug fixes", "Code refactoring", "Performance improvements", "Documentation", "Code style", "Testing", "Chore", "Build System", "Continuous Integration", "Initial Commit"]
125
125
 
126
126
 
127
127
  ##################
@@ -140,7 +140,7 @@ ignore-args = false
140
140
  ignore-kwargs = false
141
141
  ignore-no-params = true
142
142
  ignore_typechecker= false
143
- # disable = []
143
+ disable = ["SIG305", "SIG306"]
144
144
  # target = []
145
145
 
146
146
  [tool.ruff]
@@ -151,8 +151,9 @@ include = [
151
151
  "src/**/*.py",
152
152
  "src/**/*.pyi",
153
153
  "tests/**/*.py",
154
- "tests/**/*.pyi"
154
+ "tests/**/*.pyi",
155
155
  ]
156
+ output-prefer-rule-codes = true
156
157
 
157
158
  [tool.ruff.lint]
158
159
  preview = true # preview features & checks, use with caution
@@ -247,6 +248,22 @@ warn_unused_ignores = true
247
248
  warn_return_any = true
248
249
  warn_unused_configs = true
249
250
 
251
+ [tool.deptry]
252
+ known_first_party = ["utils_mystuff"]
253
+ exclude = ["docs", "tests"]
254
+ ignore_notebooks = true
255
+ github_output = true
256
+ github_warning_errors = ["DEP003"]
257
+
258
+ [tool.deptry.package_module_name_map]
259
+ easygui = "easygui"
260
+ FreeSimpleGUI = "FreeSimpleGUI"
261
+ pymsgbox = "pymsgbox"
262
+ python-dateutil = "dateutil"
263
+
264
+ [tool.deptry.per_rule_ignores]
265
+ DEP002 = ["easygui", "FreeSimpleGUI", "pymsgbox"]
266
+
250
267
  [tool.cruft]
251
268
  skip = ["README.md", "CHANGELOG.MD", "src/", "tests/", "docs/", "notebooks/"]
252
269
 
@@ -256,6 +273,10 @@ addopts = "-ra -q --doctest-glob='*.md'"
256
273
  testpaths = [
257
274
  "tests",
258
275
  ]
276
+ markers = [
277
+ "integration: integration test cases",
278
+ "local: test cases not suitable for CI",
279
+ ]
259
280
 
260
281
  [tool.coverage.run]
261
282
  branch = true
@@ -294,28 +315,29 @@ exclude_lines = [
294
315
 
295
316
  # Hatch default environment
296
317
  [tool.hatch.envs.default]
297
- # python = "3.9"
298
318
  post-install-commands = ["pre-commit install", "pre-commit install --hook-type commit-msg"]
299
319
  dependencies = [
300
320
  "pre-commit",
321
+ "pre_commit",
301
322
  "commitizen",
302
323
  ]
303
324
  # installer = "pip"
304
325
 
305
- # Hatch default test environment for "hatch test" (also used in GitAction)
326
+ # Hatch default test environment for "hatch test" (also used in GitHub Action)
327
+ # do not define scripts [tool.hatch.envs.hatch-test.scripts] without taking over hatch standard scripts!!!
306
328
  [tool.hatch.envs.hatch-test]
307
329
  dependencies = [
308
330
  "pip",
309
331
  "coverage-enable-subprocess==1.0",
310
- "coverage[toml]~=7.4",
311
- "pytest~=8.1",
312
- "pytest-mock~=3.12",
313
- "pytest-randomly~=3.15",
314
- "pytest-rerunfailures~=14.0",
315
- "pytest-xdist[psutil]~=3.5",
332
+ "coverage[toml]>=7.4",
333
+ "pytest>=8.1",
334
+ "pytest-mock>=3.12",
335
+ "pytest-randomly>=3.15",
336
+ "pytest-rerunfailures>=14.0",
337
+ "pytest-xdist[psutil]>=3.5",
316
338
  ]
317
339
 
318
- # Test environment with test-only dependencies (do not mix up with default hatch-test environment "hatch-test" !)
340
+ # Hatch local testing environment with test-only dependencies (do not mix up with default hatch-test environment "hatch-test" !)
319
341
  [tool.hatch.envs.test]
320
342
  dependencies = [
321
343
  # required test dependencies
@@ -331,37 +353,39 @@ dependencies = [
331
353
  [tool.hatch.envs.test.scripts]
332
354
  cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=src/utils_mystuff --cov=tests {args}"
333
355
  no-cov = "cov --no-cov {args}"
334
- debug = "cov --no-cov -s --pdb --pdbcls=IPython.core.debugger:Pdb {args}"
356
+ debug = "cov --no-cov -s --pdb --pdbcls=IPython.core.debugger:Pdb {args}"
357
+ test_not_local_only = "run pytest -m 'not local'"
358
+ test_local_only = "run pytest -m 'local'"
335
359
 
336
- # Hatch testing environment matrix for various Python versions replacing the functionality of tox
360
+ # Hatch local testing environment matrix for various Python versions replacing the functionality of tox
337
361
  [[tool.hatch.envs.test.matrix]]
338
362
  template = ["test"]
339
- python = ["3.9", "3.10", "3.11", "3.12", "3.13"]
363
+ python = ["3.11", "3.12", "3.13", "3.14"]
340
364
 
341
365
  # Hatch default linting environment for "hatch fmt"
342
366
  [tool.hatch.envs.hatch-static-analysis]
343
367
  dependencies = [
344
368
  "pip",
345
- "mypy==1.16.0",
346
- "ruff==0.11.12",
369
+ "mypy==2.3.0",
370
+ "ruff==0.16.2",
347
371
  ]
348
372
 
349
- # Hatch Linting environment for GitAction
373
+ # Hatch Linting environment for GitHub Action
350
374
  [tool.hatch.envs.lint]
351
375
  template = "lint" # don't inherit from default!
352
376
  dependencies = [
353
377
  "pip",
354
- "mypy==1.16.0",
355
- "ruff==0.11.12",
356
- "docsig==0.71.0",
378
+ "mypy==2.3.0",
379
+ "ruff==0.16.2",
380
+ "docsig==0.94.0",
357
381
  ]
358
382
  [tool.hatch.envs.lint.scripts]
359
383
  typing = [
360
- "echo \"VERSION: `mypy --version`\"",
384
+ "mypy --version",
361
385
  "mypy --install-types --non-interactive {args}"
362
386
  ]
363
387
  style = [
364
- "echo \"VERSION: `ruff --version`\"",
388
+ "ruff --version",
365
389
  "ruff check {args:.}",
366
390
  "ruff format --check {args:.}",
367
391
  ]
@@ -379,8 +403,10 @@ all = [
379
403
  # Hatch environment for building documentation
380
404
  [tool.hatch.envs.docs]
381
405
  dependencies = [
382
- "mkdocs~=1.6",
383
- "mkdocs-material[imaging]~=9.4",
406
+ "pre-commit", # needed otherwise error
407
+ "pre_commit", # needed otherwise error
408
+ "properdocs",
409
+ "mkdocs-materialx[imaging]",
384
410
  # Plugins
385
411
  "mkdocs-include-markdown-plugin",
386
412
  "mkdocs-gen-files",
@@ -402,10 +428,10 @@ dependencies = [
402
428
  [tool.hatch.envs.docs.env-vars]
403
429
  SOURCE_DATE_EPOCH = "1580601600"
404
430
  PYTHONUNBUFFERED = "1"
405
- MKDOCS_CONFIG = "mkdocs.yml"
431
+ MKDOCS_CONFIG = "properdocs.yml"
406
432
  [tool.hatch.envs.docs.scripts]
407
- build = "mkdocs build --config-file {env:MKDOCS_CONFIG} --clean --strict {args}"
408
- serve = "mkdocs serve --config-file {env:MKDOCS_CONFIG} --dev-addr localhost:8000 {args}"
433
+ build = "properdocs build --config-file {env:MKDOCS_CONFIG} --clean --strict {args}"
434
+ serve = "properdocs serve --config-file {env:MKDOCS_CONFIG} --dev-addr localhost:8000 {args}"
409
435
  ci-build = "mike deploy --config-file {env:MKDOCS_CONFIG} --update-aliases {args}"
410
436
  # --ignore-url=None since the SUMMARY.md file leaves a <toc>None</toc> in sitemap.xml
411
437
  validate = "linkchecker --config .linkcheckerrc --ignore-url=/reference --ignore-url=None site"
@@ -29,20 +29,9 @@ Raises:
29
29
  # fmt: off
30
30
 
31
31
 
32
- # version determination
33
-
34
- # original Hatchlor version
35
- # from importlib.metadata import PackageNotFoundError, version
36
- # try:
37
- # __version__ = version('{{ cookiecutter.project_slug }}')
38
- # except PackageNotFoundError: # pragma: no cover
39
- # __version__ = 'unknown'
40
- # finally:
41
- # del version, PackageNotFoundError
42
-
43
- # latest import requirement for hatch-vcs-footgun-example
44
- from utils_mystuff.version import __version__
45
32
 
33
+ # version determination - latest import requirement for hatch-vcs-footgun-example
34
+ from utils_mystuff.version import __version__
46
35
 
47
36
  from .logger_CLI import *
48
37
  from .utils_filehandling import *
@@ -49,7 +49,7 @@ Example / doctest (note escaping in output to avoid error):
49
49
  # boolean-type arguments
50
50
  # ruff: noqa: FBT001, FBT002, Q003
51
51
  # others
52
- # ruff: noqa: E501
52
+ # ruff: noqa: E501, RUF105
53
53
 
54
54
  # fmt: off
55
55
 
@@ -13,7 +13,7 @@ parsed arguments structure.
13
13
  # naming conventions
14
14
  # ruff: noqa: N801, N802, N803, N806, N812, N813, N815, N816, N818, N999
15
15
  # others
16
- # ruff: noqa: E115, E501, RUF059, SIM102
16
+ # ruff: noqa: E115, E501, RUF059, RUF105, SIM102
17
17
  #
18
18
  # disable mypy errors
19
19
  # - mypy error "'object' has no attribute 'xyz' [attr-defined]" when accessing attributes of
@@ -48,7 +48,7 @@ True
48
48
  # boolean-type arguments
49
49
  # ruff: noqa: FBT001, FBT002
50
50
  # others
51
- # ruff: noqa: B006, E501, F841, PLW3301, RUF022
51
+ # ruff: noqa: B006, E501, F841, PLW3301, RUF022, RUF105
52
52
  #
53
53
  # disable mypy errors
54
54
  # - errors occur when attributes of dynamically (re)loaded module(s)
@@ -59,7 +59,7 @@ True
59
59
 
60
60
 
61
61
 
62
- from typing import Any, Union
62
+ from typing import Any
63
63
 
64
64
  import sys
65
65
  import os.path
@@ -193,7 +193,7 @@ class GUIwrapperClass:
193
193
  title: str = "",
194
194
  choices: list[str] = [],
195
195
  multiselect: bool = False
196
- ) -> Union[str, list[str]]:
196
+ ) -> str | list[str]:
197
197
  """
198
198
  listbox - display listbox with single or multiple selection option
199
199
 
@@ -206,7 +206,7 @@ class GUIwrapperClass:
206
206
  Returns:
207
207
  Union[str, List[str]]: selected option(s)
208
208
  """
209
- retval: Union[str, list[str]] = "" # dummy assignment for mypy
209
+ retval: str | list[str] = "" # dummy assignment for mypy
210
210
 
211
211
  if title == "":
212
212
  title = os.path.basename(sys.argv[0])
@@ -373,7 +373,7 @@ def listbox(
373
373
  title: str = "",
374
374
  choices: list[str] = [],
375
375
  multiselect: bool = False
376
- ) -> Union[str, list[str]]:
376
+ ) -> str | list[str]:
377
377
  """
378
378
  listbox - caller stub for singleton GUIwrapperClass object method
379
379
 
@@ -12,15 +12,13 @@ Module contains filesystem related utilities.
12
12
  # naming conventions
13
13
  # ruff: noqa: N801, N802, N803, N806, N812, N813, N815, N816, N818, N999
14
14
  # others
15
- # ruff: noqa: E501, PLR1702, PLW1514, SIM102, SIM115, TID252, UP015
15
+ # ruff: noqa: E501, PLR1702, PLW1514, RUF105, SIM102, SIM115, TID252, UP015
16
16
 
17
17
  # fmt: off
18
18
 
19
19
 
20
20
 
21
- from typing import Optional, Union
22
-
23
- import sys
21
+ import glob
24
22
  import os
25
23
  import fnmatch
26
24
  import datetime
@@ -28,14 +26,6 @@ import dateutil.tz
28
26
  import pytz
29
27
  import time
30
28
 
31
- from .utils_GUI import alertbox
32
-
33
- if os.name == "nt" or sys.platform == "win32":
34
- from .utils_win32 import close_app_windowtitle
35
- else:
36
- err_msg = f"No implementation for your platform ('{os.name}') available"
37
- raise ImportError(err_msg)
38
-
39
29
 
40
30
 
41
31
  # check if file is locked
@@ -84,13 +74,98 @@ def is_file_locked(filepath: str, waittime: float = 0.1) -> bool:
84
74
  return file_locked(filepath, waittime)
85
75
 
86
76
 
77
+ # wait for file with timeout
78
+ # approaches here: https://stackoverflow.com/questions/54487381/check-for-a-files-availability-for-a-certain-time-and-then-break
79
+ def wait_for_file(filepath: str, timeout: int = 5, waittime: float = 0.1) -> bool:
80
+ """
81
+ wait_for_file - wait until file is available or timeout
82
+
83
+ Args:
84
+ filepath (str): filepath to be checked
85
+ timeout (int): timeout period
86
+ waittime (float): waittime between two checks
87
+
88
+ Returns:
89
+ bool: True if file exists
90
+ """
91
+
92
+ start_time = time.time()
93
+ file_exists = os.path.exists(filepath)
94
+
95
+ while not file_exists:
96
+ time.sleep(waittime)
97
+ file_exists = os.path.exists(filepath)
98
+ elapsed_time = time.time() - start_time
99
+ if timeout > 0 and elapsed_time >= timeout:
100
+ break
101
+
102
+ return file_exists
103
+
104
+
105
+ def wait_for_file_with_wildcard(filepath: str, timeout: float = 5, waittime: float = 0.1) -> str | None:
106
+ """
107
+ wait_for_file_with_wildcard - wait until file is available or timeout
108
+
109
+ Args:
110
+ filepath (str): filepath with wildcard to be checked
111
+ timeout (int): timeout period
112
+ waittime (float): waittime between two checks
113
+
114
+ Returns:
115
+ str: first found filename if found, otherwise None
116
+ """
117
+
118
+ start_time = time.time()
119
+ files = None
120
+
121
+ while not files:
122
+ time.sleep(waittime)
123
+ files = glob.glob(filepath)
124
+ if files:
125
+ return files[0]
126
+ elapsed_time = time.time() - start_time
127
+ if timeout > 0 and elapsed_time >= timeout:
128
+ break
129
+
130
+ return None
131
+
132
+
133
+ def wait_for_file_out_of_list(filepaths: list[str], timeout: float = 5, waittime: float = 0.1) -> str | None:
134
+ """
135
+ wait_for_file_out_of_list - wait for file out of list
136
+
137
+ Args:
138
+ filepaths (str): list of filepaths to be checked
139
+ timeout (int): timeout period
140
+ waittime (float): waittime between two checks
141
+
142
+ Returns:
143
+ str: first found filename if found, otherwise None
144
+ """
145
+
146
+ start_time = time.time()
147
+ file = None
148
+
149
+ while not file:
150
+ time.sleep(waittime)
151
+ for filepath in filepaths:
152
+ file = wait_for_file_with_wildcard(filepath, timeout=0.1, waittime=0.1)
153
+ if file:
154
+ return file
155
+ elapsed_time = time.time() - start_time
156
+ if timeout > 0 and elapsed_time >= timeout:
157
+ break
158
+
159
+ return None
160
+
161
+
87
162
  # find latest changed file in searchpath matching filename pattern provided as searchpattern
88
163
  # timestamp referring to nanoseconds timestamp from filesystem, otherwise problems in rare cases
89
164
  # (1 second resolution not sufficient)
90
165
  def find_last_changed_file(
91
166
  searchpath: str,
92
167
  searchpattern: str,
93
- searchstart: Optional[datetime.datetime] = None,
168
+ searchstart: datetime.datetime | None = None,
94
169
  timeout_sec: int = 10
95
170
  ) -> str:
96
171
  """
@@ -118,7 +193,7 @@ def find_last_changed_file(
118
193
  while (lastchangedfile == "") and (datetime.datetime.now(dateutil.tz.tz.tzlocal()) <= timenow + datetime.timedelta(seconds=timeout_sec)):
119
194
 
120
195
  with os.scandir(searchpath) as searchpathscan:
121
- scanentry: os.DirEntry # overcome PyCharm IDE error - workaround derived from https://youtrack.jetbrains.com/issue/PY-46041
196
+ scanentry: os.DirEntry # overcome PyCharm IDE error - workaround derived from https://youtrack.jetbrains.com/issue/PY-46041
122
197
  for scanentry in searchpathscan:
123
198
  if fnmatch.fnmatch(scanentry.name, searchpattern):
124
199
  filemodified = scanentry.stat().st_mtime_ns / 1000000000
@@ -136,7 +211,7 @@ def find_last_changed_file(
136
211
 
137
212
 
138
213
  # load text file
139
- def load_textfile(txt_filename: str, mode: str = "str") -> Union[list[str], str]:
214
+ def load_textfile(txt_filename: str, mode: str = "str") -> list[str] | str:
140
215
  """
141
216
  load_textfile - load textfile to list of strings or str
142
217
 
@@ -148,7 +223,7 @@ def load_textfile(txt_filename: str, mode: str = "str") -> Union[list[str], str]
148
223
  Union[list[str], str]: content of textfile as list of string or string
149
224
  """
150
225
 
151
- txt: Union[list[str], str] = ""
226
+ txt: list[str] | str = ""
152
227
 
153
228
  fileexists = os.path.isfile(txt_filename)
154
229
 
@@ -184,21 +259,3 @@ def load_textfile(txt_filename: str, mode: str = "str") -> Union[list[str], str]
184
259
  raise Exception(err_msg)
185
260
 
186
261
  return txt
187
-
188
-
189
- # close file
190
- def close_app_file(filename: str, msg: str, title: str) -> None:
191
- """
192
- close_app_file - close data file opened by an application
193
-
194
- Args:
195
- filename (str): filename
196
- msg (str): message for alert box
197
- title (str): title for alert box
198
- """
199
-
200
- close_app_windowtitle(filename)
201
- if file_locked(filename):
202
- close_app_windowtitle(os.path.splitext(os.path.basename(filename))[0])
203
- while file_locked(filename):
204
- alertbox(msg, title)
@@ -14,7 +14,7 @@ Module contains a collection of miscellaneous utilities.
14
14
  # boolean-type arguments
15
15
  # ruff: noqa: FBT001, FBT002, S101
16
16
  # others
17
- # ruff: noqa: B006, B905, DTZ007, E501, PLW0602, SIM102, SIM105, UP007, UP045
17
+ # ruff: noqa: B006, B905, DTZ007, E501, PLW0602, RUF105, SIM102, SIM105, UP007, UP045
18
18
  #
19
19
  # disable mypy errors
20
20
  # mypy: disable-error-code = "unused-ignore"
@@ -25,12 +25,8 @@ Module contains a collection of miscellaneous utilities.
25
25
 
26
26
 
27
27
 
28
- from typing import Any, Callable, Optional, TypeVar, Union
29
- # importing ParamSpec in backwards compatible way
30
- try:
31
- from typing import ParamSpec # type: ignore
32
- except ImportError:
33
- from typing_extensions import ParamSpec # type: ignore
28
+ from typing import Any, ParamSpec, TypeVar
29
+ from collections.abc import Callable
34
30
 
35
31
  import sys
36
32
  import os
@@ -103,7 +99,7 @@ def get_real_apppath() -> tuple[str, str]:
103
99
  # read config file with standardized boolean states into ConfigParser object
104
100
  def readconfigfile(
105
101
  configfile: str,
106
- optionxform: Optional[Callable[[str], str]] = None,
102
+ optionxform: Callable[[str], str] | None = None,
107
103
  encoding: str = "utf-8"
108
104
  ) -> configparser.ConfigParser:
109
105
  """
@@ -143,7 +139,7 @@ def readconfigfile(
143
139
 
144
140
  def read_configfile(
145
141
  configfile: str,
146
- optionxform: Optional[Callable[[str], str]] = None,
142
+ optionxform: Callable[[str], str] | None = None,
147
143
  encoding: str = "utf-8"
148
144
  ) -> configparser.ConfigParser:
149
145
  """
@@ -275,7 +271,7 @@ def set_loglevel_from_config(logger: logging.Logger, config: configparser.Config
275
271
 
276
272
 
277
273
  # convert to bool - useful for evaluation of CLI parameters
278
- def to_bool(value: Union[str, int, float, bool], truevalues: list[str] = ["true", "yes", "x", "1", "-1"]) -> bool:
274
+ def to_bool(value: str | int | float | bool, truevalues: list[str] = ["true", "yes", "x", "1", "-1"]) -> bool:
279
275
  """
280
276
  to_bool - convert basic scalar types to bool
281
277
 
@@ -297,7 +293,7 @@ def to_bool(value: Union[str, int, float, bool], truevalues: list[str] = ["true"
297
293
  else:
298
294
  return False
299
295
 
300
- def to_boolean(value: Union[str, int, float, bool], truevalues: list[str] = ["true", "yes", "x", "1", "-1"]) -> bool:
296
+ def to_boolean(value: str | int | float | bool, truevalues: list[str] = ["true", "yes", "x", "1", "-1"]) -> bool:
301
297
  """
302
298
  to_boolean - convert basic scalar types to bool
303
299
 
@@ -314,6 +310,7 @@ def to_boolean(value: Union[str, int, float, bool], truevalues: list[str] = ["tr
314
310
 
315
311
  # create localized parserinfo object for dateutil.parser
316
312
  # inspired by https://stackoverflow.com/questions/19927654/using-dateutil-parser-to-parse-a-date-in-another-language/62581811#62581811
313
+ # note changed initialization of WEEEKDAYS because method references to calendar do not work
317
314
  class parserinfo_localized(dateutil.parser.parserinfo):
318
315
  """
319
316
  parserinfo_localized - create localized date parser object
@@ -323,7 +320,8 @@ class parserinfo_localized(dateutil.parser.parserinfo):
323
320
  """ initialize parserinfo localized """
324
321
 
325
322
  with setlocale(localeID):
326
- self.WEEKDAYS = zip(calendar.day_abbr, calendar.day_name) # type: ignore[assignment]
323
+ # self.WEEKDAYS = zip(calendar.day_abbr, calendar.day_name) # type: ignore[assignment]
324
+ self.WEEKDAYS = list(zip([calendar.day_abbr[x] for x in range(0, 7)], [calendar.day_name[x] for x in range(0, 7)])) # type: ignore[assignment]
327
325
  self.MONTHS = list(zip(calendar.month_abbr, calendar.month_name))[1:] # type: ignore[assignment]
328
326
  super().__init__(*args, **kwargs)
329
327
 
@@ -382,12 +380,12 @@ def copydictfields(source: dict, target: Any) -> None:
382
380
 
383
381
  Args:
384
382
  source (dict): source dictionary
385
- target (Any): target dictionary
383
+ target (Any): target structure
386
384
  """
387
385
 
388
386
  for key, value in source.items():
389
387
  if hasattr(target, key):
390
- target.key = value
388
+ setattr(target, key, value)
391
389
  elif isinstance(target, dict):
392
390
  if key in target:
393
391
  target[key] = value
@@ -401,7 +399,7 @@ def copy_dictfields(source: dict, target: Any) -> None:
401
399
 
402
400
  Args:
403
401
  source (dict): source dictionary
404
- target (Any): target dictionary
402
+ target (Any): target structure
405
403
  """
406
404
  copy_dictfields(source, target)
407
405
 
@@ -420,7 +418,7 @@ _FuncT = TypeVar('_FuncT', bound=Callable[..., Any])
420
418
  # - definition of ignored exceptions in decorator parameter using closure
421
419
  # - no change of signature of decorated function
422
420
  # Note: Optional added for cases where exception is caught (hint from AI)
423
- def ignore_exceptions_parameterized(ignored_exceptions: tuple[type[BaseException]]) -> Callable[[Callable[_P, _R]], Callable[_P, Optional[_R]]]: # type: ignore
421
+ def ignore_exceptions_parameterized(ignored_exceptions: tuple[type[BaseException]]) -> Callable[[Callable[_P, _R]], Callable[_P, _R | None]]: # type: ignore
424
422
  """
425
423
  ignore_exceptions_parameterized - parameterized decorator for ignoring exceptions using closure
426
424
 
@@ -6,7 +6,7 @@ Based on <https://github.com/maresb/hatch-vcs-footgun-example>.
6
6
 
7
7
  # ruff and mypy per file settings
8
8
  # others
9
- # ruff: noqa: PLC0415
9
+ # ruff: noqa: E302, PLC0415, RUF105
10
10
 
11
11
  # fmt: off
12
12
 
@@ -14,11 +14,11 @@ Based on <https://github.com/maresb/hatch-vcs-footgun-example>.
14
14
  def _get_hatch_version():
15
15
  """Compute the most up-to-date version number in a development environment.
16
16
 
17
- Returns `None` if Hatchling is not installed, e.g. in a production environment.
18
-
19
17
  For more details, see <https://github.com/maresb/hatch-vcs-footgun-example/>.
20
18
  """
21
19
  import os
20
+ # preparation for Pathlib
21
+ # from pathlib import path
22
22
 
23
23
  try:
24
24
  from hatchling.metadata.core import ProjectMetadata
@@ -33,9 +33,19 @@ def _get_hatch_version():
33
33
  err_msg = "pyproject.toml not found although hatchling is installed"
34
34
  raise RuntimeError(err_msg)
35
35
  root = os.path.dirname(pyproject_toml)
36
- metadata = ProjectMetadata(root=root, plugin_manager=PluginManager())
37
- # Version can be either statically set in pyproject.toml or computed dynamically:
38
- return metadata.core.version or metadata.hatch.version.cached
36
+ # preparation for Pathlib
37
+ # root = Path(pyproject_toml).parent
38
+ # Temporarily set cwd to project root for PEP 517 compliance.
39
+ old_cwd = os.getcwd()
40
+ # preparation for Pathlib
41
+ # old_cwd = Path.cwd()
42
+ os.chdir(root)
43
+ try:
44
+ metadata = ProjectMetadata(root=str(root), plugin_manager=PluginManager())
45
+ # Version can be static in pyproject.toml or computed dynamically:
46
+ return metadata.core.version or metadata.hatch.version.cached
47
+ finally:
48
+ os.chdir(old_cwd)
39
49
 
40
50
 
41
51
  def _get_importlib_metadata_version():
File without changes
File without changes
File without changes
File without changes