[go: nahoru, domu]

Skip to content
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

Forced installation of matplotlib #259

Open
AxelVoitier opened this issue Jan 28, 2021 · 6 comments · Fixed by #260
Open

Forced installation of matplotlib #259

AxelVoitier opened this issue Jan 28, 2021 · 6 comments · Fixed by #260
Assignees

Comments

@AxelVoitier
Copy link
Collaborator

Hello,

I noticed the new plot feature is creating a hard dependency on matplotlib.
Can this be avoided?

We are installing this package on restricted embedded targets. Just declaring the dependency creates all kind of issues just by installing cantools: from disk usage to compilation time (as it goes through qemu ARM emulation). Especially since matplotlib also depends on numpy...

Can that be declared as an extras in setup.py? And have the main be clever enough to skip on adding subparsers when their importation fails?

Also related is that comment in the main about curses (which actually used to create us issues in the past, as we did not have it on the target :D).

I can send a PR for that later (some times in February, maybe).

Cheers,
Axel

@eerimoq
Copy link
Collaborator
eerimoq commented Jan 28, 2021

I understand. Feel free to submit a PR that makes all troublesome dependencies optional. One option could be to split the cantools package into one core package and one or more smaller for certain tools. But let's try to avoid that.

@tjhowse
Copy link
Collaborator
tjhowse commented Jan 28, 2021

This also affects us: we're running cantools on a resource- and bandwidth-constrained platform and would rather remove the install hacks that uninstall matplotlib after installing cantools :)

@segaura
Copy link
segaura commented Feb 16, 2021

I am running cantools 36.2.0 on "raspbian-server" without graphical (X) environment, and installed matplotlib 3.3.4

$ pip show matplotlib
Name: matplotlib
Version: 3.3.4
Summary: Python plotting package
Home-page: https://matplotlib.org
Author: John D. Hunter, Michael Droettboom
Author-email: matplotlib-users@python.org
License: PSF
Location: /home/pi/.local/lib/python3.7/site-packages
Requires: python-dateutil, pyparsing, pillow, kiwisolver, cycler, numpy
Required-by:

commands like cantools decode shows this error

matplotlib package not installed. Required for producing plots.
Traceback (most recent call last):
  File "/home/pi/.local/bin/cantools", line 10, in <module>
    sys.exit(_main())
  File "/home/pi/.local/lib/python3.7/site-packages/cantools/__init__.py", line 38, in _main
    from .subparsers import plot
  File "/home/pi/.local/lib/python3.7/site-packages/cantools/subparsers/plot.py", line 59, in <module>
    plt.rcParams["date.autoformatter.hour"] = "%H:%M"
NameError: name 'plt' is not defined

trying to use matplotlib alone just to test its installation it doesn't work.

As a workaround I reverted to cantools 35.5.0 but if there's a way to use the latest version without the need for a working matplotlib, it would be better.

@AxelVoitier
Copy link
Collaborator Author

I will give it a go, I have more time to work on it right now.

@AxelVoitier
Copy link
Collaborator Author
AxelVoitier commented Feb 17, 2021

Actually, #265 should fixes your issue @segaura. It's a matter of having it in a released version now.

I will just add an extra in setup.py for plot that will declare a dependency on matplotlib, and document it in README.rst.

@eerimoq
Copy link
Collaborator
eerimoq commented Feb 17, 2021

@AxelVoitier Feel free to review, merge and tag the fix. Tagged commits are automatically published on PyPI, so it should be easy. I'll be less active in the project from now on and I hope everyone interested in cantools will figure out a way for it to continue being successful.

VonSquiggles pushed a commit to VonSquiggles/cantools that referenced this issue May 13, 2022
* p402: Do not switch any states during setup_402_state_machine().

Reading the PDO configuration is possible in OPERATIONAL or
PRE-OPERATIONAL states, so switching that is unnecessary.  The
application should be responsible to handle such transitions, and the
library function should be usable without disturbing the application
logic.

Changing the DS402 state machine to SWITCH ON DISABLED is also not
necessary.  The drive may be in whatever state from a previous usage,
and then the change to SWITCH ON DISABLED may even trigger an
exception because there is no way to reach it directly.  So this
transition should also be the application's responsibility.

* p402: Check NMT state before reading PDO configuration.

SDOs are allowed in all but the STOPPED state.  That would lead to a
timeout and an SdoCommunicationError exception.  Checking the NMT
state here raises an exception without a timeout involved.

* p402: Make reading the PDO configuration optional during setup.

If the application already configured the PDOs and called .save() on
the pdo.Maps object, there is no sense in reading everything back
again in the setup_pdos() method.  Provide an optional argument to
disable that behavior.

A call to subscribe to the PDOs from the network is added because that
side-effect of pdo.read() is necessary for the TPDO callback to work.

* p402: Allow skipping PDO upload from setup_402_state_machine().

Add an optional argument which is simply passed down to setup_pdos()
to choose whether reading the PDO configuration is necessary.

* Fix DS402 documentation to match the implementation.

Besides the changes regarding setup_402_state_machine(), there were
numerous errors where the documentation talks about nonexistent or
differently named attributes.

Also fix the description regaring what the method actually does.  It
won't configure the TPDO1 to contain the Statusword, but only check
the PDO configuration for Statusword and Controlword presence.

Co-authored-by: André Filipe Silva <af-silva@users.noreply.github.com>
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 a pull request may close this issue.

4 participants