config2py 0.1.35__tar.gz → 0.1.36__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 (22) hide show
  1. {config2py-0.1.35 → config2py-0.1.36}/PKG-INFO +1 -1
  2. {config2py-0.1.35 → config2py-0.1.36}/config2py/util.py +56 -53
  3. {config2py-0.1.35 → config2py-0.1.36}/config2py.egg-info/PKG-INFO +1 -1
  4. {config2py-0.1.35 → config2py-0.1.36}/config2py.egg-info/SOURCES.txt +0 -1
  5. {config2py-0.1.35 → config2py-0.1.36}/setup.cfg +1 -1
  6. config2py-0.1.35/config2py/tests/test_util.py +0 -39
  7. {config2py-0.1.35 → config2py-0.1.36}/LICENSE +0 -0
  8. {config2py-0.1.35 → config2py-0.1.36}/README.md +0 -0
  9. {config2py-0.1.35 → config2py-0.1.36}/config2py/__init__.py +0 -0
  10. {config2py-0.1.35 → config2py-0.1.36}/config2py/base.py +0 -0
  11. {config2py-0.1.35 → config2py-0.1.36}/config2py/errors.py +0 -0
  12. {config2py-0.1.35 → config2py-0.1.36}/config2py/s_configparser.py +0 -0
  13. {config2py-0.1.35 → config2py-0.1.36}/config2py/scrap/__init__.py +0 -0
  14. {config2py-0.1.35 → config2py-0.1.36}/config2py/tests/__init__.py +0 -0
  15. {config2py-0.1.35 → config2py-0.1.36}/config2py/tests/test_tools.py +0 -0
  16. {config2py-0.1.35 → config2py-0.1.36}/config2py/tests/utils_for_testing.py +0 -0
  17. {config2py-0.1.35 → config2py-0.1.36}/config2py/tools.py +0 -0
  18. {config2py-0.1.35 → config2py-0.1.36}/config2py.egg-info/dependency_links.txt +0 -0
  19. {config2py-0.1.35 → config2py-0.1.36}/config2py.egg-info/not-zip-safe +0 -0
  20. {config2py-0.1.35 → config2py-0.1.36}/config2py.egg-info/requires.txt +0 -0
  21. {config2py-0.1.35 → config2py-0.1.36}/config2py.egg-info/top_level.txt +0 -0
  22. {config2py-0.1.35 → config2py-0.1.36}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: config2py
3
- Version: 0.1.35
3
+ Version: 0.1.36
4
4
  Summary: Simplified reading and writing configurations from various sources and formats
5
5
  Home-page: https://github.com/i2mint/config2py
6
6
  Author: OtoSense
@@ -7,6 +7,8 @@ from pathlib import Path
7
7
  from typing import Optional, Union, Any, Callable, Set, Iterable
8
8
  import getpass
9
9
 
10
+ from dol import process_path
11
+
10
12
  from i2 import mk_sentinel # TODO: Only i2 dependency. Consider replacing.
11
13
 
12
14
  # def mk_sentinel(name): # TODO: Only i2 dependency. Here's replacement, but not picklable
@@ -183,65 +185,66 @@ DFLT_APP_DATA_FOLDER = os.getenv(
183
185
  )
184
186
 
185
187
 
186
- def process_path(
187
- *path: Iterable[str],
188
- ensure_dir_exists=False,
189
- assert_exists=False,
190
- ensure_endswith_slash=False,
191
- ensure_does_not_end_with_slash=False,
192
- expanduser=True,
193
- expandvars=True,
194
- abspath=True,
195
- rootdir: str = '',
196
- ) -> str:
188
+ def create_directories(dirpath, max_dirs_to_make=None):
197
189
  """
198
- Process a path string, ensuring it exists, and optionally expanding user.
190
+ Create directories up to a specified limit.
199
191
 
200
- Args:
201
- path (Iterable[str]): The path to process. Can be multiple components of a path.
202
- ensure_dir_exists (bool): Whether to ensure the path exists.
203
- assert_exists (bool): Whether to assert that the path exists.
204
- ensure_endswith_slash (bool): Whether to ensure the path ends with a slash.
205
- ensure_does_not_end_with_slash (bool): Whether to ensure the path does not end with a slash.
206
- expanduser (bool): Whether to expand the user in the path.
207
- expandvars (bool): Whether to expand environment variables in the path.
208
- abspath (bool): Whether to convert the path to an absolute path.
209
- rootdir (str): The root directory to prepend to the path.
192
+ Parameters:
193
+ dirpath (str): The directory path to create.
194
+ max_dirs_to_make (int, optional): The maximum number of directories to create. If None, there's no limit.
210
195
 
211
196
  Returns:
212
- str: The processed path.
197
+ bool: True if the directory was created successfully, False otherwise.
198
+
199
+ Raises:
200
+ ValueError: If max_dirs_to_make is negative.
201
+
202
+ Examples:
203
+ >>> import tempfile, shutil
204
+ >>> temp_dir = tempfile.mkdtemp()
205
+ >>> target_dir = os.path.join(temp_dir, 'a', 'b', 'c')
206
+ >>> create_directories(target_dir, max_dirs_to_make=2)
207
+ False
208
+ >>> create_directories(target_dir, max_dirs_to_make=3)
209
+ True
210
+ >>> os.path.isdir(target_dir)
211
+ True
212
+ >>> shutil.rmtree(temp_dir) # Cleanup
213
+
214
+ >>> temp_dir = tempfile.mkdtemp()
215
+ >>> target_dir = os.path.join(temp_dir, 'a', 'b', 'c', 'd')
216
+ >>> create_directories(target_dir)
217
+ True
218
+ >>> os.path.isdir(target_dir)
219
+ True
220
+ >>> shutil.rmtree(temp_dir) # Cleanup
221
+ """
222
+ if max_dirs_to_make is not None and max_dirs_to_make < 0:
223
+ raise ValueError('max_dirs_to_make must be non-negative or None')
213
224
 
