-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
switch to ruff #5218
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
base: main
Are you sure you want to change the base?
switch to ruff #5218
Conversation
@gvwilson big picture comments --
|
8bb233e
to
6999c5d
Compare
- Switch to `argparse` and clean up imports in `commands.py`. - Remove `requires-optional.txt` and `test_requirements/*` (put dependencies in `pyproject.toml` instead). - Remove `black` and use `ruff` instead. - Add `--noformat` option to `python commands.py codegen` for experimenting. - Pass output directory around to control what is formatted and linted. - Add `python commands.py format` to only do formatting. - Add `python commands.py lint` to check code. - Reformat comments in `codegen/*.py`. - Use double-quoted strings for (most) code generation. - Update various GitHub templates. - Update CONTRIBUTING.md to reflect switch from black to ruff: - Reorganize sections. - Rewrite chunks of prose. - Replace mentions of `black` with mentions of `ruff`. - And describe `uv` usage. Note: 1. Only the generated code is formatted and linted: - `plotly/validators/**/*.py` - `plotly/graph_objs/**/*.py` - `plotly/graph_objects/__init__.py` 2. The strings in the data used by code generation are (for example) `"'some_name'"` (i.e., have embedded single quotes). This PR does not try to fix that: instead, we rely on reformatting to turn all the single-quoted strings into double-quoted strings. 3. `CONTRIBUTING.md` refers to `pre-commit` and the old `requires-optional.txt` installed it, but there isn't a `.pre-commit-config.yaml` file in this repository. Wuzzup?
"geopandas", | ||
"inflect", | ||
"jupyter", | ||
"kaleido==1.0.0rc15", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"kaleido==1.0.0rc15", | |
"plotly[kaleido]", |
- other pure-Python submodules are: `plotly.io` (low-level interface for | ||
displaying, reading and writing figures), `plotly.subplots` (helper function | ||
for layout of multi-plot figures) | ||
- Tests are found in `plotly/tests`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Tests are found in `plotly/tests`. | |
- Tests are found in `tests/`. |
- The documentation is in this repository, | ||
and its structure is described in [its README file](doc/README.md). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The documentation is in this repository, | |
and its structure is described in [its README file](doc/README.md). | |
- Documentation is found in `doc/`, and its structure is described in [its README file](doc/README.md). |
https://github.com/plotly/plotly.py/issues/1965. If you have writing skills, | ||
the wording of existing examples can also be improved in places. | ||
Code and documentation are not the only way to contribute: | ||
you can also hepl the project by: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can also hepl the project by: | |
you can also help the project by: |
|
||
- reporting bugs (see below). | ||
- Submitting feature request (also at <https://github.com/plotly/plotly.py/issues>). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Submitting feature request (also at <https://github.com/plotly/plotly.py/issues>). | |
- Submitting a feature request (also at <https://github.com/plotly/plotly.py/issues>). |
## Have a Bug Report? | ||
This section explains how to set up a development environment so that you can contribute code and/or tests. | ||
Note that if you are modifying a single documentation page, | ||
you can do it directly on Github by clicking on the "Edit this page on GitHub" link without cloning the repository. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can do it directly on Github by clicking on the "Edit this page on GitHub" link without cloning the repository. | |
you can do it directly on GitHub by clicking on the "Edit this page on GitHub" link without cloning the repository. |
## Have Questions about Plotly? | ||
We use Git and GitHub to manage our project; | ||
if you are not familiar with them, | ||
there are great resources like <http://try.github.io/> to get your started. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are great resources like <http://try.github.io/> to get your started. | |
there are great resources like <http://try.github.io/> to get you started. |
```bash | ||
(plotly_dev) $ pip install -e . | ||
``` | ||
This command also creates an *editable install* of plotly.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This command also creates an *editable install* of plotly.py | |
If using `conda` or `virtualenv`, you can install all packages with: | |
```bash | |
pip install -e '.[dev]' | |
``` | |
These commands creates an *editable install* of plotly.py |
This repo uses [ruff](https://astral.sh/ruff) to format Python code consistently | ||
and the [pre-commit](https://pre-commit.com/) library to manage a Git commit hook to run ruff prior to each commit. | ||
Both pre-commit and ruff are included in `pyproject.toml`, | ||
so you should have them installed already if you've been following along. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not using pre-commit hooks currently
This repo uses [ruff](https://astral.sh/ruff) to format Python code consistently | |
and the [pre-commit](https://pre-commit.com/) library to manage a Git commit hook to run ruff prior to each commit. | |
Both pre-commit and ruff are included in `pyproject.toml`, | |
so you should have them installed already if you've been following along. | |
This repo uses [ruff](https://astral.sh/ruff) to format Python code consistently. Ruff is included in the `plotly[dev]` install, so you should have it installed already if you've been following along. |
To enable the ruff formatting Git hook, | ||
run this command in your virtual environment: | ||
|
||
```bash | ||
(plotly_dev) $ pre-commit install | ||
pre-commit install | ||
``` | ||
|
||
Now, whenever you perform a commit, the Black formatter will run. If the formatter | ||
makes no changes, then the commit will proceed. But if the formatter does make changes, | ||
then the commit will abort. To proceed, stage the files that the formatter | ||
modified and commit again. | ||
ruff will now run automatically whenever you perform a commit. | ||
The commit will proceed if the formatter makes no changes, | ||
but will be aborted if it does. | ||
To proceed, | ||
add the files that the formatter modified and commit again. | ||
|
||
If you don't want to use `pre-commit`, then you can run black manually prior to making | ||
a PR as follows. | ||
If you don't want to use `pre-commit`, | ||
you can run ruff manually prior to making a PR with: | ||
|
||
```bash | ||
(plotly_dev) $ black . | ||
ruff check . | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this section -- we're not currently using pre-commit hooks in the dev process, and the pre-commit install
command fails because pre-commit
is not in the dev requirements
|
||
```bash | ||
$ python commands.py updateplotlyjs | ||
pytest tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pytest tests | |
python -m pytest tests |
```bash | ||
python commands.py updateplotlyjsdev --devrepo reponame --devbranch branchname | ||
pytest tests/test_plotly/test_plot.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pytest tests/test_plotly/test_plot.py | |
python -m pytest tests/test_plotly/test_plot.py |
|
||
```bash | ||
# In your plotly.js/ directory, prepare the package: | ||
### Generating the JavaScript Bundle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Generating the JavaScript Bundle | |
### Generating the JavaScript Bundles for Jupyter |
$ npm pack | ||
$ mv plotly.js-*.tgz plotly.js.tgz | ||
To test `go.FigureWidget` locally, you'll need to generate the JavaScript bundle as follows: | ||
|
||
# In your plotly.py/ directory: | ||
$ python commands.py updateplotlyjsdev --local /path/to/your/plotly.js/ | ||
``` | ||
cd js | ||
npm install && npm run build | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete
```bash | ||
pytest -v tests/ | ||
``` | ||
### CircleCI Release |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### CircleCI Release | |
### Using a development branch of Plotly.js |
"numpy", | ||
"pandas", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"numpy", | |
"pandas", | |
"numpy", | |
"orjson", | |
"pandas", |
This PR converts linting and formatting from
black
toruff
.requires-optional.txt
(no longer used, version conflict was confusing).commands.py
to useargparse
instead of hand-rolled.codegen/__init__.py
(all at top level)."dev"
section ofpyproject.toml
to usingruff
instead ofblack
.inflect
andrequests
.uv.lock
file used byuv
.codegen/__init__.py
to useruff
instead ofblack
.ruff
to reformat existing code (runpython commands.py format
).ruff
to check code (runpython commands.py lint
).TODO:
This PR does not reformat generated code, tests, or utilities: that, and cleaning up all the problems identified by
ruff
, will be done once this PR is approved.This PR currently fails the build because Circle CI is expecting
requires-optional.txt
, which this PR removes. We need to decide if we're leaving build on Circle CI or moving it to GitHub.