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

Extend conventional imports defaults to include TensorFlow et al #2353

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
extend conventional imports
Based on configuration from Visual Studio for Python
(https://code.visualstudio.com/docs/python/editing#_quick-fixes)
  • Loading branch information
sbrugman committed Jan 30, 2023
commit 4708a931f020a368ac58353e8a24c2d3f4b92c22
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2929,7 +2929,7 @@ allow-multiline = false
The conventional aliases for imports. These aliases can be extended by
the `extend_aliases` option.

**Default value**: `{"altair": "alt", "matplotlib.pyplot": "plt", "numpy": "np", "pandas": "pd", "seaborn": "sns"}`
**Default value**: `{"altair": "alt", "matplotlib": "mpl", "matplotlib.pyplot": "plt", "numpy": "np", "pandas": "pd", "seaborn": "sns", "tensorflow": "tf", "holoviews": "hv", "panel": "pn", "plotly.express": "px", "polars": "pl", "pyarrow": "pa"}`

**Type**: `FxHashMap<String, String>`

Expand All @@ -2944,6 +2944,7 @@ altair = "alt"
numpy = "np"
pandas = "pd"
seaborn = "sns"
scripy = "sp"
```

---
Expand Down
23 changes: 23 additions & 0 deletions resources/test/fixtures/flake8_import_conventions/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
import numpy # unconventional
import pandas # unconventional
import seaborn # unconventional
import tensorflow # unconventional
import holoviews # unconventional
import panel # unconventional
import plotly.express # unconventional
import matplotlib # unconventional
import polars # unconventional
import pyarrow # unconventional

import altair as altr # unconventional
import matplotlib.pyplot as plot # unconventional
Expand All @@ -15,6 +22,13 @@
import numpy as nmp # unconventional
import pandas as pdas # unconventional
import seaborn as sbrn # unconventional
import tensorflow as tfz # unconventional
import holoviews as hsv # unconventional
import panel as pns # unconventional
import plotly.express as pltx # unconventional
import matplotlib as ml # unconventional
import polars as ps # unconventional
import pyarrow as arr # unconventional

import altair as alt # conventional
import dask.array as da # conventional
Expand All @@ -23,3 +37,12 @@
import numpy as np # conventional
import pandas as pd # conventional
import seaborn as sns # conventional
import tensorflow as tf # conventional
import holoviews as hv # conventional
import panel as pn # conventional
import plotly.express as px # conventional
import matplotlib as mpl # conventional
import polars as pl # conventional
import pyarrow as pa # conventional

from tensorflow.keras import Model # conventional
10 changes: 9 additions & 1 deletion src/rules/flake8_import_conventions/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ use crate::settings::hashable::HashableHashMap;

const CONVENTIONAL_ALIASES: &[(&str, &str)] = &[
("altair", "alt"),
("matplotlib", "mpl"),
("matplotlib.pyplot", "plt"),
("numpy", "np"),
("pandas", "pd"),
("seaborn", "sns"),
("tensorflow", "tf"),
("holoviews", "hv"),
("panel", "pn"),
("plotly.express", "px"),
("polars", "pl"),
("pyarrow", "pa"),
];

#[derive(
Expand All @@ -27,7 +34,7 @@ const CONVENTIONAL_ALIASES: &[(&str, &str)] = &[
)]
pub struct Options {
#[option(
default = r#"{"altair": "alt", "matplotlib.pyplot": "plt", "numpy": "np", "pandas": "pd", "seaborn": "sns"}"#,
default = r#"{"altair": "alt", "matplotlib": "mpl", "matplotlib.pyplot": "plt", "numpy": "np", "pandas": "pd", "seaborn": "sns", "tensorflow": "tf", "holoviews": "hv", "panel": "pn", "plotly.express": "px", "polars": "pl", "pyarrow": "pa"}"#,
value_type = "FxHashMap<String, String>",
example = r#"
[tool.ruff.flake8-import-conventions.aliases]
Expand All @@ -37,6 +44,7 @@ pub struct Options {
numpy = "np"
pandas = "pd"
seaborn = "sns"
scripy = "sp"
"#
)]
/// The conventional aliases for imports. These aliases can be extended by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,97 @@ expression: diagnostics
parent: ~
- kind:
ImportAliasIsNotConventional:
- altair
- alt
- tensorflow
- tf
location:
row: 10
column: 0
end_location:
row: 10
column: 17
fix: ~
parent: ~
- kind:
ImportAliasIsNotConventional:
- holoviews
- hv
location:
row: 11
column: 0
end_location:
row: 11
column: 16
fix: ~
parent: ~
- kind:
ImportAliasIsNotConventional:
- panel
- pn
location:
row: 12
column: 0
end_location:
row: 12
column: 12
fix: ~
parent: ~
- kind:
ImportAliasIsNotConventional:
- plotly.express
- px
location:
row: 13
column: 0
end_location:
row: 13
column: 21
fix: ~
parent: ~
- kind:
ImportAliasIsNotConventional:
- matplotlib
- mpl
location:
row: 14
column: 0
end_location:
row: 14
column: 17
fix: ~
parent: ~
- kind:
ImportAliasIsNotConventional:
- polars
- pl
location:
row: 15
column: 0
end_location:
row: 15
column: 13
fix: ~
parent: ~
- kind:
ImportAliasIsNotConventional:
- pyarrow
- pa
location:
row: 16
column: 0
end_location:
row: 16
column: 14
fix: ~
parent: ~
- kind:
ImportAliasIsNotConventional:
- altair
- alt
location:
row: 18
column: 0
end_location:
row: 18
column: 21
fix: ~
parent: ~
Expand All @@ -103,10 +187,10 @@ expression: diagnostics
- matplotlib.pyplot
- plt
location:
row: 12
row: 19
column: 0
end_location:
row: 12
row: 19
column: 32
fix: ~
parent: ~
Expand All @@ -115,10 +199,10 @@ expression: diagnostics
- dask.array
- da
location:
row: 13
row: 20
column: 0
end_location:
row: 13
row: 20
column: 27
fix: ~
parent: ~
Expand All @@ -127,10 +211,10 @@ expression: diagnostics
- dask.dataframe
- dd
location:
row: 14
row: 21
column: 0
end_location:
row: 14
row: 21
column: 28
fix: ~
parent: ~
Expand All @@ -139,10 +223,10 @@ expression: diagnostics
- numpy
- np
location:
row: 15
row: 22
column: 0
end_location:
row: 15
row: 22
column: 19
fix: ~
parent: ~
Expand All @@ -151,10 +235,10 @@ expression: diagnostics
- pandas
- pd
location:
row: 16
row: 23
column: 0
end_location:
row: 16
row: 23
column: 21
fix: ~
parent: ~
Expand All @@ -163,11 +247,95 @@ expression: diagnostics
- seaborn
- sns
location:
row: 17
row: 24
column: 0
end_location:
row: 17
row: 24
column: 22
fix: ~
parent: ~
- kind:
ImportAliasIsNotConventional:
- tensorflow
- tf
location:
row: 25
column: 0
end_location:
row: 25
column: 24
fix: ~
parent: ~
- kind:
ImportAliasIsNotConventional:
- holoviews
- hv
location:
row: 26
column: 0
end_location:
row: 26
column: 23
fix: ~
parent: ~
- kind:
ImportAliasIsNotConventional:
- panel
- pn
location:
row: 27
column: 0
end_location:
row: 27
column: 19
fix: ~
parent: ~
- kind:
ImportAliasIsNotConventional:
- plotly.express
- px
location:
row: 28
column: 0
end_location:
row: 28
column: 29
fix: ~
parent: ~
- kind:
ImportAliasIsNotConventional:
- matplotlib
- mpl
location:
row: 29
column: 0
end_location:
row: 29
column: 23
fix: ~
parent: ~
- kind:
ImportAliasIsNotConventional:
- polars
- pl
location:
row: 30
column: 0
end_location:
row: 30
column: 19
fix: ~
parent: ~
- kind:
ImportAliasIsNotConventional:
- pyarrow
- pa
location:
row: 31
column: 0
end_location:
row: 31
column: 21
fix: ~
parent: ~