Skip to content

Add plotly[express] extra for easily installing Plotly Express dependencies #4644

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

Merged
merged 21 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 11 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
12 changes: 6 additions & 6 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,17 @@ We will support Python 3.12 and higher versions soon.

### Install requirements - (Non-Windows)
```bash
(plotly_dev) $ pip install -r packages/python/plotly/requirements.txt
(plotly_dev) $ pip install -r packages/python/plotly/optional-requirements.txt
(plotly_dev) $ pip install -r packages/python/plotly/requires-install.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this step required in contributing.md? I think it's covered by the editable install of plotly further down.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ndrezn @emilykl if you can spare time today, it would be great to get this one in - thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch @LiamConnors , I'll remove this

(I verified that the setup instructions still work without this step, at least on Mac)

(plotly_dev) $ pip install -r packages/python/plotly/requires-dev.txt
```
### Install requirements - (Windows + Conda)
Because Windows requires Visual Studio libraries to compile some of the optional dependencies, follow these steps to
complete installation and avoid gdal-config errors.

```bash
(plotly_dev) $ pip install -r packages/python/plotly/requirements.txt
(plotly_dev) $ pip install -r packages/python/plotly/requires-install.txt
(plotly_dev) $ conda install fiona
(plotly_dev) $ pip install -r packages/python/plotly/optional-requirements.txt
(plotly_dev) $ pip install -r packages/python/plotly/requires-dev.txt
```

### Editable install of plotly packages
Expand Down Expand Up @@ -178,7 +178,7 @@ documentation on _development mode_.
This repo uses the [Black](https://black.readthedocs.io/en/stable/) code formatter,
and the [pre-commit](https://pre-commit.com/) library to manage a git commit hook to
run Black prior to each commit. Both pre-commit and black are included in the
`packages/python/plotly/optional-requirements.txt` file, so you should have them
`packages/python/plotly/requires-dev.txt` file, so you should have them
installed already if you've been following along.

To enable the Black formatting git hook, run the following from within your virtual
Expand Down Expand Up @@ -266,7 +266,7 @@ We take advantage of two tools to run tests:

### Running Tests with `pytest`

Since our tests cover *all* the functionality, to prevent tons of errors from showing up and having to parse through a messy output, you'll need to install `optional-requirements.txt` as explained above.
Since our tests cover *all* the functionality, to prevent tons of errors from showing up and having to parse through a messy output, you'll need to install `requires-dev.txt` as explained above.

After you've done that, go ahead and run the test suite!

Expand Down
3 changes: 3 additions & 0 deletions packages/python/plotly/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ include LICENSE.txt
include README.md
include versioneer.py
include plotly/_version.py
include requires-install.txt
include requires-dev.txt
include requires-express.txt
include plotly/package_data/widgetbundle.js
13 changes: 12 additions & 1 deletion packages/python/plotly/plotly/express/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@
`plotly.express` is a terse, consistent, high-level wrapper around `plotly.graph_objects`
for rapid data exploration and figure generation. Learn more at https://plotly.com/python/plotly-express/
"""

from plotly import optional_imports

np = optional_imports.get_module("numpy")
if np is None:
raise ImportError(
"""\
Plotly express requires numpy to be installed."""
Plotly Express requires numpy to be installed. You can install numpy using pip with:

$ pip install numpy

Or install Plotly Express and its dependencies directly with:

$ pip install "plotly[express]"

You can also use Plotly Graph Objects to create a large number of charts without installing
numpy. See examples here: https://plotly.com/python/graph-objects/
"""
)

from ._imshow import imshow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### Optional Dependencies for Additional Plotly Functionality ###
### ###
### To install, run: ###
### $ pip install -r optional-requirements.txt ###
### $ pip install -r requires-dev.txt ###
### ###
###################################################################

Expand Down
8 changes: 8 additions & 0 deletions packages/python/plotly/requires-express.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Required dependencies for Plotly Express ###
### ###
### To install, run: ###
### $ pip install -r requires-express.txt ###
### ###
###################################################

numpy
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
### Dependencies for Core Plotly Functionality ###
### ###
### To install, run: ###
### $ pip install -r requirements.txt ###
### $ pip install -r requires-install.txt ###
### ###
###################################################

## dataframe agnostic layer ##
narwhals>=1.13.3
packaging
16 changes: 14 additions & 2 deletions packages/python/plotly/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
else:
skip_npm = False


# Load plotly.js version from js/package.json
def plotly_js_version():
path = os.path.join(here, "js", "package.json")
Expand Down Expand Up @@ -260,7 +261,6 @@ def request_json(url):


def get_latest_publish_build_info(repo, branch):

url = (
r"https://circleci.com/api/v1.1/project/github/"
r"{repo}/tree/{branch}?limit=100&filter=completed"
Expand Down Expand Up @@ -494,6 +494,14 @@ def run(self):
]

versioneer_cmds = versioneer.get_cmdclass()


def read_req_file(req_type):
with open(f"requires-{req_type}.txt", encoding="utf-8") as fp:
requires = (line.strip() for line in fp)
return [req for req in requires if req and not req.startswith("#")]


setup(
name="plotly",
version=versioneer.get_version(),
Expand Down Expand Up @@ -551,7 +559,11 @@ def run(self):
"package_data/datasets/*",
],
},
install_requires=["narwhals>=1.13.3", "packaging"],
install_requires=read_req_file("install"),
extras_require={
"express": read_req_file("express"),
"dev": read_req_file("dev"),
},
zip_safe=False,
cmdclass=dict(
build_py=js_prerelease(versioneer_cmds["build_py"]),
Expand Down