python-backpack 2.0.3__py3-none-any.whl → 2.0.4__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.
backpack/file_utils.py CHANGED
@@ -4,6 +4,7 @@
4
4
  # https://github.com/MaxRocamora/python-backpack
5
5
  # ----------------------------------------------------------------------------------------
6
6
 
7
+ import re
7
8
  from collections.abc import Sequence
8
9
 
9
10
  from backpack.logger import get_logger
@@ -94,11 +95,12 @@ def file_is_writeable(filepath: str) -> bool:
94
95
  return False
95
96
 
96
97
 
97
- def get_version_from_filename(filename: str) -> str:
98
+ def get_version_from_filename(filename: str, separator: str | None = None) -> str:
98
99
  """Extracts version from filename.
99
100
 
100
101
  Args:
101
102
  filename: (str) file name to extract version from
103
+ separator: delimiter that must precede the version; when omitted, use supported delimiters
102
104
  Returns:
103
105
  str : version extracted from filename
104
106
 
@@ -107,29 +109,32 @@ def get_version_from_filename(filename: str) -> str:
107
109
  get_version_from_filename('myfile-9.txt') -> '9'
108
110
  get_version_from_filename('myfile.130.txt') -> '130'
109
111
  get_version_from_filename('myfile_v1002.txt') -> '1002'
112
+ get_version_from_filename('XD_shot_0000.0003.ma') -> '0003'
113
+ get_version_from_filename('ANM_shot_0010.0003.ma') -> '0003'
110
114
 
111
115
  """
112
116
 
113
117
  filename_no_ext = filename.rsplit('.', 1)[0]
114
118
 
115
- # guess is the separator is an underscore, dash, dot or v, and the version is the last part before the extension
116
- separators = ['_', '-', '.', 'v']
117
- if not any(sep in filename_no_ext for sep in separators):
118
- log.info(f'No separator found in filename: {filename_no_ext}. Using fallback extraction.')
119
- else:
120
- for sep in separators:
121
- if sep in filename_no_ext:
122
- parts = filename_no_ext.split(sep)
123
- version_part = parts[-1].split('.')[0] # Get the last part before the extension
124
- if version_part.replace('.', '').isdigit(): # Check if it's a valid version number
125
- log.info(
126
- f'Extracted version: {version_part} from filename: {filename} using separator: {sep}'
127
- )
128
- return version_part
129
-
130
- # Fallback: extract from the entire filename
131
- version = filename_no_ext.lstrip('v')
132
- version = version.replace('_', '.').replace('-', '.')
133
- version = version if version.replace('.', '').isdigit() else '0'
134
- log.info(f'Extracted version: {version} from filename: {filename}')
135
- return version
119
+ if separator is not None:
120
+ if not separator:
121
+ raise ValueError('separator must not be empty')
122
+
123
+ version = filename_no_ext.rsplit(separator, 1)[-1]
124
+ if version.isdigit():
125
+ log.info(
126
+ f'Extracted version: {version} from filename: {filename} using separator: {separator}'
127
+ )
128
+ return version
129
+
130
+ log.info(f'No numeric version found in filename: {filename} using separator: {separator}')
131
+ return '0'
132
+
133
+ match = re.search(r'(?:^|[_.-])v?(\d+)$', filename_no_ext)
134
+ if match:
135
+ version = match.group(1)
136
+ log.info(f'Extracted version: {version} from filename: {filename}')
137
+ return version
138
+
139
+ log.info(f'No numeric version found in filename: {filename}')
140
+ return '0'
backpack/version.py CHANGED
@@ -11,10 +11,11 @@
11
11
  # 1.1.4 07/2025 - Moved from pipenv to poetry for dependency management.toml
12
12
  # 2.0.1 05/2026 - Remove tox workflow and setup.py, standardize uv + coverage tooling
13
13
  # 2.0.2 05/2026 - Add PyPI long description metadata and release polish
