mirror of
https://github.com/chubin/cheat.sh.git
synced 2024-11-25 23:46:00 +03:00
parent
8654d9b2f7
commit
ad0fca045d
@ -9,7 +9,12 @@ import sys
|
||||
import os
|
||||
import collections
|
||||
|
||||
from rapidfuzz import process, fuzz
|
||||
try:
|
||||
from rapidfuzz import process, fuzz
|
||||
_USING_FUZZYWUZZY=False
|
||||
except ImportError:
|
||||
from fuzzywuzzy import process, fuzz
|
||||
_USING_FUZZYWUZZY=True
|
||||
|
||||
from config import CONFIG
|
||||
from .adapter import Adapter
|
||||
@ -120,7 +125,10 @@ class UnknownPages(InternalPages):
|
||||
else:
|
||||
topics_list = [x for x in topics_list if not x.startswith(':')]
|
||||
|
||||
possible_topics = process.extract(topic, topics_list, limit=3, scorer=fuzz.ratio)
|
||||
if _USING_FUZZYWUZZY:
|
||||
possible_topics = process.extract(topic, topics_list, scorer=fuzz.ratio)[:3]
|
||||
else:
|
||||
possible_topics = process.extract(topic, topics_list, limit=3, scorer=fuzz.ratio)
|
||||
possible_topics_text = "\n".join([(" * %s %s" % x) for x in possible_topics])
|
||||
return """
|
||||
Unknown topic.
|
||||
|
@ -4,7 +4,7 @@ flask
|
||||
requests
|
||||
pygments
|
||||
dateutils
|
||||
rapidfuzz
|
||||
fuzzywuzzy
|
||||
redis
|
||||
colored
|
||||
langdetect
|
||||
|
@ -178,12 +178,36 @@ EOF
|
||||
# we use tee everywhere so we should set -o pipefail
|
||||
set -o pipefail
|
||||
|
||||
# currently the script uses python 2,
|
||||
# but cheat.sh supports python 3 too
|
||||
# if you want to switch it to python 3
|
||||
# set PYTHON2 to NO:
|
||||
# PYTHON2=NO
|
||||
#
|
||||
PYTHON2=YES
|
||||
if [[ $PYTHON2 = YES ]]; then
|
||||
python="python2"
|
||||
pip="pip"
|
||||
virtualenv_python3_option=()
|
||||
else
|
||||
python="python3"
|
||||
pip="pip3"
|
||||
virtualenv_python3_option=(-p python3)
|
||||
fi
|
||||
|
||||
_say_what_i_do Creating virtual environment
|
||||
python2 "$(command -v virtualenv)" ve \
|
||||
"$python" "$(command -v virtualenv)" "${virtualenv_python3_option[@]}" ve \
|
||||
|| fatal Could not create virtual environment with "python2 $(command -v virtualenv) ve"
|
||||
|
||||
# rapidfuzz does not support Python 2,
|
||||
# so if we are using Python 2, install fuzzywuzzy instead
|
||||
if [[ $PYTHON2 = YES ]]; then
|
||||
sed -i s/rapidfuzz/fuzzywuzzy/ requirements.txt
|
||||
echo "python-Levenshtein" >> requirements.txt
|
||||
fi
|
||||
|
||||
_say_what_i_do Installing python requirements into the virtual environment
|
||||
ve/bin/pip install -r requirements.txt > "$LOG" \
|
||||
ve/bin/"$pip" install -r requirements.txt > "$LOG" \
|
||||
|| {
|
||||
|
||||
echo "ERROR:"
|
||||
@ -193,7 +217,7 @@ EOF
|
||||
echo "See $LOG for more"
|
||||
fatal Could not install python dependencies into the virtual environment
|
||||
}
|
||||
echo "$(ve/bin/pip freeze | wc -l) dependencies were successfully installed"
|
||||
echo "$(ve/bin/"$pip" freeze | wc -l) dependencies were successfully installed"
|
||||
|
||||
_say_what_i_do Fetching the upstream cheat sheets repositories
|
||||
ve/bin/python lib/fetch.py fetch-all | tee -a "$LOG"
|
||||
|
@ -178,12 +178,36 @@ EOF
|
||||
# we use tee everywhere so we should set -o pipefail
|
||||
set -o pipefail
|
||||
|
||||
# currently the script uses python 2,
|
||||
# but cheat.sh supports python 3 too
|
||||
# if you want to switch it to python 3
|
||||
# set PYTHON2 to NO:
|
||||
# PYTHON2=NO
|
||||
#
|
||||
PYTHON2=YES
|
||||
if [[ $PYTHON2 = YES ]]; then
|
||||
python="python2"
|
||||
pip="pip"
|
||||
virtualenv_python3_option=()
|
||||
else
|
||||
python="python3"
|
||||
pip="pip3"
|
||||
virtualenv_python3_option=(-p python3)
|
||||
fi
|
||||
|
||||
_say_what_i_do Creating virtual environment
|
||||
python2 "$(command -v virtualenv)" ve \
|
||||
"$python" "$(command -v virtualenv)" "${virtualenv_python3_option[@]}" ve \
|
||||
|| fatal Could not create virtual environment with "python2 $(command -v virtualenv) ve"
|
||||
|
||||
# rapidfuzz does not support Python 2,
|
||||
# so if we are using Python 2, install fuzzywuzzy instead
|
||||
if [[ $PYTHON2 = YES ]]; then
|
||||
sed -i s/rapidfuzz/fuzzywuzzy/ requirements.txt
|
||||
echo "python-Levenshtein" >> requirements.txt
|
||||
fi
|
||||
|
||||
_say_what_i_do Installing python requirements into the virtual environment
|
||||
ve/bin/pip install -r requirements.txt > "$LOG" \
|
||||
ve/bin/"$pip" install -r requirements.txt > "$LOG" \
|
||||
|| {
|
||||
|
||||
echo "ERROR:"
|
||||
@ -193,7 +217,7 @@ EOF
|
||||
echo "See $LOG for more"
|
||||
fatal Could not install python dependencies into the virtual environment
|
||||
}
|
||||
echo "$(ve/bin/pip freeze | wc -l) dependencies were successfully installed"
|
||||
echo "$(ve/bin/"$pip" freeze | wc -l) dependencies were successfully installed"
|
||||
|
||||
_say_what_i_do Fetching the upstream cheat sheets repositories
|
||||
ve/bin/python lib/fetch.py fetch-all | tee -a "$LOG"
|
||||
|
Loading…
Reference in New Issue
Block a user