Skip to content

Conversation

@CyrilJl
Copy link
Contributor

@CyrilJl CyrilJl commented Nov 14, 2024

fs.tree(path='/start/folder', display_size=True)

/start/folder
├── folder1
│ ├── file1.txt (1.234MB)
│ └── file2.txt (0.567MB)
└── folder2
└── file3.txt (2.345MB)

>>> fs.tree(path='/start/folder', display_size=True)

/start/folder
├── folder1
│   ├── file1.txt (1.234MB)
│   └── file2.txt (0.567MB)
└── folder2
    └── file3.txt (2.345MB)
@CyrilJl CyrilJl marked this pull request as ready for review November 14, 2024 14:32
Copy link
Member

@martindurant martindurant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nice addition!

I have some suggestions, and this code could really use a test, probably using memoryFS (fixture m).

@CyrilJl
Copy link
Contributor Author

CyrilJl commented Nov 15, 2024

@martindurant I went along with your proposals. This can be used as follows:

from fsspec import filesystem

fs = filesystem('ftp', host='test.rebex.net', user='demo', password='password')
tree = fs.tree(display_size=True, recursion_limit=3, indent_size=8, max_display=10)
print(tree)

/
├────── pub (1 subfolder)
│       └────── example (16 files)
│               ├────── KeyGenerator.png (35.81 kb)
│               ├────── KeyGeneratorSmall.png (23.47 kb)
│               ├────── ResumableTransfer.png (11.28 kb)
│               ├────── WinFormClient.png (78.12 kb)
│               ├────── WinFormClientSmall.png (17.49 kb)
│               ├────── imap-console-client.png (18.71 kb)
│               ├────── mail-editor.png (16.08 kb)
│               ├────── mail-send-winforms.png (34.58 kb)
│               ├────── mime-explorer.png (47.86 kb)
│               ├────── pocketftp.png (56.66 kb)
│               └────── 6 more item(s) not displayed.
└────── readme.txt (379B)

Or:

fs = filesystem('gs')
tree = fs.tree(path='gs://gcp-public-data-arco-era5', display_size=True, recursion_limit=2, indent_size=8, max_display=5)
print(tree)

gs://gcp-public-data-arco-era5
├────── ar (19 subfolders)
│       ├────── 1959-2022-1h-240x121_equiangular_with_poles_conservative.zarr (3 files, 35 subfolders)
│       ├────── 1959-2022-1h-360x181_equiangular_with_poles_conservative.zarr (3 files, 35 subfolders)
│       ├────── 1959-2022-6h-128x64_equiangular_conservative.zarr (3 files, 42 subfolders)
│       ├────── 1959-2022-6h-128x64_equiangular_with_poles_conservative.zarr (3 files, 42 subfolders)
│       ├────── 1959-2022-6h-1440x721.zarr (3 files, 42 subfolders)
│       └────── 14 more item(s) not displayed.
├────── co (10 subfolders)
│       ├────── model-level-moisture.zarr (3 files, 13 subfolders)
│       ├────── model-level-moisture.zarr-v2 (3 files, 13 subfolders)
│       ├────── model-level-wind.zarr (3 files, 8 subfolders)
│       ├────── model-level-wind.zarr-v2 (3 files, 8 subfolders)
│       ├────── single-level-forecast.zarr (3 files, 28 subfolders)
│       └────── 5 more item(s) not displayed.
└────── raw (4 subfolders)
        ├────── ERA5GRIB (1 subfolder)
        ├────── date-variable-pressure_level (85 subfolders)
        ├────── date-variable-single_level (85 subfolders)
        └────── date-variable-static (1 subfolder)

Is this what you had in mind ?

@martindurant
Copy link
Member

Looks good!

@martindurant
Copy link
Member

It would still be nice to create some minimal test for this, based on files in memoryFS

@martindurant
Copy link
Member

(please run pre-commit run -a here; I can't do this because "master" is a taken branch name)

@martindurant
Copy link
Member

See #1755 for mention of the s3fs failure

@martindurant
Copy link
Member

The issue is closed, please again merge from master.

@martindurant martindurant merged commit bf611a3 into fsspec:master Dec 16, 2024
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants