ssb-sgis 1.1.1__py3-none-any.whl → 1.1.3__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.
sgis/__init__.py CHANGED
@@ -85,6 +85,7 @@ from .io.opener import opener
85
85
  from .io.read_parquet import read_parquet_url
86
86
  from .maps.examine import Examine
87
87
  from .maps.explore import Explore
88
+ from .maps.explore import HtmlViewer
88
89
  from .maps.httpserver import run_html_server
89
90
  from .maps.legend import Legend
90
91
  from .maps.maps import clipmap
sgis/conf.py CHANGED
@@ -1,16 +1,72 @@
1
1
  try:
2
2
  from gcsfs import GCSFileSystem
3
+
4
+ file_system = GCSFileSystem
3
5
  except ImportError:
6
+ import datetime
7
+ import glob
8
+ import io
9
+ import os
10
+ import pathlib
11
+ from concurrent.futures import ThreadPoolExecutor
12
+ from typing import Any
13
+
14
+ class LocalFileSystem:
15
+ """Mimicks GCS's FileSystem but using standard library (os, glob)."""
16
+
17
+ @staticmethod
18
+ def glob(
19
+ path: str,
20
+ detail: bool = False,
21
+ recursive: bool = True,
22
+ include_hidden: bool = True,
23
+ **kwargs,
24
+ ) -> list[dict] | list[str]:
25
+ """Like GCSFileSystem.glob."""
26
+ relevant_paths = glob.iglob(
27
+ path, recursive=recursive, include_hidden=include_hidden, **kwargs
28
+ )
29
+
30
+ if not detail:
31
+ return list(relevant_paths)
32
+ with ThreadPoolExecutor() as executor:
33
+ return list(executor.map(get_file_info, relevant_paths))
34
+
35
+ @classmethod
36
+ def ls(
37
+ cls, path: str, detail: bool = False, **kwargs
38
+ ) -> list[dict] | list[str]:
39
+ """Like GCSFileSystem.ls."""
40
+ return cls().glob(
41
+ str(pathlib.Path(path) / "**"), detail=detail, recursive=False, **kwargs
42
+ )
43
+
44
+ @staticmethod
45
+ def info(path) -> dict[str, Any]:
46
+ """Like GCSFileSystem.info."""
47
+ return get_file_info(path)
48
+
49
+ @staticmethod
50
+ def open(path: str, *args, **kwargs) -> io.TextIOWrapper:
51
+ """Built in open."""
52
+ return open(path, *args, **kwargs)
4
53
 
5
- class GCSFileSystem:
6
- """Placeholder."""
54
+ @staticmethod
55
+ def exists(path: str) -> bool:
56
+ """os.path.exists."""
57
+ return os.path.exists(path)
7
58
 
8
- def __init__(self, *args, **kwargs) -> None:
9
- """Placeholder."""
10
- raise ImportError("gcsfs")
59
+ def get_file_info(path) -> dict[str, str | float]:
60
+ return {
61
+ "updated": datetime.datetime.fromtimestamp(os.path.getmtime(path)),
62
+ "size": os.path.getsize(path),
63
+ "name": path,
64
+ "type": "directory" if os.path.isdir(path) else "file",
65
+ }
11
66
 
67
+ file_system = LocalFileSystem
12
68
 
13
69
  config = {
14
70
  "n_jobs": 1,
15
- "file_system": GCSFileSystem,
71
+ "file_system": file_system,
16
72
  }