Skip to content

Commit 6c0e2ec

Browse files
committed
refactor: move commands into bin and write Makefile to run them
1 parent b105c8b commit 6c0e2ec

15 files changed

+448
-403
lines changed

CONTRIBUTING.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ it is important to understand the structure of the code and the repository.
1919
- The [`plotly.graph_objects`](https://plotly.com/python/graph-objects/) module (usually imported as `go`)
2020
is [generated from the plotly.js schema](https://plotly.com/python/figure-structure/),
2121
so changes to be made in this package need to be contributed to [plotly.js](https://github.com/plotly/plotly.js)
22-
or to the code generation system in `./codegen/`.
22+
or to the code generation system in `./bin/codegen/`.
2323
Code generation creates traces and layout classes that have a direct correspondence to their JavaScript counterparts,
2424
while higher-level methods that work on figures regardless of the current schema (e.g., `BaseFigure.for_each_trace`)
2525
are defined in `plotly/basedatatypes.py`.
@@ -42,12 +42,13 @@ it is important to understand the structure of the code and the repository.
4242
The documentation is a great place to start contributing,
4343
since you can add or modify examples without setting up a full environment.
4444

45-
Code and documentation are not the only way to contribute:
46-
you can also help by:
45+
Code and documentation are not the only way to contribute.
46+
You can also help by:
4747

4848
- Reporting bugs at <https://github.com/plotly/plotly.py/issues>.
4949
Please take a moment to see if your problem has already been reported, and if so, add a comment to the existing issue;
50-
we will try to prioritize those that affect the most people.
50+
we will try to prioritize those that affect the most people
51+
and that are accompanied by small, runnable examples.
5152

5253
- Submitting feature requests (also at <https://github.com/plotly/plotly.py/issues>).
5354
Again, please add a comment to an existing issue if the feature you want has already been requested.
@@ -219,11 +220,11 @@ Once you have done that,
219220
run the `updateplotlyjs` command:
220221

221222
```bash
222-
python commands.py updateplotlyjs
223+
python bin/updatejs.py
223224
```
224225

225226
This downloads new versions of `plot-schema.json` and `plotly.min.js` from the `plotly/plotly.js` GitHub repository
226-
and places them in `plotly/package_data`.
227+
and places them in `resources` and `plotly/package_data` respectively.
227228
It then regenerates all of the `graph_objs` classes based on the new schema.
228229

229230
### Using a Development Branch of Plotly.js
@@ -232,7 +233,8 @@ If your development branch is in [the plotly.js repository](https://github.com/p
232233
you can update to development versions of `plotly.js` with this command:
233234

234235
```bash
235-
python commands.py updateplotlyjsdev --devrepo reponame --devbranch branchname
236+
# FIXME commands.py didn't provide --devrepo or --devbranch
237+
python bin/updatejs.py --dev --devrepo reponame --devbranch branchname
236238
```
237239

238240
This fetches the `plotly.js` in the CircleCI artifact of the branch `branchname` of the repo `reponame`.
@@ -255,5 +257,6 @@ You can then run the following command
255257
*in your local plotly.py repository*:
256258

257259
```bash
258-
python commands.py updateplotlyjsdev --local /path/to/your/plotly.js/
260+
# FIXME: commands.py didn't provide --local
261+
python bin/updatejs.py --dev --local /path/to/your/plotly.js/
259262
```

Makefile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Manage snailz project.
2+
3+
PYTHON = uv run python
4+
CODE_DIRS = _plotly_utils plotly scripts
5+
6+
## commands: show available commands
7+
commands:
8+
@grep -h -E '^##' ${MAKEFILE_LIST} | sed -e 's/## //g' | column -t -s ':'
9+
10+
## docs: rebuild documentation
11+
.PHONY: docs
12+
docs:
13+
${PYTHON} -m mkdocs build
14+
15+
## format: reformat code
16+
format:
17+
${PYTHON} -m ruff format ${CODE_DIRS}
18+
19+
## generate: generate code
20+
generate:
21+
${PYTHON} bin/generate_code.py --codedir plotly
22+
23+
## lint: check the code
24+
lint:
25+
${PYTHON} -m ruff check ${CODE_DIRS}
26+
27+
## test: run tests
28+
test:
29+
${PYTHON_M} pytest tests
30+
31+
## updatejs: update JavaScript bundle
32+
updatejs:
33+
${PYTHON} bin/updatejs.py --codedir plotly
34+
35+
## --: --
36+
37+
## clean: clean up repository
38+
clean:
39+
@find . -name '*~' -delete
40+
@find . -name '.DS_Store' -delete
41+
@rm -rf .coverage
42+
@rm -rf .pytest_cache
43+
@rm -rf .ruff_cache
44+
@rm -rf dist
45+
46+
## sync: update Python packages
47+
sync:
48+
uv sync --extra dev

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,21 @@ Built on top of [plotly.js](https://github.com/plotly/plotly.js), `plotly.py` is
7676

7777
## Installation
7878

79-
plotly.py may be installed using pip
79+
plotly.py may be installed using pip:
8080

8181
```
8282
pip install plotly
8383
```
8484

85-
or conda.
85+
or conda:
8686

8787
```
8888
conda install -c conda-forge plotly
8989
```
9090

9191
### Jupyter Widget Support
9292

93-
For use as a Jupyter widget, install `jupyter` and `anywidget`
94-
packages using `pip`:
93+
For use as a Jupyter widget, install the `jupyter` and `anywidget` packages using `pip`:
9594

9695
```
9796
pip install jupyter anywidget
@@ -112,14 +111,14 @@ command line utility (legacy as of `plotly` version 4.9).
112111

113112
#### Kaleido
114113

115-
The [`kaleido`](https://github.com/plotly/Kaleido) package has no dependencies and can be installed
116-
using pip
114+
The [`kaleido`](https://github.com/plotly/Kaleido) package has no dependencies
115+
and can be installed using pip:
117116

118117
```
119118
pip install -U kaleido
120119
```
121120

122-
or conda
121+
or conda:
123122

124123
```
125124
conda install -c conda-forge python-kaleido
@@ -129,13 +128,13 @@ conda install -c conda-forge python-kaleido
129128

130129
Some plotly.py features rely on fairly large geographic shape files. The county
131130
choropleth figure factory is one such example. These shape files are distributed as a
132-
separate `plotly-geo` package. This package can be installed using pip...
131+
separate `plotly-geo` package. This package can be installed using pip:
133132

134133
```
135134
pip install plotly-geo==1.0.0
136135
```
137136

138-
or conda
137+
or conda:
139138

140139
```
141140
conda install -c plotly plotly-geo=1.0.0
@@ -145,7 +144,7 @@ conda install -c plotly plotly-geo=1.0.0
145144

146145
## Copyright and Licenses
147146

148-
Code and documentation copyright 2019 Plotly, Inc.
147+
Code and documentation copyright Plotly, Inc.
149148

150149
Code released under the [MIT license](https://github.com/plotly/plotly.py/blob/main/LICENSE.txt).
151150

codegen/__init__.py renamed to bin/codegen/__init__.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,6 @@ def make_paths(outdir):
9696
return validators_dir, graph_objs_dir, graph_objects_path
9797

9898

99-
def lint_code(outdir):
100-
"""Check Python code using settings in pyproject.toml."""
101-
102-
subprocess.call(["ruff", "check", *make_paths(outdir)])
103-
104-
105-
def reformat_code(outdir):
106-
"""Reformat Python code using settings in pyproject.toml."""
107-
108-
subprocess.call(["ruff", "format", *make_paths(outdir)])
109-
110-
11199
def perform_codegen(outdir, noformat=False):
112100
"""Generate code (and possibly reformat)."""
113101

@@ -123,7 +111,7 @@ def perform_codegen(outdir, noformat=False):
123111
# Load plotly schema
124112
project_root = opath.dirname(outdir)
125113
plot_schema_path = opath.join(
126-
project_root, "codegen", "resources", "plot-schema.json"
114+
project_root, "resources", "plot-schema.json"
127115
)
128116

129117
with open(plot_schema_path, "r") as f:
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

bin/generate_code.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Generate code."""
2+
3+
import argparse
4+
5+
import utils
6+
7+
8+
def main():
9+
"""Main driver."""
10+
11+
args = parse_args()
12+
codedir = utils.select_code_directory(args)
13+
utils.perform_codegen(codedir, noformat=args.noformat)
14+
15+
16+
def parse_args():
17+
"""Parse command-line arguments."""
18+
19+
parser = argparse.ArgumentParser()
20+
parser.add_argument(
21+
"--noformat", action="store_true", help="prevent reformatting"
22+
)
23+
parser.add_argument("--codedir", type=str, help="code directory")
24+
return parser.parse_args()
25+
26+
27+
if __name__ == "__main__":
28+
main()

0 commit comments

Comments
 (0)