minimindslab-filename-split 0.1.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MiniMindsLab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,72 @@
1
+ Metadata-Version: 2.4
2
+ Name: minimindslab-filename-split
3
+ Version: 0.1.0
4
+ Summary: Parse file names into base name and multi-part extension in a deterministic way, with optional support for known compound extensions like .tar.gz.
5
+ Author: MiniMindsLab
6
+ License: MIT
7
+ Keywords: filename,extension,path,utilities
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Requires-Python: >=3.11
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Dynamic: license-file
20
+
21
+ # MiniMindsLab Filename Split
22
+
23
+ A tiny, deterministic utility for splitting a filename into:
24
+
25
+ - **stem** (base name)
26
+ - **suffix** (extension), including optional handling of known compound extensions such as `.tar.gz`.
27
+
28
+ ## Features
29
+
30
+ - Pure Python (standard library only)
31
+ - Deterministic behavior
32
+ - Correct handling for common edge cases like dotfiles
33
+
34
+ ## Usage
35
+
36
+ ```python
37
+ from minimindslab_filename_split import split_filename
38
+
39
+ print(split_filename("archive.tar.gz"))
40
+ # ('archive', '.tar.gz')
41
+
42
+ print(split_filename("report.csv"))
43
+ # ('report', '.csv')
44
+
45
+ print(split_filename(".env"))
46
+ # ('.env', '')
47
+
48
+ print(split_filename("notes"))
49
+ # ('notes', '')
50
+ ```
51
+
52
+ ### Disabling compound extension handling
53
+
54
+ ```python
55
+ from minimindslab_filename_split import split_filename
56
+
57
+ print(split_filename("archive.tar.gz", allow_compound=False))
58
+ # ('archive.tar', '.gz')
59
+ ```
60
+
61
+ ## API
62
+
63
+ ### `split_filename(filename: str, allow_compound: bool = True, compound_extensions: tuple[str, ...] | None = None) -> tuple[str, str]`
64
+
65
+ Splits a filename into `(stem, suffix)`.
66
+
67
+ - `allow_compound`: When `True`, known compound extensions are recognized.
68
+ - `compound_extensions`: Optional custom compound extension list; each must start with `.`.
69
+
70
+ ## License
71
+
72
+ MIT
@@ -0,0 +1,52 @@
1
+ # MiniMindsLab Filename Split
2
+
3
+ A tiny, deterministic utility for splitting a filename into:
4
+
5
+ - **stem** (base name)
6
+ - **suffix** (extension), including optional handling of known compound extensions such as `.tar.gz`.
7
+
8
+ ## Features
9
+
10
+ - Pure Python (standard library only)
11
+ - Deterministic behavior
12
+ - Correct handling for common edge cases like dotfiles
13
+
14
+ ## Usage
15
+
16
+ ```python
17
+ from minimindslab_filename_split import split_filename
18
+
19
+ print(split_filename("archive.tar.gz"))
20
+ # ('archive', '.tar.gz')
21
+
22
+ print(split_filename("report.csv"))
23
+ # ('report', '.csv')
24
+
25
+ print(split_filename(".env"))
26
+ # ('.env', '')
27
+
28
+ print(split_filename("notes"))
29
+ # ('notes', '')
30
+ ```
31
+
32
+ ### Disabling compound extension handling
33
+
34
+ ```python
35
+ from minimindslab_filename_split import split_filename
36
+
37
+ print(split_filename("archive.tar.gz", allow_compound=False))
38
+ # ('archive.tar', '.gz')
39
+ ```
40
+
41
+ ## API
42
+
43
+ ### `split_filename(filename: str, allow_compound: bool = True, compound_extensions: tuple[str, ...] | None = None) -> tuple[str, str]`
44
+
45
+ Splits a filename into `(stem, suffix)`.
46
+
47
+ - `allow_compound`: When `True`, known compound extensions are recognized.
48
+ - `compound_extensions`: Optional custom compound extension list; each must start with `.`.
49
+
50
+ ## License
51
+
52
+ MIT
@@ -0,0 +1,32 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77.0.3"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "minimindslab-filename-split"
7
+ version = "0.1.0"
8
+ description = "Parse file names into base name and multi-part extension in a deterministic way, with optional support for known compound extensions like .tar.gz."
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = { text = "MIT" }
12
+ dependencies = []
13
+ authors = [
14
+ { name = "MiniMindsLab" }
15
+ ]
16
+ keywords = ["filename", "extension", "path", "utilities"]
17
+ classifiers = [
18
+ "Development Status :: 3 - Alpha",
19
+ "Intended Audience :: Developers",
20
+ "License :: OSI Approved :: MIT License",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Operating System :: OS Independent",
25
+ "Topic :: Software Development :: Libraries :: Python Modules"
26
+ ]
27
+
28
+ [tool.setuptools]
29
+ package-dir = {"" = "src"}
30
+
31
+ [tool.setuptools.packages.find]
32
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,71 @@
1
+ """MiniMindsLab Filename Split.
2
+
3
+ Deterministically split filenames into stem and suffix, with optional
4
+ support for known compound extensions.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from pathlib import PurePath
10
+
11
+ __all__ = ["split_filename", "DEFAULT_COMPOUND_EXTENSIONS"]
12
+ __version__ = "0.1.0"
13
+
14
+ DEFAULT_COMPOUND_EXTENSIONS: tuple[str, ...] = (
15
+ ".tar.gz",
16
+ ".tar.bz2",
17
+ ".tar.xz",
18
+ ".tar.zst",
19
+ )
20
+
21
+
22
+ def split_filename(
23
+ filename: str,
24
+ allow_compound: bool = True,
25
+ compound_extensions: tuple[str, ...] | None = None,
26
+ ) -> tuple[str, str]:
27
+ """Split a filename into ``(stem, suffix)``.
28
+
29
+ Parameters
30
+ ----------
31
+ filename:
32
+ Input file name or path-like string. Only the final path segment is used.
33
+ allow_compound:
34
+ When True, recognizes known compound extensions (e.g. ``.tar.gz``).
35
+ compound_extensions:
36
+ Optional override for compound extension candidates. Each item must start
37
+ with ``.`` and contain at least one additional ``.``.
38
+
39
+ Returns
40
+ -------
41
+ tuple[str, str]
42
+ A 2-tuple of ``(stem, suffix)``.
43
+ """
44
+ if not isinstance(filename, str):
45
+ raise TypeError("filename must be a str")
46
+
47
+ name = PurePath(filename).name
48
+ if name == "":
49
+ return "", ""
50
+
51
+ if name.startswith(".") and name.count(".") == 1:
52
+ return name, ""
53
+
54
+ suffixes = PurePath(name).suffixes
55
+ if not suffixes:
56
+ return name, ""
57
+
58
+ if allow_compound:
59
+ candidates = compound_extensions or DEFAULT_COMPOUND_EXTENSIONS
60
+ for ext in candidates:
61
+ if not isinstance(ext, str) or not ext.startswith(".") or ext.count(".") < 2:
62
+ raise ValueError(
63
+ "compound_extensions items must be strings starting with '.' and contain at least two dots"
64
+ )
65
+ for ext in sorted(candidates, key=len, reverse=True):
66
+ if name.lower().endswith(ext.lower()) and len(name) > len(ext):
67
+ return name[: -len(ext)], ext
68
+
69
+ suffix = suffixes[-1]
70
+ stem = name[: -len(suffix)] if suffix else name
71
+ return stem, suffix
@@ -0,0 +1,72 @@
1
+ Metadata-Version: 2.4
2
+ Name: minimindslab-filename-split
3
+ Version: 0.1.0
4
+ Summary: Parse file names into base name and multi-part extension in a deterministic way, with optional support for known compound extensions like .tar.gz.
5
+ Author: MiniMindsLab
6
+ License: MIT
7
+ Keywords: filename,extension,path,utilities
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Requires-Python: >=3.11
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Dynamic: license-file
20
+
21
+ # MiniMindsLab Filename Split
22
+
23
+ A tiny, deterministic utility for splitting a filename into:
24
+
25
+ - **stem** (base name)
26
+ - **suffix** (extension), including optional handling of known compound extensions such as `.tar.gz`.
27
+
28
+ ## Features
29
+
30
+ - Pure Python (standard library only)
31
+ - Deterministic behavior
32
+ - Correct handling for common edge cases like dotfiles
33
+
34
+ ## Usage
35
+
36
+ ```python
37
+ from minimindslab_filename_split import split_filename
38
+
39
+ print(split_filename("archive.tar.gz"))
40
+ # ('archive', '.tar.gz')
41
+
42
+ print(split_filename("report.csv"))
43
+ # ('report', '.csv')
44
+
45
+ print(split_filename(".env"))
46
+ # ('.env', '')
47
+
48
+ print(split_filename("notes"))
49
+ # ('notes', '')
50
+ ```
51
+
52
+ ### Disabling compound extension handling
53
+
54
+ ```python
55
+ from minimindslab_filename_split import split_filename
56
+
57
+ print(split_filename("archive.tar.gz", allow_compound=False))
58
+ # ('archive.tar', '.gz')
59
+ ```
60
+
61
+ ## API
62
+
63
+ ### `split_filename(filename: str, allow_compound: bool = True, compound_extensions: tuple[str, ...] | None = None) -> tuple[str, str]`
64
+
65
+ Splits a filename into `(stem, suffix)`.
66
+
67
+ - `allow_compound`: When `True`, known compound extensions are recognized.
68
+ - `compound_extensions`: Optional custom compound extension list; each must start with `.`.
69
+
70
+ ## License
71
+
72
+ MIT
@@ -0,0 +1,9 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/minimindslab_filename_split/__init__.py
5
+ src/minimindslab_filename_split.egg-info/PKG-INFO
6
+ src/minimindslab_filename_split.egg-info/SOURCES.txt
7
+ src/minimindslab_filename_split.egg-info/dependency_links.txt
8
+ src/minimindslab_filename_split.egg-info/top_level.txt
9
+ tests/test_filename_split.py
@@ -0,0 +1,79 @@
1
+ import ast
2
+ import pathlib
3
+ import unittest
4
+
5
+ from minimindslab_filename_split import split_filename
6
+
7
+
8
+ class TestFilenameSplitAcceptance(unittest.TestCase):
9
+ def test_archive_tar_gz_compound_enabled(self):
10
+ self.assertEqual(split_filename("archive.tar.gz"), ("archive", ".tar.gz"))
11
+
12
+ def test_report_csv(self):
13
+ self.assertEqual(split_filename("report.csv"), ("report", ".csv"))
14
+
15
+ def test_dotenv(self):
16
+ self.assertEqual(split_filename(".env"), (".env", ""))
17
+
18
+ def test_no_extension(self):
19
+ self.assertEqual(split_filename("notes"), ("notes", ""))
20
+
21
+
22
+ class TestFilenameSplitNegative(unittest.TestCase):
23
+ def test_type_error_non_string(self):
24
+ with self.assertRaises(TypeError):
25
+ split_filename(123) # type: ignore[arg-type]
26
+
27
+ def test_invalid_compound_extension_definition(self):
28
+ with self.assertRaises(ValueError):
29
+ split_filename("archive.tar.gz", compound_extensions=("tar.gz",))
30
+
31
+ def test_compound_disabled(self):
32
+ self.assertEqual(
33
+ split_filename("archive.tar.gz", allow_compound=False),
34
+ ("archive.tar", ".gz"),
35
+ )
36
+
37
+
38
+ class TestSecurityConstraints(unittest.TestCase):
39
+ def test_no_forbidden_calls_or_imports_in_core(self):
40
+ root = pathlib.Path(__file__).resolve().parents[1]
41
+ core_file = root / "src" / "minimindslab_filename_split" / "__init__.py"
42
+ source = core_file.read_text(encoding="utf-8")
43
+ tree = ast.parse(source)
44
+
45
+ forbidden_imports = {
46
+ "socket",
47
+ }
48
+ forbidden_calls = {"eval", "exec", "system"}
49
+
50
+ for node in ast.walk(tree):
51
+ if isinstance(node, ast.Import):
52
+ for alias in node.names:
53
+ self.assertNotIn(alias.name, forbidden_imports)
54
+ elif isinstance(node, ast.ImportFrom):
55
+ module = node.module or ""
56
+ self.assertNotIn(module, forbidden_imports)
57
+ elif isinstance(node, ast.Call):
58
+ if isinstance(node.func, ast.Name):
59
+ self.assertNotIn(node.func.id, forbidden_calls)
60
+ elif isinstance(node.func, ast.Attribute):
61
+ self.assertFalse(
62
+ node.func.attr == "system"
63
+ and isinstance(node.func.value, ast.Name)
64
+ and node.func.value.id == "os"
65
+ )
66
+
67
+ def test_no_forbidden_tokens_in_repository_files(self):
68
+ root = pathlib.Path(__file__).resolve().parents[1]
69
+ forbidden_tokens = ["sub" + "process", "re" + "quests", "ht" + "tpx", "aio" + "http", "url" + "lib.request"]
70
+
71
+ for path in root.rglob("*.py"):
72
+ text = path.read_text(encoding="utf-8")
73
+ lowered = text.lower()
74
+ for token in forbidden_tokens:
75
+ self.assertNotIn(token, lowered)
76
+
77
+
78
+ if __name__ == "__main__":
79
+ unittest.main()