From fdddedb8bd5d38884ea136171cde315014e16f50 Mon Sep 17 00:00:00 2001 From: Chris Lane Date: Thu, 7 Feb 2019 13:34:20 -0500 Subject: [PATCH] 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. --- README.md | 5 ++++- Vagrantfile | 9 ++++++--- cheat/configuration.py | 5 +++++ setup.py | 24 +++++++++++++++++++----- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8d67e00..7742a31 100644 --- a/README.md +++ b/README.md @@ -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]. diff --git a/Vagrantfile b/Vagrantfile index 3ab20e3..51fcf46 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -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 diff --git a/cheat/configuration.py b/cheat/configuration.py index b85cd24..27949f5 100644 --- a/cheat/configuration.py +++ b/cheat/configuration.py @@ -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', ]) diff --git a/setup.py b/setup.py index 2eb47a4..726daa6 100644 --- a/setup.py +++ b/setup.py @@ -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']), ], )