timofurrer / w1thermsensor

A Python package and CLI tool to work with w1 temperature sensors like DS1822, DS18S20 & DS18B20 on the Raspberry Pi, Beagle Bone and other devices.
MIT License
493 stars 113 forks source link

setup.py: Make click dependency optional #72

Closed jonte closed 4 years ago

jonte commented 4 years ago

This makes it easier to install only the python modules, and not the w1thermsensor command line utility.

If there is only interest in the python modules, do the following:

pip install w1thermsensor

If the w1thermsensor utility is invoked when the package has been installed in this way, an informative error message is displayed, notifying that click needs to be installed.

To ensure that the w1thermsor utility also works, specify additional dependencies using [CLI], as such:

pip install w1thermsensor[CLI]

Signed-off-by: Jonatan Pålsson jonatan.p@gmail.com

codecov-io commented 4 years ago

Codecov Report

Merging #72 into master will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #72   +/-   ##
=======================================
  Coverage   45.47%   45.47%           
=======================================
  Files           6        6           
  Lines         552      552           
=======================================
  Hits          251      251           
  Misses        301      301

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update e3dff2e...0ec971d. Read the comment docs.

jonte commented 4 years ago

There are two issues with this, as I see it now:

What do you think @timofurrer ?

jonte commented 4 years ago

Perhaps some background information is in place as well.. I wish to install this module in my Yocto build, but I do not use the w1thermsensor utility. In my BitBake recipe, I will make the w1thermsensor utility a separate package, which can be optionally selected by users of the BitBake recipe.. This means that the utility must also be optional when building w1thermsensor itself.

An altenative way to solve this would be to patch w1thermsensor in the BitBake recipe in order to make the command line utility optional, but I would rather have that feature upstream (here :)) if possible.

timofurrer commented 4 years ago

Not sure what setuptools and pip support regarding those extras for entry_points. According to https://packaging.python.org/specifications/entry-points/#data-model this should actually be supported, but is no longer recommended.

However, I don't really understand why and am not sure what a successor of this should be. I'd consider this feature as useful.

Did you get any further? @jonte

jonte commented 4 years ago

Hi,

I didn't really get further unfortunately. I asked on the Distutils-SIG ML a few months back, and got this reply:

I would like to change the behavior, so that the entry point is not installed if the extra dependencies are not available (and perhaps also show a warning, indicating that this entry point has not been installed).

I don't believe this is possible. Achieving this new behavior would, at a minimum, require changes to pip (and possibly also to the entry points format in order to indicate which behavior is desired). As associating extras with entry points is currently considered deprecated to begin with, I doubt you'd have much luck convincing the pip maintainers to add such a feature.

The closest way to get the behavior you want would be to split off the CLI-specific code from your project into a separate project, and have this new project install the entry point while always depending on the first project and the "CLI" extras.

The last paragraph hints towards a workaround. I did not try this yet though.

timofurrer commented 4 years ago

That really sounds unfortunate for our use case here ...

The closest way to get the behavior you want would be to split off the CLI-specific code from your project into a separate project, and have this new project install the entry point while always depending on the first project and the "CLI" extras.

I doubt that this is going to happen for w1thermsensor. It would add an overhead which really is undesired. If a distribution wants to split CLI and Python API into different packages they are free to do so.

If the Python packaging situation changes, I'm happy to tackle this again - for now, I'm going to close this :tada: