Skip to content

Commit 9cb21d3

Browse files
authored
refactor: extend the length of the black lines to 100 chars (#916)
2 parents 2d0174c + 9601dea commit 9cb21d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+120
-357
lines changed

noxfile.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def lint(session):
1414
"""Apply the pre-commits."""
1515
session.install("pre-commit")
16-
session.run("pre-commit", "run", "--a", *session.posargs)
16+
session.run("pre-commit", "run", "--all-files", *session.posargs)
1717

1818

1919
@nox.session(reuse_venv=True)
@@ -56,9 +56,7 @@ def docs(session):
5656
# build the api doc files
5757
templates = "docs/source/_templates/apidoc"
5858
modules = "docs/source/modules"
59-
session.run(
60-
"sphinx-apidoc", f"--templatedir={templates}", "-o", modules, "sepal_ui"
61-
)
59+
session.run("sphinx-apidoc", f"--templatedir={templates}", "-o", modules, "sepal_ui")
6260

6361
# build the documentation
6462
source = "docs/source"

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,6 @@ using = "PEP631:test;dev;doc"
181181

182182
[tool.codespell]
183183
skip = 'CHANGELOG.md,sepal_ui/message/**/*.json,sepal_ui/data/gaul_iso.json'
184+
185+
[tool.black]
186+
line-length = 100

sepal_ui/aoi/aoi_model.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ def __init__(
154154
self.gee = gee
155155
if gee:
156156
su.init_ee()
157-
self.folder = (
158-
str(folder) or f"projects/{ee.data._cloud_api_user_project}/assets/"
159-
)
157+
self.folder = str(folder) or f"projects/{ee.data._cloud_api_user_project}/assets/"
160158

161159
# set default values
162160
self.set_default(vector, admin, asset)
@@ -177,22 +175,16 @@ def set_default(
177175
# save the default values
178176
self.default_vector = vector
179177
self.default_asset = self.asset_name = str(asset) if asset else None
180-
self.asset_json = (
181-
{"pathname": asset, "column": "ALL", "value": None} if asset else None
182-
)
178+
self.asset_json = {"pathname": asset, "column": "ALL", "value": None} if asset else None
183179
self.default_admin = self.admin = admin
184180

185181
# cast the vector to json
186182
self.vector_json = (
187-
{"pathname": str(vector), "column": "ALL", "value": None}
188-
if vector
189-
else None
183+
{"pathname": str(vector), "column": "ALL", "value": None} if vector else None
190184
)
191185

192186
# cast the asset to json
193-
self.asset_json = (
194-
{"pathname": asset, "column": "ALL", "value": None} if asset else None
195-
)
187+
self.asset_json = {"pathname": asset, "column": "ALL", "value": None} if asset else None
196188

197189
# set the default gdf if possible
198190
if self.vector_json is not None:
@@ -285,9 +277,7 @@ def _from_points(self, point_json: dict) -> Self:
285277
self.gdf = gpd.GeoDataFrame(
286278
df,
287279
crs="EPSG:4326",
288-
geometry=gpd.points_from_xy(
289-
df[point_json["lng_column"]], df[point_json["lat_column"]]
290-
),
280+
geometry=gpd.points_from_xy(df[point_json["lng_column"]], df[point_json["lat_column"]]),
291281
)
292282

293283
# set the name
@@ -449,9 +439,7 @@ def get_columns(self) -> List[str]:
449439
if self.gee:
450440
aoi_ee = ee.Feature(self.feature_collection.first())
451441
columns = aoi_ee.propertyNames().getInfo()
452-
list_ = [
453-
col for col in columns if col not in ["system:index", "Shape_Area"]
454-
]
442+
list_ = [col for col in columns if col not in ["system:index", "Shape_Area"]]
455443
else:
456444
list_ = list(set(["geometry"]) ^ set(self.gdf.columns.to_list()))
457445

@@ -478,9 +466,7 @@ def get_fields(self, column: str) -> List[str]:
478466

479467
return sorted(list_)
480468

481-
def get_selected(
482-
self, column: str, field: str
483-
) -> Union[ee.Feature, gpd.GeoDataFrame]:
469+
def get_selected(self, column: str, field: str) -> Union[ee.Feature, gpd.GeoDataFrame]:
484470
"""Select an ee object based on selected column and field.
485471
486472
Args:
@@ -494,9 +480,7 @@ def get_selected(
494480
raise Exception(ms.aoi_sel.exception.no_gdf)
495481

496482
if self.gee:
497-
selected_feature = self.feature_collection.filterMetadata(
498-
column, "equals", field
499-
)
483+
selected_feature = self.feature_collection.filterMetadata(column, "equals", field)
500484
else:
501485
selected_feature = self.gdf[self.gdf[column] == field]
502486

sepal_ui/aoi/aoi_view.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,9 @@ def __init__(
5050
if methods == "ALL":
5151
self.methods = select_methods
5252
elif methods == "ADMIN":
53-
self.methods = {
54-
k: v for k, v in select_methods.items() if v["type"] == ADMIN
55-
}
53+
self.methods = {k: v for k, v in select_methods.items() if v["type"] == ADMIN}
5654
elif methods == "CUSTOM":
57-
self.methods = {
58-
k: v for k, v in select_methods.items() if v["type"] == CUSTOM
59-
}
55+
self.methods = {k: v for k, v in select_methods.items() if v["type"] == CUSTOM}
6056
elif type(methods) == list:
6157
if any(m[0] == "-" for m in methods) != all(m[0] == "-" for m in methods):
6258
raise Exception("You mixed adding and removing, punk")
@@ -65,9 +61,7 @@ def __init__(
6561
to_remove = [method[1:] for method in methods]
6662

6763
# Rewrite the methods instead of mutate the class methods
68-
self.methods = {
69-
k: v for k, v in select_methods.items() if k not in to_remove
70-
}
64+
self.methods = {k: v for k, v in select_methods.items() if k not in to_remove}
7165

7266
else:
7367
self.methods = {k: select_methods[k] for k in methods}
@@ -104,9 +98,7 @@ class AdminField(sw.Select):
10498
parent: Optional[sw.Select] = None
10599
"The parent adminfield object"
106100

107-
def __init__(
108-
self, level: int, parent: Optional[sw.Select] = None, gee: bool = True
109-
) -> None:
101+
def __init__(self, level: int, parent: Optional[sw.Select] = None, gee: bool = True) -> None:
110102
"""An admin level selector.
111103
112104
It is binded to ee (GAUL 2015) or not (GADM). Allows to select administrative codes taking into account the administrative parent code and displaying humanly readable administrative names.
@@ -124,9 +116,7 @@ def __init__(
124116
self.parent = parent
125117

126118
# init an empty widget
127-
super().__init__(
128-
v_model=None, items=[], clearable=True, label=ms.aoi_sel.adm[level]
129-
)
119+
super().__init__(v_model=None, items=[], clearable=True, label=ms.aoi_sel.adm[level])
130120

131121
# add js behaviour
132122
self.parent is None or self.parent.observe(self._update, "v_model")
@@ -333,9 +323,7 @@ def __init__(
333323
self.btn = sw.Btn(msg=ms.aoi_sel.btn)
334324

335325
# create the widget
336-
self.children = (
337-
[self.w_method] + [*self.components.values()] + [self.btn, self.alert]
338-
)
326+
self.children = [self.w_method] + [*self.components.values()] + [self.btn, self.alert]
339327

340328
super().__init__(**kwargs)
341329

sepal_ui/bin/activate_venv.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ def main() -> None:
4141
test_venv_path = Path.home() / "module-venv"
4242
if test_venv_path.exists():
4343
test_envs = pd.DataFrame(
44-
list(
45-
[f"test {el.name}", str(el)]
46-
for el in test_venv_path.glob("[!.]*")
47-
if el.is_dir()
48-
)
44+
list([f"test {el.name}", str(el)] for el in test_venv_path.glob("[!.]*") if el.is_dir())
4945
)
5046
venvs = pd.concat([venvs, test_envs])
5147
venvs = venvs.reset_index(drop=True)
@@ -59,9 +55,7 @@ def main() -> None:
5955
while not valid:
6056

6157
selection = int(
62-
input(
63-
f"{Fore.CYAN} Select the venv number you want to activate: \n{Fore.RESET}"
64-
)
58+
input(f"{Fore.CYAN} Select the venv number you want to activate: \n{Fore.RESET}")
6559
)
6660

6761
if selection not in venvs.index.unique():
@@ -84,9 +78,7 @@ def main() -> None:
8478
# The following lines won't be executed because the previous subprocess kill the kernel
8579

8680
# Confirm that we are in the new env
87-
result = subprocess.run(
88-
["echo", "$VIRTUAL_ENV"], shell=True, stdout=subprocess.PIPE
89-
)
81+
result = subprocess.run(["echo", "$VIRTUAL_ENV"], shell=True, stdout=subprocess.PIPE)
9082

9183
print(f"The current env is: {result.stdout!r}")
9284

sepal_ui/bin/module_deploy.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ def write_reqs(file: Union[str, Path]) -> None:
4646

4747
# add the custom libs
4848
tmp_file = Path.cwd() / "req_tmp.txt"
49-
subprocess.run(
50-
["pipreqs", "--savepath", str(tmp_file), str(Path.cwd())], cwd=Path.cwd()
51-
)
49+
subprocess.run(["pipreqs", "--savepath", str(tmp_file), str(Path.cwd())], cwd=Path.cwd())
5250

5351
# add the libs in the final file
5452
with file.open("a") as dst:
@@ -79,9 +77,7 @@ def clean_dulpicate(file: Union[str, Path]) -> None:
7977
for line in text[idx:]:
8078
if any(lib in line for lib in libs):
8179
lib = next(lb for lb in libs if lb in line)
82-
print(
83-
f"Removing {Style.BRIGHT}{lib}{Style.NORMAL} from reqs, duplicated from default."
84-
)
80+
print(f"Removing {Style.BRIGHT}{lib}{Style.NORMAL} from reqs, duplicated from default.")
8581
continue
8682
final_text.append(line)
8783

@@ -113,9 +109,7 @@ def clean_troubleshouting(file: Union[str, Path]) -> None:
113109
# gdal and osgeo are part of pygdal
114110
# we use a specific version of earthengine in SEPAl, let's stick to it
115111
if "ee" in line:
116-
print(
117-
f"Removing {Style.BRIGHT}ee{Style.NORMAL} from reqs, included in sepal_ui."
118-
)
112+
print(f"Removing {Style.BRIGHT}ee{Style.NORMAL} from reqs, included in sepal_ui.")
119113
continue
120114
elif any(lib in line for lib in ["osgeo"]):
121115
print(f"Removing {Style.BRIGHT}'osgeo'{Style.NORMAL} as part of gdal")
@@ -144,9 +138,7 @@ def freeze_sepal_ui(file: Union[str, Path]) -> None:
144138
text = file.read_text().split("\n")
145139

146140
# search for the sepal_ui line
147-
idx, _ = next(
148-
(i, il) for i, il in enumerate(text) if "#" not in il and "sepal_ui" in il
149-
)
141+
idx, _ = next((i, il) for i, il in enumerate(text) if "#" not in il and "sepal_ui" in il)
150142

151143
text[idx] = f"sepal_ui=={sepal_ui.__version__}"
152144

sepal_ui/bin/module_factory.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
parser = argparse.ArgumentParser(description=__doc__, usage="module_factory")
2323

2424

25-
def set_default_readme(
26-
folder: Path, module_name: str, description: str, url: str
27-
) -> None:
25+
def set_default_readme(folder: Path, module_name: str, description: str, url: str) -> None:
2826
"""Write a default README.md file and overwrite the existing one.
2927
3028
Args:
@@ -194,9 +192,7 @@ def main() -> None:
194192
subprocess.run(["cp", "-r", str(template_dir), str(folder)], cwd=Path.cwd())
195193

196194
# replace the placeholders
197-
url = github_url.replace(".git", "").replace(
198-
"[email protected]:", "https://github.com/"
199-
)
195+
url = github_url.replace(".git", "").replace("[email protected]:", "https://github.com/")
200196

201197
set_default_readme(folder, module_name, description, url)
202198
set_default_about(folder, description)

sepal_ui/frontend/resize_trigger.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ class ResizeTrigger(v.VuetifyTemplate):
1919
# load the js file
2020
js = (Path(__file__).parent / "js/jupyter_resize.js").read_text()
2121
template = Unicode(
22-
"<script class='sepal-ui-script'>{methods: {jupyter_resize(){%s}}}</script>"
23-
% js
22+
"<script class='sepal-ui-script'>{methods: {jupyter_resize(){%s}}}</script>" % js
2423
).tag(sync=True)
2524
"Unicode: the javascript script to manually trigger the resize event"
2625

sepal_ui/mapping/aoi_control.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ def __init__(self, m: Map, **kwargs) -> None:
5050
self.menu.cole_on_content_click = True
5151

5252
# set the size of the card to 0 so that the list controls the widget display
53-
self.set_size(
54-
min_width="200px", max_width="200px", min_height=None, max_height="300px"
55-
)
53+
self.set_size(min_width="200px", max_width="200px", min_height=None, max_height="300px")
5654

5755
# add js behaviours
5856
self.menu.v_slots[0]["children"].on_event("click", self.click_btn)
@@ -74,9 +72,7 @@ def click_btn(self, *args) -> None:
7472
return
7573

7674
@sd.need_ee
77-
def add_aoi(
78-
self, name: str, item: Union[sg.base.BaseGeometry, ee.ComputedObject]
79-
) -> None:
75+
def add_aoi(self, name: str, item: Union[sg.base.BaseGeometry, ee.ComputedObject]) -> None:
8076
"""Add an AOI to the list and refresh the list displayed. the AOI will be composed of a name and the bounds of the provided item.
8177
8278
Args:

sepal_ui/mapping/fullscreen_control.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ class FullScreenControl(WidgetControl):
2626
template: Optional[v.VuetifyTemplate] = None
2727
"Embeds the 2 javascripts methods to change the rendering of the map"
2828

29-
def __init__(
30-
self, m: Map, fullscreen: bool = False, fullapp: bool = False, **kwargs
31-
) -> None:
29+
def __init__(self, m: Map, fullscreen: bool = False, fullapp: bool = False, **kwargs) -> None:
3230
"""A custom Fullscreen Button ready to be embed in a map object.
3331
3432
This button will force the display of the map in fullscreen mode. It should be used instead of the built-in ipyleaflet FullscreenControl if your map is embedding ipyvuetify widgets. I tends to solve the issue raised here: https://github.com/widgetti/ipyvuetify/issues/141. The idea is to fake the fullscreen display by forcing the map container to extend to the full extend of the screen without using a z-index superior to the ipyvuetify overlay.

sepal_ui/mapping/inspector_control.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ def read_data(self, **kwargs) -> None:
147147
elif isinstance(lyr, Marker):
148148
continue
149149
else:
150-
data = {
151-
ms.inspector_control.info.header: ms.inspector_control.info.text
152-
}
150+
data = {ms.inspector_control.info.header: ms.inspector_control.info.text}
153151

154152
items.append(
155153
{
@@ -218,9 +216,7 @@ def _from_eelayer(self, ee_obj: ee.ComputedObject, coords: Sequence[float]) -> d
218216
).getInfo()
219217

220218
else:
221-
raise ValueError(
222-
f'the layer object is a "{type(ee_obj)}" which is not accepted.'
223-
)
219+
raise ValueError(f'the layer object is a "{type(ee_obj)}" which is not accepted.')
224220

225221
return pixel_values
226222

@@ -280,22 +276,17 @@ def _from_raster(self, raster: Union[str, Path], coords: Sequence[float]) -> dic
280276
window = rio.windows.from_bounds(*bounds, transform=da.rio.transform())
281277
da_filtered = da.rio.isel_window(window)
282278
means = da_filtered.mean(axis=(1, 2)).to_numpy()
283-
pixel_values = {
284-
ms.inspector_control.band.format(i + 1): v for i, v in enumerate(means)
285-
}
279+
pixel_values = {ms.inspector_control.band.format(i + 1): v for i, v in enumerate(means)}
286280

287281
# if the point is out of the image display None
288282
else:
289283
pixel_values = {
290-
ms.inspector_control.band.format(i + 1): None
291-
for i in range(da.rio.count)
284+
ms.inspector_control.band.format(i + 1): None for i in range(da.rio.count)
292285
}
293286

294287
return pixel_values
295288

296289

297-
@deprecated(
298-
version="2.15.1", reason="ValueInspector class is now renamed InspectorControl"
299-
)
290+
@deprecated(version="2.15.1", reason="ValueInspector class is now renamed InspectorControl")
300291
class ValueInspector(InspectorControl):
301292
pass

sepal_ui/mapping/layers_control.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,7 @@ def __init__(self, m: Map, **kwargs) -> None:
181181
# set the kwargs parameters
182182
kwargs.setdefault("position", "topright")
183183
super().__init__(
184-
icon_content="fa-solid fa-layer-group",
185-
card_content=self.tile,
186-
m=m,
187-
**kwargs
184+
icon_content="fa-solid fa-layer-group", card_content=self.tile, m=m, **kwargs
188185
)
189186

190187
# customize the menu to make it look more like a layercontrol
@@ -226,9 +223,7 @@ def update_table(self, change: dict) -> None:
226223
# the error raised if you delete the last one is a feature
227224
bases = [lyr for lyr in self.m.layers if lyr.base is True]
228225
base_rows = []
229-
current = next(
230-
(lyr for lyr in bases if lyr.visible is True), SimpleNamespace(name=None)
231-
)
226+
current = next((lyr for lyr in bases if lyr.visible is True), SimpleNamespace(name=None))
232227
if len(bases) > 0:
233228
head = [HeaderRow(ms.layer_control.basemap.header)]
234229
empy_cell = sw.Html(tag="td", children=[" "], attributes={"colspan": 3})

0 commit comments

Comments
 (0)