validfilepath 0.1__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.
@@ -0,0 +1,13 @@
1
+ from .validfilepath import valid_filepath_input
2
+ from .validfilepath import valid_filepath_output
3
+
4
+ __all__ = [
5
+ "valid_path_input_file",
6
+ "valid_path_output_file",
7
+ ]
8
+
9
+ from importlib.metadata import version, PackageNotFoundError
10
+ try:
11
+ __version__ = version("validfilepath")
12
+ except PackageNotFoundError:
13
+ __version__ = "unknown"
@@ -0,0 +1,37 @@
1
+ import argparse
2
+ import os
3
+
4
+ def valid_filepath_input(path):
5
+ if not os.path.isfile(path):
6
+ raise argparse.ArgumentTypeError(
7
+ f"File not found: {path}"
8
+ )
9
+ return path
10
+
11
+ def valid_filepath_output(path):
12
+ dir_name, file_name = os.path.split(path)
13
+ if not dir_name:
14
+ dir_name = '.'
15
+ # make sure parent directory exists
16
+ if not os.path.exists(dir_name):
17
+ raise argparse.ArgumentTypeError(
18
+ f'File {path} cannot be created ' + \
19
+ 'as its parent directory does not exist: {dir_name}'
20
+ )
21
+ # make sure parent directory is writable
22
+ if not os.access(dir_name, os.W_OK):
23
+ raise argparse.ArgumentTypeError(
24
+ f'Parent directory is not writable: {dir_name}'
25
+ )
26
+ # make sure path is not directory
27
+ if os.path.isdir(path):
28
+ raise argparse.ArgumentTypeError(
29
+ f'Path is directory: {path}'
30
+ )
31
+ # if a file exists, make sure it is writable
32
+ if os.path.exists(path):
33
+ if not os.access(path, os.W_OK):
34
+ raise argparse.ArgumentTypeError(
35
+ f'File exists and cannot be written: {path}'
36
+ )
37
+ return path
@@ -0,0 +1,21 @@
1
+ Metadata-Version: 2.1
2
+ Name: validfilepath
3
+ Version: 0.1
4
+ Summary: Path validators to be used with argparse
5
+ Author-Email: Mariusz Radon <mariusz.radon@gmail.com>
6
+ License: MIT
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+
10
+ # validfilepath
11
+
12
+ Path validators to be used with argparse.
13
+
14
+ ## Usage
15
+ ```python
16
+ import argparse
17
+ from validfilepath import valid_filepath_input, valid_filepath_output
18
+ ap = argparse.ArgumentParser()
19
+ ap.add_argument('--infile', type=valid_filepath_input)
20
+ ap.add_argument('--outfile', type=valid_filepath_output)
21
+ ```
@@ -0,0 +1,7 @@
1
+ validfilepath-0.1.dist-info/METADATA,sha256=4RIOrXKkOkq1iG0DicTXeZFo4HvpqI3cDmV4R_EIPlM,548
2
+ validfilepath-0.1.dist-info/WHEEL,sha256=IuIk3wbaEnFH1cx75iM2R1CmliRI3dFLXTbRakgvgFQ,90
3
+ validfilepath-0.1.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
+ validfilepath-0.1.dist-info/licenses/LICENSE,sha256=GMb_C3M-qF-cKK6nZP4a6sk6O_1lL7BPtntKoQWUHbA,1070
5
+ validfilepath/__init__.py,sha256=N-knX2sJJ_4n-1nk6VAee5WR_RTFnsvvPcr67Ythlgg,338
6
+ validfilepath/validfilepath.py,sha256=_nKv55Crm9d4i-0F0GLBPNLG2j02JpBOquS_ExSOefE,1179
7
+ validfilepath-0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: pdm-backend (2.5.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,4 @@
1
+ [console_scripts]
2
+
3
+ [gui_scripts]
4
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mariusz Radon
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.