Skip to content

Commit 6cf20b2

Browse files
committed
First commit.
0 parents  commit 6cf20b2

File tree

5 files changed

+190
-0
lines changed

5 files changed

+190
-0
lines changed

.gitignore

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
env/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
27+
# PyInstaller
28+
# Usually these files are written by a python script from a template
29+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
30+
*.manifest
31+
*.spec
32+
33+
# Installer logs
34+
pip-log.txt
35+
pip-delete-this-directory.txt
36+
37+
# Unit test / coverage reports
38+
htmlcov/
39+
.tox/
40+
.coverage
41+
.coverage.*
42+
.cache
43+
nosetests.xml
44+
coverage.xml
45+
*,cover
46+
.hypothesis/
47+
48+
# Translations
49+
*.mo
50+
*.pot
51+
52+
# Django stuff:
53+
*.log
54+
local_settings.py
55+
56+
# Flask stuff:
57+
instance/
58+
.webassets-cache
59+
60+
# Scrapy stuff:
61+
.scrapy
62+
63+
# Sphinx documentation
64+
docs/_build/
65+
66+
# PyBuilder
67+
target/
68+
69+
# IPython Notebook
70+
.ipynb_checkpoints
71+
72+
# pyenv
73+
.python-version
74+
75+
# celery beat schedule file
76+
celerybeat-schedule
77+
78+
# dotenv
79+
.env
80+
81+
# virtualenv
82+
venv/
83+
ENV/
84+
85+
# Spyder project settings
86+
.spyderproject
87+
88+
# Rope project settings
89+
.ropeproject

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Jacopo Notarstefano
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# flask-shell-ptpython #
2+
3+
Replace the default `flask shell` command with a similar command running
4+
Ptython. Inspired by `flask-shell-ipython` by @ei-grad.
5+
6+
## Install ##
7+
8+
```
9+
pip install flask-shell-ptpython
10+
```
11+
12+
## Usage ##
13+
14+
```
15+
% FLASK_APP=hello.py flask shell
16+
>>>
17+
```
18+
19+
## Author ##
20+
21+
Jacopo Notarstefano [(@Jaconotar)](https://twitter.com/Jaconotar)
22+
23+
## License ##
24+
25+
MIT

flask_shell_ptpython.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import os
2+
3+
import click
4+
5+
from flask.cli import with_appcontext
6+
7+
8+
@click.command('shell', short_help='Runs a shell in the app context.')
9+
@with_appcontext
10+
def shell_command():
11+
"""Runs an interactive Python shell in the context of a given
12+
Flask application. The application will populate the default
13+
namespace of this shell according to its configuration.
14+
15+
This is useful for executing small snippets of management code
16+
without having to manually configuring the application.
17+
"""
18+
from flask.globals import _app_ctx_stack
19+
from ptpython.repl import embed
20+
21+
app = _app_ctx_stack.top.app
22+
ctx = {}
23+
24+
# Support the regular Python interpreter startup script if someone
25+
# is using it.
26+
startup = os.environ.get('PYTHONSTARTUP')
27+
if startup and os.path.isfile(startup):
28+
with open(startup, 'r') as f:
29+
eval(compile(f.read(), startup, 'exec'), ctx)
30+
31+
ctx.update(app.make_shell_context())
32+
33+
embed(globals=ctx)

setup.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from setuptools import setup
2+
3+
4+
setup(
5+
name="flask-shell-ptpython",
6+
author="Jacopo Notarstefano",
7+
author_email="[email protected]",
8+
description="Replace the default `flask shell` command with a similar command running Ptpython.",
9+
url="http://github.com/jacquerie/flask-shell-ptpython",
10+
version="0.0.1",
11+
py_modules=['flask_shell_ptpython'],
12+
install_requires=[
13+
'flask>=0.11',
14+
'click',
15+
'ptpython>=0.15',
16+
],
17+
entry_points={
18+
'flask.commands': [
19+
'shell=flask_shell_ptpython:shell_command',
20+
],
21+
},
22+
)

0 commit comments

Comments
 (0)