Repository: pwr-Solaar/Solaar

Issue:
Incorrect packaging of the `/etc` directory
**Information**
<!-- Do not bother opening an issue for version 0.9.2 or older, it is extremely outdated. Please update to the latest one and see if your issue persists. -->
- Solaar version (`git describe --tags` if cloned from Solaar repository): `master`

**Describe the bug**
A Solaar wheel contains the following.
```tree
.install-cache/pkg/
├── etc
│   ├── udev
│   │   └── rules.d
│   │       └── 42-logitech-unify-permissions.rules
│   └── xdg
│       └── autostart
│           └── solaar.desktop
├── hidapi
│   ├── hidconsole.py
│   ├── __init__.py
│   └── udev.py
├── logitech_receiver
│   ├── base.py
│   ├── base_usb.py
│   ├── common.py
│   ├── descriptors.py
│   ├── hidpp10.py
│   ├── hidpp20.py
│   ├── i18n.py
│   ├── __init__.py
│   ├── listener.py
│   ├── notifications.py
│   ├── receiver.py
│   ├── settings.py
│   ├── settings_templates.py
│   ├── special_keys.py
│   └── status.py
├── solaar
│   ├── cli
│   │   ├── config.py
│   │   ├── __init__.py
│   │   ├── pair.py
│   │   ├── probe.py
│   │   ├── show.py
│   │   └── unpair.py
│   ├── configuration.py
│   ├── gtk.py
│   ├── i18n.py
│   ├── __init__.py
│   ├── listener.py
│   ├── tasks.py
│   ├── ui
│   │   ├── about.py
│   │   ├── action.py
│   │   ├── config_panel.py
│   │   ├── icons.py
│   │   ├── __init__.py
│   │   ├── notify.py
│   │   ├── pair_window.py
│   │   ├── tray.py
│   │   └── window.py
│   └── upower.py
├── solaar-1.0.2.data
│   ├── data
│   │   └── share
│   │       ├── applications
│   │       │   └── solaar.desktop
│   │       ├── icons
│   │       │   └── hicolor
│   │       │       └── scalable
│   │       │           └── apps
│   │       │               └── solaar.svg
│   │       └── solaar
│   │           └── icons
│   │               ├── light_000.png
│   │               ├── light_020.png
│   │               ├── light_040.png
│   │               ├── light_060.png
│   │               ├── light_080.png
│   │               ├── light_100.png
│   │               ├── light_unknown.png
│   │               ├── solaar-attention.svg
│   │               ├── solaar-init.svg
│   │               └── solaar.svg
│   └── scripts
│       ├── solaar
│       └── solaar-cli
└── solaar-1.0.2.dist-info
    ├── COPYING
    ├── METADATA
    ├── RECORD
    ├── top_level.txt
    └── WHEEL

22 directories, 61 files
```

`/etc` is wrongfully present at the top level, it shouldn't be there. Using a correct (follows the spec) installer, it would result in the file being installed to the python modules directory. Unfortunately, [PEP427](https://www.python.org/dev/peps/pep-0427/) does not specify any way of installing to `sysconfdir`, we should put it under `data` and copy it at runtime if not present.

Another thing, I don't think we should be shipping `hidapi` and `logitech_receiver` as top-level modules.

**To Reproduce**
Steps to reproduce the behavior:
`python setup.py bdist_wheel`



Discussion:
Solaar needs /etc/udev/rules.d/42-logitech-unify-pemissions.rules for proper operation, and /etc/xdg/autostart/solaar.desktop for autostart.  How should they be distributed?

I'm not sure about hidapi and logitech_receiver.  What are the impacts of making them top level?  What needs to be changed if they are moved under solaar?
Also, it is probably time to drop bin/solaar-cli, as it has been deprecated since 2013.

How about trying for a 1.1 release with these changes?
Copying the udev file at runtime would require root access for solaar.
Copying the autostart file won't acheive the desired effect.
> Also, it is probably time to drop bin/solaar-cli, as it has been deprecated since 2013.

Agreed.

> How about trying for a 1.1 release with these changes?

Why `1.1` instead of `1.0.3`?

> Copying the udev file at runtime would require root access for solaar.

You can use polkit to ask permission to the user. But you can also just install to `~/.local` instead.

Most people will be installing via package manager either way so they shouldn't run into this issue.

> Copying the autostart file won't acheive the desired effect.

How so?
1.1 because it removes something that is currently possible, and so probably should not be in a dot-dot release.

I don't think that udev will read files in ~/.local.  The file might better go in /lib/udev, but I don't think that this helps.  The autostart file needs to be in place before Solaar starts.  

It would be possible to just remove these files from setup.py and have them installed via package managers only.  This would mean that `sudo pip install solaar` would not install the files, but that might be OK.
If this is done, then Solaar should probably check for at least the udev file and complain if it is not present.

Resolving patch:
diff --git a/lib/solaar/__init__.py b/lib/solaar/__init__.py
--- a/lib/solaar/__init__.py
+++ b/lib/solaar/__init__.py
@@ -19,5 +19,5 @@
 
 from __future__ import absolute_import, division, print_function, unicode_literals
 
-__version__ = '1.0.2'
+__version__ = '1.0.3rc1'
 NAME = 'Solaar'
diff --git a/lib/solaar/gtk.py b/lib/solaar/gtk.py
--- a/lib/solaar/gtk.py
+++ b/lib/solaar/gtk.py
@@ -21,6 +21,7 @@
 from __future__ import absolute_import, division, print_function, unicode_literals
 
 import importlib
+import os.path
 
 from logging import INFO as _INFO
 from logging import getLogger
@@ -137,6 +138,16 @@ def main():
     gi = _require('gi', 'python3-gi or python3-gobject')
     _require('gi.repository.Gtk', 'gir1.2-gtk-3.0', gi, 'Gtk', '3.0')
 
+    udev_file = '42-logitech-unify-permissions.rules'
+    if not os.path.isfile('/etc/udev/rules.d/' + udev_file) and not os.path.isfile('/lib/udev/rules.d/' + udev_file):
+        print(_i18n._('Solaar depends on a udev file that is not present'))
+        print(
+            _i18n._(
+                'For more information see the Solaar installation directions\n'
+                'at https://pwr-solaar.github.io/Solaar/installation'
+            )
+        )
+
     try:
         import solaar.ui as ui
         import solaar.listener as listener
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -7,10 +7,8 @@
 except ImportError:
     from distutils.core import setup
 
-autostart_path = '/etc/xdg/autostart'
-
 # from solaar import NAME, __version__
-__version__ = '1.0.2'
+__version__ = '1.0.3rc1'
 NAME = 'Solaar'
 
 
@@ -25,8 +23,7 @@ def _data_files():
         yield _dirname(mo), [mo]
 
     yield 'share/applications', ['share/applications/solaar.desktop']
-    yield autostart_path, ['share/autostart/solaar.desktop']
-    yield '/etc/udev/rules.d', ['rules.d/42-logitech-unify-permissions.rules']
+    yield 'share/solaar/udev-rules.d', ['rules.d/42-logitech-unify-permissions.rules']
 
     del _dirname
 
@@ -60,7 +57,7 @@ def _data_files():
     # sudo apt install python-gi python3-gi \
     #        gir1.2-gtk-3.0 gir1.2-notify-0.7 gir1.2-ayatanaappindicator3-0.1
     # os_requires=['gi.repository.GObject (>= 2.0)', 'gi.repository.Gtk (>= 3.0)'],
-    python_requires='>=3.5',
+    python_requires='>=3.6',
     install_requires=[
         'pyudev (>= 0.13)',
     ],


Test patch: