Alaea 2.7.0__tar.gz → 2.7.1__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.
Files changed (67) hide show
  1. alaea-2.7.1/.VERSION +1 -0
  2. {alaea-2.7.0 → alaea-2.7.1}/Alaea/Blogging.py +25 -24
  3. {alaea-2.7.0 → alaea-2.7.1/Alaea.egg-info}/PKG-INFO +1 -1
  4. {alaea-2.7.0 → alaea-2.7.1}/Alaea.egg-info/SOURCES.txt +2 -1
  5. {alaea-2.7.0 → alaea-2.7.1}/ChangeLog.md +10 -0
  6. {alaea-2.7.0/Alaea.egg-info → alaea-2.7.1}/PKG-INFO +1 -1
  7. {alaea-2.7.0 → alaea-2.7.1}/setup.py +1 -1
  8. {alaea-2.7.0 → alaea-2.7.1}/tests/test_logging_multiprocess.py +8 -5
  9. alaea-2.7.1/tests/test_logging_retention.py +86 -0
  10. alaea-2.7.0/.VERSION +0 -1
  11. {alaea-2.7.0 → alaea-2.7.1}/Alaea/Pyshell/RS_File.py +0 -0
  12. {alaea-2.7.0 → alaea-2.7.1}/Alaea/Pyshell/__init__.py +0 -0
  13. {alaea-2.7.0 → alaea-2.7.1}/Alaea/S_DateTime.py +0 -0
  14. {alaea-2.7.0 → alaea-2.7.1}/Alaea/SameAsMATLAB/CoorTrans.py +0 -0
  15. {alaea-2.7.0 → alaea-2.7.1}/Alaea/SameAsMATLAB/__init__.py +0 -0
  16. {alaea-2.7.0 → alaea-2.7.1}/Alaea/SameAsMATLAB/calculatefuns.py +0 -0
  17. {alaea-2.7.0 → alaea-2.7.1}/Alaea/Standard/__init__.py +0 -0
  18. {alaea-2.7.0 → alaea-2.7.1}/Alaea/Standard/vars_name.py +0 -0
  19. {alaea-2.7.0 → alaea-2.7.1}/Alaea/Standard/xr_atmos.py +0 -0
  20. {alaea-2.7.0 → alaea-2.7.1}/Alaea/Standard/xr_attrs.py +0 -0
  21. {alaea-2.7.0 → alaea-2.7.1}/Alaea/Standard/xr_ice.py +0 -0
  22. {alaea-2.7.0 → alaea-2.7.1}/Alaea/Standard/xr_netcdf.py +0 -0
  23. {alaea-2.7.0 → alaea-2.7.1}/Alaea/Standard/xr_vars.py +0 -0
  24. {alaea-2.7.0 → alaea-2.7.1}/Alaea/Standard/xr_wave.py +0 -0
  25. {alaea-2.7.0 → alaea-2.7.1}/Alaea/Standard/xr_wind.py +0 -0
  26. {alaea-2.7.0 → alaea-2.7.1}/Alaea/__init__.py +0 -0
  27. {alaea-2.7.0 → alaea-2.7.1}/Alaea/baysalt/Forage/__init__.py +0 -0
  28. {alaea-2.7.0 → alaea-2.7.1}/Alaea/baysalt/Forage/erosion_data/__init__.py +0 -0
  29. {alaea-2.7.0 → alaea-2.7.1}/Alaea/baysalt/__init__.py +0 -0
  30. {alaea-2.7.0 → alaea-2.7.1}/Alaea/baysalt/erosion_coastline.py +0 -0
  31. {alaea-2.7.0 → alaea-2.7.1}/Alaea/commonCode.py +0 -0
  32. {alaea-2.7.0 → alaea-2.7.1}/Alaea/cprintfs.py +0 -0
  33. {alaea-2.7.0 → alaea-2.7.1}/Alaea/exutils/Interp/Interp_g2s.py +0 -0
  34. {alaea-2.7.0 → alaea-2.7.1}/Alaea/exutils/Interp/Interp_s2g.py +0 -0
  35. {alaea-2.7.0 → alaea-2.7.1}/Alaea/exutils/Interp/__init__.py +0 -0
  36. {alaea-2.7.0 → alaea-2.7.1}/Alaea/exutils/Interp/interpolate.py +0 -0
  37. {alaea-2.7.0 → alaea-2.7.1}/Alaea/exutils/__init__.py +0 -0
  38. {alaea-2.7.0 → alaea-2.7.1}/Alaea/netcdf_input.py +0 -0
  39. {alaea-2.7.0 → alaea-2.7.1}/Alaea/pFVCOM/__init__.py +0 -0
  40. {alaea-2.7.0 → alaea-2.7.1}/Alaea/pFVCOM/fvcom_class.py +0 -0
  41. {alaea-2.7.0 → alaea-2.7.1}/Alaea/pFVCOM/fvcom_image.py +0 -0
  42. {alaea-2.7.0 → alaea-2.7.1}/Alaea/pFVCOM/fvcom_load.py +0 -0
  43. {alaea-2.7.0 → alaea-2.7.1}/Alaea/pFVCOM/fvcom_tools.py +0 -0
  44. {alaea-2.7.0 → alaea-2.7.1}/Alaea/pFVCOM/writeFile.py +0 -0
  45. {alaea-2.7.0 → alaea-2.7.1}/Alaea/processBar.py +0 -0
  46. {alaea-2.7.0 → alaea-2.7.1}/Alaea/read_conf.py +0 -0
  47. {alaea-2.7.0 → alaea-2.7.1}/Alaea/server_info.py +0 -0
  48. {alaea-2.7.0 → alaea-2.7.1}/Alaea/storage.py +0 -0
  49. {alaea-2.7.0 → alaea-2.7.1}/Alaea/tools/P_params.py +0 -0
  50. {alaea-2.7.0 → alaea-2.7.1}/Alaea/tools/Read.py +0 -0
  51. {alaea-2.7.0 → alaea-2.7.1}/Alaea/tools/__init__.py +0 -0
  52. {alaea-2.7.0 → alaea-2.7.1}/Alaea/tools/download_check.py +0 -0
  53. {alaea-2.7.0 → alaea-2.7.1}/Alaea/tools/geo_distance.py +0 -0
  54. {alaea-2.7.0 → alaea-2.7.1}/Alaea/tools/kml2shp.py +0 -0
  55. {alaea-2.7.0 → alaea-2.7.1}/Alaea/warningTools/__init__.py +0 -0
  56. {alaea-2.7.0 → alaea-2.7.1}/Alaea.egg-info/dependency_links.txt +0 -0
  57. {alaea-2.7.0 → alaea-2.7.1}/Alaea.egg-info/requires.txt +0 -0
  58. {alaea-2.7.0 → alaea-2.7.1}/Alaea.egg-info/top_level.txt +0 -0
  59. {alaea-2.7.0 → alaea-2.7.1}/LICENSE +0 -0
  60. {alaea-2.7.0 → alaea-2.7.1}/MANIFEST.in +0 -0
  61. {alaea-2.7.0 → alaea-2.7.1}/README.md +0 -0
  62. {alaea-2.7.0 → alaea-2.7.1}/pyproject.toml +0 -0
  63. {alaea-2.7.0 → alaea-2.7.1}/setup.cfg +0 -0
  64. {alaea-2.7.0 → alaea-2.7.1}/tests/test_atmos_weather.py +0 -0
  65. {alaea-2.7.0 → alaea-2.7.1}/tests/test_core.py +0 -0
  66. {alaea-2.7.0 → alaea-2.7.1}/tests/test_cumulative_maximum.py +0 -0
  67. {alaea-2.7.0 → alaea-2.7.1}/tests/test_erosion_dataarray.py +0 -0
alaea-2.7.1/.VERSION ADDED
@@ -0,0 +1 @@
1
+ v2.7.1
@@ -243,8 +243,32 @@ class _ProcessSafeRotatingFileHandler(_ProcessSafeRotatingMixin, RotatingFileHan
243
243
  class _ProcessSafeTimedRotatingFileHandler(_ProcessSafeRotatingMixin, TimedRotatingFileHandler):
244
244
  """受跨进程锁保护的按时间轮转 handler。"""
245
245
 
246
+ def getFilesToDelete(self):
247
+ """跨 gzip、zstd 和未压缩格式,查找超过保留数量的最旧时间归档。
248
+
249
+ Returns:
250
+ list[str]:按修改时间排序的过量归档;backupCount <= 0 时为空。
251
+
252
+ Raises:
253
+ OSError: 无法读取日志目录或归档修改时间时抛出。
254
+ """
255
+ directory, basename = os.path.split(self.baseFilename)
256
+ prefix = f'{basename}.'
257
+ archives = []
258
+ for entry in os.scandir(directory):
259
+ filename = entry.name
260
+ if not entry.is_file(follow_symlinks=False) or not filename.startswith(prefix) or filename.endswith('.tmp'):
261
+ continue
262
+ parts = filename[len(prefix):].split('.')
263
+ if parts[-1] in {'gz', 'zst'}:
264
+ parts.pop()
265
+ if parts and self.extMatch.fullmatch(parts[0]) and (len(parts) == 1 or len(parts) == 2 and parts[1].isdigit()):
266
+ archives.append(os.path.join(directory, filename))
267
+ archives.sort(key=lambda path: (os.path.getmtime(path), path))
268
+ return archives[:-self.backupCount] if self.backupCount > 0 else []
269
+
246
270
 
247
- class _SizeAndTimeRotatingFileHandler(_ProcessSafeRotatingMixin, TimedRotatingFileHandler):
271
+ class _SizeAndTimeRotatingFileHandler(_ProcessSafeTimedRotatingFileHandler):
248
272
  """在时间或文件大小任一条件满足时轮转日志。"""
249
273
 
250
274
  def __init__(self, filename, maxBytes, when, interval, backupCount, encoding='utf-8', delay=True, utc=False):
@@ -307,29 +331,6 @@ class _SizeAndTimeRotatingFileHandler(_ProcessSafeRotatingMixin, TimedRotatingFi
307
331
  sequence += 1
308
332
  return f'{stem}.{sequence}{extension}'
309
333
 
310
- def getFilesToDelete(self):
311
- """查找超过保留数量的最旧组合轮转归档。
312
-
313
- Returns:
314
- 应在本次轮转后删除的归档路径列表。
315
-
316
- Raises:
317
- OSError: 无法读取日志目录或归档修改时间时抛出。
318
- """
319
- directory, basename = os.path.split(self.baseFilename)
320
- prefix = f'{basename}.'
321
- archives = []
322
- for filename in os.listdir(directory):
323
- if not filename.startswith(prefix) or filename.endswith('.tmp'):
324
- continue
325
- parts = filename[len(prefix):].split('.')
326
- if parts[-1] in {'gz', 'zst'}:
327
- parts.pop()
328
- if parts and self.extMatch.fullmatch(parts[0]) and (len(parts) == 1 or len(parts) == 2 and parts[1].isdigit()):
329
- archives.append(os.path.join(directory, filename))
330
- archives.sort(key=lambda path: (os.path.getmtime(path), path))
331
- return archives[:-self.backupCount] if self.backupCount > 0 else []
332
-
333
334
 
334
335
  class Blog:
335
336
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Alaea
3
- Version: 2.7.0
3
+ Version: 2.7.1
4
4
  Summary: Some simple tools by Christmas
5
5
  Author: Christmas
6
6
  Author-email: 273519355@qq.com
@@ -60,4 +60,5 @@ tests/test_atmos_weather.py
60
60
  tests/test_core.py
61
61
  tests/test_cumulative_maximum.py
62
62
  tests/test_erosion_dataarray.py
63
- tests/test_logging_multiprocess.py
63
+ tests/test_logging_multiprocess.py
64
+ tests/test_logging_retention.py
@@ -1,5 +1,15 @@
1
1
  # Change Log
2
2
 
3
+ ## v2.7.1
4
+
5
+ - 修复日志切换压缩格式后旧归档不清理的问题:按时间和时间/大小组合轮转复用现有归档筛选逻辑,统一统计 `.gz`、`.zst`、未压缩及带序号的时间归档,按修改时间保留最新 `backupCount` 份;下一次轮转时清理,重启不主动删除或转码。严格限定同一日志的普通归档文件,保留临时文件、目录、符号链接及无关文件;默认保留 7 份和禁用清理的配置不变。新增跨三种压缩模式、带序号归档及文件边界回归;Python 3.12 下全套 73 项测试和独立多进程轮转检查通过。
6
+
7
+ - 修正多进程日志回归测试的同步时序:所有子进程完成导入和预热后再设置共享轮转时间,避免慢启动造成误报;不改变生产程序行为。
8
+
9
+ - 发布前源码及隔离安装 wheel 各 73 项回归通过,多进程轮转检查通过;wheel/源码包版本、Python >=3.9 元数据、源码一致性、隐藏文件及 Twine 检查通过。
10
+
11
+ - 版本从 2.7.0 提升至 2.7.1;保持 Python >=3.9、现有接口和依赖声明不变。升级后在下一次日志轮转时应用混合格式保留规则。
12
+
3
13
  ## v2.7.0
4
14
 
5
15
  - 发布前源码与隔离安装 wheel 各 71 项回归通过;源码包和 wheel 的 2.7.0 版本、Python >=3.9 元数据、源码内容、隐藏文件及 Twine 检查通过。
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Alaea
3
- Version: 2.7.0
3
+ Version: 2.7.1
4
4
  Summary: Some simple tools by Christmas
5
5
  Author: Christmas
6
6
  Author-email: 273519355@qq.com
@@ -8,7 +8,7 @@ with open("README.md", "r") as fh:
8
8
 
9
9
  setuptools.setup(
10
10
  name="Alaea",
11
- version="2.7.0",
11
+ version="2.7.1",
12
12
  author="Christmas",
13
13
  author_email="273519355@qq.com",
14
14
  description="Some simple tools by Christmas",
@@ -43,12 +43,12 @@ class FakeKernel32:
43
43
  return True
44
44
 
45
45
 
46
- def emit_after_barrier(log_path: str, rollover_at: int, barrier, message: str) -> None:
46
+ def emit_after_barrier(log_path: str, rollover_at, barrier, message: str) -> None:
47
47
  """创建进程本地日志器,并在两个进程都就绪后写入日志。
48
48
 
49
49
  Args:
50
50
  log_path: 两个进程共享的错误日志路径。
51
- rollover_at: 两个 handler 共用的预设轮转时间戳。
51
+ rollover_at: multiprocessing.Value 共享时间戳,所有进程预热后设置。
52
52
  barrier: 协调两个进程同时写入的多进程屏障。
53
53
  message: 当前进程写入的唯一日志内容。
54
54
 
@@ -61,10 +61,13 @@ def emit_after_barrier(log_path: str, rollover_at: int, barrier, message: str) -
61
61
  blog = Blog(_loger_name=f'multiprocess-rotation-{message}', _switch_write_bug_log=True, _switch_print_log=False)
62
62
  blog.setup_Blog(bug_log_filename=log_path, compression='gzip')
63
63
  handler = next(item for item in blog.logger.handlers if isinstance(item, TimedRotatingFileHandler))
64
- handler.rolloverAt = rollover_at
64
+ handler.rolloverAt = int(time.time()) + 3600 # 预热阶段不受进程导入耗时影响。
65
65
  blog.logger.error(f'warmup-{message}')
66
+ if barrier.wait(timeout=10) == 0:
67
+ rollover_at.value = int(time.time()) + 2
66
68
  barrier.wait(timeout=10)
67
- while time.time() <= rollover_at:
69
+ handler.rolloverAt = rollover_at.value
70
+ while time.time() <= rollover_at.value:
68
71
  time.sleep(0.01)
69
72
  blog.logger.error(message)
70
73
  blog.setup_Blog(switch_write_error_plus_log=False)
@@ -101,8 +104,8 @@ def main() -> None:
101
104
  with tempfile.TemporaryDirectory() as directory:
102
105
  log_path = Path(directory) / 'BUG.log'
103
106
  log_path.write_text('before\n', encoding='utf-8')
104
- rollover_at = int(time.time()) + 2
105
107
  context = multiprocessing.get_context('spawn')
108
+ rollover_at = context.Value('q', 0)
106
109
  barrier = context.Barrier(2)
107
110
  processes = [context.Process(target=emit_after_barrier,
108
111
  args=(str(log_path), rollover_at, barrier, message))
@@ -0,0 +1,86 @@
1
+ """验证切换压缩格式后的日志保留数量和文件边界。"""
2
+
3
+ import gzip
4
+ import importlib
5
+ import os
6
+ from pathlib import Path
7
+ import tempfile
8
+ import unittest
9
+ from logging.handlers import TimedRotatingFileHandler
10
+
11
+ from Alaea.Blogging import Blog
12
+
13
+ blogging = importlib.import_module('Alaea.Blogging')
14
+
15
+
16
+ class LoggingRetentionTests(unittest.TestCase):
17
+ """使用真实临时归档检验清理和压缩切换。"""
18
+
19
+ def test_rotation_cleans_mixed_formats_and_preserves_unrelated_files(self):
20
+ """各时间轮转模式只清理同日志旧归档;返回 None,断言失败时报错。"""
21
+ compressions = ['gzip', 'none'] + (['zstd'] if blogging.zstandard is not None else [])
22
+ for mode in ['time', 'both']:
23
+ for compression in compressions:
24
+ with self.subTest(mode=mode, compression=compression), tempfile.TemporaryDirectory() as directory:
25
+ root = Path(directory)
26
+ path = root / 'BUG.log'
27
+ archives = []
28
+ for index, suffix in enumerate(['.gz', '', '.zst'], start=1):
29
+ archive = root / f'BUG.log.2000-01-0{index}{suffix}'
30
+ archive.write_bytes(b'old archive')
31
+ os.utime(archive, (index, index))
32
+ archives.append(archive)
33
+ preserved = [root / name for name in [
34
+ 'OTHER.log.1999-01-01.gz', 'BUG.log.1999-01-01.gz.tmp',
35
+ 'BUG.log.1999-01-01.zip', 'BUG.log.1999-01-01.gz.extra',
36
+ 'BUG.log.not-a-date.gz',
37
+ ]]
38
+ for other in preserved:
39
+ other.write_bytes(b'keep')
40
+ directory_archive = root / 'BUG.log.1999-01-02.gz'
41
+ directory_archive.mkdir()
42
+ symlink_archive = root / 'BUG.log.1999-01-03.gz'
43
+ symlink_archive.symlink_to(preserved[0])
44
+ blog = Blog(_loger_name=f'retention-{mode}-{compression}', _switch_print_log=False)
45
+ blog.setup_Blog(switch_write_error_plus_log=True, bug_log_filename=str(path), Rotating=mode, backupCount=2, compression=compression)
46
+ try:
47
+ blog.logger.error('current content')
48
+ handler = next(item for item in blog.logger.handlers if isinstance(item, TimedRotatingFileHandler))
49
+ handler.doRollover()
50
+ self.assertFalse(archives[0].exists())
51
+ self.assertFalse(archives[1].exists())
52
+ self.assertTrue(archives[2].exists())
53
+ new_archive = next(item for item in root.iterdir() if item.name.startswith('BUG.log.') and item not in archives + preserved + [directory_archive, symlink_archive])
54
+ opener = {'gzip': gzip.open, 'none': open}.get(compression)
55
+ if compression == 'zstd':
56
+ opener = blogging.zstandard.open
57
+ with opener(new_archive, 'rt') as stream:
58
+ self.assertIn('current content', stream.read())
59
+ self.assertEqual(handler.getFilesToDelete(), [])
60
+ self.assertTrue(directory_archive.is_dir())
61
+ self.assertTrue(symlink_archive.is_symlink())
62
+ for other in preserved:
63
+ self.assertEqual(other.read_bytes(), b'keep')
64
+ blog.logger.error('after rotation')
65
+ self.assertIn('after rotation', path.read_text())
66
+ handler.backupCount = 0
67
+ self.assertEqual(handler.getFilesToDelete(), [])
68
+ finally:
69
+ blog.setup_Blog(switch_write_error_plus_log=False)
70
+
71
+ def test_numbered_archives_count_toward_same_limit(self):
72
+ """组合轮转的带序号归档共享保留额度;返回 None,断言失败时报错。"""
73
+ with tempfile.TemporaryDirectory() as directory:
74
+ handler = blogging._SizeAndTimeRotatingFileHandler(str(Path(directory) / 'BUG.log'), maxBytes=10, when='midnight', interval=1, backupCount=2)
75
+ try:
76
+ archives = [Path(directory) / name for name in ['BUG.log.2000-01-01.gz', 'BUG.log.2000-01-01.1.zst', 'BUG.log.2000-01-01.2']]
77
+ for index, path in enumerate(archives, start=1):
78
+ path.touch()
79
+ os.utime(path, (index, index))
80
+ self.assertEqual(handler.getFilesToDelete(), [str(archives[0])])
81
+ finally:
82
+ handler.close()
83
+
84
+
85
+ if __name__ == '__main__':
86
+ unittest.main()
alaea-2.7.0/.VERSION DELETED
@@ -1 +0,0 @@
1
- v2.7.0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes