treex-cli 0.1.7__tar.gz → 0.1.9__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: treex-cli
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: List directory contents as a tree with file and directory metadata
5
5
  Author: Corey Goldberg
6
6
  Maintainer: Corey Goldberg
@@ -100,7 +100,7 @@ Install `treex` from [PyPI][pypi-home] using either `pip` or `pipx`:
100
100
 
101
101
  ```
102
102
  $ treex --help
103
- usage: treex [-h] [-a] [-m] [-q] [-s] [directory]
103
+ usage: treex [-h] [-a] [-m] [-q] [-d] [-s] [directory]
104
104
 
105
105
  List directory contents as a tree with file and directory metadata.
106
106
 
@@ -109,9 +109,10 @@ positional arguments:
109
109
 
110
110
  options:
111
111
  -h, --help show this help message and exit
112
- -a, --all show all files (including those ignored by Git)
112
+ -a, --all show all files, including those ignored by Git
113
113
  -m, --modified show file modification times
114
114
  -q, --quiet don't show file metadata
115
+ -d, --dirs show directories only
115
116
  -s, --summary show summary only
116
117
  ```
117
118
 
@@ -75,7 +75,7 @@ Install `treex` from [PyPI][pypi-home] using either `pip` or `pipx`:
75
75
 
76
76
  ```
77
77
  $ treex --help
78
- usage: treex [-h] [-a] [-m] [-q] [-s] [directory]
78
+ usage: treex [-h] [-a] [-m] [-q] [-d] [-s] [directory]
79
79
 
80
80
  List directory contents as a tree with file and directory metadata.
81
81
 
@@ -84,9 +84,10 @@ positional arguments:
84
84
 
85
85
  options:
86
86
  -h, --help show this help message and exit
87
- -a, --all show all files (including those ignored by Git)
87
+ -a, --all show all files, including those ignored by Git
88
88
  -m, --modified show file modification times
89
89
  -q, --quiet don't show file metadata
90
+ -d, --dirs show directories only
90
91
  -s, --summary show summary only
91
92
  ```
92
93
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "treex-cli"
7
- version = "0.1.7"
7
+ version = "0.1.9"
8
8
  description="List directory contents as a tree with file and directory metadata"
9
9
  license = "MIT"
10
10
  license-files = ["LICENSE"]
@@ -53,6 +53,7 @@ py-modules = ["treex"]
53
53
  [tool.pytest]
54
54
  addopts = ["-v"]
55
55
  filterwarnings = ["default"]
56
+ tmp_path_retention_policy = "none"
56
57
 
57
58
  [tool.ruff]
58
59
  line-length = 88
@@ -62,7 +63,7 @@ target-version = "py310"
62
63
  [tool.ruff.lint]
63
64
  select = ["ALL"]
64
65
  ignore = [
65
- "ANN", "COM812", "D", "DTZ001", "DTZ006",
66
+ "ANN", "C901", "COM812", "D", "DTZ001", "DTZ006",
66
67
  "FBT", "PLR", "S603", "S607", "T201"
67
68
  ]
68
69
  fixable = ["ALL"]
@@ -152,6 +152,7 @@ def _collect_tree(
152
152
  rows,
153
153
  show_metadata,
154
154
  show_modified,
155
+ show_files,
155
156
  ):
156
157
  """Walk the tree once and collect the output rows."""
157
158
  entries = _get_tree_entries(path, gitignore)
@@ -159,15 +160,26 @@ def _collect_tree(
159
160
  rows.append((prefix + "└── [permission denied]", None))
160
161
  return 0
161
162
  total_size = 0
162
- for index, entry in enumerate(entries):
163
- is_last = index == len(entries) - 1
164
- connector = "└── " if is_last else "├── "
165
- tree_name = prefix + connector + entry.name
163
+ # When files are hidden, only directories determine which visible
164
+ # entry is last. Files are still processed for stats and sizes.
165
+ visible_entries = entries
166
+ if not show_files:
167
+ visible_entries = [entry for entry in entries if entry.is_dir()]
168
+ visible_index = 0
169
+ for entry in entries:
170
+ is_visible = show_files or entry.is_dir()
171
+ if is_visible:
172
+ is_last = visible_index == len(visible_entries) - 1
173
+ visible_index += 1
174
+ connector = "└── " if is_last else "├── "
175
+ tree_name = prefix + connector + entry.name
176
+ else:
177
+ tree_name = None
166
178
  if entry.is_dir():
167
179
  stats["directories"] += 1
168
180
  row_index = len(rows)
169
181
  rows.append((tree_name, None))
170
- # Indent nested entries, preserving the tree's vertical branch
182
+ # Indent nested entries, preserving the tree's vertical branch.
171
183
  extension = " " if is_last else "│ "
172
184
  dir_size = _collect_tree(
173
185
  entry,
@@ -177,6 +189,7 @@ def _collect_tree(
177
189
  rows,
178
190
  show_metadata,
179
191
  show_modified,
192
+ show_files,
180
193
  )
181
194
  total_size += dir_size
182
195
  if show_metadata:
@@ -187,27 +200,17 @@ def _collect_tree(
187
200
  stats["files"] += 1
188
201
  stats["total_size"] += size
189
202
  total_size += size
190
- timestamp = modified if show_modified else None
191
- rows.append((tree_name, (size_text, info, timestamp)))
203
+ if show_files:
204
+ timestamp = modified if show_modified else None
205
+ rows.append((tree_name, (size_text, info, timestamp)))
192
206
  else:
193
207
  stats["files"] += 1
194
208
  stats["total_size"] = None
195
- rows.append((tree_name, None))
209
+ if show_files:
210
+ rows.append((tree_name, None))
196
211
  return total_size
197
212
 
198
213
 
199
- def print_summary(stats):
200
- directories = stats["directories"]
201
- files = stats["files"]
202
- total_size = stats["total_size"]
203
- directory_label = "directory" if directories == 1 else "directories"
204
- file_label = "file" if files == 1 else "files"
205
- summary = f"{directories:,} {directory_label} • {files:,} {file_label}"
206
- if total_size is not None:
207
- summary += f" • {_format_size(total_size)}"
208
- print(summary)
209
-
210
-
211
214
  def print_tree(
212
215
  directory,
213
216
  prefix="",
@@ -216,8 +219,9 @@ def print_tree(
216
219
  show_metadata=True,
217
220
  show_modified=False,
218
221
  show_tree=True,
222
+ show_files=True,
219
223
  ):
220
- """Print the directory tree with aligned file metadata."""
224
+ """Print the directory tree with aligned metadata."""
221
225
  if stats is None:
222
226
  stats = {"directories": 0, "files": 0, "total_size": 0}
223
227
  rows = []
@@ -230,32 +234,43 @@ def print_tree(
230
234
  rows,
231
235
  show_metadata,
232
236
  show_modified,
237
+ show_files,
233
238
  )
234
239
  if show_tree:
235
- # Align file metadata with the longest tree/name
236
- max_tree_name_width = max(
237
- (len(tree_name) for tree_name, _ in rows),
238
- default=0,
239
- )
240
- for tree_name, file_info_data in rows:
241
- if file_info_data is None:
240
+ # Align metadata with the longest tree/name
241
+ max_tree_name_width = max((len(tree_name) for tree_name, _ in rows), default=0)
242
+ for tree_name, metadata in rows:
243
+ if metadata is None:
242
244
  print(tree_name)
243
245
  continue
244
- size_text, info, modified = file_info_data
246
+ size_text, info, modified = metadata
245
247
  output = f"{tree_name:<{max_tree_name_width}}{size_text:>10}"
246
248
  if info is not None:
247
- output += f" {info:<10}"
249
+ output += f" {info:<12}"
248
250
  if modified is not None:
249
251
  output += f" {modified}"
250
252
  print(output)
251
253
  return stats
252
254
 
253
255
 
256
+ def print_summary(stats):
257
+ """Print a summary of directory/file counts and total size."""
258
+ directories = stats["directories"]
259
+ files = stats["files"]
260
+ total_size = stats["total_size"]
261
+ directory_label = "directory" if directories == 1 else "directories"
262
+ file_label = "file" if files == 1 else "files"
263
+ summary = f"{directories:,} {directory_label} • {files:,} {file_label}"
264
+ if total_size is not None:
265
+ summary += f" • {_format_size(total_size)}"
266
+ print(summary)
267
+
268
+
254
269
  def parse_args(argv=None):
255
270
  """Parse command-line arguments."""
256
271
  parser = argparse.ArgumentParser(
257
- description="List directory contents as a tree with "
258
- "file and directory metadata.",
272
+ description="List directory contents as a tree "
273
+ "with file and directory metadata.",
259
274
  )
260
275
  parser.add_argument(
261
276
  "directory",
@@ -268,7 +283,7 @@ def parse_args(argv=None):
268
283
  "-a",
269
284
  "--all",
270
285
  action="store_true",
271
- help="show all files (including those ignored by Git)",
286
+ help="show all files, including those ignored by Git",
272
287
  )
273
288
  parser.add_argument(
274
289
  "-m",
@@ -282,6 +297,12 @@ def parse_args(argv=None):
282
297
  action="store_true",
283
298
  help="don't show file metadata",
284
299
  )
300
+ parser.add_argument(
301
+ "-d",
302
+ "--dirs",
303
+ action="store_true",
304
+ help="show directories only",
305
+ )
285
306
  parser.add_argument(
286
307
  "-s",
287
308
  "--summary",
@@ -302,6 +323,7 @@ def main():
302
323
  gitignore = None if args.all else GitIgnore(path)
303
324
  show_tree = not args.summary
304
325
  show_metadata = not args.quiet
326
+ show_files = not args.dirs
305
327
  if show_tree:
306
328
  print(path)
307
329
  stats = print_tree(
@@ -310,6 +332,7 @@ def main():
310
332
  show_metadata=show_metadata,
311
333
  show_modified=args.modified,
312
334
  show_tree=show_tree,
335
+ show_files=show_files,
313
336
  )
314
337
  if show_tree:
315
338
  print()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: treex-cli
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: List directory contents as a tree with file and directory metadata
5
5
  Author: Corey Goldberg
6
6
  Maintainer: Corey Goldberg
@@ -100,7 +100,7 @@ Install `treex` from [PyPI][pypi-home] using either `pip` or `pipx`:
100
100
 
101
101
  ```
102
102
  $ treex --help
103
- usage: treex [-h] [-a] [-m] [-q] [-s] [directory]
103
+ usage: treex [-h] [-a] [-m] [-q] [-d] [-s] [directory]
104
104
 
105
105
  List directory contents as a tree with file and directory metadata.
106
106
 
@@ -109,9 +109,10 @@ positional arguments:
109
109
 
110
110
  options:
111
111
  -h, --help show this help message and exit
112
- -a, --all show all files (including those ignored by Git)
112
+ -a, --all show all files, including those ignored by Git
113
113
  -m, --modified show file modification times
114
114
  -q, --quiet don't show file metadata
115
+ -d, --dirs show directories only
115
116
  -s, --summary show summary only
116
117
  ```
117
118
 
File without changes
File without changes