Skip to content

Moved examples inside project directory#2045

Merged
j9ac9k merged 3 commits intopyqtgraph:masterfrom
j9ac9k:move-examples-into-project
Oct 30, 2021
Merged

Moved examples inside project directory#2045
j9ac9k merged 3 commits intopyqtgraph:masterfrom
j9ac9k:move-examples-into-project

Conversation

@j9ac9k
Copy link
Copy Markdown
Member

@j9ac9k j9ac9k commented Oct 28, 2021

Fixes #2042

This PR moves the examples from the {project_dir}/examples to {project_dir}/pyqtgraph/examples.

This change was prompted by #2042 which @ksunden pointed out that some of the examples didn't work when pyqtgraph was installed in non-editable mode and the examples were run from outside the project directory. Given the extensive path manipulation via import initExample on every example, and in other places, figured this would be a good time to take out some of the custom code written for pyqtgraph's setup.py and use standard setuptools functionality instead.

I also took the opportunity to update MANIFEST.in which only effects source distributions.

A by-product of this change means that examples may not work if pyqtgraph is not installed via pip. Given that I'd like to phase out support for pyqtgraph to be used when not via a package manager, I'm good with this change (but others may not be).

The testing I did was as follows

I launched the example app via python -m pyqtgraph.examples and then ran the parameter tree example ensuring it ran successfully (this example is good because it imports other python modules in the example directory, and imports from pyqtgraph)

I did this for editable and non-editable installs, from both the root project directory and a directory not within the project.

Furthermore, I ran through the test suite pytest -n auto pyqtgraph/examples

What no longer works is running python -m pyqtgraph.examples from the project directory (example app pops up) but almost all examples fail as they attempt to import pyqtgraph which reports package not found. this works now

The only use-case I can identify where examples do not work is if a user attempts to run an example directly (ex: python pyqtgraph/examples/PlotSpeedTest.py and pyqtgraph is not installed; the user will get an ImportError.

EDIT: slight oddity; somewhere in the development process here, I managed to break pyopengl to the point that I would get an import error; after force-reinstalling it, I could no longer replicate

Python 3.9.7 (default, Sep 17 2021, 12:53:27)
[Clang 12.0.5 (clang-1205.0.22.11)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from OpenGL.GL import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ogi/.zinit/plugins/pyenv---pyenv/versions/3.9.7/envs/pyqtgraph-pyqt_62-py39/lib/python3.9/site-packages/OpenGL/GL/__init__.py", line 3, in <module>
    from OpenGL import error as _error
  File "/Users/ogi/.zinit/plugins/pyenv---pyenv/versions/3.9.7/envs/pyqtgraph-pyqt_62-py39/lib/python3.9/site-packages/OpenGL/error.py", line 12, in <module>
    from OpenGL import platform, _configflags
  File "/Users/ogi/.zinit/plugins/pyenv---pyenv/versions/3.9.7/envs/pyqtgraph-pyqt_62-py39/lib/python3.9/site-packages/OpenGL/platform/__init__.py", line 21, in <module>
    from OpenGL import _configflags
  File "/Users/ogi/.zinit/plugins/pyenv---pyenv/versions/3.9.7/envs/pyqtgraph-pyqt_62-py39/lib/python3.9/site-packages/OpenGL/_configflags.py", line 2, in <module>
    from OpenGL import (
ImportError: cannot import name 'ERROR_CHECKING' from 'OpenGL' (unknown location)
>>> exit()

@j9ac9k j9ac9k force-pushed the move-examples-into-project branch 2 times, most recently from c507d19 to 69bc263 Compare October 28, 2021 06:56
By adding the project root directory to PYTHONPATH and passing that
environment variable to the subprocess.Popen call, we can get pyqtgraph
to be importable despite it not being installed.

By extension, we can do the same thing within test_examples so the
examples can be tested without pyqtgraph needing to be installed as well
@j9ac9k j9ac9k force-pushed the move-examples-into-project branch from 69bc263 to 1bf49a7 Compare October 28, 2021 15:40
@j9ac9k
Copy link
Copy Markdown
Member Author

j9ac9k commented Oct 28, 2021

Made more progress, by passing along PYTHONPATH={root_project_directory} to the subprocess.Popen calls, examples now work when pyqtgraph is not installed and examples are either executed from the Example Application or when run via the test suite. Running examples by running the filename directly will fail if pyqtgraph is not installed; with the raise of an ImportError stating pyqtgraph cannot be found/imported.

@j9ac9k
Copy link
Copy Markdown
Member Author

j9ac9k commented Oct 30, 2021

I think this PR is ready for merging; I'll give folks a bit to see if they spot any issues; otherwise I'll merge over the weekend.

@j9ac9k j9ac9k force-pushed the move-examples-into-project branch from e2e7d16 to 826fac4 Compare October 30, 2021 04:42
@j9ac9k j9ac9k merged commit 259d931 into pyqtgraph:master Oct 30, 2021
@j9ac9k j9ac9k deleted the move-examples-into-project branch October 30, 2021 18:08
proc = subprocess.Popen([sys.executable, '-'], stdin=subprocess.PIPE, cwd=path, env=env)
code = str(self.ui.codeView.toPlainText()).encode('UTF-8')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This encoding still seems to be required, see issue #2060 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Imports of "examples" break in distributed package

2 participants