14
- # 2.0.3 06/2026 - Add type hints to backpack.cache, backpack.folder_utils, backpack.json_user_settings, backpack.json_utils, and backpack.logger, refactor backpack.cache to use functools.lru_cache, and add tests for backpack.cache and backpack.folder_utils.
14
+ # 2.0.3 06/2026 - Add type hints, refactor backpack.cache to use functools.lru_cache, added tests.
15
+ # 2.0.4 08/2026 - Fixed get_version_from_filename().
15
16
  # ----------------------------------------------------------------------------------------
16
17
 
17
- __version__ = '2.0.3'
18
+ __version__ = '2.0.4'
18
19
 
19
20
  VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH = map(int, __version__.split('.'))
20
21
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: python-backpack
3
- Version: 2.0.3
3
+ Version: 2.0.4
4
4
  Summary: Lightweight utilities for JSON, filesystem operations, strings, caching, and scripting.
5
5
  Project-URL: Homepage, https://github.com/MaxRocamora/python-backpack
6
6
  Project-URL: Repository, https://github.com/MaxRocamora/python-backpack.git
@@ -1,7 +1,7 @@
1
1
  backpack/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  backpack/cache.py,sha256=pAQGxIyQOMZ60Np7aOkS7QebWcJf8f4vyKts7GY5q20,3071
3
3
  backpack/custom_errors.py,sha256=tkn0AnV-Ihnge9X197nPeRpCFD6Feu9lLntejNTNpik,1358
4
- backpack/file_utils.py,sha256=kP0WC4QQVmMiea2QpzeVEn2bBO85pMC4RokM3PbEIIU,4543
4
+ backpack/file_utils.py,sha256=S_4EhipFHRuq_D5KH9GMFonQpHYltSR6Zm4a4jnx1GA,4451
5
5
  backpack/folder_utils.py,sha256=F6kaaH5K-OSRZZSNdRQjzIaxVokirm2GsGVM48_C7no,3265
6
6
  backpack/json_metadata.py,sha256=ekhzxe8u0D7xz4tcKHCzgKNc14LtF0wo2FRTJp4eoCc,4638
7
7
  backpack/json_user_settings.py,sha256=bC9BNbFroIwBlV2sPcibaFcPvUzkGRxvGxG3i1OR78o,2644
@@ -10,8 +10,8 @@ backpack/logger.py,sha256=yoo4_4Ok9MAdd3GSTeeSGaIKJ4c-KwdhI6q7lg_39oo,518
10
10
  backpack/patterns.py,sha256=qBwgbpfzMrap4KHtLLsg1CJmsmstGGXfzYLpkuUdbMI,889
11
11
  backpack/strings.py,sha256=J6GAXRXeNgdA7gvNO5hYOYpIs2jHmYoG99z9O6Sczbo,3611
12
12
  backpack/test_utils.py,sha256=am9XWt8NTDQx5gl5tFq47tTDZ7cJjSnpB7f2s603X4s,1370
13
- backpack/version.py,sha256=PNBE3ogWLVZEP90MKMa6Wqb0YN6wQ03f1JERBqTBy9g,1410
14
- python_backpack-2.0.3.dist-info/METADATA,sha256=B_tjW5uTw0Y7SsrL9ct7EnHsMAgUqd1wJoyFb-k3uKo,6665
15
- python_backpack-2.0.3.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
16
- python_backpack-2.0.3.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
17
- python_backpack-2.0.3.dist-info/RECORD,,
13
+ backpack/version.py,sha256=5W8rugrg7yvzss1RdSpTh7EZ6kuqwBn7dBHUYktOpMw,1305
14
+ python_backpack-2.0.4.dist-info/METADATA,sha256=koB5TMh4ISFQxJ0lvRIMXEZrl6qMxMq04Zy9oBfs4PA,6665
15
+ python_backpack-2.0.4.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
16
+ python_backpack-2.0.4.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
17
+ python_backpack-2.0.4.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.31.0
2
+ Generator: hatchling 1.32.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any