ryukinix / decorating Goto Github PK
View Code? Open in Web Editor NEWdecorating: Literally decorating your terminal with decorators
Home Page: http://decorating.readthedocs.io
License: MIT License
decorating: Literally decorating your terminal with decorators
Home Page: http://decorating.readthedocs.io
License: MIT License
I noticed that on urxvt terminal the output is messed up, see following screencast.
Maybe it's a bug on urxvt?
I'm using archlinux distro and urxvt terminal.
from decorating.stream import Unbuffered
from decorating.decorator import Decorator
import sys
class MonitorStream(Unbuffered):
def __init__(self, stream):
self.stream = stream
self.data = []
def write(self, message):
self.stream.write(message)
self.data.append(message)
class MonitorStdout(Decorator):
def start(self):
self.stream = MonitorStream(sys.stdout)
sys.stdout = self.stream
def stop(self):
sys.stdout = sys.__stdout__
monitor_stdout = MonitorStdout()
with monitor_stdout:
print('test')
print(monitor_stdout.stream.data)
This is just a prototype. The main ideia is get all the stdout content of a isolated context using decorated functions or context managers.
This can be useful because we can use things like this:
from decorating import Decorator
from logging import getLogger
logger = getLogger(__name__)
class ExceptionDumper(Decorator):
def wrapper(self):
try:
return super().wrapper()
except Exception as e:
logger.exception(e)
So we can decorate any function or use contextmanagers to do dump of exceptions.
When using pyinstaller to 'compile' a program using decorating, I am suddenly faced with the following:
Traceback (most recent call last):
File "threading.py", line 801, in __bootstrap_inner
File "threading.py", line 754, in run
File "site-packages/decorating/animation.py", line 157, in _spinner
File "site-packages/decorating/stream.py", line 84, in write
File "site-packages/decorating/stream.py", line 56, in write
UnicodeEncodeError: 'ascii' codec can't encode character u'\u28fe' in position 18: ordinal not in range(128)
The little research I have done points to unicode being cast as strings, and I found a few workarounds based on using locales, but so far, no success.
The library is otherwise working fine and is pretty awesome.
I have some troubles with this, always when something is printed inside of a animated context, decorated or using like context managers (with
keyword), the print have double newlines, althoug I solve the problem with the broken animation.
The attempt to fix this and other problems underlying of this subject is on that 6fc9e8a I added a example of this too on test_animated.py. You can try running this to replicate the problem.
A image running the tests is here:
Trying to run the animated
decorator example on Python 2, froze my machine. Any plans to support older versions of Python?
With version decorating (0.2.1b0)
of the library, the following code:
from decorating import animated
from time import sleep
@animated
def main():
sleep(300)
main()
gives me the traceback:
Traceback (most recent call last):
File "test.py", line 8, in <module>
main()
File "/home/rahiel/Code/test/venv/lib/python3.5/site-packages/decorating/animation.py", line 159, in __call__
if callable(args[0]):
IndexError: tuple index out of range
I've installed the package in a virtualenv.
Using with animated(...)
works fine.
Put this on README.md
The project has pretty bad English. This should be fixed. All project docs were written in a hurry and I don't have much experience with writing english documentation so I do appreciate if someone help me with this.
We should make possible to customize the three current spinners defined:
On that locations:
That way we can use the module decorating.ascii
to choose per project the desired spinner, make this animation more flexible.
Feature request:
Make the cache
decorator accept an expiry time - the number of seconds that a result should be cached before re-running the wrapped function. This is useful as a way to rate-limit queries to any kind of backing store. The default of None
would preserve the current behavior of caching 'forever'.
We just provide a PKGBUILD linked with the releases of github. A template system for python packages can be found here: https://wiki.archlinux.org/index.php/Python_package_guidelines
That bug was be added since the v0.4 version. The code to replicate this problem is:
... to add ...
https://github.com/ryukinix/decorating/blob/dev/decorating/decorator.py#L110
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.