Skip to content

Commit 35410c7

Browse files
authored
small app refresh (#49)
- drop py2 support - update py pkgs - refactor code for cheroot integration - update docs - update yaml settings example - update virtualenv setup - fix tests
1 parent b1ad40e commit 35410c7

File tree

13 files changed

+61
-59
lines changed

13 files changed

+61
-59
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ data
77
local_settings.py
88
sherlock-meta.cfg
99
local_settings.yml
10+
.vscode/settings.json

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Instructions:
1111
1. Run `sh setup/virtualenv-setup.sh` to setup an isolated environment and download core packages.
1212
1. Configure settings. The defaults in [`settings.py`](settings.py) provide documentation for each setting.
1313
- Copy [`example.local_settings.yml`](example.local_settings.yml) to `local_settings.yml`.
14-
- Override/copy any setting from [`settings.py`](settings.py) to `local_settings.yml` (change the values as needed). All YAML keys/options must be lowercase.
14+
- Override/copy any setting from [`settings.py`](settings.py) to `local_settings.yml` (change the values as needed). All YAML keys/options **must** be lowercase.
1515
1. Run `source sherlock_env/bin/activate` to enter the virtual environment.
1616
1. Run `python main.py --index update` or `--index rebuild` to index the path specified in the settings. Watch indexing output.
1717
1. Run `python main.py --runserver` to start the web server.
@@ -36,9 +36,9 @@ Includes:
3636
- End-to-end interface
3737
- Indexing and searching text (source code). Built-in support for [whoosh](https://whoosh.readthedocs.io) (fast searching) or [xapian](http://xapian.org/) (much faster searching).
3838
- Easily extend indexing or searching via custom backends.
39-
- Front end web app served using [werkzeug](http://werkzeug.pocoo.org/) or [cherrypy](http://www.cherrypy.org/).
39+
- Front end web app served using [werkzeug](http://werkzeug.pocoo.org/) or [cheroot](https://cheroot.cherrypy.org).
4040
- `werkzeug` is for development to small traffic.
41-
- `cherrypy` is a high-speed, production ready, thread pooled, generic HTTP server.
41+
- `cheroot` is the high-performance, pure-Python HTTP server used by [CherryPy](https://www.cherrypy.org).
4242
- Settings and configuration using [Python](http://python.org).
4343

4444
### Web Interface
@@ -65,18 +65,18 @@ In [`settings.py`](settings.py):
6565

6666
## Using other web servers
6767

68-
Text Sherlock has built-in support for [werkzeug](http://werkzeug.pocoo.org/) and [cherrypy](http://www.cherrypy.org/) WSGI compliant servers.
68+
Text Sherlock has built-in support for [werkzeug](http://werkzeug.pocoo.org/) and [cheroot](https://cheroot.cherrypy.org) WSGI compliant servers.
6969

7070
In [`settings.py`](settings.py):
7171

7272
- Change the `server_type` value to one of the available server types.
7373
- Possible values:
7474
- `default`, werkzeug web server (default).
75-
- `cherrypy`, production ready web server.
75+
- `cheroot`, production ready web server.
7676

7777
## Core packages
7878

79-
**Requires Python 3.3+**
79+
**Requires Python 3.5+**
8080

8181
* Whoosh - [whoosh](https://whoosh.readthedocs.io/en/latest/quickstart.html#a-quick-introduction)
8282
* Flask - [flask](http://flask.pocoo.org)
@@ -91,7 +91,7 @@ In [`settings.py`](settings.py):
9191
* http://twitter.github.com/bootstrap/examples/container-app.html
9292
* http://pygments.org/
9393
* http://docs.peewee-orm.com/
94-
* http://www.cherrypy.org/
94+
* https://cheroot.cherrypy.org/
9595
* http://xapian.org/
9696
* http://pyyaml.org/wiki/PyYAMLDocumentation
9797

core/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
'FULL_INDEX_PATHS'
1212
]
1313

14-
from cherrypy import wsgiserver as cherrypy_wsgiserver
14+
from cheroot.wsgi import Server as WSGIServer, PathInfoDispatcher as WSGIPathInfoDispatcher
1515
import configparser
1616
import codecs
1717
import flask
@@ -55,16 +55,16 @@ def get_version_info(module):
5555
"""
5656
module = module.lower()
5757

58-
def cherrypy_ver():
59-
import cherrypy
60-
return cherrypy.__version__
58+
def cheroot_ver():
59+
import cheroot
60+
return cheroot.__version__
6161

6262
def sherlock_ver():
6363
from . import sherlock
6464
return sherlock.__version__
6565

6666
return {
67-
'cherrypy': cherrypy_ver,
67+
'cheroot': cheroot_ver,
6868
'whoosh': whoosh.versionstring,
6969
'pygments': lambda: pygments.__version__,
7070
'flask': lambda: flask.__version__,

core/sherlock/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
refs:
77
http://docs.python.org/3/library/logging.html
88
"""
9-
__version__ = '0.7.3'
9+
__version__ = '0.8.0'
1010

1111
import logging
1212
logger = logging.getLogger('core.sherlock')

core/sherlock/indexer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import os
1212
import settings
1313
import shutil
14+
import contextlib
1415
from core import FULL_INDEXES_PATH, FORCE_INDEX_REBUILD
1516
from core.sherlock import logger as log
1617
from core.sherlock import searcher
@@ -39,7 +40,7 @@ def index_paths(paths, name=settings.DEFAULT_INDEX_NAME):
3940
# index files for the search
4041
with _get_indexer_with_cleanup(name) as idxr:
4142
for path in paths:
42-
idxr.index_text(unicode(path))
43+
idxr.index_text(path)
4344

4445

4546
def index_path(path, name=settings.DEFAULT_INDEX_NAME):
@@ -51,7 +52,7 @@ def index_path(path, name=settings.DEFAULT_INDEX_NAME):
5152
"""
5253
# index a file for the search
5354
with _get_indexer_with_cleanup(name) as idxr:
54-
idxr.index_text(unicode(path))
55+
idxr.index_text(path)
5556

5657

5758
@contextlib.contextmanager

example.local_settings.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ include_file_suffix: [
1818

1919
# The name of the server type to use as the web server.
2020
# type: string
21-
# default: '' or 'cherrypy'
22-
server_type: 'cherrypy'
21+
# default: '' or 'cheroot'
22+
server_type: 'cheroot'

main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def show_version():
2828
print(' Flask: v' + get_version_info('flask'))
2929
print('Pygments: v' + get_version_info('pygments'))
3030
print(' Whoosh: v' + get_version_info('whoosh'))
31-
print('CherryPy: v' + get_version_info('cherrypy'))
31+
print(' Cheroot: v' + get_version_info('cheroot'))
3232

3333

3434
def show_stats():
@@ -47,8 +47,8 @@ def run_server():
4747
if settings.LOG_PATH:
4848
print('Log path: %s' % settings.LOG_PATH)
4949
print('Backend: %s' % settings.DEFAULT_SEARCHER)
50-
print('Server: %s' % settings.SERVER_TYPE)
51-
print('Listening on: %s:%d' % (settings.SERVER_ADDRESS, settings.SERVER_PORT))
50+
print('Server: %s' % (settings.SERVER_TYPE or 'development'))
51+
print('Listening on: {}:{}'.format(settings.SERVER_ADDRESS, settings.SERVER_PORT))
5252
# launch web server
5353
server.run()
5454

@@ -65,7 +65,7 @@ def reindex():
6565
if FORCE_INDEX_REBUILD:
6666
wait_time = 5 # seconds to wait/pause until rebuilding index
6767
print('Reindexing everything!')
68-
print('Waiting %ss for interrupt...' % wait_time)
68+
print('Waiting {}s for interrupt...'.format(wait_time))
6969
import time
7070
time.sleep(wait_time)
7171
print('Indexing started.')

settings.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
DEFAULT_INDEX_NAME = config.get('default_index_name', 'main')
102102

103103
# The name of the server type to use as the web server.
104-
# CherryPy support is built-in, if production: 'cherrypy'.
104+
# Cheroot support is built-in, if production: 'cheroot'.
105105
# type: string
106106
# default: None
107107
SERVER_TYPE = config.get('server_type')
@@ -168,12 +168,3 @@
168168
# type: string
169169
# default: black
170170
SITE_BANNER_COLOR = config.get('site_banner_color', 'black')
171-
172-
173-
# Use the local_settings.yml instead, noted at the top of file
174-
try:
175-
from local_settings import *
176-
print('!!!Deprecated local_settings.py|pyc file found: Use local_settings.yml instead.')
177-
except ImportError:
178-
# ignore import error, because it's deprecated
179-
pass

setup/requirements.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
flask>=0.10,<=0.11.1
2-
whoosh<2.7.0
3-
jinja2==2.8
4-
pygments<=2.1.3
5-
cherrypy>5.0.0,<=8.1.2
6-
flask-peewee<=0.6.7
7-
peewee<=2.8.5
1+
flask==1.1.1
2+
whoosh==2.7.4
3+
jinja2==2.11.1
4+
pygments==2.5.2
5+
cheroot==8.3.0
6+
flask-peewee==3.0.3
7+
peewee==3.13.1
88
path.py
99
pyyaml

setup/virtualenv-setup.sh

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,40 @@
11
# global
22
# Created by: Christopher Bess
3-
# It is recomm. not to run this script using sudo, it is used as needed.
3+
# It is NOT recommended to run this script using sudo, it is used as needed.
44
#
55
# user$: sh virtualenv-setup.sh
66

7-
echo "Setting up virtualenv and pip - installing with sudo"
8-
sudo easy_install pip
9-
sudo pip install virtualenv
7+
if ! [ -x "$(command -v python3)" ]; then
8+
echo "Python 3+ required."
9+
exit 1
10+
fi
1011

11-
PROJROOT=$(cd $(dirname $0) && cd .. && pwd)
12+
if ! [ -x "$(command -v pip)" ]; then
13+
echo "Setting up pip - installing with sudo"
14+
15+
sudo easy_install pip
16+
fi
17+
18+
PROJ_ROOT=$(cd $(dirname $0) && cd .. && pwd)
1219

1320
# adjust permission (allow it to be executed)
14-
chmod +x ${PROJROOT}/main.py
21+
chmod +x ${PROJ_ROOT}/main.py
1522

1623
# if on a Mac exec below line (maybe)
1724
# ARCHFLAGS="-arch i386 -arch x86_64"
1825

26+
VENV_ROOT=${PROJ_ROOT}/sherlock_env
27+
1928
# setup sherlock environment
20-
mkdir -p ${PROJROOT}/data/indexes
21-
virtualenv ${PROJROOT}/sherlock_env --distribute --no-site-packages
29+
mkdir -p ${PROJ_ROOT}/data/indexes
30+
python3 -m venv ${VENV_ROOT}
2231

2332
echo "Installing sherlock dependencies"
24-
${PROJROOT}/sherlock_env/bin/pip install -r ${PROJROOT}/setup/requirements.txt
33+
${VENV_ROOT}/bin/pip install --upgrade pip
34+
${VENV_ROOT}/bin/pip install -r ${PROJ_ROOT}/setup/requirements.txt
2535

2636
# confirm installation by showing version information
2737
# echo "Sherlock version information"
28-
${PROJROOT}/sherlock_env/bin/python ${PROJROOT}/main.py -v
38+
${VENV_ROOT}/bin/python ${PROJ_ROOT}/main.py -v
2939

3040
echo "Sherlock install finished"

0 commit comments

Comments
 (0)