diff --git a/ecoscope/__init__.py b/ecoscope/__init__.py index bd90be49..2834ee92 100644 --- a/ecoscope/__init__.py +++ b/ecoscope/__init__.py @@ -11,7 +11,7 @@ __initialized = False -def init(silent=False, selenium=False, force=False): +def init(silent=False, pyppeteer=False, force=False): """ Initializes the environment with ecoscope-specific customizations. @@ -19,8 +19,8 @@ def init(silent=False, selenium=False, force=False): ---------- silent : bool, optional Removes console output - selenium : bool, optional - Installs selenium webdriver in a colab environment + pyppeteer : bool, optional + Installs Pyppeteer and Chrome in a colab environment force : bool, optional Ignores `__initialized` @@ -76,46 +76,16 @@ def explore(data, *args, **kwargs): import sys - if "google.colab" in sys.modules and selenium: + if "google.colab" in sys.modules and pyppeteer: from IPython import get_ipython - shell_text = """\ -cat > /etc/apt/sources.list.d/debian.list <<'EOF' -deb [arch=amd64 signed-by=/usr/share/keyrings/debian-bookworm.gpg] http://deb.debian.org/debian bookworm main -deb [arch=amd64 signed-by=/usr/share/keyrings/debian-bookworm-updates.gpg]\ - http://deb.debian.org/debian bookworm-updates main -deb [arch=amd64 signed-by=/usr/share/keyrings/debian-security-bookworm.gpg]\ - http://deb.debian.org/debian-security bookworm/updates main -EOF - -apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DCC9EFBF77E11517 -apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138 -apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 112695A0E562B32A - -apt-key export 77E11517 | gpg --dearmour -o /usr/share/keyrings/debian-bookworm.gpg -apt-key export 22F3D138 | gpg --dearmour -o /usr/share/keyrings/debian-bookworm-updates.gpg -apt-key export E562B32A | gpg --dearmour -o /usr/share/keyrings/debian-security-bookworm.gpg - -cat > /etc/apt/preferences.d/chromium.pref << 'EOF' -Package: * -Pin: release a=eoan -Pin-Priority: 500 - + import nest_asyncio -Package: * -Pin: origin "deb.debian.org" -Pin-Priority: 300 - - -Package: chromium* -Pin: origin "deb.debian.org" -Pin-Priority: 700 -EOF + nest_asyncio.apply() + shell_text = """\ apt-get update -apt-get install chromium chromium-driver - -pip install selenium +apt-get install libxtst6 """ if silent: diff --git a/ecoscope/mapping/map.py b/ecoscope/mapping/map.py index 4e91afa7..b9f35a63 100644 --- a/ecoscope/mapping/map.py +++ b/ecoscope/mapping/map.py @@ -183,20 +183,20 @@ def to_png(self, outfile, sleep_time=10, **kwargs): outfile : str, Pathlike Output destination sleep_time : int, optional - Additional seconds to wait before taking screenshot. Should be increased if map tiles in the output haven't - fully loaded but can also be decreased in most cases. - + Additional seconds to wait before taking screenshot. Should be increased + if map tiles in the output haven't fully loaded but can also be decreased + in most cases. """ - html_string=self.get_root().render() + html_string = self.get_root().render() - async def capture_screenshot(html_string,outfile): - browser = await launch() + async def capture_screenshot(html_string, outfile): + browser = await launch(options={"args": ["--no-sandbox"]}) page = await browser.newPage() - await page.setViewport({'width': self.px_width, 'height': self.px_height}) # Set the viewport size as needed + await page.setViewport({"width": int(self.px_width), "height": int(self.px_height)}) await page.setContent(html_string) await asyncio.sleep(sleep_time) - await page.screenshot({'path': outfile}) + await page.screenshot({"path": outfile}) await browser.close() loop = asyncio.get_event_loop() diff --git a/ecoscope/version.py b/ecoscope/version.py index 3e8d9f94..daa50c7c 100644 --- a/ecoscope/version.py +++ b/ecoscope/version.py @@ -1 +1 @@ -__version__ = "1.4.0" +__version__ = "1.4.2" diff --git a/environment.yml b/environment.yml index 6d23f247..92eaa87b 100644 --- a/environment.yml +++ b/environment.yml @@ -2,7 +2,7 @@ name: ecoscope channels: - conda-forge dependencies: - - python==3.7.12 # Fixed to mirror version on Google Colab + - python==3.10.12 # Fixed to mirror version on Google Colab - pip==22.3 - git==2.38.1 - affine==2.3.1 @@ -11,6 +11,7 @@ dependencies: - backoff==2.2.1 - branca==0.5.0 - earthengine-api==0.1.328 + - earthranger-client - geopandas==0.10.2 - ipywidgets==8.0.2 - jinja2==3.1.2 @@ -27,6 +28,7 @@ dependencies: - pyarrow==9.0.0 - pydata-sphinx-theme==0.11.0 - pypdf2==2.10.8 + - pyppeteer - pyproj==3.2.1 - pytest-cov==4.0.0 - pytest-mock==3.10.0 @@ -37,12 +39,10 @@ dependencies: - scikit-image==0.19.2 - scikit-learn==1.0.2 - scipy==1.7.3 - - selenium==4.5.0 - shapely==1.8.2 - sphinx==5.3.0 - tqdm==4.64.1 - xyzservices==2022.9.0 - - earthranger-client - pip: - coverage[toml] - nbsphinx diff --git a/setup.py b/setup.py index 396f8e8e..c2b6a7d8 100644 --- a/setup.py +++ b/setup.py @@ -18,6 +18,7 @@ "backoff", "branca", "earthengine-api", + "earthranger-client", "folium>=0.11.0", "geopandas", "igraph", @@ -31,17 +32,16 @@ "pandas", "plotly", "pyarrow", + "pyppeteer", "pyproj", "pytest-mock", "rasterio", "scikit-image", "scikit-learn", "scipy", - "selenium", "shapely", "tqdm", "xyzservices", - "earthranger-client", ] setup( @@ -76,6 +76,7 @@ "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", ], include_package_data=True, ) diff --git a/tests/test_output/png_map.png b/tests/test_output/png_map.png index 3da03694..d07d795a 100644 Binary files a/tests/test_output/png_map.png and b/tests/test_output/png_map.png differ diff --git a/tests/test_png.py b/tests/test_png.py index 198efda0..fdf7b104 100644 --- a/tests/test_png.py +++ b/tests/test_png.py @@ -1,9 +1,11 @@ import sys import os -sys.path.append('../ecoscope') from ecoscope.mapping.map import EcoMap -m=EcoMap(draw_control=False) +sys.path.append("../ecoscope") -relative_path=os.path.join('tests/test_output/png_map.png') -m.to_png(relative_path) \ No newline at end of file + +m = EcoMap(draw_control=False) + +relative_path = os.path.join("tests/test_output/png_map.png") +m.to_png(relative_path)