Installation issues

Resolves the following:

- #351 (use of `sudo` when installing)
- #420 (failure to install on Windows)
- #431 (failure to install on MacOS)

Application now relies on `appdirs` module to identify the appropriate
locations for storing configuration and data, both during installation
and runtime.
This commit is contained in:
Chris Lane 2019-02-07 13:34:20 -05:00
parent 5487314676
commit fdddedb8bd
4 changed files with 34 additions and 9 deletions

View File

@ -50,9 +50,12 @@ Installing
It is recommended to install `cheat` with `pip`:
```sh
[sudo] pip install cheat
pip install cheat --user
```
(You must ensure that the `Location` identified by `pip show cheat` exists on
your `PATH`.)
[Other installation methods are available][installing].

9
Vagrantfile vendored
View File

@ -8,10 +8,13 @@ Vagrant.configure("2") do |config|
vb.memory = "512"
end
config.vm.provision "shell", inline: <<-SHELL
config.vm.provision "shell", privileged: false, inline: <<-SHELL
sudo apt-get update
sudo apt-get install -y python-pip
su vagrant && sudo -H pip install docopt pygments termcolor flake8
cd /vagrant && sudo python setup.py install
sudo -H pip install flake8
pip install --user docopt pygments termcolor
cd /vagrant/ && python setup.py install --user
echo 'export PATH=$PATH:/home/vagrant/.local/bin' >> /home/vagrant/.bashrc
SHELL
end

View File

@ -1,4 +1,5 @@
from cheat.utils import Utils
import appdirs
import json
import os
@ -9,10 +10,12 @@ class Configuration:
# compute the location of the config files
config_file_path_global = self._select([
os.environ.get('CHEAT_GLOBAL_CONF_PATH'),
appdirs.site_config_dir('cheat', 'cheat'),
'/etc/cheat',
])
config_file_path_local = self._select([
os.environ.get('CHEAT_LOCAL_CONF_PATH'),
appdirs.user_config_dir('cheat', 'cheat'),
os.path.expanduser('~/.config/cheat/cheat'),
])
@ -81,6 +84,8 @@ class Configuration:
os.environ.get('CHEAT_PATH'),
os.environ.get('CHEATPATH'),
config.get('CHEAT_PATH'),
appdirs.user_data_dir('cheat', 'cheat'),
appdirs.site_data_dir('cheat', 'cheat'),
'/usr/share/cheat',
])

View File

@ -1,10 +1,23 @@
from distutils.core import setup
import os
# determine the directory in which to install system-wide cheatsheets
# KLUDGE: It would be better to read `/usr/share/cheat` from `config/cheat`
# rather than hard-coding it here
cheat_path = os.environ.get('CHEAT_PATH') or '/usr/share/cheat'
# install appdirs if it cannot be imported
try:
import appdirs
except ImportError:
import pip
pip.main(['install', 'appdirs'])
import appdirs
# determine the path in which to install the cheatsheets included with the
# package
cheat_path = os.environ.get('CHEAT_PATH') or \
appdirs.user_data_dir('cheat', 'cheat')
# determine the path in which to install the config file
config_path = os.environ.get('CHEAT_GLOBAL_CONF_PATH') or \
os.environ.get('CHEAT_LOCAL_CONF_PATH') or \
appdirs.user_config_dir('cheat', 'cheat')
# aggregate the systme-wide cheatsheets
cheat_files = []
@ -29,12 +42,13 @@ setup(
],
scripts=['bin/cheat'],
install_requires=[
'appdirs >= 1.4.3',
'docopt >= 0.6.1',
'pygments >= 1.6.0',
'termcolor >= 1.1.0',
],
data_files=[
(cheat_path, cheat_files),
('/etc', ['config/cheat']),
(config_path, ['config/cheat']),
],
)