Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/mckinsey/vizro into feat/ta…
Browse files Browse the repository at this point in the history
…bs_and_containers
  • Loading branch information
petar-qb committed Dec 20, 2023
2 parents 5c7404c + a30b50b commit e16cdbd
Show file tree
Hide file tree
Showing 24 changed files with 477 additions and 196 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/test-integration-vizro-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ jobs:
steps:
- uses: actions/checkout@v4

# Pinned Chrome version because chromedriver v120 recognized as chrome-headless-shell instead of chrome
# https://github.com/plotly/dash/issues/2712
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=4665
# https://github.com/mckinsey/vizro/pull/215/
# If these are fixed then this whole step can be removed.
- name: Install Chrome and chromedriver
run: |
export chrome_version=119.0.6045.105
sudo apt-get update
sudo apt-get install libu2f-udev -y
wget "https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_$chrome_version-1_amd64.deb"
sudo apt-get install -y --allow-downgrades ./google-chrome-stable_$chrome_version-1_amd64.deb
rm google-chrome-stable_$chrome_version-1_amd64.deb
wget https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/$chrome_version/linux64/chromedriver-linux64.zip
unzip chromedriver-linux64.zip
cd chromedriver-linux64
sudo mv chromedriver /usr/bin/chromedriver
sudo chown root:root /usr/bin/chromedriver
sudo chmod +x /usr/bin/chromedriver
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand Down
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,21 @@ repos:
description: Detect hardcoded secrets using Gitleaks
entry: gitleaks detect --verbose --redact --baseline-path .gitleaks-report.json
language: golang

# Configuration for https://pre-commit.ci/.
ci:
autoupdate_schedule: monthly
# Skip all hooks that just do checks without actually fixing anything.
skip:
- check-added-large-files
- check-merge-conflict
- check-case-conflict
- check-yaml
- check-json
- check-datafiles
- check-forbidden-words
- check-branch-name
- codespell
- bandit
- mypy
- gitleaks
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Highlights ✨
- A bullet item for the Highlights ✨ category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Removed
- A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->

### Added

