diff --git a/.circleci/config.yml b/.circleci/config.yml index e77a402dc67..3ce58a1eacd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,5 +1,8 @@ version: 2.1 +orbs: + browser-tools: circleci/browser-tools@1.4.1 + commands: test_core: parameters: @@ -8,12 +11,22 @@ commands: type: string steps: - checkout + - browser-tools/install-chrome + - browser-tools/install-chromedriver - run: name: Install dependencies - command: "cd packages/python; sudo pip install -r ./plotly/test_requirements/requirements_<>_core.txt" + command: | + cd packages/python/plotly + python -m venv venv + . venv/bin/activate + pip install --upgrade pip wheel + pip install -r ./test_requirements/requirements_<>_core.txt - run: name: Test core - command: "cd packages/python/plotly; pytest plotly/tests/test_core" + command: | + cd packages/python/plotly + . venv/bin/activate + pytest plotly/tests/test_core no_output_timeout: 20m test_optional: @@ -23,34 +36,62 @@ commands: type: string steps: - checkout + - browser-tools/install-chrome + - browser-tools/install-chromedriver - run: name: Install dependencies - command: "cd packages/python; sudo pip install -r ./plotly/test_requirements/requirements_<>_optional.txt" + command: | + cd packages/python/plotly + python -m venv venv + . venv/bin/activate + pip install --upgrade pip wheel + pip install -r ./test_requirements/requirements_<>_optional.txt - run: name: Install plotly-geo - command: "cd packages/python/plotly-geo; sudo pip install -e ." + command: | + cd packages/python/plotly-geo + . ../plotly/venv/bin/activate + pip install -e . - run: name: Test core - command: "cd packages/python/plotly; pytest plotly/tests/test_core" + command: | + cd packages/python/plotly + . venv/bin/activate + pytest plotly/tests/test_core no_output_timeout: 20m - run: name: Test optional - command: "cd packages/python/plotly; pytest plotly/tests/test_optional" + command: | + cd packages/python/plotly + . venv/bin/activate + pytest plotly/tests/test_optional no_output_timeout: 40m - run: name: Test utils - command: "cd packages/python/plotly; pytest _plotly_utils/tests/" + command: | + cd packages/python/plotly + . venv/bin/activate + pytest _plotly_utils/tests/ no_output_timeout: 20m - run: name: Test io - command: "cd packages/python/plotly; pytest plotly/tests/test_io" + command: | + cd packages/python/plotly + . venv/bin/activate + pytest plotly/tests/test_io no_output_timeout: 20m - run: name: Test dependencdies not imported - command: "cd packages/python/plotly; pytest -x test_init/test_dependencies_not_imported.py" + command: | + cd packages/python/plotly + . venv/bin/activate + pytest -x test_init/test_dependencies_not_imported.py - run: name: Test lazy imports - command: "cd packages/python/plotly; pytest -x test_init/test_lazy_imports.py" + command: | + cd packages/python/plotly + . venv/bin/activate + pytest -x test_init/test_lazy_imports.py test_orca: parameters: @@ -59,21 +100,36 @@ commands: type: string steps: - checkout + - browser-tools/install-chrome + - browser-tools/install-chromedriver - run: name: Install dependencies - command: "cd packages/python; sudo pip install -r ./plotly/test_requirements/requirements_<>_optional.txt" + command: | + cd packages/python/plotly + python -m venv venv + . venv/bin/activate + pip install --upgrade pip wheel + pip install -r ./test_requirements/requirements_<>_optional.txt - run: name: Install plotly-geo - command: "cd packages/python/plotly-geo; sudo pip install -e ." + command: | + cd packages/python/plotly-geo + . ../plotly/venv/bin/activate + pip install -e . - run: name: Install orca command: | - sudo npm install electron@1.8.4 sudo npm install orca + npm install electron@1.8.4 + npm install orca + sudo apt-get update sudo apt-get install -y poppler-utils libxtst6 xvfb libgtk2.0-0 libgconf-2-4 libnss3 libasound2 rename echo 'export PATH="/home/circleci/project/node_modules/.bin:$PATH"' >> $BASH_ENV - run: name: Test orca - command: "cd packages/python/plotly; pytest plotly/tests/test_orca" + command: | + cd packages/python/plotly + . venv/bin/activate + pytest plotly/tests/test_orca no_output_timeout: 20m - store_artifacts: path: packages/python/plotly/plotly/tests/test_orca/images/linux/failed @@ -81,42 +137,47 @@ commands: jobs: check-code-formatting: docker: - - image: circleci/python:3.7-stretch-node-browsers + - image: cimg/python:3.7 steps: - checkout - run: name: Install black - command: "sudo pip install black==22.3.0" + command: | + python -m venv venv + . venv/bin/activate + pip install black==22.3.0 - run: name: Check formatting with black - command: "black --check ." + command: | + . venv/bin/activate + black --check . --exclude venv # Core python_36_core: docker: - - image: circleci/python:3.6-stretch-node-browsers + - image: cimg/python:3.6-browsers steps: - test_core: py: "36" python_37_core: docker: - - image: circleci/python:3.7-stretch-node-browsers + - image: cimg/python:3.7-browsers steps: - test_core: py: "37" python_38_core: docker: - - image: circleci/python:3.8-buster-node-browsers + - image: cimg/python:3.8-browsers steps: - test_core: py: "38" python_39_core: docker: - - image: circleci/python:3.9-buster-node-browsers + - image: cimg/python:3.9-browsers steps: - test_core: py: "39" @@ -124,28 +185,28 @@ jobs: # Optional python_36_optional: docker: - - image: circleci/python:3.6-stretch-node-browsers + - image: cimg/python:3.6-browsers steps: - test_optional: py: "36" python_37_optional: docker: - - image: circleci/python:3.7-stretch-node-browsers + - image: cimg/python:3.7-browsers steps: - test_optional: py: "37" python_38_optional: docker: - - image: circleci/python:3.8-buster-node-browsers + - image: cimg/python:3.8-browsers steps: - test_optional: py: "38" python_39_optional: docker: - - image: circleci/python:3.9-buster-node-browsers + - image: cimg/python:3.9-browsers steps: - test_optional: py: "39" @@ -154,7 +215,7 @@ jobs: python_39_pandas_2_optional: docker: - - image: circleci/python:3.9-buster-node-browsers + - image: cimg/python:3.9-browsers steps: - test_optional: py: "39_pandas_2" @@ -162,7 +223,7 @@ jobs: # Orca python_38_orca: docker: - - image: circleci/python:3.8-buster-node-browsers + - image: cimg/python:3.8-browsers steps: - test_orca: py: "38" @@ -170,7 +231,7 @@ jobs: # Percy python_37_percy: docker: - - image: circleci/python:3.7-stretch-node-browsers + - image: cimg/python:3.7-browsers environment: PERCY_ENABLED: True PERCY_PROJECT: plotly/plotly.py @@ -178,6 +239,8 @@ jobs: steps: - checkout + - browser-tools/install-chrome + - browser-tools/install-chromedriver - run: name: Inject Percy Environment variables command: | @@ -185,9 +248,9 @@ jobs: - run: name: Install requirements command: | - sudo pip install --upgrade virtualenv - python -m venv venv || virtualenv venv + python -m venv venv . venv/bin/activate + pip install --upgrade pip wheel pip install -e ./packages/python/plotly pip install -e ./packages/python/plotly-geo pip install -r ./packages/python/plotly/test_requirements/requirements_37_optional.txt @@ -200,28 +263,36 @@ jobs: name: Run percy snapshots command: | npm i @percy/cli - npx percy snapshot test/percy/ + npx percy snapshot -c test/percy/snapshots.yml test/percy/ rm test/percy/*.html # Chart studio python_37_chart_studio: docker: - - image: circleci/python:3.7-stretch-node-browsers + - image: cimg/python:3.7 resource_class: large steps: - checkout - run: name: Install dependencies - command: "cd packages/python; sudo pip install -r ./chart-studio/test_requirements/requirements_37.txt" + command: | + cd packages/python/chart-studio + python -m venv venv + . venv/bin/activate + pip install --upgrade pip wheel + pip install -r ./test_requirements/requirements_37.txt - run: name: Tests - command: "cd packages/python/chart-studio; pytest -x chart_studio/tests/" + command: | + cd packages/python/chart-studio + . venv/bin/activate + pytest -x chart_studio/tests/ no_output_timeout: 20m plotlyjs_dev_build: docker: - - image: circleci/python:3.7-stretch-node-browsers + - image: cimg/python:3.7-node environment: LANG: en_US.UTF-8 resource_class: large @@ -230,16 +301,32 @@ jobs: - checkout - run: name: Install dependencies - command: "cd packages/python; sudo pip install -r ./plotly/test_requirements/requirements_37_core.txt black inflect; sudo pip install jupyterlab~=3.0" + command: | + cd packages/python/plotly + python -m venv venv + . venv/bin/activate + pip install --upgrade pip wheel + pip install -r ./test_requirements/requirements_37_core.txt black inflect + pip install jupyterlab~=3.0 - run: name: Update jupyterlab-plotly version - command: "cd packages/python/plotly; python setup.py updateplotlywidgetversion" + command: | + cd packages/python/plotly + . venv/bin/activate + python setup.py updateplotlywidgetversion - run: name: Update plotly.js to dev - command: "cd packages/python/plotly; python setup.py updateplotlyjsdev" + command: | + cd packages/python/plotly + . venv/bin/activate + python setup.py updateplotlyjsdev - run: name: Test core - command: "cd packages/python/plotly; locale; pytest -k 'not nodev' plotly/tests/test_core" + command: | + cd packages/python/plotly + . venv/bin/activate + locale + pytest -k 'not nodev' plotly/tests/test_core no_output_timeout: 20m - run: name: Commit @@ -254,6 +341,7 @@ jobs: name: Build source distribution packages command: | cd packages/python/plotly + . venv/bin/activate python setup.py sdist when: always - store_artifacts: @@ -273,7 +361,7 @@ jobs: name: Create conda environment command: | conda create -n env --yes python=3.9 conda-build conda-verify - conda install -n env -c conda-forge jupyterlab nodejs=18 + conda install -n env -c conda-forge jupyterlab nodejs=16 conda init bash mkdir output @@ -335,7 +423,7 @@ jobs: docker: # specify the version you desire here # use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers` - - image: circleci/python:3.7-stretch-node-browsers + - image: cimg/python:3.7-browsers steps: - add_ssh_keys: @@ -346,37 +434,38 @@ jobs: # Download and cache dependencies - restore_cache: - keys: - - v1-dependencies-{{ checksum "doc/requirements.txt" }} - # fallback to using the latest cache if no exact match is found - - v1-dependencies- + key: v1-dependencies-{{ checksum "doc/requirements.txt" }}-{{ checksum ".circleci/config.yml" }} + - browser-tools/install-chrome + - browser-tools/install-chromedriver - run: name: install dependencies command: | cd doc - python3 -m venv venv + python -m venv venv . venv/bin/activate - npm install electron@1.8.4 - npm install orca - pip install -U pip + pip install --upgrade pip wheel pip uninstall -y plotly pip install -r requirements.txt if [ "${CIRCLE_BRANCH}" != "doc-prod" ]; then pip uninstall -y plotly - cd ../packages/python/plotly - pip install -e . - cd ../../../doc + pip install -e ../packages/python/plotly fi - echo 'export PATH="/home/circleci/project/doc/node_modules/.bin:$PATH"' >> $BASH_ENV - sudo apt-get install -y poppler-utils libxtst6 xvfb libgtk2.0-0 libgconf-2-4 libnss3 libasound2 rename cd .. + - run: + name: Install orca + command: | + npm install electron@1.8.4 + npm install orca + sudo apt-get update + sudo apt-get install -y poppler-utils libxtst6 xvfb libgtk2.0-0 libgconf-2-4 libnss3 libasound2 rename + echo 'export PATH="/home/circleci/project/node_modules/.bin:$PATH"' >> $BASH_ENV - save_cache: paths: - ./doc/venv - ./doc/node_modules - key: v1-dependencies-{{ checksum "doc/requirements.txt" }} + key: v1-dependencies-{{ checksum "doc/requirements.txt" }}-{{ checksum ".circleci/config.yml" }} - run: name: make html diff --git a/.gitignore b/.gitignore index 96e2fdf38d7..1be270ceac4 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,5 @@ doc/check-or-enforce-order.py packages/javascript/jupyterlab-plotly/lib/ packages/python/plotly/jupyterlab_plotly/labextension/ packages/python/plotly/jupyterlab_plotly/nbextension/index.js* + +test/percy/*.html diff --git a/doc/python/static-image-export.md b/doc/python/static-image-export.md index 2d5795efb0b..48bb28366ae 100644 --- a/doc/python/static-image-export.md +++ b/doc/python/static-image-export.md @@ -109,42 +109,42 @@ If you are running this notebook live, click to [open the output directory](./im plotly.py can output figures to several raster image formats including **PNG**, ... -```python +~~~python fig.write_image("images/fig1.png") -``` +~~~ **JPEG**, ... -```python +~~~python fig.write_image("images/fig1.jpeg") -``` +~~~ and **WebP** -```python +~~~python fig.write_image("images/fig1.webp") -``` +~~~ #### Vector Formats: SVG and PDF... plotly.py can also output figures in several vector formats including **SVG**, ... -```python +~~~python fig.write_image("images/fig1.svg") -``` +~~~ **PDF**, ... -```python +~~~python fig.write_image("images/fig1.pdf") -``` +~~~ and **EPS** (requires the poppler library) -```python +~~~python fig.write_image("images/fig1.eps") -``` +~~~ **Note:** It is important to note that any figures containing WebGL traces (i.e. of type `scattergl`, `heatmapgl`, `contourgl`, `scatter3d`, `surface`, `mesh3d`, `scatterpolargl`, `cone`, `streamtube`, `splom`, or `parcoords`) that are exported in a vector format will include encapsulated rasters, instead of vectors, for some parts of the image. @@ -199,14 +199,14 @@ Image(img_bytes) If `kaleido` is installed, it will automatically be used to perform image export. If it is not installed, plotly.py will attempt to use `orca` instead. The `engine` argument to the `to_image` and `write_image` functions can be used to override this default behavior. Here is an example of specifying that orca should be used: -```python +~~~python fig.to_image(format="png", engine="orca") -``` +~~~ And, here is an example of specifying that Kaleido should be used: -```python +~~~python fig.to_image(format="png", engine="kaleido") -``` +~~~ diff --git a/packages/python/plotly/plotly/matplotlylib/mplexporter/renderers/vega_renderer.py b/packages/python/plotly/plotly/matplotlylib/mplexporter/renderers/vega_renderer.py index d7dd171b4e2..eab02e1f329 100644 --- a/packages/python/plotly/plotly/matplotlylib/mplexporter/renderers/vega_renderer.py +++ b/packages/python/plotly/plotly/matplotlylib/mplexporter/renderers/vega_renderer.py @@ -23,8 +23,18 @@ def open_axes(self, ax, props): dict(type="y", scale="y", ticks=10), ] self.scales = [ - dict(name="x", domain=props["xlim"], type="linear", range="width",), - dict(name="y", domain=props["ylim"], type="linear", range="height",), + dict( + name="x", + domain=props["xlim"], + type="linear", + range="width", + ), + dict( + name="y", + domain=props["ylim"], + type="linear", + range="height", + ), ] def draw_line(self, data, coordinates, style, label, mplobj=None): @@ -103,7 +113,7 @@ def __init__(self, renderer): def html(self): """Build the HTML representation for IPython.""" - id = random.randint(0, 2 ** 16) + id = random.randint(0, 2**16) html = '
' % id html += "