Skip to content

Imports of "examples" break in distributed package #2042

@ksunden

Description

@ksunden

Short description

Our examples, in particular noticed with parametertree.py, import the examples as a top level import designed to work when run from the top level of the repo.

We do Path mangling to insert the folder containing examples into the search path for the

Code to reproduce

From an installed version of pyqtgraph (non editable install), Not running from a directory that contains the examples folder

python -m pyqtgraph.examples

Select Parameter Tree example

Expected behavior

Parameter tree example should run

Real behavior

fails to run with Import Error

Traceback (most recent call last):
  File "/home/blaise/miniconda3/envs/edge/lib/python3.9/site-packages/pyqtgraph/examples/parametertree.py", line 15, in <module>
    from examples._buildParamTypes import makeAllParamTypes
ModuleNotFoundError: No module named 'examples'

Tested environment(s)

  • PyQtGraph version: 0.12.3 (conda)
  • Qt Python binding: Not fully sure, should be orthogonal anyway (not actually my machine)
  • Python version: 3.9
  • NumPy version: Not fully sure, should be orthogonal anyway (not actually my machine)
  • Operating system: Debian
  • Installation method: conda

Additional context

I am personally in favor of just moving the examples into the library proper and doing relative imports rather than path wrangling and imports assuming "examples" is top level.

I know the hesitation in the past has been for ease of finding the examples... and that the conclusion was that if we could reliably have symlinks the ideal solution would be to have the canonical version inside the library with a symlink to it from the top level of the repo... but symlinks are problematic on NTFS and therefore windows...

Moving it in the repo would make python -m pyqtgraph.examples work with editable installs as well as non-editable installs, and significantly simplify setup.py

My proposal is that we keep the examples folder in the top level, but with just a README.md that contains an index with links and a description of how to run the examples using python -m This keeps the discoverability of examples, while simplifying packaging and the examples themselves to always be able to do relative imports without editing path. I still think perhaps the examples have good reason to do full imports for pyqtgraph, but relative for things only within the examples submodule.

The examples assume installed anyway.

I guess the other consideration was for vendoring purposes, you can leave out the examples, but I'm not too sure that is a concern, if vendoring projects are concerned about size, it is pretty trivial to remove the folder, otherwise it has no effect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions