Datasets:

Tasks:
Other
Modalities:
Text
Formats:
parquet
ArXiv:
Libraries:
Datasets
Dask
License:
Dataset Viewer
Auto-converted to Parquet
instance_id
stringlengths
10
57
base_commit
stringlengths
40
40
created_at
stringdate
2014-04-30 14:58:36
2025-04-30 20:14:11
environment_setup_commit
stringlengths
40
40
hints_text
stringlengths
0
273k
patch
stringlengths
251
7.06M
problem_statement
stringlengths
11
52.5k
repo
stringlengths
7
53
test_patch
stringlengths
231
997k
meta
dict
version
stringclasses
864 values
install_config
dict
requirements
stringlengths
93
34.2k
environment
stringlengths
760
20.5k
FAIL_TO_PASS
listlengths
1
9.39k
FAIL_TO_FAIL
listlengths
0
2.69k
PASS_TO_PASS
listlengths
0
7.87k
PASS_TO_FAIL
listlengths
0
192
license_name
stringclasses
56 values
docker_image
stringlengths
42
89
0b01001001__spectree-64
a091fab020ac26548250c907bae0855273a98778
2020-10-12 13:21:50
a091fab020ac26548250c907bae0855273a98778
diff --git a/setup.py b/setup.py index 1b3cb64..4ef21e6 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ with open(path.join(here, 'requirements.txt'), encoding='utf-8') as f: setup( name='spectree', - version='0.3.7', + version='0.3.8', author='Keming Yang', author_email='kemingy94@gmail.com', description=('generate OpenAPI document and validate request&response ' diff --git a/spectree/utils.py b/spectree/utils.py index bb5698d..73d6c71 100644 --- a/spectree/utils.py +++ b/spectree/utils.py @@ -54,6 +54,7 @@ def parse_params(func, params, models): 'in': 'query', 'schema': schema, 'required': name in query.get('required', []), + 'description': schema.get('description', ''), }) if hasattr(func, 'headers'): @@ -64,6 +65,7 @@ def parse_params(func, params, models): 'in': 'header', 'schema': schema, 'required': name in headers.get('required', []), + 'description': schema.get('description', ''), }) if hasattr(func, 'cookies'): @@ -74,6 +76,7 @@ def parse_params(func, params, models): 'in': 'cookie', 'schema': schema, 'required': name in cookies.get('required', []), + 'description': schema.get('description', ''), }) return params
[BUG]description for query paramters can not show in swagger ui Hi, when I add a description for a schema used in query, it can not show in swagger ui but can show in Redoc ```py @HELLO.route('/', methods=['GET']) @api.validate(query=HelloForm) def hello(): """ hello 注释 :return: """ return 'ok' class HelloForm(BaseModel): """ hello表单 """ user: str # 用户名称 msg: str = Field(description='msg test', example='aa') index: int data: HelloGetListForm list: List[HelloListForm] ``` ![截屏2020-10-12 下午7 54 52](https://user-images.githubusercontent.com/60063723/95743785-de70f480-0cc4-11eb-857b-fffd3d7e9cdd.png) ![截屏2020-10-12 下午7 53 59](https://user-images.githubusercontent.com/60063723/95743805-e5980280-0cc4-11eb-99ae-11e6439bae02.png)
0b01001001/spectree
diff --git a/tests/common.py b/tests/common.py index 0f2d696..83b4140 100644 --- a/tests/common.py +++ b/tests/common.py @@ -1,7 +1,7 @@ from enum import IntEnum, Enum from typing import List -from pydantic import BaseModel, root_validator +from pydantic import BaseModel, root_validator, Field class Order(IntEnum): @@ -43,7 +43,7 @@ class Cookies(BaseModel): class DemoModel(BaseModel): uid: int limit: int - name: str + name: str = Field(..., description='user name') def get_paths(spec): diff --git a/tests/test_utils.py b/tests/test_utils.py index bf3426d..53dd3e1 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -98,8 +98,10 @@ def test_parse_params(): 'name': 'uid', 'in': 'query', 'required': True, + 'description': '', 'schema': { 'title': 'Uid', 'type': 'integer', } } + assert params[2]['description'] == 'user name'
{ "commit_name": "head_commit", "failed_lite_validators": [ "has_hyperlinks", "has_media", "has_many_modified_files", "has_many_hunks" ], "has_test_patch": true, "is_lite": false, "llm_score": { "difficulty_score": 1, "issue_text_score": 2, "test_score": 0 }, "num_modified_files": 2 }
0.3
{ "env_vars": null, "env_yml_path": null, "install": "pip install -e .[flask,falcon,starlette]", "log_parser": "parse_log_pytest", "no_use_env": null, "packages": "requirements.txt", "pip_packages": [ "pytest" ], "pre_install": null, "python": "3.9", "reqs_path": [ "requirements.txt" ], "test_cmd": "pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning" }
annotated-types==0.7.0 anyio==4.9.0 blinker==1.9.0 certifi==2025.1.31 charset-normalizer==3.4.1 click==8.1.8 exceptiongroup==1.2.2 falcon==4.0.2 Flask==3.1.0 idna==3.10 importlib_metadata==8.6.1 iniconfig==2.1.0 itsdangerous==2.2.0 Jinja2==3.1.6 MarkupSafe==3.0.2 packaging==24.2 pluggy==1.5.0 pydantic==2.11.1 pydantic_core==2.33.0 pytest==8.3.5 requests==2.32.3 sniffio==1.3.1 -e git+https://github.com/0b01001001/spectree.git@a091fab020ac26548250c907bae0855273a98778#egg=spectree starlette==0.46.1 tomli==2.2.1 typing-inspection==0.4.0 typing_extensions==4.13.0 urllib3==2.3.0 Werkzeug==3.1.3 zipp==3.21.0
name: spectree channels: - defaults - https://repo.anaconda.com/pkgs/main - https://repo.anaconda.com/pkgs/r - conda-forge dependencies: - _libgcc_mutex=0.1=main - _openmp_mutex=5.1=1_gnu - ca-certificates=2025.2.25=h06a4308_0 - ld_impl_linux-64=2.40=h12ee557_0 - libffi=3.4.4=h6a678d5_1 - libgcc-ng=11.2.0=h1234567_1 - libgomp=11.2.0=h1234567_1 - libstdcxx-ng=11.2.0=h1234567_1 - ncurses=6.4=h6a678d5_0 - openssl=3.0.16=h5eee18b_0 - pip=25.0=py39h06a4308_0 - python=3.9.21=he870216_1 - readline=8.2=h5eee18b_0 - setuptools=75.8.0=py39h06a4308_0 - sqlite=3.45.3=h5eee18b_0 - tk=8.6.14=h39e8969_0 - tzdata=2025a=h04d1e81_0 - wheel=0.45.1=py39h06a4308_0 - xz=5.6.4=h5eee18b_1 - zlib=1.2.13=h5eee18b_1 - pip: - annotated-types==0.7.0 - anyio==4.9.0 - blinker==1.9.0 - certifi==2025.1.31 - charset-normalizer==3.4.1 - click==8.1.8 - exceptiongroup==1.2.2 - falcon==4.0.2 - flask==3.1.0 - idna==3.10 - importlib-metadata==8.6.1 - iniconfig==2.1.0 - itsdangerous==2.2.0 - jinja2==3.1.6 - markupsafe==3.0.2 - packaging==24.2 - pluggy==1.5.0 - pydantic==2.11.1 - pydantic-core==2.33.0 - pytest==8.3.5 - requests==2.32.3 - sniffio==1.3.1 - starlette==0.46.1 - tomli==2.2.1 - typing-extensions==4.13.0 - typing-inspection==0.4.0 - urllib3==2.3.0 - werkzeug==3.1.3 - zipp==3.21.0 prefix: /opt/conda/envs/spectree
[ "tests/test_utils.py::test_parse_params" ]
[]
[ "tests/test_utils.py::test_comments", "tests/test_utils.py::test_parse_code", "tests/test_utils.py::test_parse_name", "tests/test_utils.py::test_has_model", "tests/test_utils.py::test_parse_resp", "tests/test_utils.py::test_parse_request" ]
[]
Apache License 2.0
swerebench/sweb.eval.x86_64.0b01001001_1776_spectree-64
12rambau__sepal_ui-347
4554f35da3fab21c32c35c4bd557ecfdec9c60c5
2021-11-19 12:32:22
114063b50ee5b1ccbab680424bb048e11939b870
diff --git a/sepal_ui/mapping/__init__.py b/sepal_ui/mapping/__init__.py index 7f72a0eb..aa84ddee 100644 --- a/sepal_ui/mapping/__init__.py +++ b/sepal_ui/mapping/__init__.py @@ -2,6 +2,7 @@ from .aoi_control import * from .draw_control import * from .fullscreen_control import * from .layer import * +from .layer_state_control import * from .map_btn import * from .sepal_map import * from .value_inspector import * diff --git a/sepal_ui/mapping/layer_state_control.py b/sepal_ui/mapping/layer_state_control.py new file mode 100644 index 00000000..eff80080 --- /dev/null +++ b/sepal_ui/mapping/layer_state_control.py @@ -0,0 +1,99 @@ +from traitlets import Int, observe +from ipyleaflet import WidgetControl + +from sepal_ui import sepalwidgets as sw +from sepal_ui.message import ms + + +class LayerStateControl(WidgetControl): + """ + A specific statebar dedicated to the the counting of loading tiles in the map + + every time a map is added to the map the counter will be raised by one. same behaviour with removed. + """ + + m = None + "SepalMap: the map connected to the control" + + w_state = None + "sw.StateBar: the stateBar displaying the number of layer loading on the map" + + nb_layer = Int(0).tag(sync=True) + "Int: the number of layers in the map" + + nb_loading_layer = Int(0).tag(sync=True) + "Int: the number of loading layer in the map" + + def __init__(self, m, **kwargs): + + # save the map as a member of the widget + self.m = m + + # create a statebar + msg = ms.layer_state.complete.format(self.nb_layer) + self.w_state = sw.StateBar(loading=False, msg=msg) + + # overwrite the widget set in the kwargs (if any) + kwargs["widget"] = self.w_state + kwargs["position"] = kwargs.pop("position", "topleft") + kwargs["transparent_bg"] = True + + # create the widget + super().__init__(**kwargs) + + # add js behaviour + self.m.observe(self.update_nb_layer, "layers") + + def update_nb_layer(self, change): + """ + Update the number of layer monitored by the statebar + """ + + # exit if nothing changed + # for example we change a layer parameters and it trigger this one + if len(change["new"]) == len(change["old"]): + return + + self.nb_layer = len([lyr for lyr in change["new"] if not lyr.base]) + + # identify the modified layer + modified_layer = list(set(change["new"]) ^ set(change["old"]))[0] + if modified_layer.base is True: + return + + # add a layer + if len(change["new"]) > len(change["old"]): + modified_layer.observe(self.update_loading, "loading") + + # remove a layer + elif len(change["new"]) < len(change["old"]): + # the test is splitted as not all the layers have a loading trait + if hasattr(modified_layer, "loading") is True: + if modified_layer.loading is True: + self.nb_loading_layer += -1 + + return + + def update_loading(self, change): + """update the nb_loading_layer value according to the number of tile loading on the map""" + + increment = [-1, 1] + self.nb_loading_layer += increment[change["new"]] + + return + + @observe("nb_loading_layer", "nb_layer") + def _update_state(self, change): + + # check if anything is loading + self.loading = bool(self.nb_loading_layer) + + # update the message + if self.loading is True: + msg = ms.layer_state.loading.format(self.nb_loading_layer, self.nb_layer) + else: + msg = ms.layer_state.complete.format(self.nb_layer) + + self.w_state.msg = msg + + return diff --git a/sepal_ui/mapping/sepal_map.py b/sepal_ui/mapping/sepal_map.py index e2860daf..4ef41d1a 100644 --- a/sepal_ui/mapping/sepal_map.py +++ b/sepal_ui/mapping/sepal_map.py @@ -31,6 +31,7 @@ import sepal_ui.frontend.styles as styles from sepal_ui.mapping.basemaps import basemap_tiles from sepal_ui.mapping.draw_control import DrawControl from sepal_ui.mapping.layer import EELayer +from sepal_ui.mapping.layer_state_control import LayerStateControl from sepal_ui.mapping.value_inspector import ValueInspector from sepal_ui.message import ms from sepal_ui.scripts import utils as su @@ -55,6 +56,7 @@ class SepalMap(ipl.Map): dc (bool, optional): wether or not the drawing control should be displayed. default to false vinspector (bool, optional): Add value inspector to map, useful to inspect pixel values. default to false gee (bool, optional): wether or not to use the ee binding. If False none of the earthengine display fonctionalities can be used. default to True + statebar (bool): wether or not to display the Statebar in the map kwargs (optional): any parameter from a ipyleaflet.Map. if set, 'ee_initialize' will be overwritten. """ @@ -74,7 +76,18 @@ class SepalMap(ipl.Map): _id = None "str: a unique 6 letters str to identify the map in the DOM" - def __init__(self, basemaps=[], dc=False, vinspector=False, gee=True, **kwargs): + state = None + "sw.StateBar: the statebar to inform the user about tile loading" + + def __init__( + self, + basemaps=[], + dc=False, + vinspector=False, + gee=True, + statebar=False, + **kwargs, + ): # set the default parameters kwargs["center"] = kwargs.pop("center", [0, 0]) @@ -114,6 +127,10 @@ class SepalMap(ipl.Map): self.v_inspector = ValueInspector(self) not vinspector or self.add_control(self.v_inspector) + # specific statebar + self.state = LayerStateControl(self) + not statebar or self.add_control(self.state) + # create a proxy ID to the element # this id should be unique and will be used by mutators to identify this map self._id = "".join(random.choice(string.ascii_lowercase) for i in range(6)) diff --git a/sepal_ui/message/en/layer_control.json b/sepal_ui/message/en/layer_control.json new file mode 100644 index 00000000..2f90d41c --- /dev/null +++ b/sepal_ui/message/en/layer_control.json @@ -0,0 +1,6 @@ +{ + "layer_state": { + "loading": "loading {} layer(s) out of {}", + "complete": "{} layer(s) loaded" + } +} \ No newline at end of file diff --git a/sepal_ui/sepalwidgets/alert.py b/sepal_ui/sepalwidgets/alert.py index e143170e..6ad4d5d0 100644 --- a/sepal_ui/sepalwidgets/alert.py +++ b/sepal_ui/sepalwidgets/alert.py @@ -250,7 +250,7 @@ class Alert(v.Alert, SepalWidget): return su.check_input(input_, msg) -class StateBar(v.SystemBar): +class StateBar(v.SystemBar, SepalWidget): """Widget to display quick messages on simple inline status bar
display a loading statebar when a layer is loading in the map ## issue I experienced some issues with the FCDM module as the map is super slow to load (it uses a adaptative buffer, the more you zoom the slower it gets it's a nightmare). The consequence is that the user clicks frantically on the `zoom` `unzoom` btn and the layer never fully loads and they eventually break the app. I've looked into the loading widgets that exists in ipyleaflet and that's not very elegant (from my perspective). ## current implementation I came up with the idea of overwriting the `add_layer` method to add a `StateBar` at the top left corner for every layer and dynamically show them when the tile are reloading. overwritting the `add_layer` method is super versatile as it's the basic function called by all the others (`add_ee_layer`, `addLayer`, `add_raster_layer` ... etc). - user doesn't change anything in the way object are added to the map - each time you add a layer, it adds a statebar writting "loading \<whatever\>" - the statebare is shown whenever the layer is loading (thank you traitlets) ## questions - should we remove them when the layer is removed (overwritting remove_layer as well) ? - should the statebar always be displayed (and instead of changing viz, we could change loading trait) ? - do you think it could be useful in general ? ## demo Here is a gif demo and the the code I used. ![feature_demo](https://user-images.githubusercontent.com/12596392/142245503-4b78f635-9700-468c-9202-fa04a13de4b8.gif) ```python from sepal_ui.mapping import SepalMap from sepal_ui import sepalwidgets as sw from ipyleaflet import WidgetControl import ee ee.Initialize() # create a custom statebar class StateBar(sw.StateBar): def __init__(self, **kwargs): name = kwargs.pop("layer", "layer") kwargs["_metadata"] = {"layer": name} super().__init__(**kwargs) self.msg = f"Loading {name}" self.loading = True def activate(self, change): if change['new']: self.show() else: self.hide() return # define a custom Map class class Map(SepalMap): layer_state_list = [] def add_layer(self, l): # call the original function super().add_layer(l) # add a layer state object state = StateBar(layer=l.name) self.layer_state_list += [state] self.add_control(WidgetControl(widget=state, position='topleft')) # link it to the layer state #layer = next(l for l in self.layers if l.name == name) l.observe(state.activate, "loading") return # create the map and zoom on congo test_map = Map() test_map.zoom = 10 test_map.center = [5.703447982149503, 28.32275390625] # load hansen & al ddataset dataset = ee.Image('UMD/hansen/global_forest_change_2020_v1_8') treeCoverVisParam = { "bands": ['treecover2000'], "min": 0, "max": 100, "palette": ['black', 'green'] } test_map.addLayer(dataset, treeCoverVisParam, 'tree cover') # load the S2 RGB product (SR) def maskS2clouds(image): qa = image.select('QA60'); # Bits 10 and 11 are clouds and cirrus, respectively. cloudBitMask = 1 << 10; cirrusBitMask = 1 << 11; # Both flags should be set to zero, indicating clear conditions. mask = ( qa .bitwiseAnd(cloudBitMask).eq(0) .And(qa.bitwiseAnd(cirrusBitMask).eq(0)) ) return image.updateMask(mask).divide(10000) dataset = ( ee.ImageCollection('COPERNICUS/S2_SR') .filterDate('2020-01-01', '2020-01-30') .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',20)) .map(maskS2clouds) ) visualization = { "min": 0.0, "max": 0.3, "bands": ['B4', 'B3', 'B2'], } test_map.addLayer(dataset.mean(), visualization, 'RGB') # display the map test_map ```
12rambau/sepal_ui
diff --git a/tests/test_LayerStateControl.py b/tests/test_LayerStateControl.py new file mode 100644 index 00000000..ce2aecb2 --- /dev/null +++ b/tests/test_LayerStateControl.py @@ -0,0 +1,84 @@ +from ipyleaflet import RasterLayer +from traitlets import Bool +import ee +import pytest + +from sepal_ui import mapping as sm +from sepal_ui.scripts import utils as su + + +class TestLayerStateControl: + def test_init(self): + + m = sm.SepalMap() + state = sm.LayerStateControl(m) + m.add_control(state) + + assert isinstance(state, sm.LayerStateControl) + assert state.w_state.loading is False + + return + + @su.need_ee + def test_update_nb_layer(self, map_with_layers): + + # create the map and controls + m = map_with_layers + state = next(c for c in m.controls if isinstance(c, sm.LayerStateControl)) + + # TODO I don't know how to check state changes but I can at least check the conclusion + assert state.w_state.msg == "2 layer(s) loaded" + + # remove a layer to update the nb_layer + m.remove_layer(-1) + assert state.w_state.msg == "1 layer(s) loaded" + + return + + def test_update_loading(self, map_with_layers): + + # get the map and control + m = map_with_layers + state = next(c for c in m.controls if isinstance(c, sm.LayerStateControl)) + + # check that the parameter is updated with existing layers + m.layers[-1].loading = True + assert state.nb_loading_layer == 1 + assert state.w_state.msg == "loading 1 layer(s) out of 2" + + # check when this loading layer is removed + m.remove_layer(-1) + assert state.nb_loading_layer == 0 + assert state.w_state.msg == "1 layer(s) loaded" + + return + + @pytest.fixture + def map_with_layers(self, fake_layer): + """create a map with 2 layers and a stateBar""" + + # create the map and controls + m = sm.SepalMap() + state = sm.LayerStateControl(m) + m.add_control(state) + + # add some ee_layer (loading very fast) + # world lights + dataset = ee.ImageCollection("NOAA/DMSP-OLS/CALIBRATED_LIGHTS_V4").filter( + ee.Filter.date("2010-01-01", "2010-12-31") + ) + m.addLayer(dataset, {}, "Nighttime Lights") + + # a fake layer with loading update possibilities + m.add_layer(fake_layer) + + return m + + @pytest.fixture + def fake_layer(self): + """create a layer from a fakelayer class that have only one parameter: the laoding trait""" + + class FakeLayer(RasterLayer): + loading = Bool(False).tag(sync=True) + + return FakeLayer() diff --git a/tests/test_SepalMap.py b/tests/test_SepalMap.py index 51f5a01a..30a0d3eb 100644 --- a/tests/test_SepalMap.py +++ b/tests/test_SepalMap.py @@ -51,6 +51,10 @@ class TestSepalMap: m = sm.SepalMap(vinspector=True) assert m.v_inspector in m.controls + # check that the map start with a statebar + m = sm.SepalMap(statebar=True) + assert m.state in m.controls + # check that a wrong layer raise an error if it's not part of the leaflet basemap list with pytest.raises(Exception): m = sm.SepalMap(["TOTO"]) diff --git a/tests/test_StateBar.py b/tests/test_StateBar.py index 9eb3ab0f..0ed4ed5c 100644 --- a/tests/test_StateBar.py +++ b/tests/test_StateBar.py @@ -7,6 +7,7 @@ class TestStateBar: # minimal state bar state_bar = sw.StateBar() assert len(state_bar.children) == 2 + assert state_bar.viz is True return
{ "commit_name": "head_commit", "failed_lite_validators": [ "has_hyperlinks", "has_media", "has_added_files", "has_many_modified_files", "has_many_hunks" ], "has_test_patch": true, "is_lite": false, "llm_score": { "difficulty_score": 2, "issue_text_score": 1, "test_score": 3 }, "num_modified_files": 3 }
2.9
{ "env_vars": null, "env_yml_path": null, "install": "pip install -e .[dev]", "log_parser": "parse_log_pytest", "no_use_env": null, "packages": "pytest", "pip_packages": [ "pytest" ], "pre_install": [ "apt-get update", "apt-get install -y gcc" ], "python": "3.9", "reqs_path": null, "test_cmd": "pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning" }
affine==2.4.0 anyio==4.9.0 argon2-cffi==23.1.0 argon2-cffi-bindings==21.2.0 arrow==1.3.0 asttokens==3.0.0 async-lru==2.0.5 attrs==25.3.0 babel==2.17.0 backcall==0.2.0 beautifulsoup4==4.13.3 bleach==6.2.0 branca==0.8.1 cachetools==5.5.2 certifi==2025.1.31 cffi==1.17.1 cfgv==3.4.0 charset-normalizer==3.4.1 click==8.1.8 click-plugins==1.1.1 cligj==0.7.2 cloudpickle==3.1.1 colorama==0.4.6 comm==0.2.2 contourpy==1.3.0 cryptography==44.0.2 cycler==0.12.1 dask==2024.8.0 debugpy==1.8.13 decorator==5.2.1 deepdiff==8.4.2 defusedxml==0.7.1 Deprecated==1.2.18 distlib==0.3.9 docopt==0.6.2 earthengine-api==1.5.8 exceptiongroup @ file:///croot/exceptiongroup_1706031385326/work executing==2.2.0 fastjsonschema==2.21.1 filelock==3.18.0 fonttools==4.56.0 fqdn==1.5.1 fsspec==2025.3.1 geopandas==1.0.1 google-api-core==2.24.2 google-api-python-client==2.166.0 google-auth==2.38.0 google-auth-httplib2==0.2.0 google-cloud-core==2.4.3 google-cloud-storage==3.1.0 google-crc32c==1.7.1 google-resumable-media==2.7.2 googleapis-common-protos==1.69.2 h11==0.14.0 haversine==2.9.0 httpcore==1.0.7 httplib2==0.22.0 httpx==0.28.1 identify==2.6.9 idna==3.10 importlib_metadata==8.6.1 importlib_resources==6.5.2 iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work ipykernel==6.29.5 ipyleaflet==0.19.2 ipyspin==1.0.1 ipython==8.12.3 ipython-genutils==0.2.0 ipyurl==0.1.3 ipyvue==1.11.2 ipyvuetify==1.11.1 ipywidgets==7.8.5 isoduration==20.11.0 jedi==0.19.2 Jinja2==3.1.6 json5==0.10.0 jsonpointer==3.0.0 jsonschema==4.23.0 jsonschema-specifications==2024.10.1 jupyter-events==0.12.0 jupyter-leaflet==0.19.2 jupyter-lsp==2.2.5 jupyter_client==8.6.3 jupyter_core==5.7.2 jupyter_server==2.15.0 jupyter_server_terminals==0.5.3 jupyter_server_xarray_leaflet==0.2.3 jupyterlab==4.3.6 jupyterlab_pygments==0.3.0 jupyterlab_server==2.27.3 jupyterlab_widgets==1.1.11 kiwisolver==1.4.7 locket==1.0.0 Markdown==3.7 MarkupSafe==3.0.2 matplotlib==3.9.4 matplotlib-inline==0.1.7 mercantile==1.2.1 mistune==3.1.3 natsort==8.4.0 nbclient==0.10.2 nbconvert==7.16.6 nbformat==5.10.4 nest-asyncio==1.6.0 nodeenv==1.9.1 notebook==7.3.3 notebook_shim==0.2.4 numpy==2.0.2 orderly-set==5.3.0 overrides==7.7.0 packaging @ file:///croot/packaging_1734472117206/work pandas==2.2.3 pandocfilters==1.5.1 parso==0.8.4 partd==1.4.2 pexpect==4.9.0 pickleshare==0.7.5 pillow==11.1.0 pipreqs==0.5.0 planet==1.5.2 platformdirs==4.3.7 pluggy @ file:///croot/pluggy_1733169602837/work pre_commit==4.2.0 prometheus_client==0.21.1 prompt_toolkit==3.0.50 proto-plus==1.26.1 protobuf==6.30.2 psutil==7.0.0 ptyprocess==0.7.0 pure_eval==0.2.3 pyasn1==0.6.1 pyasn1_modules==0.4.2 pycparser==2.22 Pygments==2.19.1 pyogrio==0.10.0 pyparsing==3.2.3 pyproj==3.6.1 pytest @ file:///croot/pytest_1738938843180/work python-box==7.3.2 python-dateutil==2.9.0.post0 python-json-logger==3.3.0 pytz==2025.2 PyYAML==6.0.2 pyzmq==26.3.0 rasterio==1.4.3 referencing==0.36.2 requests==2.32.3 requests-futures==0.9.9 rfc3339-validator==0.1.4 rfc3986-validator==0.1.1 rioxarray==0.15.0 rpds-py==0.24.0 rsa==4.9 Send2Trash==1.8.3 -e git+https://github.com/12rambau/sepal_ui.git@4554f35da3fab21c32c35c4bd557ecfdec9c60c5#egg=sepal_ui shapely==2.0.7 six==1.17.0 sniffio==1.3.1 soupsieve==2.6 stack-data==0.6.3 terminado==0.18.1 tinycss2==1.4.0 tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work toolz==1.0.0 tornado==6.4.2 tqdm==4.67.1 traitlets==5.14.3 traittypes==0.2.1 types-python-dateutil==2.9.0.20241206 typing_extensions==4.13.0 tzdata==2025.2 Unidecode==1.3.8 uri-template==1.3.0 uritemplate==4.1.1 urllib3==2.3.0 virtualenv==20.29.3 wcwidth==0.2.13 webcolors==24.11.1 webencodings==0.5.1 websocket-client==1.8.0 widgetsnbextension==3.6.10 wrapt==1.17.2 xarray==2024.7.0 xarray_leaflet==0.2.3 xyzservices==2025.1.0 yarg==0.1.9 zipp==3.21.0
name: sepal_ui channels: - defaults - https://repo.anaconda.com/pkgs/main - https://repo.anaconda.com/pkgs/r - conda-forge dependencies: - _libgcc_mutex=0.1=main - _openmp_mutex=5.1=1_gnu - ca-certificates=2025.2.25=h06a4308_0 - exceptiongroup=1.2.0=py39h06a4308_0 - iniconfig=1.1.1=pyhd3eb1b0_0 - ld_impl_linux-64=2.40=h12ee557_0 - libffi=3.4.4=h6a678d5_1 - libgcc-ng=11.2.0=h1234567_1 - libgomp=11.2.0=h1234567_1 - libstdcxx-ng=11.2.0=h1234567_1 - ncurses=6.4=h6a678d5_0 - openssl=3.0.16=h5eee18b_0 - packaging=24.2=py39h06a4308_0 - pip=25.0=py39h06a4308_0 - pluggy=1.5.0=py39h06a4308_0 - pytest=8.3.4=py39h06a4308_0 - python=3.9.21=he870216_1 - readline=8.2=h5eee18b_0 - setuptools=75.8.0=py39h06a4308_0 - sqlite=3.45.3=h5eee18b_0 - tk=8.6.14=h39e8969_0 - tomli=2.0.1=py39h06a4308_0 - wheel=0.45.1=py39h06a4308_0 - xz=5.6.4=h5eee18b_1 - zlib=1.2.13=h5eee18b_1 - pip: - affine==2.4.0 - anyio==4.9.0 - argon2-cffi==23.1.0 - argon2-cffi-bindings==21.2.0 - arrow==1.3.0 - asttokens==3.0.0 - async-lru==2.0.5 - attrs==25.3.0 - babel==2.17.0 - backcall==0.2.0 - beautifulsoup4==4.13.3 - bleach==6.2.0 - branca==0.8.1 - cachetools==5.5.2 - certifi==2025.1.31 - cffi==1.17.1 - cfgv==3.4.0 - charset-normalizer==3.4.1 - click==8.1.8 - click-plugins==1.1.1 - cligj==0.7.2 - cloudpickle==3.1.1 - colorama==0.4.6 - comm==0.2.2 - contourpy==1.3.0 - cryptography==44.0.2 - cycler==0.12.1 - dask==2024.8.0 - debugpy==1.8.13 - decorator==5.2.1 - deepdiff==8.4.2 - defusedxml==0.7.1 - deprecated==1.2.18 - distlib==0.3.9 - docopt==0.6.2 - earthengine-api==1.5.8 - executing==2.2.0 - fastjsonschema==2.21.1 - filelock==3.18.0 - fonttools==4.56.0 - fqdn==1.5.1 - fsspec==2025.3.1 - geopandas==1.0.1 - google-api-core==2.24.2 - google-api-python-client==2.166.0 - google-auth==2.38.0 - google-auth-httplib2==0.2.0 - google-cloud-core==2.4.3 - google-cloud-storage==3.1.0 - google-crc32c==1.7.1 - google-resumable-media==2.7.2 - googleapis-common-protos==1.69.2 - h11==0.14.0 - haversine==2.9.0 - httpcore==1.0.7 - httplib2==0.22.0 - httpx==0.28.1 - identify==2.6.9 - idna==3.10 - importlib-metadata==8.6.1 - importlib-resources==6.5.2 - ipykernel==6.29.5 - ipyleaflet==0.19.2 - ipyspin==1.0.1 - ipython==8.12.3 - ipython-genutils==0.2.0 - ipyurl==0.1.3 - ipyvue==1.11.2 - ipyvuetify==1.11.1 - ipywidgets==7.8.5 - isoduration==20.11.0 - jedi==0.19.2 - jinja2==3.1.6 - json5==0.10.0 - jsonpointer==3.0.0 - jsonschema==4.23.0 - jsonschema-specifications==2024.10.1 - jupyter-client==8.6.3 - jupyter-core==5.7.2 - jupyter-events==0.12.0 - jupyter-leaflet==0.19.2 - jupyter-lsp==2.2.5 - jupyter-server==2.15.0 - jupyter-server-terminals==0.5.3 - jupyter-server-xarray-leaflet==0.2.3 - jupyterlab==4.3.6 - jupyterlab-pygments==0.3.0 - jupyterlab-server==2.27.3 - jupyterlab-widgets==1.1.11 - kiwisolver==1.4.7 - locket==1.0.0 - markdown==3.7 - markupsafe==3.0.2 - matplotlib==3.9.4 - matplotlib-inline==0.1.7 - mercantile==1.2.1 - mistune==3.1.3 - natsort==8.4.0 - nbclient==0.10.2 - nbconvert==7.16.6 - nbformat==5.10.4 - nest-asyncio==1.6.0 - nodeenv==1.9.1 - notebook==7.3.3 - notebook-shim==0.2.4 - numpy==2.0.2 - orderly-set==5.3.0 - overrides==7.7.0 - pandas==2.2.3 - pandocfilters==1.5.1 - parso==0.8.4 - partd==1.4.2 - pexpect==4.9.0 - pickleshare==0.7.5 - pillow==11.1.0 - pipreqs==0.5.0 - planet==1.5.2 - platformdirs==4.3.7 - pre-commit==4.2.0 - prometheus-client==0.21.1 - prompt-toolkit==3.0.50 - proto-plus==1.26.1 - protobuf==6.30.2 - psutil==7.0.0 - ptyprocess==0.7.0 - pure-eval==0.2.3 - pyasn1==0.6.1 - pyasn1-modules==0.4.2 - pycparser==2.22 - pygments==2.19.1 - pyogrio==0.10.0 - pyparsing==3.2.3 - pyproj==3.6.1 - python-box==7.3.2 - python-dateutil==2.9.0.post0 - python-json-logger==3.3.0 - pytz==2025.2 - pyyaml==6.0.2 - pyzmq==26.3.0 - rasterio==1.4.3 - referencing==0.36.2 - requests==2.32.3 - requests-futures==0.9.9 - rfc3339-validator==0.1.4 - rfc3986-validator==0.1.1 - rioxarray==0.15.0 - rpds-py==0.24.0 - rsa==4.9 - send2trash==1.8.3 - shapely==2.0.7 - six==1.17.0 - sniffio==1.3.1 - soupsieve==2.6 - stack-data==0.6.3 - terminado==0.18.1 - tinycss2==1.4.0 - toolz==1.0.0 - tornado==6.4.2 - tqdm==4.67.1 - traitlets==5.14.3 - traittypes==0.2.1 - types-python-dateutil==2.9.0.20241206 - typing-extensions==4.13.0 - tzdata==2025.2 - unidecode==1.3.8 - uri-template==1.3.0 - uritemplate==4.1.1 - urllib3==2.3.0 - virtualenv==20.29.3 - wcwidth==0.2.13 - webcolors==24.11.1 - webencodings==0.5.1 - websocket-client==1.8.0 - widgetsnbextension==3.6.10 - wrapt==1.17.2 - xarray==2024.7.0 - xarray-leaflet==0.2.3 - xyzservices==2025.1.0 - yarg==0.1.9 - zipp==3.21.0 prefix: /opt/conda/envs/sepal_ui
[ "tests/test_StateBar.py::TestStateBar::test_init" ]
[ "tests/test_LayerStateControl.py::TestLayerStateControl::test_init", "tests/test_SepalMap.py::TestSepalMap::test_init", "tests/test_SepalMap.py::TestSepalMap::test_set_center", "tests/test_SepalMap.py::TestSepalMap::test_zoom_bounds", "tests/test_SepalMap.py::TestSepalMap::test_add_colorbar", "tests/test_SepalMap.py::TestSepalMap::test_add_ee_layer", "tests/test_SepalMap.py::TestSepalMap::test_get_basemap_list", "tests/test_SepalMap.py::TestSepalMap::test_get_viz_params", "tests/test_SepalMap.py::TestSepalMap::test_add_layer", "tests/test_SepalMap.py::TestSepalMap::test_add_basemap", "tests/test_SepalMap.py::TestSepalMap::test_get_scale", "tests/test_SepalMap.py::TestSepalMap::test_zoom_raster" ]
[ "tests/test_StateBar.py::TestStateBar::test_add_msg" ]
[]
MIT License
null
12rambau__sepal_ui-411
179bd8d089275c54e94a7614be7ed03d298ef532
2022-02-28 17:46:40
97371fbaed444727126a2969cd68f856db77221f
diff --git a/docs/source/modules/sepal_ui.sepalwidgets.DatePicker.rst b/docs/source/modules/sepal_ui.sepalwidgets.DatePicker.rst index 1a982afb..867227cb 100644 --- a/docs/source/modules/sepal_ui.sepalwidgets.DatePicker.rst +++ b/docs/source/modules/sepal_ui.sepalwidgets.DatePicker.rst @@ -8,6 +8,7 @@ sepal\_ui.sepalwidgets.DatePicker .. autosummary:: ~DatePicker.menu + ~DatePicker.disabled .. rubric:: Methods @@ -15,5 +16,8 @@ sepal\_ui.sepalwidgets.DatePicker :nosignatures: ~Datepicker.close_menu + ~DatePicker.disable -.. automethod:: sepal_ui.sepalwidgets.DatePicker.close_menu \ No newline at end of file +.. automethod:: sepal_ui.sepalwidgets.DatePicker.close_menu + +.. automethod:: sepal_ui.sepalwidgets.DatePicker.disable \ No newline at end of file diff --git a/sepal_ui/sepalwidgets/inputs.py b/sepal_ui/sepalwidgets/inputs.py index 3ad7f1a9..68b81746 100644 --- a/sepal_ui/sepalwidgets/inputs.py +++ b/sepal_ui/sepalwidgets/inputs.py @@ -1,7 +1,7 @@ from pathlib import Path import ipyvuetify as v -from traitlets import link, Int, Any, List, observe, Dict, Unicode +from traitlets import link, Int, Any, List, observe, Dict, Unicode, Bool from ipywidgets import jslink import pandas as pd import ee @@ -40,6 +40,9 @@ class DatePicker(v.Layout, SepalWidget): menu = None "v.Menu: the menu widget to display the datepicker" + disabled = Bool(False).tag(sync=True) + "traitlets.Bool: the disabled status of the Datepicker object" + def __init__(self, label="Date", **kwargs): # create the widgets @@ -93,6 +96,14 @@ class DatePicker(v.Layout, SepalWidget): return + @observe("disabled") + def disable(self, change): + """A method to disabled the appropriate components in the datipkcer object""" + + self.menu.v_slots[0]["children"].disabled = self.disabled + + return + class FileInput(v.Flex, SepalWidget): """
add a disabled trait on the datepicker I'm currently coding it in a module and the process of disabling a datepicker is uterly boring. I think we could add an extra trait to the layout and pilot the enabling and disabling directly from the built-in widget ```python self.w_start = sw.DatePicker(label="start", v_model=None) # disable both the slots (hidden to everyone) and the menu self.w_start.menu.v_slots[0]["children"].disabled = True self.w_start.menu.disabled = True ```
12rambau/sepal_ui
diff --git a/tests/test_DatePicker.py b/tests/test_DatePicker.py index f4c6d40e..e5f5d06f 100644 --- a/tests/test_DatePicker.py +++ b/tests/test_DatePicker.py @@ -35,6 +35,14 @@ class TestDatePicker: return + def test_disable(self, datepicker): + + for boolean in [True, False]: + datepicker.disabled = boolean + assert datepicker.menu.v_slots[0]["children"].disabled == boolean + + return + @pytest.fixture def datepicker(self): """create a default datepicker"""
{ "commit_name": "head_commit", "failed_lite_validators": [ "has_many_modified_files", "has_many_hunks" ], "has_test_patch": true, "is_lite": false, "llm_score": { "difficulty_score": 1, "issue_text_score": 0, "test_score": 2 }, "num_modified_files": 2 }
2.6
{ "env_vars": null, "env_yml_path": null, "install": "pip install -e .[dev]", "log_parser": "parse_log_pytest", "no_use_env": null, "packages": "requirements.txt", "pip_packages": [ "pytest", "coverage" ], "pre_install": null, "python": "3.9", "reqs_path": null, "test_cmd": "pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning" }
affine==2.4.0 anyio==4.9.0 argon2-cffi==23.1.0 argon2-cffi-bindings==21.2.0 arrow==1.3.0 asttokens==3.0.0 async-lru==2.0.5 attrs==25.3.0 babel==2.17.0 backcall==0.2.0 beautifulsoup4==4.13.3 bleach==6.2.0 bqplot==0.12.44 branca==0.4.2 cachetools==5.5.2 certifi==2025.1.31 cffi==1.17.1 cfgv==3.4.0 charset-normalizer==3.4.1 click==8.1.8 click-plugins==1.1.1 cligj==0.7.2 colorama==0.4.6 colour==0.1.5 comm==0.2.2 contourpy==1.3.0 coverage==7.8.0 cryptography==44.0.2 cycler==0.12.1 debugpy==1.8.13 decorator==5.2.1 deepdiff==8.4.2 defusedxml==0.7.1 Deprecated==1.2.18 distlib==0.3.9 docopt==0.6.2 earthengine-api==1.5.8 EditorConfig==0.17.0 exceptiongroup==1.2.2 executing==2.2.0 fastjsonschema==2.21.1 ffmpeg-python==0.2.0 filelock==3.18.0 folium==0.13.0 fonttools==4.56.0 fqdn==1.5.1 future==1.0.0 geeadd==1.2.1 geemap==0.8.9 geocoder==1.38.1 geopandas==1.0.1 google-api-core==2.24.2 google-api-python-client==2.166.0 google-auth==2.38.0 google-auth-httplib2==0.2.0 google-cloud-core==2.4.3 google-cloud-storage==3.1.0 google-crc32c==1.7.1 google-resumable-media==2.7.2 googleapis-common-protos==1.69.2 h11==0.14.0 haversine==2.9.0 httpcore==1.0.7 httplib2==0.22.0 httpx==0.28.1 identify==2.6.9 idna==3.10 importlib_metadata==8.6.1 importlib_resources==6.5.2 iniconfig==2.1.0 ipyevents==2.0.2 ipyfilechooser==0.6.0 ipykernel==6.29.5 ipyleaflet==0.13.3 ipynb-py-convert==0.4.6 ipyspin==1.0.1 ipython==8.12.3 ipython-genutils==0.2.0 ipytree==0.2.2 ipyurl==0.1.3 ipyvue==1.11.2 ipyvuetify==1.11.1 ipywidgets==7.8.5 isoduration==20.11.0 jedi==0.19.2 Jinja2==3.1.6 jsbeautifier==1.15.4 json5==0.10.0 jsonpointer==3.0.0 jsonschema==4.23.0 jsonschema-specifications==2024.10.1 jupyter-events==0.12.0 jupyter-lsp==2.2.5 jupyter_client==8.6.3 jupyter_core==5.7.2 jupyter_server==2.15.0 jupyter_server_terminals==0.5.3 jupyter_server_xarray_leaflet==0.2.3 jupyterlab==4.3.6 jupyterlab_pygments==0.3.0 jupyterlab_server==2.27.3 jupyterlab_widgets==1.1.11 kiwisolver==1.4.7 logzero==1.7.0 Markdown==3.7 MarkupSafe==3.0.2 matplotlib==3.9.4 matplotlib-inline==0.1.7 mercantile==1.2.1 mistune==3.1.3 mss==10.0.0 natsort==8.4.0 nbclient==0.10.2 nbconvert==7.16.6 nbformat==5.10.4 nest-asyncio==1.6.0 nodeenv==1.9.1 notebook==7.3.3 notebook_shim==0.2.4 numpy==2.0.2 orderly-set==5.3.0 overrides==7.7.0 packaging==24.2 pandas==2.2.3 pandocfilters==1.5.1 parso==0.8.4 pexpect==4.9.0 pickleshare==0.7.5 pillow==11.1.0 pipreqs==0.5.0 platformdirs==4.3.7 pluggy==1.5.0 pre_commit==4.2.0 prometheus_client==0.21.1 prompt_toolkit==3.0.50 proto-plus==1.26.1 protobuf==6.30.2 psutil==7.0.0 ptyprocess==0.7.0 pure_eval==0.2.3 pyasn1==0.6.1 pyasn1_modules==0.4.2 pycparser==2.22 PyCRS==1.0.2 Pygments==2.19.1 pyogrio==0.10.0 pyparsing==3.2.3 pyproj==3.6.1 pyshp==2.3.1 pytest==8.3.5 python-dateutil==2.9.0.post0 python-json-logger==3.3.0 pytz==2025.2 PyYAML==6.0.2 pyzmq==26.3.0 rasterio==1.4.3 ratelim==0.1.6 referencing==0.36.2 requests==2.32.3 rfc3339-validator==0.1.4 rfc3986-validator==0.1.1 rioxarray==0.15.0 rpds-py==0.24.0 rsa==4.9 Send2Trash==1.8.3 -e git+https://github.com/12rambau/sepal_ui.git@179bd8d089275c54e94a7614be7ed03d298ef532#egg=sepal_ui shapely==2.0.7 six==1.17.0 sniffio==1.3.1 soupsieve==2.6 stack-data==0.6.3 terminado==0.18.1 tinycss2==1.4.0 tomli==2.2.1 tornado==6.4.2 tqdm==4.67.1 traitlets==5.14.3 traittypes==0.2.1 types-python-dateutil==2.9.0.20241206 typing_extensions==4.13.0 tzdata==2025.2 Unidecode==1.3.8 uri-template==1.3.0 uritemplate==4.1.1 urllib3==2.3.0 virtualenv==20.29.3 voila==0.5.8 wcwidth==0.2.13 webcolors==24.11.1 webencodings==0.5.1 websocket-client==1.8.0 websockets==15.0.1 whitebox==2.3.6 whiteboxgui==2.3.0 widgetsnbextension==3.6.10 wrapt==1.17.2 xarray==2024.7.0 xarray_leaflet==0.2.3 yarg==0.1.9 zipp==3.21.0
name: sepal_ui channels: - defaults - https://repo.anaconda.com/pkgs/main - https://repo.anaconda.com/pkgs/r - conda-forge dependencies: - _libgcc_mutex=0.1=main - _openmp_mutex=5.1=1_gnu - ca-certificates=2025.2.25=h06a4308_0 - ld_impl_linux-64=2.40=h12ee557_0 - libffi=3.4.4=h6a678d5_1 - libgcc-ng=11.2.0=h1234567_1 - libgomp=11.2.0=h1234567_1 - libstdcxx-ng=11.2.0=h1234567_1 - ncurses=6.4=h6a678d5_0 - openssl=3.0.16=h5eee18b_0 - pip=25.0=py39h06a4308_0 - python=3.9.21=he870216_1 - readline=8.2=h5eee18b_0 - setuptools=75.8.0=py39h06a4308_0 - sqlite=3.45.3=h5eee18b_0 - tk=8.6.14=h39e8969_0 - wheel=0.45.1=py39h06a4308_0 - xz=5.6.4=h5eee18b_1 - zlib=1.2.13=h5eee18b_1 - pip: - affine==2.4.0 - anyio==4.9.0 - argon2-cffi==23.1.0 - argon2-cffi-bindings==21.2.0 - arrow==1.3.0 - asttokens==3.0.0 - async-lru==2.0.5 - attrs==25.3.0 - babel==2.17.0 - backcall==0.2.0 - beautifulsoup4==4.13.3 - bleach==6.2.0 - bqplot==0.12.44 - branca==0.4.2 - cachetools==5.5.2 - certifi==2025.1.31 - cffi==1.17.1 - cfgv==3.4.0 - charset-normalizer==3.4.1 - click==8.1.8 - click-plugins==1.1.1 - cligj==0.7.2 - colorama==0.4.6 - colour==0.1.5 - comm==0.2.2 - contourpy==1.3.0 - coverage==7.8.0 - cryptography==44.0.2 - cycler==0.12.1 - debugpy==1.8.13 - decorator==5.2.1 - deepdiff==8.4.2 - defusedxml==0.7.1 - deprecated==1.2.18 - distlib==0.3.9 - docopt==0.6.2 - earthengine-api==1.5.8 - editorconfig==0.17.0 - exceptiongroup==1.2.2 - executing==2.2.0 - fastjsonschema==2.21.1 - ffmpeg-python==0.2.0 - filelock==3.18.0 - folium==0.13.0 - fonttools==4.56.0 - fqdn==1.5.1 - future==1.0.0 - geeadd==1.2.1 - geemap==0.8.9 - geocoder==1.38.1 - geopandas==1.0.1 - google-api-core==2.24.2 - google-api-python-client==2.166.0 - google-auth==2.38.0 - google-auth-httplib2==0.2.0 - google-cloud-core==2.4.3 - google-cloud-storage==3.1.0 - google-crc32c==1.7.1 - google-resumable-media==2.7.2 - googleapis-common-protos==1.69.2 - h11==0.14.0 - haversine==2.9.0 - httpcore==1.0.7 - httplib2==0.22.0 - httpx==0.28.1 - identify==2.6.9 - idna==3.10 - importlib-metadata==8.6.1 - importlib-resources==6.5.2 - iniconfig==2.1.0 - ipyevents==2.0.2 - ipyfilechooser==0.6.0 - ipykernel==6.29.5 - ipyleaflet==0.13.3 - ipynb-py-convert==0.4.6 - ipyspin==1.0.1 - ipython==8.12.3 - ipython-genutils==0.2.0 - ipytree==0.2.2 - ipyurl==0.1.3 - ipyvue==1.11.2 - ipyvuetify==1.11.1 - ipywidgets==7.8.5 - isoduration==20.11.0 - jedi==0.19.2 - jinja2==3.1.6 - jsbeautifier==1.15.4 - json5==0.10.0 - jsonpointer==3.0.0 - jsonschema==4.23.0 - jsonschema-specifications==2024.10.1 - jupyter-client==8.6.3 - jupyter-core==5.7.2 - jupyter-events==0.12.0 - jupyter-lsp==2.2.5 - jupyter-server==2.15.0 - jupyter-server-terminals==0.5.3 - jupyter-server-xarray-leaflet==0.2.3 - jupyterlab==4.3.6 - jupyterlab-pygments==0.3.0 - jupyterlab-server==2.27.3 - jupyterlab-widgets==1.1.11 - kiwisolver==1.4.7 - logzero==1.7.0 - markdown==3.7 - markupsafe==3.0.2 - matplotlib==3.9.4 - matplotlib-inline==0.1.7 - mercantile==1.2.1 - mistune==3.1.3 - mss==10.0.0 - natsort==8.4.0 - nbclient==0.10.2 - nbconvert==7.16.6 - nbformat==5.10.4 - nest-asyncio==1.6.0 - nodeenv==1.9.1 - notebook==7.3.3 - notebook-shim==0.2.4 - numpy==2.0.2 - orderly-set==5.3.0 - overrides==7.7.0 - packaging==24.2 - pandas==2.2.3 - pandocfilters==1.5.1 - parso==0.8.4 - pexpect==4.9.0 - pickleshare==0.7.5 - pillow==11.1.0 - pipreqs==0.5.0 - platformdirs==4.3.7 - pluggy==1.5.0 - pre-commit==4.2.0 - prometheus-client==0.21.1 - prompt-toolkit==3.0.50 - proto-plus==1.26.1 - protobuf==6.30.2 - psutil==7.0.0 - ptyprocess==0.7.0 - pure-eval==0.2.3 - pyasn1==0.6.1 - pyasn1-modules==0.4.2 - pycparser==2.22 - pycrs==1.0.2 - pygments==2.19.1 - pyogrio==0.10.0 - pyparsing==3.2.3 - pyproj==3.6.1 - pyshp==2.3.1 - pytest==8.3.5 - python-dateutil==2.9.0.post0 - python-json-logger==3.3.0 - pytz==2025.2 - pyyaml==6.0.2 - pyzmq==26.3.0 - rasterio==1.4.3 - ratelim==0.1.6 - referencing==0.36.2 - requests==2.32.3 - rfc3339-validator==0.1.4 - rfc3986-validator==0.1.1 - rioxarray==0.15.0 - rpds-py==0.24.0 - rsa==4.9 - send2trash==1.8.3 - shapely==2.0.7 - six==1.17.0 - sniffio==1.3.1 - soupsieve==2.6 - stack-data==0.6.3 - terminado==0.18.1 - tinycss2==1.4.0 - tomli==2.2.1 - tornado==6.4.2 - tqdm==4.67.1 - traitlets==5.14.3 - traittypes==0.2.1 - types-python-dateutil==2.9.0.20241206 - typing-extensions==4.13.0 - tzdata==2025.2 - unidecode==1.3.8 - uri-template==1.3.0 - uritemplate==4.1.1 - urllib3==2.3.0 - virtualenv==20.29.3 - voila==0.5.8 - wcwidth==0.2.13 - webcolors==24.11.1 - webencodings==0.5.1 - websocket-client==1.8.0 - websockets==15.0.1 - whitebox==2.3.6 - whiteboxgui==2.3.0 - widgetsnbextension==3.6.10 - wrapt==1.17.2 - xarray==2024.7.0 - xarray-leaflet==0.2.3 - yarg==0.1.9 - zipp==3.21.0 prefix: /opt/conda/envs/sepal_ui
[ "tests/test_DatePicker.py::TestDatePicker::test_disable" ]
[]
[ "tests/test_DatePicker.py::TestDatePicker::test_init", "tests/test_DatePicker.py::TestDatePicker::test_bind" ]
[]
MIT License
swerebench/sweb.eval.x86_64.12rambau_1776_sepal_ui-411
12rambau__sepal_ui-416
8b76805db051d6d15024bd9ec2d78502cd92132e
2022-03-11 19:47:50
97371fbaed444727126a2969cd68f856db77221f
diff --git a/docs/source/modules/sepal_ui.sepalwidgets.DrawerItem.rst b/docs/source/modules/sepal_ui.sepalwidgets.DrawerItem.rst index a3280cd3..22b87b44 100644 --- a/docs/source/modules/sepal_ui.sepalwidgets.DrawerItem.rst +++ b/docs/source/modules/sepal_ui.sepalwidgets.DrawerItem.rst @@ -7,7 +7,9 @@ sepal\_ui.sepalwidgets.DrawerItem .. autosummary:: - ~DrawerItem.rt + ~DrawerItem.rt + ~DrawerItem.alert + ~DrawerItem.alert_badge .. rubric:: Methods @@ -15,5 +17,11 @@ sepal\_ui.sepalwidgets.DrawerItem :nosignatures: ~DrawerItem.display_tile + ~DrawerItem.add_notif + ~DrawerItem.remove_notif -.. automethod:: sepal_ui.sepalwidgets.DrawerItem.display_tile \ No newline at end of file +.. automethod:: sepal_ui.sepalwidgets.DrawerItem.display_tile + +.. automethod:: sepal_ui.sepalwidgets.DrawerItem.add_notif + +.. automethod:: sepal_ui.sepalwidgets.DrawerItem.remove_notif \ No newline at end of file diff --git a/sepal_ui/sepalwidgets/app.py b/sepal_ui/sepalwidgets/app.py index a1aff843..2a87de83 100644 --- a/sepal_ui/sepalwidgets/app.py +++ b/sepal_ui/sepalwidgets/app.py @@ -1,3 +1,4 @@ +from traitlets import link, Bool, observe from functools import partial from datetime import datetime @@ -73,12 +74,29 @@ class DrawerItem(v.ListItem, SepalWidget): card (str, optional): the mount_id of tiles in the app href (str, optional): the absolute link to an external web page kwargs (optional): any parameter from a v.ListItem. If set, '_metadata', 'target', 'link' and 'children' will be overwritten. + model (optional): sepalwidget model where is defined the bin_var trait + bind_var (optional): required when model is selected. Trait to link with 'alert' self trait parameter """ rt = None "sw.ResizeTrigger: the trigger to resize maps and other javascript object when jumping from a tile to another" - def __init__(self, title, icon=None, card=None, href=None, **kwargs): + alert = Bool(False).tag(sync=True) + "Bool: trait to control visibility of an alert in the drawer item" + + alert_badge = None + "v.ListItemAction: red circle to display in the drawer" + + def __init__( + self, + title, + icon=None, + card=None, + href=None, + model=None, + bind_var=None, + **kwargs + ): # set the resizetrigger self.rt = js.rt @@ -108,6 +126,45 @@ class DrawerItem(v.ListItem, SepalWidget): # call the constructor super().__init__(**kwargs) + # cannot be set as a class member because it will be shared with all + # the other draweritems. + self.alert_badge = v.ListItemAction( + children=[v.Icon(children=["fas fa-circle"], x_small=True, color="red")] + ) + + if model: + if not bind_var: + raise Exception( + "You have selected a model, you need a trait to bind with drawer." + ) + + link((model, bind_var), (self, "alert")) + + @observe("alert") + def add_notif(self, change): + """Add a notification alert to drawer""" + + if change["new"]: + if self.alert_badge not in self.children: + new_children = self.children[:] + new_children.append(self.alert_badge) + self.children = new_children + else: + self.remove_notif() + + return + + def remove_notif(self): + """Remove notification alert""" + + if self.alert_badge in self.children: + new_children = self.children[:] + new_children.remove(self.alert_badge) + + self.children = new_children + + return + def display_tile(self, tiles): """ Display the apropriate tiles when the item is clicked. @@ -138,6 +195,9 @@ class DrawerItem(v.ListItem, SepalWidget): # change the current item status self.input_value = True + # Remove notification + self.remove_notif() + return self
Interact with navigation drawers Sometimes is useful to pass some data from the module model to the app environment and so far we do not have this implementation. We can add two simple methods to the drawers so they can update their state with icons, badges, and so.
12rambau/sepal_ui
diff --git a/tests/test_DrawerItem.py b/tests/test_DrawerItem.py index ad26c3a2..0e80ffc9 100644 --- a/tests/test_DrawerItem.py +++ b/tests/test_DrawerItem.py @@ -1,3 +1,6 @@ +import pytest +from sepal_ui.model import Model +from traitlets import Bool import ipyvuetify as v from sepal_ui import sepalwidgets as sw @@ -60,3 +63,32 @@ class TestDrawerItem: assert tile.viz is False return + + @pytest.fixture + def model(self): + class TestModel(Model): + app_ready = Bool(False).tag(sync=True) + + return TestModel() + + def test_add_notif(self, model): + + drawer_item = sw.DrawerItem("title", model=model, bind_var="app_ready") + + model.app_ready = True + + assert drawer_item.alert_badge in drawer_item.children + + model.app_ready = False + + assert drawer_item.alert_badge not in drawer_item.children + + def test_remove_notif(self, model): + + drawer_item = sw.DrawerItem("title", model=model, bind_var="app_ready") + + model.app_ready = True + + drawer_item.remove_notif() + + assert drawer_item.alert_badge not in drawer_item.children
{ "commit_name": "head_commit", "failed_lite_validators": [ "has_many_modified_files", "has_many_hunks" ], "has_test_patch": true, "is_lite": false, "llm_score": { "difficulty_score": 1, "issue_text_score": 2, "test_score": 3 }, "num_modified_files": 2 }
2.6
{ "env_vars": null, "env_yml_path": null, "install": "pip install -e .[dev]", "log_parser": "parse_log_pytest", "no_use_env": null, "packages": "requirements.txt", "pip_packages": [ "pytest", "coverage" ], "pre_install": null, "python": "3.9", "reqs_path": null, "test_cmd": "pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning" }
affine==2.4.0 anyio==4.9.0 argon2-cffi==23.1.0 argon2-cffi-bindings==21.2.0 arrow==1.3.0 asttokens==3.0.0 async-lru==2.0.5 attrs==25.3.0 babel==2.17.0 backcall==0.2.0 beautifulsoup4==4.13.3 bleach==6.2.0 bqplot==0.12.44 branca==0.4.2 cachetools==5.5.2 certifi==2025.1.31 cffi==1.17.1 cfgv==3.4.0 charset-normalizer==3.4.1 click==8.1.8 click-plugins==1.1.1 cligj==0.7.2 colorama==0.4.6 colour==0.1.5 comm==0.2.2 contourpy==1.3.0 coverage==7.8.0 cryptography==44.0.2 cycler==0.12.1 debugpy==1.8.13 decorator==5.2.1 deepdiff==8.4.2 defusedxml==0.7.1 Deprecated==1.2.18 distlib==0.3.9 docopt==0.6.2 earthengine-api==1.5.8 EditorConfig==0.17.0 exceptiongroup==1.2.2 executing==2.2.0 fastjsonschema==2.21.1 ffmpeg-python==0.2.0 filelock==3.18.0 folium==0.13.0 fonttools==4.56.0 fqdn==1.5.1 future==1.0.0 geeadd==1.2.1 geemap==0.8.9 geocoder==1.38.1 geopandas==1.0.1 google-api-core==2.24.2 google-api-python-client==2.166.0 google-auth==2.38.0 google-auth-httplib2==0.2.0 google-cloud-core==2.4.3 google-cloud-storage==3.1.0 google-crc32c==1.7.1 google-resumable-media==2.7.2 googleapis-common-protos==1.69.2 h11==0.14.0 haversine==2.9.0 httpcore==1.0.7 httplib2==0.22.0 httpx==0.28.1 identify==2.6.9 idna==3.10 importlib_metadata==8.6.1 importlib_resources==6.5.2 iniconfig==2.1.0 ipyevents==2.0.2 ipyfilechooser==0.6.0 ipykernel==6.29.5 ipyleaflet==0.13.3 ipynb-py-convert==0.4.6 ipyspin==1.0.1 ipython==8.12.3 ipython-genutils==0.2.0 ipytree==0.2.2 ipyurl==0.1.3 ipyvue==1.11.2 ipyvuetify==1.11.1 ipywidgets==7.8.5 isoduration==20.11.0 jedi==0.19.2 Jinja2==3.1.6 jsbeautifier==1.15.4 json5==0.10.0 jsonpointer==3.0.0 jsonschema==4.23.0 jsonschema-specifications==2024.10.1 jupyter-events==0.12.0 jupyter-lsp==2.2.5 jupyter_client==8.6.3 jupyter_core==5.7.2 jupyter_server==2.15.0 jupyter_server_terminals==0.5.3 jupyter_server_xarray_leaflet==0.2.3 jupyterlab==4.3.6 jupyterlab_pygments==0.3.0 jupyterlab_server==2.27.3 jupyterlab_widgets==1.1.11 kiwisolver==1.4.7 logzero==1.7.0 Markdown==3.7 MarkupSafe==3.0.2 matplotlib==3.9.4 matplotlib-inline==0.1.7 mercantile==1.2.1 mistune==3.1.3 mss==10.0.0 natsort==8.4.0 nbclient==0.10.2 nbconvert==7.16.6 nbformat==5.10.4 nest-asyncio==1.6.0 nodeenv==1.9.1 notebook==7.3.3 notebook_shim==0.2.4 numpy==2.0.2 orderly-set==5.3.0 overrides==7.7.0 packaging==24.2 pandas==2.2.3 pandocfilters==1.5.1 parso==0.8.4 pexpect==4.9.0 pickleshare==0.7.5 pillow==11.1.0 pipreqs==0.5.0 platformdirs==4.3.7 pluggy==1.5.0 pre_commit==4.2.0 prometheus_client==0.21.1 prompt_toolkit==3.0.50 proto-plus==1.26.1 protobuf==6.30.2 psutil==7.0.0 ptyprocess==0.7.0 pure_eval==0.2.3 pyasn1==0.6.1 pyasn1_modules==0.4.2 pycparser==2.22 PyCRS==1.0.2 Pygments==2.19.1 pyogrio==0.10.0 pyparsing==3.2.3 pyproj==3.6.1 pyshp==2.3.1 pytest==8.3.5 python-dateutil==2.9.0.post0 python-json-logger==3.3.0 pytz==2025.2 PyYAML==6.0.2 pyzmq==26.3.0 rasterio==1.4.3 ratelim==0.1.6 referencing==0.36.2 requests==2.32.3 rfc3339-validator==0.1.4 rfc3986-validator==0.1.1 rioxarray==0.15.0 rpds-py==0.24.0 rsa==4.9 Send2Trash==1.8.3 -e git+https://github.com/12rambau/sepal_ui.git@8b76805db051d6d15024bd9ec2d78502cd92132e#egg=sepal_ui shapely==2.0.7 six==1.17.0 sniffio==1.3.1 soupsieve==2.6 stack-data==0.6.3 terminado==0.18.1 tinycss2==1.4.0 tomli==2.2.1 tornado==6.4.2 tqdm==4.67.1 traitlets==5.14.3 traittypes==0.2.1 types-python-dateutil==2.9.0.20241206 typing_extensions==4.13.0 tzdata==2025.2 Unidecode==1.3.8 uri-template==1.3.0 uritemplate==4.1.1 urllib3==2.3.0 virtualenv==20.29.3 voila==0.5.8 wcwidth==0.2.13 webcolors==24.11.1 webencodings==0.5.1 websocket-client==1.8.0 websockets==15.0.1 whitebox==2.3.6 whiteboxgui==2.3.0 widgetsnbextension==3.6.10 wrapt==1.17.2 xarray==2024.7.0 xarray_leaflet==0.2.3 yarg==0.1.9 zipp==3.21.0
name: sepal_ui channels: - defaults - https://repo.anaconda.com/pkgs/main - https://repo.anaconda.com/pkgs/r - conda-forge dependencies: - _libgcc_mutex=0.1=main - _openmp_mutex=5.1=1_gnu - ca-certificates=2025.2.25=h06a4308_0 - ld_impl_linux-64=2.40=h12ee557_0 - libffi=3.4.4=h6a678d5_1 - libgcc-ng=11.2.0=h1234567_1 - libgomp=11.2.0=h1234567_1 - libstdcxx-ng=11.2.0=h1234567_1 - ncurses=6.4=h6a678d5_0 - openssl=3.0.16=h5eee18b_0 - pip=25.0=py39h06a4308_0 - python=3.9.21=he870216_1 - readline=8.2=h5eee18b_0 - setuptools=75.8.0=py39h06a4308_0 - sqlite=3.45.3=h5eee18b_0 - tk=8.6.14=h39e8969_0 - wheel=0.45.1=py39h06a4308_0 - xz=5.6.4=h5eee18b_1 - zlib=1.2.13=h5eee18b_1 - pip: - affine==2.4.0 - anyio==4.9.0 - argon2-cffi==23.1.0 - argon2-cffi-bindings==21.2.0 - arrow==1.3.0 - asttokens==3.0.0 - async-lru==2.0.5 - attrs==25.3.0 - babel==2.17.0 - backcall==0.2.0 - beautifulsoup4==4.13.3 - bleach==6.2.0 - bqplot==0.12.44 - branca==0.4.2 - cachetools==5.5.2 - certifi==2025.1.31 - cffi==1.17.1 - cfgv==3.4.0 - charset-normalizer==3.4.1 - click==8.1.8 - click-plugins==1.1.1 - cligj==0.7.2 - colorama==0.4.6 - colour==0.1.5 - comm==0.2.2 - contourpy==1.3.0 - coverage==7.8.0 - cryptography==44.0.2 - cycler==0.12.1 - debugpy==1.8.13 - decorator==5.2.1 - deepdiff==8.4.2 - defusedxml==0.7.1 - deprecated==1.2.18 - distlib==0.3.9 - docopt==0.6.2 - earthengine-api==1.5.8 - editorconfig==0.17.0 - exceptiongroup==1.2.2 - executing==2.2.0 - fastjsonschema==2.21.1 - ffmpeg-python==0.2.0 - filelock==3.18.0 - folium==0.13.0 - fonttools==4.56.0 - fqdn==1.5.1 - future==1.0.0 - geeadd==1.2.1 - geemap==0.8.9 - geocoder==1.38.1 - geopandas==1.0.1 - google-api-core==2.24.2 - google-api-python-client==2.166.0 - google-auth==2.38.0 - google-auth-httplib2==0.2.0 - google-cloud-core==2.4.3 - google-cloud-storage==3.1.0 - google-crc32c==1.7.1 - google-resumable-media==2.7.2 - googleapis-common-protos==1.69.2 - h11==0.14.0 - haversine==2.9.0 - httpcore==1.0.7 - httplib2==0.22.0 - httpx==0.28.1 - identify==2.6.9 - idna==3.10 - importlib-metadata==8.6.1 - importlib-resources==6.5.2 - iniconfig==2.1.0 - ipyevents==2.0.2 - ipyfilechooser==0.6.0 - ipykernel==6.29.5 - ipyleaflet==0.13.3 - ipynb-py-convert==0.4.6 - ipyspin==1.0.1 - ipython==8.12.3 - ipython-genutils==0.2.0 - ipytree==0.2.2 - ipyurl==0.1.3 - ipyvue==1.11.2 - ipyvuetify==1.11.1 - ipywidgets==7.8.5 - isoduration==20.11.0 - jedi==0.19.2 - jinja2==3.1.6 - jsbeautifier==1.15.4 - json5==0.10.0 - jsonpointer==3.0.0 - jsonschema==4.23.0 - jsonschema-specifications==2024.10.1 - jupyter-client==8.6.3 - jupyter-core==5.7.2 - jupyter-events==0.12.0 - jupyter-lsp==2.2.5 - jupyter-server==2.15.0 - jupyter-server-terminals==0.5.3 - jupyter-server-xarray-leaflet==0.2.3 - jupyterlab==4.3.6 - jupyterlab-pygments==0.3.0 - jupyterlab-server==2.27.3 - jupyterlab-widgets==1.1.11 - kiwisolver==1.4.7 - logzero==1.7.0 - markdown==3.7 - markupsafe==3.0.2 - matplotlib==3.9.4 - matplotlib-inline==0.1.7 - mercantile==1.2.1 - mistune==3.1.3 - mss==10.0.0 - natsort==8.4.0 - nbclient==0.10.2 - nbconvert==7.16.6 - nbformat==5.10.4 - nest-asyncio==1.6.0 - nodeenv==1.9.1 - notebook==7.3.3 - notebook-shim==0.2.4 - numpy==2.0.2 - orderly-set==5.3.0 - overrides==7.7.0 - packaging==24.2 - pandas==2.2.3 - pandocfilters==1.5.1 - parso==0.8.4 - pexpect==4.9.0 - pickleshare==0.7.5 - pillow==11.1.0 - pipreqs==0.5.0 - platformdirs==4.3.7 - pluggy==1.5.0 - pre-commit==4.2.0 - prometheus-client==0.21.1 - prompt-toolkit==3.0.50 - proto-plus==1.26.1 - protobuf==6.30.2 - psutil==7.0.0 - ptyprocess==0.7.0 - pure-eval==0.2.3 - pyasn1==0.6.1 - pyasn1-modules==0.4.2 - pycparser==2.22 - pycrs==1.0.2 - pygments==2.19.1 - pyogrio==0.10.0 - pyparsing==3.2.3 - pyproj==3.6.1 - pyshp==2.3.1 - pytest==8.3.5 - python-dateutil==2.9.0.post0 - python-json-logger==3.3.0 - pytz==2025.2 - pyyaml==6.0.2 - pyzmq==26.3.0 - rasterio==1.4.3 - ratelim==0.1.6 - referencing==0.36.2 - requests==2.32.3 - rfc3339-validator==0.1.4 - rfc3986-validator==0.1.1 - rioxarray==0.15.0 - rpds-py==0.24.0 - rsa==4.9 - send2trash==1.8.3 - shapely==2.0.7 - six==1.17.0 - sniffio==1.3.1 - soupsieve==2.6 - stack-data==0.6.3 - terminado==0.18.1 - tinycss2==1.4.0 - tomli==2.2.1 - tornado==6.4.2 - tqdm==4.67.1 - traitlets==5.14.3 - traittypes==0.2.1 - types-python-dateutil==2.9.0.20241206 - typing-extensions==4.13.0 - tzdata==2025.2 - unidecode==1.3.8 - uri-template==1.3.0 - uritemplate==4.1.1 - urllib3==2.3.0 - virtualenv==20.29.3 - voila==0.5.8 - wcwidth==0.2.13 - webcolors==24.11.1 - webencodings==0.5.1 - websocket-client==1.8.0 - websockets==15.0.1 - whitebox==2.3.6 - whiteboxgui==2.3.0 - widgetsnbextension==3.6.10 - wrapt==1.17.2 - xarray==2024.7.0 - xarray-leaflet==0.2.3 - yarg==0.1.9 - zipp==3.21.0 prefix: /opt/conda/envs/sepal_ui
[ "tests/test_DrawerItem.py::TestDrawerItem::test_add_notif", "tests/test_DrawerItem.py::TestDrawerItem::test_remove_notif" ]
[]
[ "tests/test_DrawerItem.py::TestDrawerItem::test_init_cards", "tests/test_DrawerItem.py::TestDrawerItem::test_display_tile" ]
[]
MIT License
null
12rambau__sepal_ui-418
8b76805db051d6d15024bd9ec2d78502cd92132e
2022-03-14 14:24:04
97371fbaed444727126a2969cd68f856db77221f
diff --git a/docs/source/modules/sepal_ui.sepalwidgets.DatePicker.rst b/docs/source/modules/sepal_ui.sepalwidgets.DatePicker.rst index 867227cb..322cca23 100644 --- a/docs/source/modules/sepal_ui.sepalwidgets.DatePicker.rst +++ b/docs/source/modules/sepal_ui.sepalwidgets.DatePicker.rst @@ -9,6 +9,7 @@ sepal\_ui.sepalwidgets.DatePicker ~DatePicker.menu ~DatePicker.disabled + ~DatePicker.date_text .. rubric:: Methods @@ -17,7 +18,13 @@ sepal\_ui.sepalwidgets.DatePicker ~Datepicker.close_menu ~DatePicker.disable + ~DatePicker.is_valid_date + ~DatePicker.check_date .. automethod:: sepal_ui.sepalwidgets.DatePicker.close_menu -.. automethod:: sepal_ui.sepalwidgets.DatePicker.disable \ No newline at end of file +.. automethod:: sepal_ui.sepalwidgets.DatePicker.disable + +.. automethod:: sepal_ui.sepalwidgets.DatePicker.check_date + +.. autofunction:: sepal_ui.sepalwidgets.DatePicker.disable \ No newline at end of file diff --git a/sepal_ui/sepalwidgets/inputs.py b/sepal_ui/sepalwidgets/inputs.py index 7d003229..bf1adf0b 100644 --- a/sepal_ui/sepalwidgets/inputs.py +++ b/sepal_ui/sepalwidgets/inputs.py @@ -1,4 +1,5 @@ from pathlib import Path +from datetime import datetime import ipyvuetify as v from traitlets import link, Int, Any, List, observe, Dict, Unicode, Bool @@ -40,6 +41,9 @@ class DatePicker(v.Layout, SepalWidget): menu = None "v.Menu: the menu widget to display the datepicker" + date_text = None + "v.TextField: the text field of the datepicker widget" + disabled = Bool(False).tag(sync=True) "traitlets.Bool: the disabled status of the Datepicker object" @@ -48,7 +52,7 @@ class DatePicker(v.Layout, SepalWidget): # create the widgets date_picker = v.DatePicker(no_title=True, v_model=None, scrollable=True) - date_text = v.TextField( + self.date_text = v.TextField( v_model=None, label=label, hint="YYYY-MM-DD format", @@ -69,7 +73,7 @@ class DatePicker(v.Layout, SepalWidget): { "name": "activator", "variable": "menuData", - "children": date_text, + "children": self.date_text, } ], ) @@ -84,8 +88,28 @@ class DatePicker(v.Layout, SepalWidget): # call the constructor super().__init__(**kwargs) - jslink((date_picker, "v_model"), (date_text, "v_model")) - jslink((date_picker, "v_model"), (self, "v_model")) + jslink((date_picker, "v_model"), (self.date_text, "v_model")) + jslink((self, "v_model"), (date_picker, "v_model")) + + @observe("v_model") + def check_date(self, change): + """ + A method to check if the value of the set v_model is a correctly formated date + Reset the widget and display an error if it's not the case + """ + + self.date_text.error_messages = None + + # exit immediately if nothing is set + if change["new"] is None: + return + + # change the error status + if not self.is_valid_date(change["new"]): + msg = self.date_text.hint + self.date_text.error_messages = msg + + return @observe("v_model") def close_menu(self, change): @@ -104,6 +128,27 @@ class DatePicker(v.Layout, SepalWidget): return + @staticmethod + def is_valid_date(date): + """ + Check if the date is provided using the date format required for the widget + + Args: + date (str): the date to test in YYYY-MM-DD format + + Return: + (bool): the date to test + """ + + try: + date = datetime.strptime(date, "%Y-%m-%d") + valid = True + + except Exception: + valid = False + + return valid + class FileInput(v.Flex, SepalWidget): """
Can't instantiate a sw.DatePicker with initial v_model Is not possible to instantiate the sepal DatePicker with an initially given date through the `v_model` parameter
12rambau/sepal_ui
diff --git a/tests/test_DatePicker.py b/tests/test_DatePicker.py index e5f5d06f..48993736 100644 --- a/tests/test_DatePicker.py +++ b/tests/test_DatePicker.py @@ -17,6 +17,11 @@ class TestDatePicker: datepicker = sw.DatePicker("toto") assert isinstance(datepicker, sw.DatePicker) + # datepicker with default value + value = "2022-03-14" + datepicker = sw.DatePicker(v_model=value) + assert datepicker.v_model == value + return def test_bind(self, datepicker): @@ -43,6 +48,34 @@ class TestDatePicker: return + def test_is_valid_date(self, datepicker): + + # a nicely shaped date + test = "2022-03-14" + assert datepicker.is_valid_date(test) is True + + # a badly shaped date + test = "2022-50-14" + assert datepicker.is_valid_date(test) is False + + return + + def test_check_date(self, datepicker): + + # manually update the value with a badely shaped date + test = "2022-50-14" + datepicker.v_model = test + assert datepicker.v_model == test + assert datepicker.date_text.error_messages is not None + + # manually update the value with a nicely shaped date + test = "2022-03-14" + datepicker.v_model = test + assert datepicker.v_model == test + assert datepicker.date_text.error_messages is None + + return + @pytest.fixture def datepicker(self): """create a default datepicker"""
{ "commit_name": "head_commit", "failed_lite_validators": [ "has_short_problem_statement", "has_many_modified_files", "has_many_hunks" ], "has_test_patch": true, "is_lite": false, "llm_score": { "difficulty_score": 1, "issue_text_score": 1, "test_score": 2 }, "num_modified_files": 2 }
2.6
{ "env_vars": null, "env_yml_path": null, "install": "pip install -e .[dev]", "log_parser": "parse_log_pytest", "no_use_env": null, "packages": "requirements.txt", "pip_packages": [ "pytest", "coverage" ], "pre_install": null, "python": "3.9", "reqs_path": null, "test_cmd": "pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning" }
affine==2.4.0 anyio==4.9.0 argon2-cffi==23.1.0 argon2-cffi-bindings==21.2.0 arrow==1.3.0 asttokens==3.0.0 async-lru==2.0.5 attrs==25.3.0 babel==2.17.0 backcall==0.2.0 beautifulsoup4==4.13.3 bleach==6.2.0 bqplot==0.12.44 branca==0.4.2 cachetools==5.5.2 certifi==2025.1.31 cffi==1.17.1 cfgv==3.4.0 charset-normalizer==3.4.1 click==8.1.8 click-plugins==1.1.1 cligj==0.7.2 colorama==0.4.6 colour==0.1.5 comm==0.2.2 contourpy==1.3.0 coverage==7.8.0 cryptography==44.0.2 cycler==0.12.1 debugpy==1.8.13 decorator==5.2.1 deepdiff==8.4.2 defusedxml==0.7.1 Deprecated==1.2.18 distlib==0.3.9 docopt==0.6.2 earthengine-api==1.5.8 EditorConfig==0.17.0 exceptiongroup==1.2.2 executing==2.2.0 fastjsonschema==2.21.1 ffmpeg-python==0.2.0 filelock==3.18.0 folium==0.13.0 fonttools==4.56.0 fqdn==1.5.1 future==1.0.0 geeadd==1.2.1 geemap==0.8.9 geocoder==1.38.1 geopandas==1.0.1 google-api-core==2.24.2 google-api-python-client==2.166.0 google-auth==2.38.0 google-auth-httplib2==0.2.0 google-cloud-core==2.4.3 google-cloud-storage==3.1.0 google-crc32c==1.7.1 google-resumable-media==2.7.2 googleapis-common-protos==1.69.2 h11==0.14.0 haversine==2.9.0 httpcore==1.0.7 httplib2==0.22.0 httpx==0.28.1 identify==2.6.9 idna==3.10 importlib_metadata==8.6.1 importlib_resources==6.5.2 iniconfig==2.1.0 ipyevents==2.0.2 ipyfilechooser==0.6.0 ipykernel==6.29.5 ipyleaflet==0.13.3 ipynb-py-convert==0.4.6 ipyspin==1.0.1 ipython==8.12.3 ipython-genutils==0.2.0 ipytree==0.2.2 ipyurl==0.1.3 ipyvue==1.11.2 ipyvuetify==1.11.1 ipywidgets==7.8.5 isoduration==20.11.0 jedi==0.19.2 Jinja2==3.1.6 jsbeautifier==1.15.4 json5==0.10.0 jsonpointer==3.0.0 jsonschema==4.23.0 jsonschema-specifications==2024.10.1 jupyter-events==0.12.0 jupyter-lsp==2.2.5 jupyter_client==8.6.3 jupyter_core==5.7.2 jupyter_server==2.15.0 jupyter_server_terminals==0.5.3 jupyter_server_xarray_leaflet==0.2.3 jupyterlab==4.3.6 jupyterlab_pygments==0.3.0 jupyterlab_server==2.27.3 jupyterlab_widgets==1.1.11 kiwisolver==1.4.7 logzero==1.7.0 Markdown==3.7 MarkupSafe==3.0.2 matplotlib==3.9.4 matplotlib-inline==0.1.7 mercantile==1.2.1 mistune==3.1.3 mss==10.0.0 natsort==8.4.0 nbclient==0.10.2 nbconvert==7.16.6 nbformat==5.10.4 nest-asyncio==1.6.0 nodeenv==1.9.1 notebook==7.3.3 notebook_shim==0.2.4 numpy==2.0.2 orderly-set==5.3.0 overrides==7.7.0 packaging==24.2 pandas==2.2.3 pandocfilters==1.5.1 parso==0.8.4 pexpect==4.9.0 pickleshare==0.7.5 pillow==11.1.0 pipreqs==0.5.0 platformdirs==4.3.7 pluggy==1.5.0 pre_commit==4.2.0 prometheus_client==0.21.1 prompt_toolkit==3.0.50 proto-plus==1.26.1 protobuf==6.30.2 psutil==7.0.0 ptyprocess==0.7.0 pure_eval==0.2.3 pyasn1==0.6.1 pyasn1_modules==0.4.2 pycparser==2.22 PyCRS==1.0.2 Pygments==2.19.1 pyogrio==0.10.0 pyparsing==3.2.3 pyproj==3.6.1 pyshp==2.3.1 pytest==8.3.5 python-dateutil==2.9.0.post0 python-json-logger==3.3.0 pytz==2025.2 PyYAML==6.0.2 pyzmq==26.3.0 rasterio==1.4.3 ratelim==0.1.6 referencing==0.36.2 requests==2.32.3 rfc3339-validator==0.1.4 rfc3986-validator==0.1.1 rioxarray==0.15.0 rpds-py==0.24.0 rsa==4.9 Send2Trash==1.8.3 -e git+https://github.com/12rambau/sepal_ui.git@8b76805db051d6d15024bd9ec2d78502cd92132e#egg=sepal_ui shapely==2.0.7 six==1.17.0 sniffio==1.3.1 soupsieve==2.6 stack-data==0.6.3 terminado==0.18.1 tinycss2==1.4.0 tomli==2.2.1 tornado==6.4.2 tqdm==4.67.1 traitlets==5.14.3 traittypes==0.2.1 types-python-dateutil==2.9.0.20241206 typing_extensions==4.13.0 tzdata==2025.2 Unidecode==1.3.8 uri-template==1.3.0 uritemplate==4.1.1 urllib3==2.3.0 virtualenv==20.29.3 voila==0.5.8 wcwidth==0.2.13 webcolors==24.11.1 webencodings==0.5.1 websocket-client==1.8.0 websockets==15.0.1 whitebox==2.3.6 whiteboxgui==2.3.0 widgetsnbextension==3.6.10 wrapt==1.17.2 xarray==2024.7.0 xarray_leaflet==0.2.3 yarg==0.1.9 zipp==3.21.0
name: sepal_ui channels: - defaults - https://repo.anaconda.com/pkgs/main - https://repo.anaconda.com/pkgs/r - conda-forge dependencies: - _libgcc_mutex=0.1=main - _openmp_mutex=5.1=1_gnu - ca-certificates=2025.2.25=h06a4308_0 - ld_impl_linux-64=2.40=h12ee557_0 - libffi=3.4.4=h6a678d5_1 - libgcc-ng=11.2.0=h1234567_1 - libgomp=11.2.0=h1234567_1 - libstdcxx-ng=11.2.0=h1234567_1 - ncurses=6.4=h6a678d5_0 - openssl=3.0.16=h5eee18b_0 - pip=25.0=py39h06a4308_0 - python=3.9.21=he870216_1 - readline=8.2=h5eee18b_0 - setuptools=75.8.0=py39h06a4308_0 - sqlite=3.45.3=h5eee18b_0 - tk=8.6.14=h39e8969_0 - wheel=0.45.1=py39h06a4308_0 - xz=5.6.4=h5eee18b_1 - zlib=1.2.13=h5eee18b_1 - pip: - affine==2.4.0 - anyio==4.9.0 - argon2-cffi==23.1.0 - argon2-cffi-bindings==21.2.0 - arrow==1.3.0 - asttokens==3.0.0 - async-lru==2.0.5 - attrs==25.3.0 - babel==2.17.0 - backcall==0.2.0 - beautifulsoup4==4.13.3 - bleach==6.2.0 - bqplot==0.12.44 - branca==0.4.2 - cachetools==5.5.2 - certifi==2025.1.31 - cffi==1.17.1 - cfgv==3.4.0 - charset-normalizer==3.4.1 - click==8.1.8 - click-plugins==1.1.1 - cligj==0.7.2 - colorama==0.4.6 - colour==0.1.5 - comm==0.2.2 - contourpy==1.3.0 - coverage==7.8.0 - cryptography==44.0.2 - cycler==0.12.1 - debugpy==1.8.13 - decorator==5.2.1 - deepdiff==8.4.2 - defusedxml==0.7.1 - deprecated==1.2.18 - distlib==0.3.9 - docopt==0.6.2 - earthengine-api==1.5.8 - editorconfig==0.17.0 - exceptiongroup==1.2.2 - executing==2.2.0 - fastjsonschema==2.21.1 - ffmpeg-python==0.2.0 - filelock==3.18.0 - folium==0.13.0 - fonttools==4.56.0 - fqdn==1.5.1 - future==1.0.0 - geeadd==1.2.1 - geemap==0.8.9 - geocoder==1.38.1 - geopandas==1.0.1 - google-api-core==2.24.2 - google-api-python-client==2.166.0 - google-auth==2.38.0 - google-auth-httplib2==0.2.0 - google-cloud-core==2.4.3 - google-cloud-storage==3.1.0 - google-crc32c==1.7.1 - google-resumable-media==2.7.2 - googleapis-common-protos==1.69.2 - h11==0.14.0 - haversine==2.9.0 - httpcore==1.0.7 - httplib2==0.22.0 - httpx==0.28.1 - identify==2.6.9 - idna==3.10 - importlib-metadata==8.6.1 - importlib-resources==6.5.2 - iniconfig==2.1.0 - ipyevents==2.0.2 - ipyfilechooser==0.6.0 - ipykernel==6.29.5 - ipyleaflet==0.13.3 - ipynb-py-convert==0.4.6 - ipyspin==1.0.1 - ipython==8.12.3 - ipython-genutils==0.2.0 - ipytree==0.2.2 - ipyurl==0.1.3 - ipyvue==1.11.2 - ipyvuetify==1.11.1 - ipywidgets==7.8.5 - isoduration==20.11.0 - jedi==0.19.2 - jinja2==3.1.6 - jsbeautifier==1.15.4 - json5==0.10.0 - jsonpointer==3.0.0 - jsonschema==4.23.0 - jsonschema-specifications==2024.10.1 - jupyter-client==8.6.3 - jupyter-core==5.7.2 - jupyter-events==0.12.0 - jupyter-lsp==2.2.5 - jupyter-server==2.15.0 - jupyter-server-terminals==0.5.3 - jupyter-server-xarray-leaflet==0.2.3 - jupyterlab==4.3.6 - jupyterlab-pygments==0.3.0 - jupyterlab-server==2.27.3 - jupyterlab-widgets==1.1.11 - kiwisolver==1.4.7 - logzero==1.7.0 - markdown==3.7 - markupsafe==3.0.2 - matplotlib==3.9.4 - matplotlib-inline==0.1.7 - mercantile==1.2.1 - mistune==3.1.3 - mss==10.0.0 - natsort==8.4.0 - nbclient==0.10.2 - nbconvert==7.16.6 - nbformat==5.10.4 - nest-asyncio==1.6.0 - nodeenv==1.9.1 - notebook==7.3.3 - notebook-shim==0.2.4 - numpy==2.0.2 - orderly-set==5.3.0 - overrides==7.7.0 - packaging==24.2 - pandas==2.2.3 - pandocfilters==1.5.1 - parso==0.8.4 - pexpect==4.9.0 - pickleshare==0.7.5 - pillow==11.1.0 - pipreqs==0.5.0 - platformdirs==4.3.7 - pluggy==1.5.0 - pre-commit==4.2.0 - prometheus-client==0.21.1 - prompt-toolkit==3.0.50 - proto-plus==1.26.1 - protobuf==6.30.2 - psutil==7.0.0 - ptyprocess==0.7.0 - pure-eval==0.2.3 - pyasn1==0.6.1 - pyasn1-modules==0.4.2 - pycparser==2.22 - pycrs==1.0.2 - pygments==2.19.1 - pyogrio==0.10.0 - pyparsing==3.2.3 - pyproj==3.6.1 - pyshp==2.3.1 - pytest==8.3.5 - python-dateutil==2.9.0.post0 - python-json-logger==3.3.0 - pytz==2025.2 - pyyaml==6.0.2 - pyzmq==26.3.0 - rasterio==1.4.3 - ratelim==0.1.6 - referencing==0.36.2 - requests==2.32.3 - rfc3339-validator==0.1.4 - rfc3986-validator==0.1.1 - rioxarray==0.15.0 - rpds-py==0.24.0 - rsa==4.9 - send2trash==1.8.3 - shapely==2.0.7 - six==1.17.0 - sniffio==1.3.1 - soupsieve==2.6 - stack-data==0.6.3 - terminado==0.18.1 - tinycss2==1.4.0 - tomli==2.2.1 - tornado==6.4.2 - tqdm==4.67.1 - traitlets==5.14.3 - traittypes==0.2.1 - types-python-dateutil==2.9.0.20241206 - typing-extensions==4.13.0 - tzdata==2025.2 - unidecode==1.3.8 - uri-template==1.3.0 - uritemplate==4.1.1 - urllib3==2.3.0 - virtualenv==20.29.3 - voila==0.5.8 - wcwidth==0.2.13 - webcolors==24.11.1 - webencodings==0.5.1 - websocket-client==1.8.0 - websockets==15.0.1 - whitebox==2.3.6 - whiteboxgui==2.3.0 - widgetsnbextension==3.6.10 - wrapt==1.17.2 - xarray==2024.7.0 - xarray-leaflet==0.2.3 - yarg==0.1.9 - zipp==3.21.0 prefix: /opt/conda/envs/sepal_ui
[ "tests/test_DatePicker.py::TestDatePicker::test_is_valid_date", "tests/test_DatePicker.py::TestDatePicker::test_check_date" ]
[]
[ "tests/test_DatePicker.py::TestDatePicker::test_init", "tests/test_DatePicker.py::TestDatePicker::test_bind", "tests/test_DatePicker.py::TestDatePicker::test_disable" ]
[]
MIT License
null
12rambau__sepal_ui-419
97371fbaed444727126a2969cd68f856db77221f
2022-03-15 11:14:02
97371fbaed444727126a2969cd68f856db77221f
diff --git a/docs/source/modules/sepal_ui.rst b/docs/source/modules/sepal_ui.rst index 366a3fb2..2650327b 100644 --- a/docs/source/modules/sepal_ui.rst +++ b/docs/source/modules/sepal_ui.rst @@ -24,3 +24,11 @@ Content sepal_ui.theme sepal_ui.color sepal_ui.config_file + +.. rubric:: Attributes + +.. autosummary:: + + sepal_ui.get_theme + +.. autofunction:: sepal_ui.get_theme diff --git a/docs/source/modules/sepal_ui.scripts.utils.rst b/docs/source/modules/sepal_ui.scripts.utils.rst index d4a30a14..6c404e8a 100644 --- a/docs/source/modules/sepal_ui.scripts.utils.rst +++ b/docs/source/modules/sepal_ui.scripts.utils.rst @@ -23,6 +23,7 @@ sepal\_ui.scripts.utils switch to_colors set_config_locale + set_config_theme .. autofunction:: sepal_ui.scripts.utils.catch_errors @@ -54,6 +55,8 @@ sepal\_ui.scripts.utils .. autofunction:: sepal_ui.scripts.utils.set_config_locale +.. autofunction:: sepal_ui.scripts.utils.set_config_theme + diff --git a/docs/source/modules/sepal_ui.sepalwidgets.AppBar.rst b/docs/source/modules/sepal_ui.sepalwidgets.AppBar.rst index 3787c444..011eae2b 100644 --- a/docs/source/modules/sepal_ui.sepalwidgets.AppBar.rst +++ b/docs/source/modules/sepal_ui.sepalwidgets.AppBar.rst @@ -10,6 +10,7 @@ sepal\_ui.sepalwidgets.AppBar ~AppBar.toogle_button ~AppBar.title ~AppBar.locale + ~AppBar.theme .. rubric:: Methods diff --git a/docs/source/modules/sepal_ui.sepalwidgets.ThemeSelect.rst b/docs/source/modules/sepal_ui.sepalwidgets.ThemeSelect.rst new file mode 100644 index 00000000..5c4e14d0 --- /dev/null +++ b/docs/source/modules/sepal_ui.sepalwidgets.ThemeSelect.rst @@ -0,0 +1,21 @@ +sepal\_ui.sepalwidgets.ThemeSelect +================================== + +.. autoclass:: sepal_ui.sepalwidgets.ThemeSelect + + .. rubric:: Attributes + + .. autosummary:: + + ~ThemeSelect.THEME_ICONS + ~ThemeSelect.theme + + .. rubric:: Methods + + .. autosummary:: + :nosignatures: + + ~ThemeSelect.toggle_theme + +.. automethod:: sepal_ui.sepalwidgets.ThemeSelect.toggle_theme + \ No newline at end of file diff --git a/docs/source/modules/sepal_ui.sepalwidgets.rst b/docs/source/modules/sepal_ui.sepalwidgets.rst index b1bc9ef1..9d0c6864 100644 --- a/docs/source/modules/sepal_ui.sepalwidgets.rst +++ b/docs/source/modules/sepal_ui.sepalwidgets.rst @@ -33,3 +33,4 @@ sepal\_ui.sepalwidgets sepal_ui.sepalwidgets.Tooltip sepal_ui.sepalwidgets.VectorField sepal_ui.sepalwidgets.LocaleSelect + sepal_ui.sepalwidgets.ThemeSelect diff --git a/sepal_ui/__init__.py b/sepal_ui/__init__.py index 69eccad6..bf79e175 100644 --- a/sepal_ui/__init__.py +++ b/sepal_ui/__init__.py @@ -1,18 +1,49 @@ +from types import SimpleNamespace +from pathlib import Path +from configparser import ConfigParser + +import ipyvuetify as v + +from sepal_ui.frontend import styles + __author__ = """Pierrick Rambaud""" __email__ = "pierrick.rambaud49@gmail.com" __version__ = "2.6.2" -# direct access to colors -from sepal_ui.frontend import styles -import ipyvuetify as v -from types import SimpleNamespace -from pathlib import Path -theme = v.theme.themes.dark if v.theme.dark else v.theme.themes.light +def get_theme(config_file): + """ + get the theme from the config file (default to dark) + + Return: + (str): the theme to use + """ + + # init theme + theme = "dark" + + # read the config file if existing + if config_file.is_file(): + config = ConfigParser() + config.read(config_file) + theme = config.get("sepal-ui", "theme", fallback="dark") + + # set vuetify theme + v.theme.dark = True if theme == "dark" else False + + return theme + + +config_file = Path.home() / ".sepal-ui-config" +"Pathlib.Path: the configuration file generated by sepal-ui based application to save parameters as language or theme" + +theme = getattr(v.theme.themes, get_theme(config_file)) "traitlets: the theme used in sepal" color = SimpleNamespace( - bg=styles.bg_color, + main=theme.main, + darker=theme.darker, + bg=theme.bg_color, primary=theme.primary, accent=theme.accent, secondary=theme.secondary, @@ -20,8 +51,6 @@ color = SimpleNamespace( info=theme.info, warning=theme.warning, error=theme.error, + menu=theme.menu, ) -'SimpleNamespace: the colors of sepal. members are in the following list: "bg, primary, accent, secondary, success, info, warning, error". They will render according to the selected theme.' - -config_file = Path.home() / ".sepal-ui-config" -"Pathlib.Path: the configuration file generated by sepal-ui based application to save parameters as language or theme" +'SimpleNamespace: the colors of sepal. members are in the following list: "main, darker, bg, primary, accent, secondary, success, info, warning, error, menu". They will render according to the selected theme.' diff --git a/sepal_ui/aoi/aoi_model.py b/sepal_ui/aoi/aoi_model.py index d713e7b9..0ecfdd74 100644 --- a/sepal_ui/aoi/aoi_model.py +++ b/sepal_ui/aoi/aoi_model.py @@ -10,6 +10,7 @@ from ipyleaflet import GeoJSON import geemap import ee +from sepal_ui import color from sepal_ui.frontend.styles import AOI_STYLE from sepal_ui.scripts import utils as su from sepal_ui.scripts import gee @@ -626,9 +627,12 @@ class AoiModel(Model): for f in data["features"]: f["properties"]["name"] = self.name + # adapt the style to the theme + style = {**AOI_STYLE, "color": color.success, "fillColor": color.success} + # create a GeoJSON object self.ipygeojson = GeoJSON( - data=data, style=AOI_STYLE, name="aoi", attribution="SEPA(c)" + data=data, style=style, name="aoi", attribution="SEPAL(c)" ) return self.ipygeojson diff --git a/sepal_ui/bin/module_theme b/sepal_ui/bin/module_theme new file mode 100755 index 00000000..8d153333 --- /dev/null +++ b/sepal_ui/bin/module_theme @@ -0,0 +1,55 @@ +#!/usr/bin/python3 + +from colorama import init, Fore, Style + +from sepal_ui.scripts import utils as su + +# init colors for all plateforms +init() + + +def check_theme(theme): + """ + Check if the theme is a legit name + + Return: + (bool) + """ + + themes = ["dark", "light"] + + return theme in themes + + +if __name__ == "__main__": + + # welcome the user + print(Fore.YELLOW) + print("##########################################") + print("# #") + print("# SEPAL MODULE THEMING TOOL #") + print("# #") + print("##########################################") + print(Fore.RESET) + print(f"Welcome in the {Style.BRIGHT}module theming{Style.NORMAL} interface.") + + # select a language + is_theme = False + while is_theme is False: + + theme = input(f"{Fore.CYAN}Provide a theme name: \n{Fore.RESET}") + is_theme = check_theme(theme) + + # display an error if the language does not exist + if is_theme is False: + print( + f'{Fore.RED} The provided theme name ("{theme}") is not a supported theme. {Fore.RESET}' + ) + + # write the new color code in the config file + su.set_config_theme(theme) + + # display information + print( + f'{Fore.GREEN} The provided theme ("{theme}") has been set as default theme for all SEPAL applications.{Fore.RESET}' + ) diff --git a/sepal_ui/frontend/styles.py b/sepal_ui/frontend/styles.py index cf4b2971..a48b3dea 100644 --- a/sepal_ui/frontend/styles.py +++ b/sepal_ui/frontend/styles.py @@ -2,24 +2,28 @@ from traitlets import Unicode from IPython.display import display import ipyvuetify as v -# change vuetify theming -v.theme.dark = True - # set the colors for the dark theme -v.theme.themes.dark.primary = "#B3842E" +v.theme.themes.dark.primary = "#b3842e" v.theme.themes.dark.accent = "#a1458e" v.theme.themes.dark.secondary = "#324a88" -v.theme.themes.dark.success = "#3F802A" -v.theme.themes.dark.info = "#79B1C9" +v.theme.themes.dark.success = "#3f802a" +v.theme.themes.dark.info = "#79b1c9" v.theme.themes.dark.warning = "#b8721d" -v.theme.themes.dark.error = "#A63228" +v.theme.themes.dark.error = "#a63228" -# fixed colors -sepal_main = "#24221F" -sepal_darker = "#1a1a1a" +# fixed colors for drawer and appbar +v.theme.themes.dark.main = "#24221f" +v.theme.themes.light.main = "#2e7d32" +v.theme.themes.dark.darker = "#1a1a1a" +v.theme.themes.light.darker = "#005005" # set the background -bg_color = "#121212" if v.theme.dark else "#fff" +v.theme.themes.dark.bg_color = "#121212" +v.theme.themes.light.bg_color = "#fff" + +# set a specific color for menus +v.theme.themes.dark.menu = "#424242" +v.theme.themes.light.menu = "#fff" class Styles(v.VuetifyTemplate): @@ -49,30 +53,33 @@ class Styles(v.VuetifyTemplate): styles = Styles() display(styles) -COMPONENTS = { - "PROGRESS_BAR": { - "color": "indigo", - } -} - # default styling of the aoi layer AOI_STYLE = { "stroke": True, - "color": v.theme.themes.dark.success, + "color": "grey", "weight": 2, "opacity": 1, "fill": True, - "fillColor": v.theme.themes.dark.success, + "fillColor": "grey", "fillOpacity": 0.4, } +# the colors are set as follow. +# 1 (True): dark theme +# 0 (false): light theme +# This will need to be changed if we want to support more than 2 theme +COMPONENTS = { + "PROGRESS_BAR": { + "color": ["#2196f3", "#3f51b5"], + } +} -_folder = {"color": "amber", "icon": "far fa-folder"} -_table = {"color": "green accent-4", "icon": "far fa-table"} -_vector = {"color": "deep-purple", "icon": "far fa-vector-square"} -_other = {"color": "light-blue", "icon": "far fa-file"} -_parent = {"color": "white", "icon": "far fa-folder-open"} -_image = {"color": "deep-purple", "icon": "far fa-image"} +_folder = {"color": ["#ffca28", "#ffc107"], "icon": "far fa-folder"} +_table = {"color": ["#4caf50", "#00c853"], "icon": "far fa-table"} +_vector = {"color": ["#9c27b0", "#673ab7"], "icon": "far fa-vector-square"} +_other = {"color": ["#00bcd4", "#03a9f4"], "icon": "far fa-file"} +_parent = {"color": ["#424242", "#ffffff"], "icon": "far fa-folder-open"} +_image = {"color": ["#9c27b0", "#673ab7"], "icon": "far fa-image"} ICON_TYPES = { "": _folder, diff --git a/sepal_ui/mapping/mapping.py b/sepal_ui/mapping/mapping.py index ab44e84c..1dae10f3 100644 --- a/sepal_ui/mapping/mapping.py +++ b/sepal_ui/mapping/mapping.py @@ -100,7 +100,10 @@ class SepalMap(geemap.Map): if len(basemaps): [self.add_basemap(basemap) for basemap in set(basemaps)] else: - self.add_basemap("CartoDB.DarkMatter") + default_basemap = ( + "CartoDB.DarkMatter" if v.theme.dark is True else "CartoDB.Positron" + ) + self.add_basemap(default_basemap) # add the base controls self.clear_controls() diff --git a/sepal_ui/message/en/locale.json b/sepal_ui/message/en/locale.json index da5c4efc..c96a4857 100644 --- a/sepal_ui/message/en/locale.json +++ b/sepal_ui/message/en/locale.json @@ -155,7 +155,10 @@ } }, "locale": { - "change": "The locale \"{0}\" will now be used as default language in SEPAL apps. please restart the current application to take this change into account. Note that if \"{0}\" is not avalaible in another application, SEPAL will fallback to the closest possible language", + "change": "The locale \"{0}\" will now be used as default language in SEPAL apps. Please restart the current application to take this change into account. Note that if \"{0}\" is not avalaible in another application, SEPAL will fallback to the closest possible language", "fallback": "The \"{0}\" locale is not available for this application. We will be using \"{1}\" instead. Please report to the maintainer if you want to add \"{0}\" to the suported languages." + }, + "theme": { + "change": "The theme \"{0}\" will be used as default theme in SEPAL apps. Please restart the current application to take this change into account." } } \ No newline at end of file diff --git a/sepal_ui/scripts/utils.py b/sepal_ui/scripts/utils.py index adbce606..2cd55df9 100644 --- a/sepal_ui/scripts/utils.py +++ b/sepal_ui/scripts/utils.py @@ -521,3 +521,31 @@ def set_config_locale(locale): config.write(config_file.open("w")) return + + +@versionadded(version="2.7.0") +def set_config_theme(theme): + """ + Set the provided theme in the sepal-ui config file + + Args: + theme (str): a theme name (currently supporting "dark" and "light") + """ + + config = ConfigParser() + + # read the existing file if available + if config_file.is_file(): + config.read(config_file) + + # set the section if needed + if "sepal-ui" not in config.sections(): + config.add_section("sepal-ui") + + # set the value + config.set("sepal-ui", "theme", theme) + + # save back the file + config.write(config_file.open("w")) + + return diff --git a/sepal_ui/sepalwidgets/app.py b/sepal_ui/sepalwidgets/app.py index 2d26b7e1..15bcd5f2 100644 --- a/sepal_ui/sepalwidgets/app.py +++ b/sepal_ui/sepalwidgets/app.py @@ -2,20 +2,29 @@ from traitlets import link, Bool, observe from functools import partial from datetime import datetime from pathlib import Path +from itertools import cycle import ipyvuetify as v from deprecated.sphinx import versionadded import pandas as pd from ipywidgets import jsdlink +import sepal_ui from sepal_ui.sepalwidgets.sepalwidget import SepalWidget from sepal_ui import color -from sepal_ui.frontend.styles import sepal_main, sepal_darker from sepal_ui.frontend import js from sepal_ui.scripts import utils as su from sepal_ui.message import ms -__all__ = ["AppBar", "DrawerItem", "NavDrawer", "Footer", "App", "LocaleSelect"] +__all__ = [ + "AppBar", + "DrawerItem", + "NavDrawer", + "Footer", + "App", + "LocaleSelect", + "ThemeSelect", +] class AppBar(v.AppBar, SepalWidget): @@ -37,6 +46,9 @@ class AppBar(v.AppBar, SepalWidget): locale = None "sw.LocaleSelect: the locale selector of all apps" + theme = None + "sw.ThemeSelect: the theme selector of all apps" + def __init__(self, title="SEPAL module", translator=None, **kwargs): self.toggle_button = v.Btn( @@ -47,13 +59,20 @@ class AppBar(v.AppBar, SepalWidget): self.title = v.ToolbarTitle(children=[title]) self.locale = LocaleSelect(translator=translator) + self.theme = ThemeSelect() # set the default parameters - kwargs["color"] = kwargs.pop("color", sepal_main) + kwargs["color"] = kwargs.pop("color", color.main) kwargs["class_"] = kwargs.pop("class_", "white--text") kwargs["dense"] = kwargs.pop("dense", True) kwargs["app"] = True - kwargs["children"] = [self.toggle_button, self.title, v.Spacer(), self.locale] + kwargs["children"] = [ + self.toggle_button, + self.title, + v.Spacer(), + self.locale, + self.theme, + ] super().__init__(**kwargs) @@ -252,7 +271,7 @@ class NavDrawer(v.NavigationDrawer, SepalWidget): # set default parameters kwargs["v_model"] = kwargs.pop("v_model", True) kwargs["app"] = True - kwargs["color"] = kwargs.pop("color", sepal_darker) + kwargs["color"] = kwargs.pop("color", color.darker) kwargs["children"] = children # call the constructor @@ -313,7 +332,7 @@ class Footer(v.Footer, SepalWidget): text = text if text != "" else "SEPAL \u00A9 {}".format(datetime.today().year) # set default parameters - kwargs["color"] = kwargs.pop("color", sepal_main) + kwargs["color"] = kwargs.pop("color", color.main) kwargs["class_"] = kwargs.pop("class_", "white--text") kwargs["app"] = True kwargs["children"] = [text] @@ -414,6 +433,7 @@ class App(v.App, SepalWidget): # add js event self.appBar.locale.observe(self._locale_info, "value") + self.appBar.theme.observe(self._theme_info, "v_model") def show_tile(self, name): """ @@ -442,13 +462,14 @@ class App(v.App, SepalWidget): return self @versionadded(version="2.4.1", reason="New end user interaction method") - def add_banner(self, msg, **kwargs): + def add_banner(self, msg, id_=None, **kwargs): """ Display an alert object on top of the app to communicate development information to end user (release date, known issues, beta version). The alert is dissmisable and prominent Args: msg (str): the message to write in the Alert kwargs: any arguments of the v.Alert constructor. if set, 'children' will be overwritten. + id_ (str, optional): unique banner identificator to avoid multiple aggregations. Return: self @@ -457,16 +478,28 @@ class App(v.App, SepalWidget): kwargs["type"] = kwargs.pop("type", "info") kwargs["border"] = kwargs.pop("border", "left") kwargs["class_"] = kwargs.pop("class_", "mt-5") - kwargs["transition"] = kwargs.pop("transition", "slide-x-transition") + kwargs["transition"] = kwargs.pop("transition", "scroll-x-transition") kwargs["prominent"] = kwargs.pop("prominent", True) kwargs["dismissible"] = kwargs.pop("dismissible", True) kwargs["children"] = [msg] # cannot be overwritten + kwargs["attributes"] = {"id": id_} + kwargs["v_model"] = kwargs.pop("v_model", False) + + # Verify if alert is already in the app. + children = self.content.children.copy() - # create the alert + # remove already existing alert + alert = next((c for c in children if c.attributes.get("id") == id_), False) + alert is False or children.remove(alert) + + # create alert alert = v.Alert(**kwargs) - # add the alert to the app - self.content.children = [alert] + self.content.children.copy() + # add the alert to the app if not already there + self.content.children = [alert] + children + + # Display the alert + alert.v_model = True return self @@ -475,7 +508,16 @@ class App(v.App, SepalWidget): if change["new"] != "": msg = ms.locale.change.format(change["new"]) - self.add_banner(msg, type="success") + self.add_banner(msg, id_="locale") + + return + + def _theme_info(self, change): + """display information about the theme change""" + + if change["new"] != "": + msg = ms.theme.change.format(change["new"]) + self.add_banner(msg, id_="theme") return @@ -535,7 +577,7 @@ class LocaleSelect(v.Menu, SepalWidget): self.language_list = v.List( dense=True, flat=True, - color="grey darken-3", + color=color.menu, v_model=True, max_height="300px", style_="overflow: auto; border-radius: 0 0 0 0;", @@ -600,3 +642,62 @@ class LocaleSelect(v.Menu, SepalWidget): su.set_config_locale(loc.code) return + + +class ThemeSelect(v.Btn, SepalWidget): + """ + A theme selector for sepal-ui based application. + + It displays the currently requested theme (default to dark). + When value is changed, the sepal-ui config file is updated. It is designed to be used in a AppBar component. + + .. versionadded:: 2.7.0 + + Args: + kwargs (dict, optional): any arguments for a Btn object, children and v_model will be override + """ + + THEME_ICONS = {"dark": "fas fa-moon", "light": "fas fa-sun"} + "dict: the dictionnry of icons to use for each theme (used as keys)" + + theme = "dark" + "str: the current theme of the widget (default to dark)" + + def __init__(self, **kwargs): + + # get the current theme name + self.theme = sepal_ui.get_theme(sepal_ui.config_file) + + # set the btn parameters + kwargs["x_small"] = kwargs.pop("x_small", True) + kwargs["fab"] = kwargs.pop("fab", True) + kwargs["class_"] = kwargs.pop("class_", "ml-2") + kwargs["children"] = [v.Icon(children=[self.THEME_ICONS[self.theme]])] + kwargs["v_model"] = self.theme + + # create the btn + super().__init__(**kwargs) + + # add some js events + self.on_event("click", self.toggle_theme) + + def toggle_theme(self, widget, event, data): + """ + toggle the btn icon from dark to light and adapt the configuration file at the same time + """ + # use a cycle to go through the themes + theme_cycle = cycle(self.THEME_ICONS.keys()) + next(t for t in theme_cycle if t == self.theme) + self.theme = next(t for t in theme_cycle) + + # change icon + self.color = "info" + self.children[0].children = [self.THEME_ICONS[self.theme]] + + # change the paramater file + su.set_config_theme(self.theme) + + # trigger other events by changing v_model + self.v_model = self.theme + + return diff --git a/sepal_ui/sepalwidgets/inputs.py b/sepal_ui/sepalwidgets/inputs.py index bf1adf0b..365d4f0b 100644 --- a/sepal_ui/sepalwidgets/inputs.py +++ b/sepal_ui/sepalwidgets/inputs.py @@ -9,7 +9,7 @@ import ee import geopandas as gpd from natsort import humansorted - +from sepal_ui import color from sepal_ui.message import ms from sepal_ui.frontend.styles import COMPONENTS, ICON_TYPES from sepal_ui.scripts import utils as su @@ -215,13 +215,13 @@ class FileInput(v.Flex, SepalWidget): self.loading = v.ProgressLinear( indeterminate=False, - background_color="grey darken-3", - color=COMPONENTS["PROGRESS_BAR"]["color"], + background_color=color.menu, + color=COMPONENTS["PROGRESS_BAR"]["color"][v.theme.dark], ) self.file_list = v.List( dense=True, - color="grey darken-3", + color=color.menu, flat=True, v_model=True, max_height="300px", @@ -374,13 +374,13 @@ class FileInput(v.Flex, SepalWidget): if el.is_dir(): icon = ICON_TYPES[""]["icon"] - color = ICON_TYPES[""]["color"] + color = ICON_TYPES[""]["color"][v.theme.dark] elif el.suffix in ICON_TYPES.keys(): icon = ICON_TYPES[el.suffix]["icon"] - color = ICON_TYPES[el.suffix]["color"] + color = ICON_TYPES[el.suffix]["color"][v.theme.dark] else: icon = ICON_TYPES["DEFAULT"]["icon"] - color = ICON_TYPES["DEFAULT"]["color"] + color = ICON_TYPES["DEFAULT"]["color"][v.theme.dark] children = [ v.ListItemAction(children=[v.Icon(color=color, children=[icon])]), @@ -405,7 +405,7 @@ class FileInput(v.Flex, SepalWidget): v.ListItemAction( children=[ v.Icon( - color=ICON_TYPES["PARENT"]["color"], + color=ICON_TYPES["PARENT"]["color"][v.theme.dark], children=[ICON_TYPES["PARENT"]["icon"]], ) ] diff --git a/sepal_ui/translator/translator.py b/sepal_ui/translator/translator.py index 3982aad6..f0a39f77 100644 --- a/sepal_ui/translator/translator.py +++ b/sepal_ui/translator/translator.py @@ -119,7 +119,7 @@ class Translator(SimpleNamespace): if config_file.is_file(): config = ConfigParser() config.read(config_file) - target = config["sepal-ui"]["locale"] + target = config.get("sepal-ui", "locale", fallback="en") else: return ("en", None) diff --git a/setup.py b/setup.py index d7f3d03e..1b207b7e 100644 --- a/setup.py +++ b/setup.py @@ -57,7 +57,7 @@ setup_params = { "pytest", ], "doc": [ - "jupyter-sphinx @ git+git://github.com/jupyter/jupyter-sphinx.git", + "jupyter-sphinx @ git+https://github.com/jupyter/jupyter-sphinx.git", "pydata-sphinx-theme", "sphinx-notfound-page", "Sphinx",
automatically detect the theme used and adapt the frontend accordingly I have seen it on several zoom : it's so cool to display everything in dark but look so wrong when people are actually just developing in there own env in light theme. Several situation that I would like to handle : - voila theme - jupyterLab theme - jupyter notebook theme
12rambau/sepal_ui
diff --git a/tests/test_LocaleSelect.py b/tests/test_LocaleSelect.py index 5da8c6e0..1813b58d 100644 --- a/tests/test_LocaleSelect.py +++ b/tests/test_LocaleSelect.py @@ -6,7 +6,7 @@ from sepal_ui import sepalwidgets as sw from sepal_ui import config_file -class TestBtn: +class TestLocalSelect: def test_init(self, locale_select): # minimal btn diff --git a/tests/test_SepalMap.py b/tests/test_SepalMap.py index 440ce972..43f32238 100644 --- a/tests/test_SepalMap.py +++ b/tests/test_SepalMap.py @@ -53,8 +53,8 @@ class TestSepalMap: m.set_drawing_controls(True) assert isinstance(m.dc, geemap.DrawControl) - assert m.dc.rectangle == {"shapeOptions": {"color": "#79B1C9"}} - assert m.dc.polygon == {"shapeOptions": {"color": "#79B1C9"}} + assert m.dc.rectangle == {"shapeOptions": {"color": "#79b1c9"}} + assert m.dc.polygon == {"shapeOptions": {"color": "#79b1c9"}} assert m.dc.marker == {} assert m.dc.polyline == {} diff --git a/tests/test_ThemeSelect.py b/tests/test_ThemeSelect.py new file mode 100644 index 00000000..0de07d20 --- /dev/null +++ b/tests/test_ThemeSelect.py @@ -0,0 +1,36 @@ +from configparser import ConfigParser + +import pytest + +from sepal_ui import sepalwidgets as sw +from sepal_ui import config_file + + +class TestThemeSelect: + def test_init(self, theme_select): + + # minimal btn + assert isinstance(theme_select, sw.ThemeSelect) + + return + + def test_change_language(self, theme_select): + + # change value + theme_select.fire_event("click", None) + config = ConfigParser() + config.read(config_file) + assert "sepal-ui" in config.sections() + assert config["sepal-ui"]["theme"] == "light" + + return + + @pytest.fixture + def theme_select(self): + """Create a simple theme_select""" + + # destroy any existing config file + if config_file.is_file(): + config_file.unlink() + + return sw.ThemeSelect() diff --git a/tests/test_utils.py b/tests/test_utils.py index a648b462..05136ab4 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -326,3 +326,29 @@ class TestUtils: config_file.unlink() return + + def test_set_config_theme(self): + + # remove any config file that could exist + if config_file.is_file(): + config_file.unlink() + + # create a config_file with a set language + theme = "dark" + su.set_config_theme(theme) + + config = ConfigParser() + config.read(config_file) + assert "sepal-ui" in config.sections() + assert config["sepal-ui"]["theme"] == theme + + # change an existing locale + theme = "light" + su.set_config_theme(theme) + config.read(config_file) + assert config["sepal-ui"]["theme"] == theme + + # destroy the file again + config_file.unlink() + + return
{ "commit_name": "head_commit", "failed_lite_validators": [ "has_added_files", "has_many_modified_files", "has_many_hunks" ], "has_test_patch": true, "is_lite": false, "llm_score": { "difficulty_score": 2, "issue_text_score": 2, "test_score": 0 }, "num_modified_files": 14 }
2.6
{ "env_vars": null, "env_yml_path": null, "install": "pip install -e .[dev]", "log_parser": "parse_log_pytest", "no_use_env": null, "packages": "requirements.txt", "pip_packages": [ "numpy>=1.16.0", "pandas>=1.0.0", "ipyvuetify", "pytest" ], "pre_install": [ "apt-get update", "apt-get install -y gcc" ], "python": "3.9", "reqs_path": [ "requirements/base.txt" ], "test_cmd": "pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning" }
affine==2.4.0 anyio==4.9.0 argon2-cffi==23.1.0 argon2-cffi-bindings==21.2.0 arrow==1.3.0 asttokens==3.0.0 async-lru==2.0.5 attrs==25.3.0 babel==2.17.0 backcall==0.2.0 beautifulsoup4==4.13.3 bleach==6.2.0 bqplot==0.12.44 branca==0.4.2 cachetools==5.5.2 certifi==2025.1.31 cffi==1.17.1 cfgv==3.4.0 charset-normalizer==3.4.1 click==8.1.8 click-plugins==1.1.1 cligj==0.7.2 colorama==0.4.6 colour==0.1.5 comm==0.2.2 contourpy==1.3.0 cryptography==44.0.2 cycler==0.12.1 debugpy==1.8.13 decorator==5.2.1 deepdiff==8.4.2 defusedxml==0.7.1 Deprecated==1.2.18 distlib==0.3.9 docopt==0.6.2 earthengine-api==1.5.8 EditorConfig==0.17.0 exceptiongroup==1.2.2 executing==2.2.0 fastjsonschema==2.21.1 ffmpeg-python==0.2.0 filelock==3.18.0 folium==0.13.0 fonttools==4.56.0 fqdn==1.5.1 future==1.0.0 geeadd==1.2.1 geemap==0.8.9 geocoder==1.38.1 geopandas==1.0.1 google-api-core==2.24.2 google-api-python-client==2.166.0 google-auth==2.38.0 google-auth-httplib2==0.2.0 google-cloud-core==2.4.3 google-cloud-storage==3.1.0 google-crc32c==1.7.1 google-resumable-media==2.7.2 googleapis-common-protos==1.69.2 h11==0.14.0 haversine==2.9.0 httpcore==1.0.7 httplib2==0.22.0 httpx==0.28.1 identify==2.6.9 idna==3.10 importlib_metadata==8.6.1 importlib_resources==6.5.2 iniconfig==2.1.0 ipyevents==2.0.2 ipyfilechooser==0.6.0 ipykernel==6.29.5 ipyleaflet==0.13.3 ipynb-py-convert==0.4.6 ipyspin==1.0.1 ipython==8.12.3 ipython-genutils==0.2.0 ipytree==0.2.2 ipyurl==0.1.3 ipyvue==1.11.2 ipyvuetify==1.11.1 ipywidgets==7.8.5 isoduration==20.11.0 jedi==0.19.2 Jinja2==3.1.6 jsbeautifier==1.15.4 json5==0.10.0 jsonpointer==3.0.0 jsonschema==4.23.0 jsonschema-specifications==2024.10.1 jupyter-events==0.12.0 jupyter-lsp==2.2.5 jupyter_client==8.6.3 jupyter_core==5.7.2 jupyter_server==2.15.0 jupyter_server_terminals==0.5.3 jupyter_server_xarray_leaflet==0.2.3 jupyterlab==4.3.6 jupyterlab_pygments==0.3.0 jupyterlab_server==2.27.3 jupyterlab_widgets==1.1.11 kiwisolver==1.4.7 logzero==1.7.0 Markdown==3.7 MarkupSafe==3.0.2 matplotlib==3.9.4 matplotlib-inline==0.1.7 mercantile==1.2.1 mistune==3.1.3 mss==10.0.0 natsort==8.4.0 nbclient==0.10.2 nbconvert==7.16.6 nbformat==5.10.4 nest-asyncio==1.6.0 nodeenv==1.9.1 notebook==7.3.3 notebook_shim==0.2.4 numpy==2.0.2 orderly-set==5.3.0 overrides==7.7.0 packaging==24.2 pandas==2.2.3 pandocfilters==1.5.1 parso==0.8.4 pexpect==4.9.0 pickleshare==0.7.5 pillow==11.1.0 pipreqs==0.5.0 platformdirs==4.3.7 pluggy==1.5.0 pre_commit==4.2.0 prometheus_client==0.21.1 prompt_toolkit==3.0.50 proto-plus==1.26.1 protobuf==6.30.2 psutil==7.0.0 ptyprocess==0.7.0 pure_eval==0.2.3 pyasn1==0.6.1 pyasn1_modules==0.4.2 pycparser==2.22 PyCRS==1.0.2 Pygments==2.19.1 pyogrio==0.10.0 pyparsing==3.2.3 pyproj==3.6.1 pyshp==2.3.1 pytest==8.3.5 python-dateutil==2.9.0.post0 python-json-logger==3.3.0 pytz==2025.2 PyYAML==6.0.2 pyzmq==26.3.0 rasterio==1.4.3 ratelim==0.1.6 referencing==0.36.2 requests==2.32.3 rfc3339-validator==0.1.4 rfc3986-validator==0.1.1 rioxarray==0.15.0 rpds-py==0.24.0 rsa==4.9 Send2Trash==1.8.3 -e git+https://github.com/12rambau/sepal_ui.git@97371fbaed444727126a2969cd68f856db77221f#egg=sepal_ui shapely==2.0.7 six==1.17.0 sniffio==1.3.1 soupsieve==2.6 stack-data==0.6.3 terminado==0.18.1 tinycss2==1.4.0 tomli==2.2.1 tornado==6.4.2 tqdm==4.67.1 traitlets==5.14.3 traittypes==0.2.1 types-python-dateutil==2.9.0.20241206 typing_extensions==4.13.0 tzdata==2025.2 Unidecode==1.3.8 uri-template==1.3.0 uritemplate==4.1.1 urllib3==2.3.0 virtualenv==20.29.3 voila==0.5.8 wcwidth==0.2.13 webcolors==24.11.1 webencodings==0.5.1 websocket-client==1.8.0 websockets==15.0.1 whitebox==2.3.6 whiteboxgui==2.3.0 widgetsnbextension==3.6.10 wrapt==1.17.2 xarray==2024.7.0 xarray_leaflet==0.2.3 yarg==0.1.9 zipp==3.21.0
name: sepal_ui channels: - defaults - https://repo.anaconda.com/pkgs/main - https://repo.anaconda.com/pkgs/r - conda-forge dependencies: - _libgcc_mutex=0.1=main - _openmp_mutex=5.1=1_gnu - ca-certificates=2025.2.25=h06a4308_0 - ld_impl_linux-64=2.40=h12ee557_0 - libffi=3.4.4=h6a678d5_1 - libgcc-ng=11.2.0=h1234567_1 - libgomp=11.2.0=h1234567_1 - libstdcxx-ng=11.2.0=h1234567_1 - ncurses=6.4=h6a678d5_0 - openssl=3.0.16=h5eee18b_0 - pip=25.0=py39h06a4308_0 - python=3.9.21=he870216_1 - readline=8.2=h5eee18b_0 - setuptools=75.8.0=py39h06a4308_0 - sqlite=3.45.3=h5eee18b_0 - tk=8.6.14=h39e8969_0 - wheel=0.45.1=py39h06a4308_0 - xz=5.6.4=h5eee18b_1 - zlib=1.2.13=h5eee18b_1 - pip: - affine==2.4.0 - anyio==4.9.0 - argon2-cffi==23.1.0 - argon2-cffi-bindings==21.2.0 - arrow==1.3.0 - asttokens==3.0.0 - async-lru==2.0.5 - attrs==25.3.0 - babel==2.17.0 - backcall==0.2.0 - beautifulsoup4==4.13.3 - bleach==6.2.0 - bqplot==0.12.44 - branca==0.4.2 - cachetools==5.5.2 - certifi==2025.1.31 - cffi==1.17.1 - cfgv==3.4.0 - charset-normalizer==3.4.1 - click==8.1.8 - click-plugins==1.1.1 - cligj==0.7.2 - colorama==0.4.6 - colour==0.1.5 - comm==0.2.2 - contourpy==1.3.0 - cryptography==44.0.2 - cycler==0.12.1 - debugpy==1.8.13 - decorator==5.2.1 - deepdiff==8.4.2 - defusedxml==0.7.1 - deprecated==1.2.18 - distlib==0.3.9 - docopt==0.6.2 - earthengine-api==1.5.8 - editorconfig==0.17.0 - exceptiongroup==1.2.2 - executing==2.2.0 - fastjsonschema==2.21.1 - ffmpeg-python==0.2.0 - filelock==3.18.0 - folium==0.13.0 - fonttools==4.56.0 - fqdn==1.5.1 - future==1.0.0 - geeadd==1.2.1 - geemap==0.8.9 - geocoder==1.38.1 - geopandas==1.0.1 - google-api-core==2.24.2 - google-api-python-client==2.166.0 - google-auth==2.38.0 - google-auth-httplib2==0.2.0 - google-cloud-core==2.4.3 - google-cloud-storage==3.1.0 - google-crc32c==1.7.1 - google-resumable-media==2.7.2 - googleapis-common-protos==1.69.2 - h11==0.14.0 - haversine==2.9.0 - httpcore==1.0.7 - httplib2==0.22.0 - httpx==0.28.1 - identify==2.6.9 - idna==3.10 - importlib-metadata==8.6.1 - importlib-resources==6.5.2 - iniconfig==2.1.0 - ipyevents==2.0.2 - ipyfilechooser==0.6.0 - ipykernel==6.29.5 - ipyleaflet==0.13.3 - ipynb-py-convert==0.4.6 - ipyspin==1.0.1 - ipython==8.12.3 - ipython-genutils==0.2.0 - ipytree==0.2.2 - ipyurl==0.1.3 - ipyvue==1.11.2 - ipyvuetify==1.11.1 - ipywidgets==7.8.5 - isoduration==20.11.0 - jedi==0.19.2 - jinja2==3.1.6 - jsbeautifier==1.15.4 - json5==0.10.0 - jsonpointer==3.0.0 - jsonschema==4.23.0 - jsonschema-specifications==2024.10.1 - jupyter-client==8.6.3 - jupyter-core==5.7.2 - jupyter-events==0.12.0 - jupyter-lsp==2.2.5 - jupyter-server==2.15.0 - jupyter-server-terminals==0.5.3 - jupyter-server-xarray-leaflet==0.2.3 - jupyterlab==4.3.6 - jupyterlab-pygments==0.3.0 - jupyterlab-server==2.27.3 - jupyterlab-widgets==1.1.11 - kiwisolver==1.4.7 - logzero==1.7.0 - markdown==3.7 - markupsafe==3.0.2 - matplotlib==3.9.4 - matplotlib-inline==0.1.7 - mercantile==1.2.1 - mistune==3.1.3 - mss==10.0.0 - natsort==8.4.0 - nbclient==0.10.2 - nbconvert==7.16.6 - nbformat==5.10.4 - nest-asyncio==1.6.0 - nodeenv==1.9.1 - notebook==7.3.3 - notebook-shim==0.2.4 - numpy==2.0.2 - orderly-set==5.3.0 - overrides==7.7.0 - packaging==24.2 - pandas==2.2.3 - pandocfilters==1.5.1 - parso==0.8.4 - pexpect==4.9.0 - pickleshare==0.7.5 - pillow==11.1.0 - pipreqs==0.5.0 - platformdirs==4.3.7 - pluggy==1.5.0 - pre-commit==4.2.0 - prometheus-client==0.21.1 - prompt-toolkit==3.0.50 - proto-plus==1.26.1 - protobuf==6.30.2 - psutil==7.0.0 - ptyprocess==0.7.0 - pure-eval==0.2.3 - pyasn1==0.6.1 - pyasn1-modules==0.4.2 - pycparser==2.22 - pycrs==1.0.2 - pygments==2.19.1 - pyogrio==0.10.0 - pyparsing==3.2.3 - pyproj==3.6.1 - pyshp==2.3.1 - pytest==8.3.5 - python-dateutil==2.9.0.post0 - python-json-logger==3.3.0 - pytz==2025.2 - pyyaml==6.0.2 - pyzmq==26.3.0 - rasterio==1.4.3 - ratelim==0.1.6 - referencing==0.36.2 - requests==2.32.3 - rfc3339-validator==0.1.4 - rfc3986-validator==0.1.1 - rioxarray==0.15.0 - rpds-py==0.24.0 - rsa==4.9 - send2trash==1.8.3 - shapely==2.0.7 - six==1.17.0 - sniffio==1.3.1 - soupsieve==2.6 - stack-data==0.6.3 - terminado==0.18.1 - tinycss2==1.4.0 - tomli==2.2.1 - tornado==6.4.2 - tqdm==4.67.1 - traitlets==5.14.3 - traittypes==0.2.1 - types-python-dateutil==2.9.0.20241206 - typing-extensions==4.13.0 - tzdata==2025.2 - unidecode==1.3.8 - uri-template==1.3.0 - uritemplate==4.1.1 - urllib3==2.3.0 - virtualenv==20.29.3 - voila==0.5.8 - wcwidth==0.2.13 - webcolors==24.11.1 - webencodings==0.5.1 - websocket-client==1.8.0 - websockets==15.0.1 - whitebox==2.3.6 - whiteboxgui==2.3.0 - widgetsnbextension==3.6.10 - wrapt==1.17.2 - xarray==2024.7.0 - xarray-leaflet==0.2.3 - yarg==0.1.9 - zipp==3.21.0 prefix: /opt/conda/envs/sepal_ui
[ "tests/test_ThemeSelect.py::TestThemeSelect::test_init", "tests/test_ThemeSelect.py::TestThemeSelect::test_change_language", "tests/test_utils.py::TestUtils::test_set_config_theme" ]
[ "tests/test_SepalMap.py::TestSepalMap::test_init", "tests/test_SepalMap.py::TestSepalMap::test_set_drawing_controls", "tests/test_SepalMap.py::TestSepalMap::test_remove_last_layer", "tests/test_SepalMap.py::TestSepalMap::test_zoom_bounds", "tests/test_SepalMap.py::TestSepalMap::test_show_dc", "tests/test_SepalMap.py::TestSepalMap::test_change_cursor", "tests/test_SepalMap.py::TestSepalMap::test_add_colorbar", "tests/test_SepalMap.py::TestSepalMap::test_addLayer", "tests/test_SepalMap.py::TestSepalMap::test_get_viz_params", "tests/test_utils.py::TestUtils::test_init_ee" ]
[ "tests/test_LocaleSelect.py::TestLocalSelect::test_init", "tests/test_LocaleSelect.py::TestLocalSelect::test_change_language", "tests/test_SepalMap.py::TestSepalMap::test_get_basemap_list", "tests/test_utils.py::TestUtils::test_hide_component", "tests/test_utils.py::TestUtils::test_show_component", "tests/test_utils.py::TestUtils::test_download_link", "tests/test_utils.py::TestUtils::test_is_absolute", "tests/test_utils.py::TestUtils::test_random_string", "tests/test_utils.py::TestUtils::test_get_file_size", "tests/test_utils.py::TestUtils::test_catch_errors", "tests/test_utils.py::TestUtils::test_loading_button", "tests/test_utils.py::TestUtils::test_to_colors", "tests/test_utils.py::TestUtils::test_switch", "tests/test_utils.py::TestUtils::test_next_string", "tests/test_utils.py::TestUtils::test_set_config_locale" ]
[]
MIT License
null
12rambau__sepal_ui-459
a4b3091755a11ef31a3714858007a93b750b6a79
2022-05-04 08:13:02
7eb3f48735e1cfeac75fecf88dd8194c8daea3d3
diff --git a/docs/source/modules/sepal_ui.translator.Translator.rst b/docs/source/modules/sepal_ui.translator.Translator.rst index 60fa976c..642a3ab6 100644 --- a/docs/source/modules/sepal_ui.translator.Translator.rst +++ b/docs/source/modules/sepal_ui.translator.Translator.rst @@ -27,6 +27,7 @@ sepal\_ui.translator.Translator ~Translator.find_target ~Translator.available_locales ~Translator.merge_dict + ~Translator.delete_empty .. automethod:: sepal_ui.translator.Translator.missing_keys @@ -38,6 +39,8 @@ sepal\_ui.translator.Translator .. automethod:: sepal_ui.translator.Translator.merge_dict +.. automethod:: sepal_ui.translator.Translator.delete_empty + .. autofunction:: sepal_ui.translator.Translator.find_target \ No newline at end of file diff --git a/sepal_ui/message/en/locale.json b/sepal_ui/message/en/locale.json index 632249f8..22b77234 100644 --- a/sepal_ui/message/en/locale.json +++ b/sepal_ui/message/en/locale.json @@ -2,11 +2,6 @@ "test_key": "Test key", "status": "Status: {}", "widgets": { - "navdrawer": { - "code": "Source code", - "wiki": "Wiki", - "bug": "Bug report" - }, "asset_select": { "types": { "0": "Raster", diff --git a/sepal_ui/sepalwidgets/app.py b/sepal_ui/sepalwidgets/app.py index b004b9ee..df1e81d8 100644 --- a/sepal_ui/sepalwidgets/app.py +++ b/sepal_ui/sepalwidgets/app.py @@ -255,19 +255,13 @@ class NavDrawer(v.NavigationDrawer, SepalWidget): code_link = [] if code: - item_code = DrawerItem( - ms.widgets.navdrawer.code, icon="far fa-file-code", href=code - ) + item_code = DrawerItem("Source code", icon="far fa-file-code", href=code) code_link.append(item_code) if wiki: - item_wiki = DrawerItem( - ms.widgets.navdrawer.wiki, icon="fas fa-book-open", href=wiki - ) + item_wiki = DrawerItem("Wiki", icon="fas fa-book-open", href=wiki) code_link.append(item_wiki) if issue: - item_bug = DrawerItem( - ms.widgets.navdrawer.bug, icon="fas fa-bug", href=issue - ) + item_bug = DrawerItem("Bug report", icon="fas fa-bug", href=issue) code_link.append(item_bug) children = [ diff --git a/sepal_ui/translator/translator.py b/sepal_ui/translator/translator.py index f0a39f77..f4fdec47 100644 --- a/sepal_ui/translator/translator.py +++ b/sepal_ui/translator/translator.py @@ -166,7 +166,8 @@ class Translator(SimpleNamespace): Identify numbered dictionnaries embeded in the dict and transform them into lists This function is an helper to prevent deprecation after the introduction of pontoon for translation. - The user is now force to use keys even for numbered lists. SimpleNamespace doesn't support integer indexing so this function will transform back this "numbered" dictionnary (with integer keys) into lists. + The user is now force to use keys even for numbered lists. SimpleNamespace doesn't support integer indexing + so this function will transform back this "numbered" dictionnary (with integer keys) into lists. Args: d (dict): the dictionnary to sanitize @@ -252,7 +253,8 @@ class Translator(SimpleNamespace): """ gather all the .json file in the provided l10n folder as 1 single json dict - the json dict will be sanitysed and the key will be used as if they were coming from 1 single file. be careful with duplication + the json dict will be sanitysed and the key will be used as if they were coming from 1 single file. + be careful with duplication. empty string keys will be removed. Args: folder (pathlib.path) @@ -264,6 +266,29 @@ class Translator(SimpleNamespace): final_json = {} for f in folder.glob("*.json"): - final_json = {**final_json, **cls.sanitize(json.loads(f.read_text()))} + tmp_dict = cls.delete_empty(json.loads(f.read_text())) + final_json = {**final_json, **cls.sanitize(tmp_dict)} return final_json + + @versionadded(version="2.8.1") + @classmethod + def delete_empty(cls, d): + """ + Remove empty strings ("") recursively from the dictionaries. This is to prevent untranslated strings from + Crowdin to be uploaded. The dictionnary must only embed dictionnaries and no lists. + + Args: + d (dict): the dictionnary to sanitize + + Return: + (dict): the sanitized dictionnary + + """ + for k, v in list(d.items()): + if isinstance(v, dict): + cls.delete_empty(v) + elif v == "": + del d[k] + + return d
crowdin untranslated keys are marked as empty string These string are interpreted as "something" by the translator leading to empty strings everywhere in the build-in component. They should be ignored
12rambau/sepal_ui
diff --git a/tests/test_Translator.py b/tests/test_Translator.py index 930a533e..c6d0e85e 100644 --- a/tests/test_Translator.py +++ b/tests/test_Translator.py @@ -49,25 +49,29 @@ class TestTranslator: # a test dict with many embeded numbered list # but also an already existing list test = { - "foo1": {"0": "foo2", "1": "foo3"}, - "foo4": { - "foo5": {"0": "foo6", "1": "foo7"}, - "foo8": "foo9", - }, - "foo10": ["foo11", "foo12"], + "a": {"0": "b", "1": "c"}, + "d": {"e": {"0": "f", "1": "g"}, "h": "i"}, + "j": ["k", "l"], } # the sanitize version of this result = { - "foo1": ["foo2", "foo3"], - "foo4": {"foo5": ["foo6", "foo7"], "foo8": "foo9"}, - "foo10": ["foo11", "foo12"], + "a": ["b", "c"], + "d": {"e": ["f", "g"], "h": "i"}, + "j": ["k", "l"], } assert Translator.sanitize(test) == result return + def test_delete_empty(self): + + test = {"a": "", "b": 1, "c": {"d": ""}, "e": {"f": "", "g": 2}} + result = {"b": 1, "c": {}, "e": {"g": 2}} + + assert Translator.delete_empty(test) == result + def test_missing_keys(self, translation_folder): # check that all keys are in the fr dict
{ "commit_name": "head_commit", "failed_lite_validators": [ "has_short_problem_statement", "has_many_modified_files", "has_many_hunks" ], "has_test_patch": true, "is_lite": false, "llm_score": { "difficulty_score": 1, "issue_text_score": 2, "test_score": 0 }, "num_modified_files": 4 }
2.8
{ "env_vars": null, "env_yml_path": null, "install": "pip install -e .[dev]", "log_parser": "parse_log_pytest", "no_use_env": null, "packages": "requirements.txt", "pip_packages": [ "pytest" ], "pre_install": null, "python": "3.9", "reqs_path": null, "test_cmd": "pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning" }
affine==2.4.0 anyio==4.9.0 argon2-cffi==23.1.0 argon2-cffi-bindings==21.2.0 arrow==1.3.0 asttokens==3.0.0 async-lru==2.0.5 attrs==25.3.0 babel==2.17.0 backcall==0.2.0 beautifulsoup4==4.13.3 bleach==6.2.0 bqplot==0.12.44 branca==0.4.2 cachetools==5.5.2 certifi==2025.1.31 cffi==1.17.1 cfgv==3.4.0 charset-normalizer==3.4.1 click==8.1.8 click-plugins==1.1.1 cligj==0.7.2 colorama==0.4.6 colour==0.1.5 comm==0.2.2 contourpy==1.3.0 cryptography==44.0.2 cycler==0.12.1 debugpy==1.8.13 decorator==5.2.1 deepdiff==8.4.2 defusedxml==0.7.1 Deprecated==1.2.18 distlib==0.3.9 docopt==0.6.2 earthengine-api==1.5.8 EditorConfig==0.17.0 exceptiongroup==1.2.2 executing==2.2.0 fastjsonschema==2.21.1 ffmpeg-python==0.2.0 filelock==3.18.0 folium==0.13.0 fonttools==4.56.0 fqdn==1.5.1 future==1.0.0 geeadd==1.2.1 geemap==0.8.9 geocoder==1.38.1 geopandas==1.0.1 google-api-core==2.24.2 google-api-python-client==2.166.0 google-auth==2.38.0 google-auth-httplib2==0.2.0 google-cloud-core==2.4.3 google-cloud-storage==3.1.0 google-crc32c==1.7.1 google-resumable-media==2.7.2 googleapis-common-protos==1.69.2 h11==0.14.0 haversine==2.9.0 httpcore==1.0.7 httplib2==0.22.0 httpx==0.28.1 identify==2.6.9 idna==3.10 importlib_metadata==8.6.1 importlib_resources==6.5.2 iniconfig==2.1.0 ipyevents==2.0.2 ipyfilechooser==0.6.0 ipykernel==6.29.5 ipyleaflet==0.13.3 ipynb-py-convert==0.4.6 ipyspin==1.0.1 ipython==8.12.3 ipython-genutils==0.2.0 ipytree==0.2.2 ipyurl==0.1.3 ipyvue==1.11.2 ipyvuetify==1.11.1 ipywidgets==7.8.5 isoduration==20.11.0 jedi==0.19.2 Jinja2==3.1.6 jsbeautifier==1.15.4 json5==0.10.0 jsonpointer==3.0.0 jsonschema==4.23.0 jsonschema-specifications==2024.10.1 jupyter-events==0.12.0 jupyter-lsp==2.2.5 jupyter_client==8.6.3 jupyter_core==5.7.2 jupyter_server==2.15.0 jupyter_server_terminals==0.5.3 jupyter_server_xarray_leaflet==0.2.3 jupyterlab==4.3.6 jupyterlab_pygments==0.3.0 jupyterlab_server==2.27.3 jupyterlab_widgets==1.1.11 kiwisolver==1.4.7 logzero==1.7.0 Markdown==3.7 MarkupSafe==3.0.2 matplotlib==3.9.4 matplotlib-inline==0.1.7 mercantile==1.2.1 mistune==3.1.3 mss==10.0.0 natsort==8.4.0 nbclient==0.10.2 nbconvert==7.16.6 nbformat==5.10.4 nest-asyncio==1.6.0 nodeenv==1.9.1 notebook==7.3.3 notebook_shim==0.2.4 numpy==2.0.2 orderly-set==5.3.0 overrides==7.7.0 packaging==24.2 pandas==2.2.3 pandocfilters==1.5.1 parso==0.8.4 pexpect==4.9.0 pickleshare==0.7.5 pillow==11.1.0 pipreqs==0.5.0 platformdirs==4.3.7 pluggy==1.5.0 pre_commit==4.2.0 prometheus_client==0.21.1 prompt_toolkit==3.0.50 proto-plus==1.26.1 protobuf==6.30.2 psutil==7.0.0 ptyprocess==0.7.0 pure_eval==0.2.3 pyasn1==0.6.1 pyasn1_modules==0.4.2 pycparser==2.22 PyCRS==1.0.2 Pygments==2.19.1 pyogrio==0.10.0 pyparsing==3.2.3 pyproj==3.6.1 pyshp==2.3.1 pytest==8.3.5 python-dateutil==2.9.0.post0 python-json-logger==3.3.0 pytz==2025.2 PyYAML==6.0.2 pyzmq==26.3.0 rasterio==1.4.3 ratelim==0.1.6 referencing==0.36.2 requests==2.32.3 rfc3339-validator==0.1.4 rfc3986-validator==0.1.1 rioxarray==0.15.0 rpds-py==0.24.0 rsa==4.9 Send2Trash==1.8.3 -e git+https://github.com/12rambau/sepal_ui.git@a4b3091755a11ef31a3714858007a93b750b6a79#egg=sepal_ui shapely==2.0.7 six==1.17.0 sniffio==1.3.1 soupsieve==2.6 stack-data==0.6.3 terminado==0.18.1 tinycss2==1.4.0 tomli==2.2.1 tornado==6.4.2 tqdm==4.67.1 traitlets==5.14.3 traittypes==0.2.1 types-python-dateutil==2.9.0.20241206 typing_extensions==4.13.0 tzdata==2025.2 Unidecode==1.3.8 uri-template==1.3.0 uritemplate==4.1.1 urllib3==2.3.0 virtualenv==20.29.3 voila==0.5.8 wcwidth==0.2.13 webcolors==24.11.1 webencodings==0.5.1 websocket-client==1.8.0 websockets==15.0.1 whitebox==2.3.6 whiteboxgui==2.3.0 widgetsnbextension==3.6.10 wrapt==1.17.2 xarray==2024.7.0 xarray_leaflet==0.2.3 yarg==0.1.9 zipp==3.21.0
name: sepal_ui channels: - defaults - https://repo.anaconda.com/pkgs/main - https://repo.anaconda.com/pkgs/r - conda-forge dependencies: - _libgcc_mutex=0.1=main - _openmp_mutex=5.1=1_gnu - ca-certificates=2025.2.25=h06a4308_0 - ld_impl_linux-64=2.40=h12ee557_0 - libffi=3.4.4=h6a678d5_1 - libgcc-ng=11.2.0=h1234567_1 - libgomp=11.2.0=h1234567_1 - libstdcxx-ng=11.2.0=h1234567_1 - ncurses=6.4=h6a678d5_0 - openssl=3.0.16=h5eee18b_0 - pip=25.0=py39h06a4308_0 - python=3.9.21=he870216_1 - readline=8.2=h5eee18b_0 - setuptools=75.8.0=py39h06a4308_0 - sqlite=3.45.3=h5eee18b_0 - tk=8.6.14=h39e8969_0 - wheel=0.45.1=py39h06a4308_0 - xz=5.6.4=h5eee18b_1 - zlib=1.2.13=h5eee18b_1 - pip: - affine==2.4.0 - anyio==4.9.0 - argon2-cffi==23.1.0 - argon2-cffi-bindings==21.2.0 - arrow==1.3.0 - asttokens==3.0.0 - async-lru==2.0.5 - attrs==25.3.0 - babel==2.17.0 - backcall==0.2.0 - beautifulsoup4==4.13.3 - bleach==6.2.0 - bqplot==0.12.44 - branca==0.4.2 - cachetools==5.5.2 - certifi==2025.1.31 - cffi==1.17.1 - cfgv==3.4.0 - charset-normalizer==3.4.1 - click==8.1.8 - click-plugins==1.1.1 - cligj==0.7.2 - colorama==0.4.6 - colour==0.1.5 - comm==0.2.2 - contourpy==1.3.0 - cryptography==44.0.2 - cycler==0.12.1 - debugpy==1.8.13 - decorator==5.2.1 - deepdiff==8.4.2 - defusedxml==0.7.1 - deprecated==1.2.18 - distlib==0.3.9 - docopt==0.6.2 - earthengine-api==1.5.8 - editorconfig==0.17.0 - exceptiongroup==1.2.2 - executing==2.2.0 - fastjsonschema==2.21.1 - ffmpeg-python==0.2.0 - filelock==3.18.0 - folium==0.13.0 - fonttools==4.56.0 - fqdn==1.5.1 - future==1.0.0 - geeadd==1.2.1 - geemap==0.8.9 - geocoder==1.38.1 - geopandas==1.0.1 - google-api-core==2.24.2 - google-api-python-client==2.166.0 - google-auth==2.38.0 - google-auth-httplib2==0.2.0 - google-cloud-core==2.4.3 - google-cloud-storage==3.1.0 - google-crc32c==1.7.1 - google-resumable-media==2.7.2 - googleapis-common-protos==1.69.2 - h11==0.14.0 - haversine==2.9.0 - httpcore==1.0.7 - httplib2==0.22.0 - httpx==0.28.1 - identify==2.6.9 - idna==3.10 - importlib-metadata==8.6.1 - importlib-resources==6.5.2 - iniconfig==2.1.0 - ipyevents==2.0.2 - ipyfilechooser==0.6.0 - ipykernel==6.29.5 - ipyleaflet==0.13.3 - ipynb-py-convert==0.4.6 - ipyspin==1.0.1 - ipython==8.12.3 - ipython-genutils==0.2.0 - ipytree==0.2.2 - ipyurl==0.1.3 - ipyvue==1.11.2 - ipyvuetify==1.11.1 - ipywidgets==7.8.5 - isoduration==20.11.0 - jedi==0.19.2 - jinja2==3.1.6 - jsbeautifier==1.15.4 - json5==0.10.0 - jsonpointer==3.0.0 - jsonschema==4.23.0 - jsonschema-specifications==2024.10.1 - jupyter-client==8.6.3 - jupyter-core==5.7.2 - jupyter-events==0.12.0 - jupyter-lsp==2.2.5 - jupyter-server==2.15.0 - jupyter-server-terminals==0.5.3 - jupyter-server-xarray-leaflet==0.2.3 - jupyterlab==4.3.6 - jupyterlab-pygments==0.3.0 - jupyterlab-server==2.27.3 - jupyterlab-widgets==1.1.11 - kiwisolver==1.4.7 - logzero==1.7.0 - markdown==3.7 - markupsafe==3.0.2 - matplotlib==3.9.4 - matplotlib-inline==0.1.7 - mercantile==1.2.1 - mistune==3.1.3 - mss==10.0.0 - natsort==8.4.0 - nbclient==0.10.2 - nbconvert==7.16.6 - nbformat==5.10.4 - nest-asyncio==1.6.0 - nodeenv==1.9.1 - notebook==7.3.3 - notebook-shim==0.2.4 - numpy==2.0.2 - orderly-set==5.3.0 - overrides==7.7.0 - packaging==24.2 - pandas==2.2.3 - pandocfilters==1.5.1 - parso==0.8.4 - pexpect==4.9.0 - pickleshare==0.7.5 - pillow==11.1.0 - pipreqs==0.5.0 - platformdirs==4.3.7 - pluggy==1.5.0 - pre-commit==4.2.0 - prometheus-client==0.21.1 - prompt-toolkit==3.0.50 - proto-plus==1.26.1 - protobuf==6.30.2 - psutil==7.0.0 - ptyprocess==0.7.0 - pure-eval==0.2.3 - pyasn1==0.6.1 - pyasn1-modules==0.4.2 - pycparser==2.22 - pycrs==1.0.2 - pygments==2.19.1 - pyogrio==0.10.0 - pyparsing==3.2.3 - pyproj==3.6.1 - pyshp==2.3.1 - pytest==8.3.5 - python-dateutil==2.9.0.post0 - python-json-logger==3.3.0 - pytz==2025.2 - pyyaml==6.0.2 - pyzmq==26.3.0 - rasterio==1.4.3 - ratelim==0.1.6 - referencing==0.36.2 - requests==2.32.3 - rfc3339-validator==0.1.4 - rfc3986-validator==0.1.1 - rioxarray==0.15.0 - rpds-py==0.24.0 - rsa==4.9 - send2trash==1.8.3 - shapely==2.0.7 - six==1.17.0 - sniffio==1.3.1 - soupsieve==2.6 - stack-data==0.6.3 - terminado==0.18.1 - tinycss2==1.4.0 - tomli==2.2.1 - tornado==6.4.2 - tqdm==4.67.1 - traitlets==5.14.3 - traittypes==0.2.1 - types-python-dateutil==2.9.0.20241206 - typing-extensions==4.13.0 - tzdata==2025.2 - unidecode==1.3.8 - uri-template==1.3.0 - uritemplate==4.1.1 - urllib3==2.3.0 - virtualenv==20.29.3 - voila==0.5.8 - wcwidth==0.2.13 - webcolors==24.11.1 - webencodings==0.5.1 - websocket-client==1.8.0 - websockets==15.0.1 - whitebox==2.3.6 - whiteboxgui==2.3.0 - widgetsnbextension==3.6.10 - wrapt==1.17.2 - xarray==2024.7.0 - xarray-leaflet==0.2.3 - yarg==0.1.9 - zipp==3.21.0 prefix: /opt/conda/envs/sepal_ui
[ "tests/test_Translator.py::TestTranslator::test_delete_empty" ]
[]
[ "tests/test_Translator.py::TestTranslator::test_init", "tests/test_Translator.py::TestTranslator::test_search_key", "tests/test_Translator.py::TestTranslator::test_sanitize", "tests/test_Translator.py::TestTranslator::test_missing_keys", "tests/test_Translator.py::TestTranslator::test_find_target", "tests/test_Translator.py::TestTranslator::test_available_locales" ]
[]
MIT License
null
12rambau__sepal_ui-501
7eb3f48735e1cfeac75fecf88dd8194c8daea3d3
2022-06-09 11:09:52
7eb3f48735e1cfeac75fecf88dd8194c8daea3d3
diff --git a/docs/source/modules/sepal_ui.translator.Translator.rst b/docs/source/modules/sepal_ui.translator.Translator.rst index 642a3ab6..7f11e39f 100644 --- a/docs/source/modules/sepal_ui.translator.Translator.rst +++ b/docs/source/modules/sepal_ui.translator.Translator.rst @@ -2,19 +2,6 @@ sepal\_ui.translator.Translator =============================== .. autoclass:: sepal_ui.translator.Translator - - .. rubric:: Attributes - - .. autosummary:: - - ~Translator.default_dict - ~Translator.target_dict - ~Translator.default - ~Translator.target - ~Translator.targeted - ~Translator.match - ~Translator.keys - ~Translator.folder .. rubric:: Methods @@ -33,7 +20,7 @@ sepal\_ui.translator.Translator .. automethod:: sepal_ui.translator.Translator.sanitize -.. automethod:: sepal_ui.translator.Translator.search_key +.. autofunction:: sepal_ui.translator.Translator.search_key .. automethod:: sepal_ui.translator.Translator.available_locales diff --git a/sepal_ui/sepalwidgets/app.py b/sepal_ui/sepalwidgets/app.py index 96c10461..bfd59e3d 100644 --- a/sepal_ui/sepalwidgets/app.py +++ b/sepal_ui/sepalwidgets/app.py @@ -602,7 +602,7 @@ class LocaleSelect(v.Menu, SepalWidget): # extract the language information from the translator # if not set default to english - code = "en" if translator is None else translator.target + code = "en" if translator is None else translator._target loc = self.COUNTRIES[self.COUNTRIES.code == code].squeeze() attr = {**self.ATTR, "src": self.FLAG.format(loc.flag), "alt": loc.name} diff --git a/sepal_ui/translator/translator.py b/sepal_ui/translator/translator.py index f4fdec47..efa29bc9 100644 --- a/sepal_ui/translator/translator.py +++ b/sepal_ui/translator/translator.py @@ -1,21 +1,26 @@ import json -from types import SimpleNamespace from pathlib import Path from collections import abc -from deepdiff import DeepDiff from configparser import ConfigParser -from deprecated.sphinx import versionadded +from deprecated.sphinx import versionadded, deprecated +from box import Box from sepal_ui import config_file -class Translator(SimpleNamespace): +class Translator(Box): """ - The translator is a SimpleNamespace of Simplenamespace. It reads 2 Json files, the first one being the source language (usually English) and the second one the target language. + The translator is a Python Box of boxes. It reads 2 Json files, the first one being the source language (usually English) and the second one the target language. It will replace in the source dictionary every key that exist in both json dictionaries. Following this procedure, every message that is not translated can still be accessed in the source language. To access the dictionary keys, instead of using [], you can simply use key name as in an object ex: translator.first_key.secondary_key. There are no depth limits, just respect the snake_case convention when naming your keys in the .json files. + 5 internal keys are created upon initialization (there name cannot be used as keys in the translation message): + - (str) _default : the default locale of the translator + - (str) _targeted : the initially requested language. Use to display debug information to the user agent + - (str) _target : the target locale of the translator + - (bool) _match : if the target language match the one requested one by user, used to trigger information in appBar + - (str) _folder : the path to the l10n folder Args: json_folder (str | pathlib.Path): The folder where the dictionaries are stored @@ -23,75 +28,60 @@ class Translator(SimpleNamespace): default (str, optional): The language code (IETF BCP 47) of the source lang. default to "en" (it should be the same as the source dictionary) """ - FORBIDDEN_KEYS = [ - "default_dict", - "target_dict", - "in", - "class", - "default", - "target", - "match", - ] - "list(str): list of the forbidden keys, using one of them in a translation dict will throw an error" - - target_dict = {} - "(dict): the target language dictionary" - - default_dict = {} - "dict: the source language dictionary" - - default = None - "str: the default locale of the translator" - - targeted = None - "str: the initially requested language. Use to display debug information to the user agent" - - target = None - "str: the target locale of the translator" - - match = None - "bool: if the target language match the one requested one by user, used to trigger information in appBar" - - keys = None - "all the keys can be acceced as attributes" - - folder = None - "pathlib.Path: the path to the l10n folder" + _protected_keys = [ + "find_target", + "search_key", + "sanitize", + "_update", + "missing_keys", + "available_locales", + "merge_dict", + "delete_empty", + ] + dir(Box) + "keys that cannot be used as var names as they are protected for methods" def __init__(self, json_folder, target=None, default="en"): - # init the simple namespace - super().__init__() + # the name of the 5 variables that cannot be used as init keys + FORBIDDEN_KEYS = ["_folder", "_default", "_target", "_targeted", "_match"] - # force cast to path - self.folder = Path(json_folder) + # init the box with the folder + folder = Path(json_folder) # reading the default dict - self.default = default - self.default_dict = self.merge_dict(self.folder / default) + default_dict = self.merge_dict(folder / default) # create a dictionary in the target language - self.targeted, target = self.find_target(self.folder, target) - self.target = target or default - self.target_dict = self.merge_dict(self.folder / self.target) + targeted, target = self.find_target(folder, target) + target = target or default + target_dict = self.merge_dict(folder / target) # evaluate the matching of requested and obtained values - self.match = self.targeted == self.target + match = targeted == target # create the composite dictionary - ms_dict = self._update(self.default_dict, self.target_dict) + ms_dict = self._update(default_dict, target_dict) # check if forbidden keys are being used - [self.search_key(ms_dict, k) for k in self.FORBIDDEN_KEYS] + # this will raise an error if any + [self.search_key(ms_dict, k) for k in FORBIDDEN_KEYS] - # transform it into a json str + # # unpack the json as a simple namespace ms_json = json.dumps(ms_dict) + ms_boxes = json.loads(ms_json, object_hook=lambda d: Box(**d, frozen_box=True)) - # unpack the json as a simple namespace - ms = json.loads(ms_json, object_hook=lambda d: SimpleNamespace(**d)) + private_keys = { + "_folder": str(folder), + "_default": default, + "_targeted": targeted, + "_target": target, + "_match": match, + } - for k, v in ms.__dict__.items(): - setattr(self, k, getattr(ms, k)) + # the final box is not frozen + # waiting for an answer here: https://github.com/cdgriffith/Box/issues/223 + # it the meantime it's easy to call the translator using a frozen_box argument + super(Box, self).__init__(**private_keys, **ms_boxes) @versionadded(version="2.7.0") @staticmethod @@ -139,8 +129,8 @@ class Translator(SimpleNamespace): return (target, lang) - @classmethod - def search_key(cls, d, key): + @staticmethod + def search_key(d, key): """ Search a specific key in the d dictionary and raise an error if found @@ -149,14 +139,9 @@ class Translator(SimpleNamespace): key (str): the key to look for """ - for k, v in d.items(): - if isinstance(v, abc.Mapping): - cls.search_key(v, key) - else: - if k == key: - raise Exception( - f"You cannot use the key {key} in your translation dictionary" - ) + if key in d: + msg = f"You cannot use the key {key} in your translation dictionary" + raise Exception(msg) return @@ -218,34 +203,19 @@ class Translator(SimpleNamespace): return ms + @deprecated(version="2.9.0", reason="Not needed with automatic translators") def missing_keys(self): - """ - this function is intended for developer use only - print the list of the missing keys in the target dictionnairie - - Return: - (str): the list of missing keys - """ - - # find all the missing keys - try: - ddiff = DeepDiff(self.default_dict, self.target_dict)[ - "dictionary_item_removed" - ] - except Exception: - ddiff = ["All messages are translated"] - - return "\n".join(ddiff) + pass def available_locales(self): """ Return the available locales in the l10n folder Return: - (list): the lilst of str codes + (list): the list of str codes """ - return [f.name for f in self.folder.iterdir() if f.is_dir()] + return [f.name for f in Path(self._folder).glob("[!^._]*") if f.is_dir()] @versionadded(version="2.7.0") @classmethod
use box for the translator ? I discovered this lib while working on the geemap drop. I think it could be super handy for the translator keys and maybe faster. https://github.com/cdgriffith/Box side note: we will need it anyway for the geemap drop
12rambau/sepal_ui
diff --git a/tests/test_Translator.py b/tests/test_Translator.py index c6d0e85e..ff6c46f8 100644 --- a/tests/test_Translator.py +++ b/tests/test_Translator.py @@ -35,9 +35,10 @@ class TestTranslator: def test_search_key(self): - # assert that having a wrong key in the json will raise an error + # assert that having a wrong key at root level + # in the json will raise an error key = "toto" - d = {"a": {"toto": "b"}, "c": "d"} + d = {"toto": {"a": "b"}, "c": "d"} with pytest.raises(Exception): Translator.search_key(d, key) @@ -72,16 +73,6 @@ class TestTranslator: assert Translator.delete_empty(test) == result - def test_missing_keys(self, translation_folder): - - # check that all keys are in the fr dict - translator = Translator(translation_folder, "fr") - assert translator.missing_keys() == "All messages are translated" - - # check that 1 key is missing - translator = Translator(translation_folder, "es") - assert translator.missing_keys() == "root['test_key']" - return def test_find_target(self, translation_folder): @@ -114,6 +105,12 @@ class TestTranslator: for locale in res: assert locale in translator.available_locales() + # Check no hidden and protected files are in locales + locales = translator.available_locales() + assert not all( + [(loc.startswith(".") or loc.startswith("_")) for loc in locales] + ) + return @pytest.fixture(scope="class")
{ "commit_name": "head_commit", "failed_lite_validators": [ "has_hyperlinks", "has_many_modified_files", "has_many_hunks" ], "has_test_patch": true, "is_lite": false, "llm_score": { "difficulty_score": 1, "issue_text_score": 3, "test_score": 3 }, "num_modified_files": 3 }
2.8
{ "env_vars": null, "env_yml_path": null, "install": "pip install -e .[dev]", "log_parser": "parse_log_pytest", "no_use_env": null, "packages": "pytest", "pip_packages": [ "pytest", "coverage" ], "pre_install": null, "python": "3.9", "reqs_path": null, "test_cmd": "pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning" }
affine==2.4.0 anyio==4.9.0 argon2-cffi==23.1.0 argon2-cffi-bindings==21.2.0 arrow==1.3.0 asttokens==3.0.0 async-lru==2.0.5 attrs==25.3.0 babel==2.17.0 backcall==0.2.0 beautifulsoup4==4.13.3 bleach==6.2.0 branca==0.8.1 cachetools==5.5.2 certifi==2025.1.31 cffi==1.17.1 cfgv==3.4.0 charset-normalizer==3.4.1 click==8.1.8 click-plugins==1.1.1 cligj==0.7.2 cloudpickle==3.1.1 colorama==0.4.6 comm==0.2.2 contourpy==1.3.0 coverage==7.8.0 cryptography==44.0.2 cycler==0.12.1 dask==2024.8.0 debugpy==1.8.13 decorator==5.2.1 deepdiff==8.4.2 defusedxml==0.7.1 Deprecated==1.2.18 distlib==0.3.9 docopt==0.6.2 earthengine-api==1.5.8 exceptiongroup @ file:///croot/exceptiongroup_1706031385326/work executing==2.2.0 fastjsonschema==2.21.1 filelock==3.18.0 fonttools==4.56.0 fqdn==1.5.1 fsspec==2025.3.2 geojson==3.2.0 geopandas==1.0.1 google-api-core==2.24.2 google-api-python-client==2.166.0 google-auth==2.38.0 google-auth-httplib2==0.2.0 google-cloud-core==2.4.3 google-cloud-storage==3.1.0 google-crc32c==1.7.1 google-resumable-media==2.7.2 googleapis-common-protos==1.69.2 h11==0.14.0 haversine==2.9.0 httpcore==1.0.7 httplib2==0.22.0 httpx==0.28.1 identify==2.6.9 idna==3.10 importlib_metadata==8.6.1 importlib_resources==6.5.2 iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work ipykernel==6.29.5 ipyleaflet==0.19.2 ipyspin==1.0.1 ipython==8.12.3 ipython-genutils==0.2.0 ipyurl==0.1.3 ipyvue==1.11.2 ipyvuetify==1.11.1 ipywidgets==7.8.5 isoduration==20.11.0 jedi==0.19.2 Jinja2==3.1.6 json5==0.10.0 jsonpointer==3.0.0 jsonschema==4.23.0 jsonschema-specifications==2024.10.1 jupyter-events==0.12.0 jupyter-leaflet==0.19.2 jupyter-lsp==2.2.5 jupyter_client==8.6.3 jupyter_core==5.7.2 jupyter_server==2.15.0 jupyter_server_terminals==0.5.3 jupyter_server_xarray_leaflet==0.2.3 jupyterlab==4.3.6 jupyterlab_pygments==0.3.0 jupyterlab_server==2.27.3 jupyterlab_widgets==1.1.11 kiwisolver==1.4.7 locket==1.0.0 Markdown==3.7 MarkupSafe==3.0.2 matplotlib==3.9.4 matplotlib-inline==0.1.7 mercantile==1.2.1 mistune==3.1.3 natsort==8.4.0 nbclient==0.10.2 nbconvert==7.16.6 nbformat==5.10.4 nest-asyncio==1.6.0 nodeenv==1.9.1 notebook==7.3.3 notebook_shim==0.2.4 numpy==2.0.2 orderly-set==5.3.0 overrides==7.7.0 packaging @ file:///croot/packaging_1734472117206/work pandas==2.2.3 pandocfilters==1.5.1 parso==0.8.4 partd==1.4.2 pexpect==4.9.0 pickleshare==0.7.5 pillow==11.1.0 pipreqs==0.5.0 planet==2.19.0 platformdirs==4.3.7 pluggy @ file:///croot/pluggy_1733169602837/work pre_commit==4.2.0 prometheus_client==0.21.1 prompt_toolkit==3.0.50 proto-plus==1.26.1 protobuf==6.30.2 psutil==7.0.0 ptyprocess==0.7.0 pure_eval==0.2.3 pyasn1==0.6.1 pyasn1_modules==0.4.2 pycparser==2.22 Pygments==2.19.1 PyJWT==2.10.1 pyogrio==0.10.0 pyparsing==3.2.3 pyproj==3.6.1 pytest @ file:///croot/pytest_1738938843180/work python-box==7.3.2 python-dateutil==2.9.0.post0 python-json-logger==3.3.0 pytz==2025.2 PyYAML==6.0.2 pyzmq==26.3.0 rasterio==1.4.3 referencing==0.36.2 requests==2.32.3 rfc3339-validator==0.1.4 rfc3986-validator==0.1.1 rioxarray==0.15.0 rpds-py==0.24.0 rsa==4.9 Send2Trash==1.8.3 -e git+https://github.com/12rambau/sepal_ui.git@7eb3f48735e1cfeac75fecf88dd8194c8daea3d3#egg=sepal_ui shapely==2.0.7 six==1.17.0 sniffio==1.3.1 soupsieve==2.6 stack-data==0.6.3 terminado==0.18.1 tinycss2==1.4.0 tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work toolz==1.0.0 tornado==6.4.2 tqdm==4.67.1 traitlets==5.14.3 traittypes==0.2.1 types-python-dateutil==2.9.0.20241206 typing_extensions==4.13.0 tzdata==2025.2 Unidecode==1.3.8 uri-template==1.3.0 uritemplate==4.1.1 urllib3==2.3.0 virtualenv==20.29.3 wcwidth==0.2.13 webcolors==24.11.1 webencodings==0.5.1 websocket-client==1.8.0 widgetsnbextension==3.6.10 wrapt==1.17.2 xarray==2024.7.0 xarray_leaflet==0.2.3 xyzservices==2025.1.0 yarg==0.1.9 zipp==3.21.0
name: sepal_ui channels: - defaults - https://repo.anaconda.com/pkgs/main - https://repo.anaconda.com/pkgs/r - conda-forge dependencies: - _libgcc_mutex=0.1=main - _openmp_mutex=5.1=1_gnu - ca-certificates=2025.2.25=h06a4308_0 - exceptiongroup=1.2.0=py39h06a4308_0 - iniconfig=1.1.1=pyhd3eb1b0_0 - ld_impl_linux-64=2.40=h12ee557_0 - libffi=3.4.4=h6a678d5_1 - libgcc-ng=11.2.0=h1234567_1 - libgomp=11.2.0=h1234567_1 - libstdcxx-ng=11.2.0=h1234567_1 - ncurses=6.4=h6a678d5_0 - openssl=3.0.16=h5eee18b_0 - packaging=24.2=py39h06a4308_0 - pip=25.0=py39h06a4308_0 - pluggy=1.5.0=py39h06a4308_0 - pytest=8.3.4=py39h06a4308_0 - python=3.9.21=he870216_1 - readline=8.2=h5eee18b_0 - setuptools=75.8.0=py39h06a4308_0 - sqlite=3.45.3=h5eee18b_0 - tk=8.6.14=h39e8969_0 - tomli=2.0.1=py39h06a4308_0 - wheel=0.45.1=py39h06a4308_0 - xz=5.6.4=h5eee18b_1 - zlib=1.2.13=h5eee18b_1 - pip: - affine==2.4.0 - anyio==4.9.0 - argon2-cffi==23.1.0 - argon2-cffi-bindings==21.2.0 - arrow==1.3.0 - asttokens==3.0.0 - async-lru==2.0.5 - attrs==25.3.0 - babel==2.17.0 - backcall==0.2.0 - beautifulsoup4==4.13.3 - bleach==6.2.0 - branca==0.8.1 - cachetools==5.5.2 - certifi==2025.1.31 - cffi==1.17.1 - cfgv==3.4.0 - charset-normalizer==3.4.1 - click==8.1.8 - click-plugins==1.1.1 - cligj==0.7.2 - cloudpickle==3.1.1 - colorama==0.4.6 - comm==0.2.2 - contourpy==1.3.0 - coverage==7.8.0 - cryptography==44.0.2 - cycler==0.12.1 - dask==2024.8.0 - debugpy==1.8.13 - decorator==5.2.1 - deepdiff==8.4.2 - defusedxml==0.7.1 - deprecated==1.2.18 - distlib==0.3.9 - docopt==0.6.2 - earthengine-api==1.5.8 - executing==2.2.0 - fastjsonschema==2.21.1 - filelock==3.18.0 - fonttools==4.56.0 - fqdn==1.5.1 - fsspec==2025.3.2 - geojson==3.2.0 - geopandas==1.0.1 - google-api-core==2.24.2 - google-api-python-client==2.166.0 - google-auth==2.38.0 - google-auth-httplib2==0.2.0 - google-cloud-core==2.4.3 - google-cloud-storage==3.1.0 - google-crc32c==1.7.1 - google-resumable-media==2.7.2 - googleapis-common-protos==1.69.2 - h11==0.14.0 - haversine==2.9.0 - httpcore==1.0.7 - httplib2==0.22.0 - httpx==0.28.1 - identify==2.6.9 - idna==3.10 - importlib-metadata==8.6.1 - importlib-resources==6.5.2 - ipykernel==6.29.5 - ipyleaflet==0.19.2 - ipyspin==1.0.1 - ipython==8.12.3 - ipython-genutils==0.2.0 - ipyurl==0.1.3 - ipyvue==1.11.2 - ipyvuetify==1.11.1 - ipywidgets==7.8.5 - isoduration==20.11.0 - jedi==0.19.2 - jinja2==3.1.6 - json5==0.10.0 - jsonpointer==3.0.0 - jsonschema==4.23.0 - jsonschema-specifications==2024.10.1 - jupyter-client==8.6.3 - jupyter-core==5.7.2 - jupyter-events==0.12.0 - jupyter-leaflet==0.19.2 - jupyter-lsp==2.2.5 - jupyter-server==2.15.0 - jupyter-server-terminals==0.5.3 - jupyter-server-xarray-leaflet==0.2.3 - jupyterlab==4.3.6 - jupyterlab-pygments==0.3.0 - jupyterlab-server==2.27.3 - jupyterlab-widgets==1.1.11 - kiwisolver==1.4.7 - locket==1.0.0 - markdown==3.7 - markupsafe==3.0.2 - matplotlib==3.9.4 - matplotlib-inline==0.1.7 - mercantile==1.2.1 - mistune==3.1.3 - natsort==8.4.0 - nbclient==0.10.2 - nbconvert==7.16.6 - nbformat==5.10.4 - nest-asyncio==1.6.0 - nodeenv==1.9.1 - notebook==7.3.3 - notebook-shim==0.2.4 - numpy==2.0.2 - orderly-set==5.3.0 - overrides==7.7.0 - pandas==2.2.3 - pandocfilters==1.5.1 - parso==0.8.4 - partd==1.4.2 - pexpect==4.9.0 - pickleshare==0.7.5 - pillow==11.1.0 - pipreqs==0.5.0 - planet==2.19.0 - platformdirs==4.3.7 - pre-commit==4.2.0 - prometheus-client==0.21.1 - prompt-toolkit==3.0.50 - proto-plus==1.26.1 - protobuf==6.30.2 - psutil==7.0.0 - ptyprocess==0.7.0 - pure-eval==0.2.3 - pyasn1==0.6.1 - pyasn1-modules==0.4.2 - pycparser==2.22 - pygments==2.19.1 - pyjwt==2.10.1 - pyogrio==0.10.0 - pyparsing==3.2.3 - pyproj==3.6.1 - python-box==7.3.2 - python-dateutil==2.9.0.post0 - python-json-logger==3.3.0 - pytz==2025.2 - pyyaml==6.0.2 - pyzmq==26.3.0 - rasterio==1.4.3 - referencing==0.36.2 - requests==2.32.3 - rfc3339-validator==0.1.4 - rfc3986-validator==0.1.1 - rioxarray==0.15.0 - rpds-py==0.24.0 - rsa==4.9 - send2trash==1.8.3 - shapely==2.0.7 - six==1.17.0 - sniffio==1.3.1 - soupsieve==2.6 - stack-data==0.6.3 - terminado==0.18.1 - tinycss2==1.4.0 - toolz==1.0.0 - tornado==6.4.2 - tqdm==4.67.1 - traitlets==5.14.3 - traittypes==0.2.1 - types-python-dateutil==2.9.0.20241206 - typing-extensions==4.13.0 - tzdata==2025.2 - unidecode==1.3.8 - uri-template==1.3.0 - uritemplate==4.1.1 - urllib3==2.3.0 - virtualenv==20.29.3 - wcwidth==0.2.13 - webcolors==24.11.1 - webencodings==0.5.1 - websocket-client==1.8.0 - widgetsnbextension==3.6.10 - wrapt==1.17.2 - xarray==2024.7.0 - xarray-leaflet==0.2.3 - xyzservices==2025.1.0 - yarg==0.1.9 - zipp==3.21.0 prefix: /opt/conda/envs/sepal_ui
[ "tests/test_Translator.py::TestTranslator::test_search_key" ]
[]
[ "tests/test_Translator.py::TestTranslator::test_init", "tests/test_Translator.py::TestTranslator::test_sanitize", "tests/test_Translator.py::TestTranslator::test_delete_empty", "tests/test_Translator.py::TestTranslator::test_find_target", "tests/test_Translator.py::TestTranslator::test_available_locales" ]
[]
MIT License
swerebench/sweb.eval.x86_64.12rambau_1776_sepal_ui-501
12rambau__sepal_ui-516
9c319b0c21b8b1ba75173f3f85fd184747c398de
2022-07-03 07:19:07
114063b50ee5b1ccbab680424bb048e11939b870
diff --git a/docs/source/modules/sepal_ui.aoi.AoiModel.rst b/docs/source/modules/sepal_ui.aoi.AoiModel.rst index 0f5b8f1a..ccdcab52 100644 --- a/docs/source/modules/sepal_ui.aoi.AoiModel.rst +++ b/docs/source/modules/sepal_ui.aoi.AoiModel.rst @@ -12,7 +12,6 @@ sepal\_ui.aoi.AoiModel ~AoiModel.NAME ~AoiModel.ISO ~AoiModel.GADM_BASE_URL - ~AoiModel.GADM_ZIP_DIR ~AoiModel.GAUL_ASSET ~AoiModel.ASSET_SUFFIX ~AoiModel.CUSTOM diff --git a/sepal_ui/aoi/aoi_model.py b/sepal_ui/aoi/aoi_model.py index ad2a72fb..40f9b4e6 100644 --- a/sepal_ui/aoi/aoi_model.py +++ b/sepal_ui/aoi/aoi_model.py @@ -61,11 +61,6 @@ class AoiModel(Model): GADM_BASE_URL = "https://biogeo.ucdavis.edu/data/gadm3.6/gpkg/gadm36_{}_gpkg.zip" "str: the base url to download gadm maps" - GADM_ZIP_DIR = Path.home() / "tmp" / "GADM_zip" - "pathlib.Path: the zip dir where we download the zips" - - GADM_ZIP_DIR.mkdir(parents=True, exist_ok=True) - GAUL_ASSET = "FAO/GAUL/2015/level{}" "str: the GAUL asset name" diff --git a/sepal_ui/mapping/sepal_map.py b/sepal_ui/mapping/sepal_map.py index 6a518ccc..6ca115fc 100644 --- a/sepal_ui/mapping/sepal_map.py +++ b/sepal_ui/mapping/sepal_map.py @@ -16,7 +16,7 @@ import random from haversine import haversine import numpy as np import rioxarray -import xarray_leaflet +import xarray_leaflet # noqa: F401 import matplotlib.pyplot as plt from matplotlib import colors as mpc from matplotlib import colorbar @@ -38,11 +38,6 @@ from sepal_ui.mapping.basemaps import basemap_tiles __all__ = ["SepalMap"] -# call x_array leaflet at least once -# flake8 will complain as it's a pluggin (i.e. never called) -# We don't want to ignore testing F401 -xarray_leaflet - class SepalMap(ipl.Map): """ diff --git a/sepal_ui/mapping/value_inspector.py b/sepal_ui/mapping/value_inspector.py index f848018f..783d68ad 100644 --- a/sepal_ui/mapping/value_inspector.py +++ b/sepal_ui/mapping/value_inspector.py @@ -3,7 +3,7 @@ import ee import geopandas as gpd from shapely import geometry as sg import rioxarray -import xarray_leaflet +import xarray_leaflet # noqa: F401 from rasterio.crs import CRS import rasterio as rio import ipyvuetify as v @@ -16,11 +16,6 @@ from sepal_ui.mapping.map_btn import MapBtn from sepal_ui.frontend.styles import COMPONENTS from sepal_ui.message import ms -# call x_array leaflet at least once -# flake8 will complain as it's a pluggin (i.e. never called) -# We don't want to ignore testing F401 -xarray_leaflet - class ValueInspector(WidgetControl): """ diff --git a/sepal_ui/sepalwidgets/tile.py b/sepal_ui/sepalwidgets/tile.py index dec40168..69a92dc0 100644 --- a/sepal_ui/sepalwidgets/tile.py +++ b/sepal_ui/sepalwidgets/tile.py @@ -76,7 +76,7 @@ class Tile(v.Layout, SepalWidget): self._metadata["mount_id"] = "nested_tile" # remove elevation - self.elevation = False + self.children[0].elevation = False # remove title self.set_title()
deprecate zip_dir https://github.com/12rambau/sepal_ui/blob/a9255e7c566aac31ee7f8303e74fb7e8a3d57e5f/sepal_ui/aoi/aoi_model.py#L64 This folder is created on AOI call but is not used anymore as we are using the tmp module to create the tmp directory.
12rambau/sepal_ui
diff --git a/tests/test_Tile.py b/tests/test_Tile.py index aa22d301..de0de97e 100644 --- a/tests/test_Tile.py +++ b/tests/test_Tile.py @@ -81,7 +81,7 @@ class TestTile: assert res == tile assert tile._metadata["mount_id"] == "nested_tile" - assert tile.elevation is False + assert tile.children[0].elevation == 0 assert len(tile.children[0].children) == 1 return
{ "commit_name": "head_commit", "failed_lite_validators": [ "has_short_problem_statement", "has_many_modified_files", "has_many_hunks" ], "has_test_patch": true, "is_lite": false, "llm_score": { "difficulty_score": 0, "issue_text_score": 1, "test_score": 3 }, "num_modified_files": 5 }
2.9
{ "env_vars": null, "env_yml_path": null, "install": "pip install -e .[dev]", "log_parser": "parse_log_pytest", "no_use_env": null, "packages": "pytest", "pip_packages": [ "pytest" ], "pre_install": null, "python": "3.9", "reqs_path": null, "test_cmd": "pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning" }
affine==2.4.0 anyio==4.9.0 argon2-cffi==23.1.0 argon2-cffi-bindings==21.2.0 arrow==1.3.0 asttokens==3.0.0 async-lru==2.0.5 attrs==25.3.0 babel==2.17.0 backcall==0.2.0 beautifulsoup4==4.13.3 bleach==6.2.0 branca==0.8.1 cachetools==5.5.2 certifi==2025.1.31 cffi==1.17.1 cfgv==3.4.0 charset-normalizer==3.4.1 click==8.1.8 click-plugins==1.1.1 cligj==0.7.2 cloudpickle==3.1.1 colorama==0.4.6 comm==0.2.2 contourpy==1.3.0 cryptography==44.0.2 cycler==0.12.1 dask==2024.8.0 debugpy==1.8.13 decorator==5.2.1 deepdiff==8.4.2 defusedxml==0.7.1 Deprecated==1.2.18 distlib==0.3.9 docopt==0.6.2 earthengine-api==1.5.8 exceptiongroup @ file:///croot/exceptiongroup_1706031385326/work executing==2.2.0 fastjsonschema==2.21.1 filelock==3.18.0 fonttools==4.56.0 fqdn==1.5.1 fsspec==2025.3.2 geopandas==1.0.1 google-api-core==2.24.2 google-api-python-client==2.166.0 google-auth==2.38.0 google-auth-httplib2==0.2.0 google-cloud-core==2.4.3 google-cloud-storage==3.1.0 google-crc32c==1.7.1 google-resumable-media==2.7.2 googleapis-common-protos==1.69.2 h11==0.14.0 haversine==2.9.0 httpcore==1.0.7 httplib2==0.22.0 httpx==0.28.1 identify==2.6.9 idna==3.10 importlib_metadata==8.6.1 importlib_resources==6.5.2 iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work ipykernel==6.29.5 ipyleaflet==0.19.2 ipyspin==1.0.1 ipython==8.12.3 ipython-genutils==0.2.0 ipyurl==0.1.3 ipyvue==1.11.2 ipyvuetify==1.11.1 ipywidgets==7.8.5 isoduration==20.11.0 jedi==0.19.2 Jinja2==3.1.6 json5==0.10.0 jsonpointer==3.0.0 jsonschema==4.23.0 jsonschema-specifications==2024.10.1 jupyter-events==0.12.0 jupyter-leaflet==0.19.2 jupyter-lsp==2.2.5 jupyter_client==8.6.3 jupyter_core==5.7.2 jupyter_server==2.15.0 jupyter_server_terminals==0.5.3 jupyter_server_xarray_leaflet==0.2.3 jupyterlab==4.3.6 jupyterlab_pygments==0.3.0 jupyterlab_server==2.27.3 jupyterlab_widgets==1.1.11 kiwisolver==1.4.7 locket==1.0.0 Markdown==3.7 MarkupSafe==3.0.2 matplotlib==3.9.4 matplotlib-inline==0.1.7 mercantile==1.2.1 mistune==3.1.3 natsort==8.4.0 nbclient==0.10.2 nbconvert==7.16.6 nbformat==5.10.4 nest-asyncio==1.6.0 nodeenv==1.9.1 notebook==7.3.3 notebook_shim==0.2.4 numpy==2.0.2 orderly-set==5.3.0 overrides==7.7.0 packaging @ file:///croot/packaging_1734472117206/work pandas==2.2.3 pandocfilters==1.5.1 parso==0.8.4 partd==1.4.2 pexpect==4.9.0 pickleshare==0.7.5 pillow==11.1.0 pipreqs==0.5.0 planet==1.5.2 platformdirs==4.3.7 pluggy @ file:///croot/pluggy_1733169602837/work pre_commit==4.2.0 prometheus_client==0.21.1 prompt_toolkit==3.0.50 proto-plus==1.26.1 protobuf==6.30.2 psutil==7.0.0 ptyprocess==0.7.0 pure_eval==0.2.3 pyasn1==0.6.1 pyasn1_modules==0.4.2 pycparser==2.22 Pygments==2.19.1 pyogrio==0.10.0 pyparsing==3.2.3 pyproj==3.6.1 pytest @ file:///croot/pytest_1738938843180/work python-box==7.3.2 python-dateutil==2.9.0.post0 python-json-logger==3.3.0 pytz==2025.2 PyYAML==6.0.2 pyzmq==26.3.0 rasterio==1.4.3 referencing==0.36.2 requests==2.32.3 requests-futures==0.9.9 rfc3339-validator==0.1.4 rfc3986-validator==0.1.1 rioxarray==0.15.0 rpds-py==0.24.0 rsa==4.9 Send2Trash==1.8.3 -e git+https://github.com/12rambau/sepal_ui.git@9c319b0c21b8b1ba75173f3f85fd184747c398de#egg=sepal_ui shapely==2.0.7 six==1.17.0 sniffio==1.3.1 soupsieve==2.6 stack-data==0.6.3 terminado==0.18.1 tinycss2==1.4.0 tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work toolz==1.0.0 tornado==6.4.2 tqdm==4.67.1 traitlets==5.14.3 traittypes==0.2.1 types-python-dateutil==2.9.0.20241206 typing_extensions==4.13.0 tzdata==2025.2 Unidecode==1.3.8 uri-template==1.3.0 uritemplate==4.1.1 urllib3==2.3.0 virtualenv==20.29.3 wcwidth==0.2.13 webcolors==24.11.1 webencodings==0.5.1 websocket-client==1.8.0 widgetsnbextension==3.6.10 wrapt==1.17.2 xarray==2024.7.0 xarray_leaflet==0.2.3 xyzservices==2025.1.0 yarg==0.1.9 zipp==3.21.0
name: sepal_ui channels: - defaults - https://repo.anaconda.com/pkgs/main - https://repo.anaconda.com/pkgs/r - conda-forge dependencies: - _libgcc_mutex=0.1=main - _openmp_mutex=5.1=1_gnu - ca-certificates=2025.2.25=h06a4308_0 - exceptiongroup=1.2.0=py39h06a4308_0 - iniconfig=1.1.1=pyhd3eb1b0_0 - ld_impl_linux-64=2.40=h12ee557_0 - libffi=3.4.4=h6a678d5_1 - libgcc-ng=11.2.0=h1234567_1 - libgomp=11.2.0=h1234567_1 - libstdcxx-ng=11.2.0=h1234567_1 - ncurses=6.4=h6a678d5_0 - openssl=3.0.16=h5eee18b_0 - packaging=24.2=py39h06a4308_0 - pip=25.0=py39h06a4308_0 - pluggy=1.5.0=py39h06a4308_0 - pytest=8.3.4=py39h06a4308_0 - python=3.9.21=he870216_1 - readline=8.2=h5eee18b_0 - setuptools=75.8.0=py39h06a4308_0 - sqlite=3.45.3=h5eee18b_0 - tk=8.6.14=h39e8969_0 - tomli=2.0.1=py39h06a4308_0 - wheel=0.45.1=py39h06a4308_0 - xz=5.6.4=h5eee18b_1 - zlib=1.2.13=h5eee18b_1 - pip: - affine==2.4.0 - anyio==4.9.0 - argon2-cffi==23.1.0 - argon2-cffi-bindings==21.2.0 - arrow==1.3.0 - asttokens==3.0.0 - async-lru==2.0.5 - attrs==25.3.0 - babel==2.17.0 - backcall==0.2.0 - beautifulsoup4==4.13.3 - bleach==6.2.0 - branca==0.8.1 - cachetools==5.5.2 - certifi==2025.1.31 - cffi==1.17.1 - cfgv==3.4.0 - charset-normalizer==3.4.1 - click==8.1.8 - click-plugins==1.1.1 - cligj==0.7.2 - cloudpickle==3.1.1 - colorama==0.4.6 - comm==0.2.2 - contourpy==1.3.0 - cryptography==44.0.2 - cycler==0.12.1 - dask==2024.8.0 - debugpy==1.8.13 - decorator==5.2.1 - deepdiff==8.4.2 - defusedxml==0.7.1 - deprecated==1.2.18 - distlib==0.3.9 - docopt==0.6.2 - earthengine-api==1.5.8 - executing==2.2.0 - fastjsonschema==2.21.1 - filelock==3.18.0 - fonttools==4.56.0 - fqdn==1.5.1 - fsspec==2025.3.2 - geopandas==1.0.1 - google-api-core==2.24.2 - google-api-python-client==2.166.0 - google-auth==2.38.0 - google-auth-httplib2==0.2.0 - google-cloud-core==2.4.3 - google-cloud-storage==3.1.0 - google-crc32c==1.7.1 - google-resumable-media==2.7.2 - googleapis-common-protos==1.69.2 - h11==0.14.0 - haversine==2.9.0 - httpcore==1.0.7 - httplib2==0.22.0 - httpx==0.28.1 - identify==2.6.9 - idna==3.10 - importlib-metadata==8.6.1 - importlib-resources==6.5.2 - ipykernel==6.29.5 - ipyleaflet==0.19.2 - ipyspin==1.0.1 - ipython==8.12.3 - ipython-genutils==0.2.0 - ipyurl==0.1.3 - ipyvue==1.11.2 - ipyvuetify==1.11.1 - ipywidgets==7.8.5 - isoduration==20.11.0 - jedi==0.19.2 - jinja2==3.1.6 - json5==0.10.0 - jsonpointer==3.0.0 - jsonschema==4.23.0 - jsonschema-specifications==2024.10.1 - jupyter-client==8.6.3 - jupyter-core==5.7.2 - jupyter-events==0.12.0 - jupyter-leaflet==0.19.2 - jupyter-lsp==2.2.5 - jupyter-server==2.15.0 - jupyter-server-terminals==0.5.3 - jupyter-server-xarray-leaflet==0.2.3 - jupyterlab==4.3.6 - jupyterlab-pygments==0.3.0 - jupyterlab-server==2.27.3 - jupyterlab-widgets==1.1.11 - kiwisolver==1.4.7 - locket==1.0.0 - markdown==3.7 - markupsafe==3.0.2 - matplotlib==3.9.4 - matplotlib-inline==0.1.7 - mercantile==1.2.1 - mistune==3.1.3 - natsort==8.4.0 - nbclient==0.10.2 - nbconvert==7.16.6 - nbformat==5.10.4 - nest-asyncio==1.6.0 - nodeenv==1.9.1 - notebook==7.3.3 - notebook-shim==0.2.4 - numpy==2.0.2 - orderly-set==5.3.0 - overrides==7.7.0 - pandas==2.2.3 - pandocfilters==1.5.1 - parso==0.8.4 - partd==1.4.2 - pexpect==4.9.0 - pickleshare==0.7.5 - pillow==11.1.0 - pipreqs==0.5.0 - planet==1.5.2 - platformdirs==4.3.7 - pre-commit==4.2.0 - prometheus-client==0.21.1 - prompt-toolkit==3.0.50 - proto-plus==1.26.1 - protobuf==6.30.2 - psutil==7.0.0 - ptyprocess==0.7.0 - pure-eval==0.2.3 - pyasn1==0.6.1 - pyasn1-modules==0.4.2 - pycparser==2.22 - pygments==2.19.1 - pyogrio==0.10.0 - pyparsing==3.2.3 - pyproj==3.6.1 - python-box==7.3.2 - python-dateutil==2.9.0.post0 - python-json-logger==3.3.0 - pytz==2025.2 - pyyaml==6.0.2 - pyzmq==26.3.0 - rasterio==1.4.3 - referencing==0.36.2 - requests==2.32.3 - requests-futures==0.9.9 - rfc3339-validator==0.1.4 - rfc3986-validator==0.1.1 - rioxarray==0.15.0 - rpds-py==0.24.0 - rsa==4.9 - send2trash==1.8.3 - shapely==2.0.7 - six==1.17.0 - sniffio==1.3.1 - soupsieve==2.6 - stack-data==0.6.3 - terminado==0.18.1 - tinycss2==1.4.0 - toolz==1.0.0 - tornado==6.4.2 - tqdm==4.67.1 - traitlets==5.14.3 - traittypes==0.2.1 - types-python-dateutil==2.9.0.20241206 - typing-extensions==4.13.0 - tzdata==2025.2 - unidecode==1.3.8 - uri-template==1.3.0 - uritemplate==4.1.1 - urllib3==2.3.0 - virtualenv==20.29.3 - wcwidth==0.2.13 - webcolors==24.11.1 - webencodings==0.5.1 - websocket-client==1.8.0 - widgetsnbextension==3.6.10 - wrapt==1.17.2 - xarray==2024.7.0 - xarray-leaflet==0.2.3 - xyzservices==2025.1.0 - yarg==0.1.9 - zipp==3.21.0 prefix: /opt/conda/envs/sepal_ui
[ "tests/test_Tile.py::TestTile::test_nest" ]
[]
[ "tests/test_Tile.py::TestTile::test_init", "tests/test_Tile.py::TestTile::test_set_content", "tests/test_Tile.py::TestTile::test_set_title", "tests/test_Tile.py::TestTile::test_hide", "tests/test_Tile.py::TestTile::test_show", "tests/test_Tile.py::TestTile::test_toggle_inputs", "tests/test_Tile.py::TestTile::test_get_id", "tests/test_Tile.py::TestTile::test_tile_about", "tests/test_Tile.py::TestTile::test_tile_disclaimer" ]
[]
MIT License
swerebench/sweb.eval.x86_64.12rambau_1776_sepal_ui-516
12rambau__sepal_ui-517
9c319b0c21b8b1ba75173f3f85fd184747c398de
2022-07-03 10:05:47
114063b50ee5b1ccbab680424bb048e11939b870
"diff --git a/sepal_ui/message/en/utils.json b/sepal_ui/message/en/utils.json\nnew file mode 100644\(...TRUNCATED)
"refactor check_input to raise error instead of displaying a message?\nhttps://github.com/12rambau/s(...TRUNCATED)
12rambau/sepal_ui
"diff --git a/tests/test_Alert.py b/tests/test_Alert.py\nindex 6116cbc7..d125b74e 100644\n--- a/test(...TRUNCATED)
{"commit_name":"head_commit","failed_lite_validators":["has_added_files","has_many_modified_files","(...TRUNCATED)
2.9
{"env_vars":null,"env_yml_path":null,"install":"pip install -e .[dev]","log_parser":"parse_log_pytes(...TRUNCATED)
"affine==2.4.0\nanyio==4.9.0\nargon2-cffi==23.1.0\nargon2-cffi-bindings==21.2.0\narrow==1.3.0\nastto(...TRUNCATED)
"name: sepal_ui\nchannels:\n - defaults\n - https://repo.anaconda.com/pkgs/main\n - https://repo.(...TRUNCATED)
["tests/test_Alert.py::TestAlert::test_check_input","tests/test_utils.py::TestUtils::test_check_inpu(...TRUNCATED)
["tests/test_utils.py::TestUtils::test_init_ee","tests/test_utils.py::TestUtils::test_geojson_to_ee"(...TRUNCATED)
["tests/test_Alert.py::TestAlert::test_init","tests/test_Alert.py::TestAlert::test_add_msg","tests/t(...TRUNCATED)
[]
MIT License
null
End of preview. Expand in Data Studio

Dataset Summary

SWE-rebench is a large-scale dataset designed to support training and evaluation of LLM-based software engineering (SWE) agents, building upon and expanding our earlier release, SWE-bench-extra. It is constructed using a fully automated pipeline that continuously extracts real-world interactive SWE tasks from GitHub repositories at scale, as detailed in our paper SWE-rebench: An Automated Pipeline for Task Collection and Decontaminated Evaluation of Software Engineering Agents. The dataset currently comprises over 21,000 issue–pull request pairs from 3,400+ Python repositories, each validated for correctness through automated environment setup and test execution. A curated subset of these tasks also forms the basis of our continuously updated SWE-rebench leaderboard. SWE-rebench builds upon and extends the methodology of SWE-bench by incorporating several key enhancements detailed in our paper, including:

  • A fully automated pipeline for continuous task collection.
  • LLM-driven extraction and validation of environment installation instructions.
  • An automated LLM-based task quality assessment pipeline that annotates tasks with labels such as clarity, complexity, or test patch validity.

We’ve released 7,500 pre-built Docker images used in our RL pipeline. They’re publicly available on Docker Hub. You do not need to build them yourself.

News

[2025/08/05] Uploaded the corresponding Docker images for 7,500 tasks to Docker Hub.

How to Use

from datasets import load_dataset
ds = load_dataset('nebius/SWE-rebench')

Dataset Structure

The SWE-rebench dataset schema extends the original SWE-bench schema with additional fields to support richer analysis. The complete schema is detailed in the table below. For more information about this data and methodology behind collecting it, please refer to our paper.

Field name Type Description
instance_id str A formatted instance identifier, usually as repo_owner__repo_name-PR-number.
patch str The gold patch, the patch generated by the PR (minus test-related code), that resolved the issue.
repo str The repository owner/name identifier from GitHub.
base_commit str The commit hash of the repository representing the HEAD of the repository before the solution PR is applied.
hints_text str Comments made on the issue prior to the creation of the solution PR’s first commit creation date.
created_at str The creation date of the pull request.
test_patch str A test-file patch that was contributed by the solution PR.
problem_statement str The issue title and body.
version str Installation version to use for running evaluation.
environment_setup_commit str Commit hash to use for environment setup and installation.
FAIL_TO_PASS str A JSON list of strings that represent the set of tests resolved by the PR and tied to the issue resolution.
PASS_TO_PASS str A JSON list of strings that represent tests that should pass before and after the PR application.
meta str A JSON dictionary indicating whether the instance is lite, along with a list of failed lite validators if it is not.
license_name str The type of license of the repository.
install_config str Installation configuration for setting up the repository.
requirements str Freezed requirements for the repository.
environment str Environment configuration for the repository.

To execute tasks from SWE-rebench (i.e., set up their environments, apply patches, and run tests), we provide a fork of the original SWE-bench execution framework, adapted for our dataset's structure and features. Our fork is based on the SWE-bench framework, specifically from its Release 4.0.3. The primary modification introduces functionality to source environment installation constants directly from the install_config field present in each task instance within SWE-rebench. This allows for more flexible and task-specific environment setups.

You can find the details of this modification in the following commit:

To build the necessary Docker images and run agents on SWE-rebench tasks, you have two main options:

  1. Use our SWE-bench fork directly: Clone the fork and utilize its scripts for building images and executing tasks. The framework will automatically use the install_config from each task.
  2. Integrate similar functionality into your existing codebase: If you have your own execution framework based on SWE-bench or a different system, you can adapt it by implementing a similar mechanism to parse and utilize the install_config field from the SWE-rebench task instances. The aforementioned commit can serve as a reference for this integration.

License

The dataset is licensed under the Creative Commons Attribution 4.0 license. However, please respect the license of each specific repository on which a particular instance is based. To facilitate this, the license of each repository at the time of the commit is provided for every instance.

Citation

@misc{badertdinov2025swerebenchautomatedpipelinetask,
      title={SWE-rebench: An Automated Pipeline for Task Collection and Decontaminated Evaluation of Software Engineering Agents}, 
      author={Ibragim Badertdinov and Alexander Golubev and Maksim Nekrashevich and Anton Shevtsov and Simon Karasik and Andrei Andriushchenko and Maria Trofimova and Daria Litvintseva and Boris Yangel},
      year={2025},
      eprint={2505.20411},
      archivePrefix={arXiv},
      primaryClass={cs.SE},
      url={https://arxiv.org/abs/2505.20411}
}
Downloads last month
1,827,041