Skip to content

Commit

Permalink
pycharm support
Browse files Browse the repository at this point in the history
  • Loading branch information
rasbt committed Sep 8, 2016
1 parent 33cd9cd commit b7b2636
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 115 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 2.9.9
================
- added PyCharm support

Version 2.9.8
================
- raise `ValueError` if `monitor` is set to `True` and `psutils` is not installed
Expand Down
140 changes: 35 additions & 105 deletions examples/pyprind_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"CPython 3.5.2\n",
"IPython 5.1.0\n",
"\n",
"pyprind 2.9.8\n"
"pyprind 2.9.9\n"
]
}
],
Expand Down Expand Up @@ -78,8 +78,7 @@
"- [Progress Bar/Percentage Indicator - Changing the output stream](#Progress-Bar/Percentage-Indicator---Setting-a-title)\n",
"- [Stopping the Progress Bar/Percentage Indicator early](#Stopping-the-Progress-Bar/Percentage-Indicator-early)\n",
"- [Choosing your own progress bar style](#Choosing-your-own-progress-bar-style)\n",
"- [Controlling the update frequency](#Controlling-the-update-frequency)\n",
"- [Pyprind in PyCharm](#Pyprind in PyCharm)"
"- [Controlling the update frequency](#Controlling-the-update-frequency)"
]
},
{
Expand Down Expand Up @@ -169,7 +168,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 4,
"metadata": {
"collapsed": false
},
Expand All @@ -188,8 +187,8 @@
"output_type": "stream",
"text": [
"Title: while example\n",
" Started: 09/07/2016 13:06:58\n",
" Finished: 09/07/2016 13:07:03\n",
" Started: 09/07/2016 21:32:36\n",
" Finished: 09/07/2016 21:32:41\n",
" Total time elapsed: 00:00:05\n"
]
}
Expand Down Expand Up @@ -246,7 +245,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -299,7 +298,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {
"collapsed": false
},
Expand All @@ -321,7 +320,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -372,7 +371,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {
"collapsed": false
},
Expand All @@ -391,8 +390,8 @@
"output_type": "stream",
"text": [
"Title: \n",
" Started: 03/05/2016 14:44:22\n",
" Finished: 03/05/2016 14:44:28\n",
" Started: 09/07/2016 21:32:58\n",
" Finished: 09/07/2016 21:33:03\n",
" Total time elapsed: 00:00:05\n"
]
}
Expand All @@ -407,7 +406,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {
"collapsed": false,
"scrolled": true
Expand All @@ -428,11 +427,11 @@
"output_type": "stream",
"text": [
"Title: Job_1\n",
" Started: 03/05/2016 14:44:28\n",
" Finished: 03/05/2016 14:44:33\n",
" Started: 09/07/2016 21:33:03\n",
" Finished: 09/07/2016 21:33:08\n",
" Total time elapsed: 00:00:05\n",
" CPU %: 1.00\n",
" Memory %: 0.39\n"
" CPU %: 2.10\n",
" Memory %: 0.48\n"
]
}
],
Expand Down Expand Up @@ -504,8 +503,8 @@
"output_type": "stream",
"text": [
"Title: \n",
" Started: 09/07/2016 13:14:09\n",
" Finished: 09/07/2016 13:14:14\n",
" Started: 09/07/2016 21:33:08\n",
" Finished: 09/07/2016 21:33:13\n",
" Total time elapsed: 00:00:05\n",
" CPU %: 1.90\n",
" Memory %: 0.48\n"
Expand Down Expand Up @@ -547,10 +546,10 @@
"output_type": "stream",
"text": [
"Title: \n",
" Started: 09/07/2016 13:14:14\n",
" Finished: 09/07/2016 13:14:19\n",
" Started: 09/07/2016 21:33:13\n",
" Finished: 09/07/2016 21:33:19\n",
" Total time elapsed: 00:00:05\n",
" CPU %: 3.40\n",
" CPU %: 2.90\n",
" Memory %: 0.48\n"
]
}
Expand Down Expand Up @@ -595,7 +594,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"metadata": {
"collapsed": false
},
Expand All @@ -620,7 +619,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 13,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -674,7 +673,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 14,
"metadata": {
"collapsed": false
},
Expand All @@ -698,7 +697,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 15,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -752,7 +751,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 16,
"metadata": {
"collapsed": false
},
Expand All @@ -776,7 +775,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"metadata": {
"collapsed": false
},
Expand All @@ -800,21 +799,11 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0% 100%\n",
"[##############################] | ETA: 00:00:00\n",
"Total time elapsed: 00:00:05\n"
]
}
],
"outputs": [],
"source": [
"import sys\n",
"\n",
Expand Down Expand Up @@ -855,7 +844,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -910,7 +899,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 20,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -960,7 +949,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 21,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -1015,7 +1004,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 22,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -1054,7 +1043,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 23,
"metadata": {
"collapsed": false
},
Expand All @@ -1079,7 +1068,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 24,
"metadata": {
"collapsed": false
},
Expand All @@ -1100,65 +1089,6 @@
" time.sleep(0.2) # do some computation\n",
" bar.update()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<br>\n",
"<br>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Pyprind in PyCharm"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[[back to section overview](#sections)]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you are using PyCharm, you need to pass the `stdout` or `stderr` from the `sys` module as a `stream` argument to the `ProgBar` or `ProgPercent` class as shown in the example below:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0% 100%\n",
"[##############################] | ETA: 00:00:00\n",
"Total time elapsed: 00:00:05\n"
]
}
],
"source": [
"import time\n",
"import sys\n",
"\n",
"n = 100\n",
"timesleep = 0.05\n",
"\n",
"bar = pyprind.ProgBar(n, stream=sys.stdout)\n",
"for i in range(n):\n",
" time.sleep(timesleep) # your computation here\n",
" bar.update()"
]
}
],
"metadata": {
Expand Down
2 changes: 1 addition & 1 deletion pyprind/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
from .generator_factory import prog_bar


__version__ = '2.9.8'
__version__ = '2.9.9'
23 changes: 14 additions & 9 deletions pyprind/prog_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,21 @@ def stop(self):
def _check_stream(self):
"""Determines which output stream (stdout, stderr, or custom) to use"""
if self.stream:

try:
if self.stream == 1 and os.isatty(sys.stdout.fileno()):
self._stream_out = sys.stdout.write
self._stream_flush = sys.stdout.flush
elif self.stream == 2 and os.isatty(sys.stderr.fileno()):
self._stream_out = sys.stderr.write
self._stream_flush = sys.stderr.flush
supported = ('PYCHARM_HOSTED' in os.environ or
os.isatty(sys.stdout.fileno()))

# a fix for IPython notebook "IOStream has no fileno."
except UnsupportedOperation:
except(UnsupportedOperation):
supported = True

else:
if self.stream is not None and hasattr(self.stream, 'write'):
self._stream_out = self.stream.write
self._stream_flush = self.stream.flush

if supported:
if self.stream == 1:
self._stream_out = sys.stdout.write
self._stream_flush = sys.stdout.flush
Expand All @@ -105,8 +110,8 @@ def _check_stream(self):
if self.stream is not None and hasattr(self.stream, 'write'):
self._stream_out = self.stream.write
self._stream_flush = self.stream.flush
else:
print('Warning: No valid output stream.')
else:
print('Warning: No valid output stream.')

def _elapsed(self):
""" Returns elapsed time at update. """
Expand Down

0 comments on commit b7b2636

Please sign in to comment.