- When set, the dashboard title appears alongside the individual page title as the text labeling a browser tab. ([#228](https://github.com/mckinsey/vizro/pull/228))

<!--
### Changed
- A bullet item for the Changed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#228](https://github.com/mckinsey/vizro/pull/228))
-->
<!--
### Deprecated
- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Fixed
- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Security
- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Highlights ✨
- A bullet item for the Highlights ✨ category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Removed
- A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Added
- A bullet item for the Added category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Changed
- A bullet item for the Changed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Deprecated
- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Fixed
- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Security
- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
48 changes: 48 additions & 0 deletions vizro-core/changelog.d/20231219_125122_antony.milne_pre_commit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Highlights ✨
- A bullet item for the Highlights ✨ category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Removed
- A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Added
- A bullet item for the Added category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Changed
- A bullet item for the Changed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Deprecated
- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Fixed
- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Security
- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Highlights ✨
- A bullet item for the Highlights ✨ category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Removed
- A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Added
- A bullet item for the Added category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Changed
- A bullet item for the Changed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Deprecated
- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Fixed
- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Security
- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
6 changes: 4 additions & 2 deletions vizro-core/docs/pages/development/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,14 @@ target-version = ["py37"]
line-length = 120
```

Linting checks are enforced in CI. To run pre-commit hooks locally, there are two options:
We use [`pre-commit ci`](https://pre-commit.ci/) to automatically fix all the linting checks that we can (e.g. `black` formatting) when a PR is pushed. Other linting failures (e.g. `mypy`) need manual intervention from the developer.

To run pre-commit hooks locally, there are two options:

1. Run `hatch run pre-commit install` to automatically run the hooks on every commit (you can always skip the checks with `git commit --no-verify`). In case this fails due to `gitleaks`, please read below for an explanation and how to install `go`.
2. Run `hatch run lint` to run `pre-commit` hooks on all files. (You can run e.g. `hatch run lint mypy -a` to only run specific linters, here mypy, on all files.)

Note that Hatch's `default` environment specifies `pre-commit` as a dependency but otherwise _does not_ specify dependencies for linting tools such as `black`. These are controlled by [.pre-commit-config.yaml](https://github.com/mckinsey/vizro/blob/main/.pre-commit-config.yaml) and can be updated when required with `pre-commit autoupdate`.
Note that Hatch's `default` environment specifies `pre-commit` as a dependency but otherwise _does not_ specify dependencies for linting tools such as `black`. These are controlled by [.pre-commit-config.yaml](https://github.com/mckinsey/vizro/blob/main/.pre-commit-config.yaml) and can be updated when required with `pre-commit autoupdate`. Once per month, `pre-commit ci` raises a PR to do so.

## Secret scans

Expand Down
7 changes: 5 additions & 2 deletions vizro-core/docs/pages/user_guides/dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This guide shows you how to configure and call a [`Dashboard`][vizro.models.Dashboard] using either
pydantic models, python dictionaries, yaml or json.

To create a dashboard, do the following steps:
To create a dashboard:

1. Choose one of the possible configuration syntaxes
2. Create your `pages`, see our guide on [Pages](pages.md)
Expand Down Expand Up @@ -191,4 +191,7 @@ After running the dashboard, you can access the dashboard via `localhost:8050`.

## Adding a dashboard title

When providing a `title` to the [`Dashboard`][vizro.models.Dashboard], it will automatically be added as a header for each [`Page`][vizro.models.Page].
If supplied, the `title` of the [`Dashboard`][vizro.models.Dashboard] displays a heading at the top left of every page. It is also combined with the `title` specified in [`Page`][vizro.models.Page] to set:

- `<title>` HTML element that controls the text labeling a browser window;
- `<meta>` elements that control how a preview is generated when sharing a link to your dashboard (e.g. on social media).
3 changes: 3 additions & 0 deletions vizro-core/schemas/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

if args.check:
if json.loads(schema_path.read_text()) != json.loads(schema_json):
# Ideally just doing hatch run:schema would be fine, but the schema slightly depends
# on Python version (Python 3.8 vs. Python 3.11 give different results), even
# for the same pydantic version.
sys.exit("JSON schema is out of date. Run `hatch run all.py3.11:schema` to update it.")
print("JSON schema is up to date.") # noqa: T201
else:
Expand Down
6 changes: 5 additions & 1 deletion vizro-core/src/vizro/_vizro.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, **kwargs):
kwargs: Passed through to `Dash.__init__`, e.g. `assets_folder`, `url_base_pathname`. See
[Dash documentation](https://dash.plotly.com/reference#dash.dash) for possible arguments.
"""
self.dash = dash.Dash(**kwargs, use_pages=True, pages_folder="")
self.dash = dash.Dash(**kwargs, use_pages=True, pages_folder="", title="Vizro")
self.dash.config.external_stylesheets.append(
"https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined"
)
Expand Down Expand Up @@ -61,6 +61,10 @@ def build(self, dashboard: Dashboard):
Returns:
Vizro: App object
"""
# Note Dash.index uses self.dash.title instead of self.dash.app.config.title.
if dashboard.title:
self.dash.title = dashboard.title

# Note that model instantiation and pre_build are independent of Dash.
self._pre_build()

Expand Down
8 changes: 1 addition & 7 deletions vizro-core/src/vizro/models/_components/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ class Button(VizroBaseModel):
@_log_call
def build(self):
return html.Div(
[
dbc.Button(
id=self.id,
children=self.text,
className="button_primary",
),
],
dbc.Button(id=self.id, children=self.text, className="button_primary"),
className="button_container",
id=f"{self.id}_outer",
)
8 changes: 6 additions & 2 deletions vizro-core/src/vizro/models/_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ def pre_build(self):
# For now the homepage (path /) corresponds to self.pages[0].
# Note redirect_from=["/"] doesn't work and so the / route must be defined separately.
for order, page in enumerate(self.pages):
path = page.path if order else "/"
dash.register_page(
module=page.id, name=page.title, path=path, order=order, layout=partial(self._make_page_layout, page)
module=page.id,
name=page.title,
title=f"{self.title}: {page.title}" if self.title else page.title,
path=page.path if order else "/",
order=order,
layout=partial(self._make_page_layout, page),
)
dash.register_page(module=MODULE_PAGE_404, layout=self._make_page_404_layout())

Expand Down
3 changes: 1 addition & 2 deletions vizro-core/tests/integration/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ def dashboard(request, monkeypatch):
def test_dashboard(dash_duo, dashboard):
app = Vizro(assets_folder=Path(__file__).parents[2] / "examples/assets").build(dashboard).dash
dash_duo.start_server(app)
# TODO: resolve the problem with driver recognized as chrome-headless-shell instead of chrome
# assert dash_duo.get_logs() == []
assert dash_duo.get_logs() == []
2 changes: 1 addition & 1 deletion vizro-core/tests/integration/test_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,4 @@ def label_cases(cases, label):
def test_navigation_build(dashboard_result, dashboard_expected):
result = dashboard_result.navigation.build()
expected = dashboard_expected.navigation.build()
assert_component_equal(result, expected)
assert_component_equal(result, expected, keys_to_strip={"id"})
Loading

0 comments on commit e16cdbd

Please sign in to comment.