214
- >>> process_path('a', 'b', 'c') # doctest: +ELLIPSIS
215
- '...a/b/c'
216
- >>> from functools import partial
217
- >>> process_path('a', 'b', 'c', rootdir='/root/dir/', ensure_endswith_slash=True)
218
- '/root/dir/a/b/c/'
225
+ if os.path.exists(dirpath):
226
+ return True
219
227
 
220
- """
221
- path = os.path.join(*path)
222
- if ensure_endswith_slash and ensure_does_not_end_with_slash:
223
- raise ValueError(
224
- 'Cannot ensure both ends with slash and does not end with slash.'
225
- )
226
- if rootdir:
227
- path = os.path.join(rootdir, path)
228
- if expanduser:
229
- path = os.path.expanduser(path)
230
- if expandvars:
231
- path = os.path.expandvars(path)
232
- if abspath:
233
- path = os.path.abspath(path)
234
- if ensure_endswith_slash:
235
- if not path.endswith('/'):
236
- path = path + '/'
237
- if ensure_does_not_end_with_slash:
238
- if path.endswith('/'):
239
- path = path[:-1]
240
- if ensure_dir_exists:
241
- os.makedirs(path, exist_ok=True)
242
- if assert_exists:
243
- assert os.path.exists(path), f'Path does not exist: {path}'
244
- return path
228
+ if max_dirs_to_make is None:
229
+ os.makedirs(dirpath, exist_ok=True)
230
+ return True
231
+
232
+ # Calculate the number of directories to create
233
+ dirs_to_make = []
234
+ current_path = dirpath
235
+
236
+ while not os.path.exists(current_path):
237
+ dirs_to_make.append(current_path)
238
+ current_path, _ = os.path.split(current_path)
239
+
240
+ if len(dirs_to_make) > max_dirs_to_make:
241
+ return False
242
+
243
+ # Create directories from the top level down
244
+ for dir_to_make in reversed(dirs_to_make):
245
+ os.mkdir(dir_to_make)
246
+
247
+ return True
245
248
 
246
249
 
247
250
  # Note: First possible i2 dependency -- vendoring for now
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: config2py
3
- Version: 0.1.35
3
+ Version: 0.1.36
4
4
  Summary: Simplified reading and writing configurations from various sources and formats
5
5
  Home-page: https://github.com/i2mint/config2py
6
6
  Author: OtoSense
@@ -17,5 +17,4 @@ config2py.egg-info/top_level.txt
17
17
  config2py/scrap/__init__.py
18
18
  config2py/tests/__init__.py
19
19
  config2py/tests/test_tools.py
20
- config2py/tests/test_util.py
21
20
  config2py/tests/utils_for_testing.py
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = config2py
3
- version = 0.1.35
3
+ version = 0.1.36
4
4
  url = https://github.com/i2mint/config2py
5
5
  platforms = any
6
6
  description_file = README.md
@@ -1,39 +0,0 @@
1
- import tempfile
2
- import os
3
- import pytest
4
- from config2py.util import process_path
5
-
6
-
7
- def test_process_path():
8
- # Create a temporary directory
9
- with tempfile.TemporaryDirectory() as temp_dir:
10
- temp_path = os.path.join(temp_dir, 'foo/bar')
11
-
12
- output_path = process_path(temp_path)
13
- assert output_path == temp_path
14
- assert not os.path.exists(output_path)
15
-
16
- output_path = process_path(temp_path, expanduser=False)
17
- assert output_path == temp_path
18
- assert not os.path.exists(output_path)
19
-
20
- with pytest.raises(AssertionError):
21
- output_path = process_path(temp_path, assert_exists=True)
22
-
23
- output_path = process_path(temp_path, ensure_dir_exists=True)
24
- assert output_path == temp_path
25
- assert os.path.exists(output_path)
26
-
27
- output_path = process_path(temp_path, assert_exists=True)
28
- assert output_path == temp_path
29
- assert os.path.exists(output_path)
30
-
31
- # If path doesn't end with a (system file separator) slash, add one:
32
- output_path = process_path(temp_path, ensure_endswith_slash=True)
33
- assert output_path == temp_path + os.path.sep
34
-
35
- # If path ends with a (system file separator) slash, remove it.
36
- output_path = process_path(
37
- temp_path + os.path.sep, ensure_does_not_end_with_slash=True
38
- )
39
- assert output_path == temp_path
File without changes
File without changes
File without changes
File without changes