Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Swap package dependency ruff for black and autoflake #757

Merged
merged 13 commits into from
Sep 30, 2024
Merged
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

- 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
maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved

- Changed dependency from `ruff` to `black` and `autoflake` in order to facilitate installation on pyodide ([#757](https://github.com/mckinsey/vizro/pull/757))

<!--
### 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))

-->
2 changes: 1 addition & 1 deletion vizro-ai/docs/pages/user-guides/customize-vizro-ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ vizro_ai = VizroAI(model="<chosen model>")
| API key | `MISTRAL_API_KEY` |
| Base API URL | `MISTRAL_BASE_URL` |

To use Mistral with Vizro-AI, you can either use their API, which comes with [an associated cost](https://mistral.ai/technology/#pricing), or you could use their models for free under the Apache 2.0 license. In that case you need to setup the model API yourself. You can check [all available Mistral models including pricing on their website](https://docs.mistral.ai/getting-started/models/). This will also explain which version the below string acronyms currently point to.
To use Mistral with Vizro-AI, you can either use their API, which comes with [an associated cost](https://mistral.ai/technology/#pricing), or you could use their models for free under the Apache 2.0 license. In that case you need to setup the model API yourself. You can check [all available Mistral models including pricing on their website](https://docs.mistral.ai/getting-started/models/models_overview). This will also explain which version the below string acronyms currently point to.

- `mistral-large-latest`
- `open-mistral-nemo`
Expand Down
3 changes: 2 additions & 1 deletion vizro-ai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ dependencies = [
"python-dotenv>=1.0.0", # TODO decide env var management to see if we need this
"vizro>=0.1.21",
"langchain_openai", # Base dependency, ie minimum model working
"ruff"
"black",
"autoflake"
]
description = "Vizro-AI is a tool for generating data visualizations"
dynamic = ["version"]
Expand Down
15 changes: 8 additions & 7 deletions vizro-ai/src/vizro_ai/plot/_response_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
except ImportError: # pragma: no cov
from pydantic import BaseModel, Field, PrivateAttr, create_model, validator
import logging
import subprocess
from typing import List, Optional, Union

import autoflake
import black
import pandas as pd
import plotly.graph_objects as go

Expand All @@ -26,12 +27,12 @@
def _format_and_lint(code_string: str) -> str:
# Tracking https://github.com/astral-sh/ruff/issues/659 for proper python API
# Good example: https://github.com/astral-sh/ruff/issues/8401#issuecomment-1788806462
linted = subprocess.check_output(
["ruff", "check", "--fix", "--exit-zero", "--silent", "--isolated", "-"], input=code_string, encoding="utf-8"
)
formatted = subprocess.check_output(
["ruff", "format", "--silent", "--isolated", "-"], input=linted, encoding="utf-8"
)
# While we wait for the API, we can autoflake and black to process code strings.

removed_imports = autoflake.fix_code(code_string, remove_all_unused_imports=True)
# Black doesn't yet have a Python API, so format_str might not work at some point in the future.
# https://black.readthedocs.io/en/stable/faq.html#does-black-have-an-api
formatted = black.format_str(removed_imports, mode=black.Mode())
return formatted


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--
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

- Changed dependency from `ruff` to `black` and `autoflake` in order to facilitate installation on pyodide ([#757](https://github.com/mckinsey/vizro/pull/757))

<!--
### 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))

-->
1 change: 0 additions & 1 deletion vizro-core/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ markdown_extensions:
type: vizro
requirements: |
vizro==0.1.23
ruff==0.6.1 # mock
- pymdownx.tabbed:
alternate_style: true
- pymdownx.mark
Expand Down
3 changes: 2 additions & 1 deletion vizro-core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ dependencies = [
"dash_mantine_components<0.13.0", # 0.13.0 is not compatible with 0.12,
"flask_caching>=2",
"wrapt>=1",
"ruff"
"black",
"autoflake"
]
description = "Vizro is a package to facilitate visual analytics."
dynamic = ["version"]
Expand Down
15 changes: 8 additions & 7 deletions vizro-core/src/vizro/models/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

import inspect
import logging
import subprocess
import textwrap

import autoflake
import black
from typing_extensions import Annotated

from vizro.managers import model_manager
Expand Down Expand Up @@ -73,12 +74,12 @@ def _patch_vizro_base_model_dict():
def _format_and_lint(code_string: str) -> str:
# Tracking https://github.com/astral-sh/ruff/issues/659 for proper python API
# Good example: https://github.com/astral-sh/ruff/issues/8401#issuecomment-1788806462
linted = subprocess.check_output(
["ruff", "check", "--fix", "--exit-zero", "--silent", "--isolated", "-"], input=code_string, encoding="utf-8"
)
formatted = subprocess.check_output(
["ruff", "format", "--silent", "--isolated", "-"], input=linted, encoding="utf-8"
)
# While we wait for the API, we can use autoflake and black to process code strings

removed_imports = autoflake.fix_code(code_string, remove_all_unused_imports=True)
# Black doesn't yet have a Python API, so format_str might not work at some point in the future.
# https://black.readthedocs.io/en/stable/faq.html#does-black-have-an-api
formatted = black.format_str(removed_imports, mode=black.Mode())
return formatted


Expand Down
Loading