Skip to content

Commit

Permalink
|\ merge from release-0.9, released as 0.9.
Browse files Browse the repository at this point in the history
  • Loading branch information
StyXman committed Dec 6, 2016
2 parents dc63dd0 + 75f797f commit f9bf855
Show file tree
Hide file tree
Showing 28 changed files with 1,400 additions and 451 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ dist
MANIFEST
trash & toys
.merge_message
*.pyc
*.pyo
.tox
rsa_server_key*
17 changes: 16 additions & 1 deletion ChangeLog.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
ayrton (0.9) unstable; urgency=medium

* The 'No Government' release.
* Test functions are no longer called `_X` but `-X`, which is more scripting friendly.
* Some if those tests had to be fixed.
* Dropped support for `py3.3` because the importer does not work there.
* `tox` support, but not yet part of the stable test suite.
* Lots and lots of more tests.
* Lots of improvements in the `remote()` tests; in particular, make sure they don't hang waiting for someone who's not gonna come.
* Ignore ssh `remote()` tests if there's not password/phrase-less connection.
* Fixed several fd leaks.
* `_in`, `_out` and `_err` also accept a tuple `(path, flags)`, so you can specify things like `os.O_APPEND`. Mostly used internally.

-- Marcos Dione <[email protected]> Tue, 06 Dec 2016 19:37:33 +0100

ayrton (0.8.1.0) unstable; urgency=medium

* The 'Release From The Bus' release.
Expand All @@ -10,7 +25,7 @@ ayrton (0.8.1.0) unstable; urgency=medium
* Calling `ayrton -c <script>` was failing because the file name properly was not properly (f|b)aked.
* `ayrton --version` didn't work!

-- Marcos Dione <mdione@diablo.grulicueva.local> Mon, 21 Nov 2016 20:36:31 +0100
-- Marcos Dione <mdione@grulic.org.ar> Mon, 21 Nov 2016 20:36:31 +0100

ayrton (0.8) unstable; urgency=medium

Expand Down
27 changes: 16 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
DEBUG_MULTI=strace -tt -T -ff -o debug/runner -s 128
DEBUG_SIMPLE=strace -tt -T -o debug/runner -s 128
PYTHON=python3.5
# RUNNER=python3.5
RUNNER=python3-coverage run
# can't use --buffer because:
# File "/home/mdione/src/projects/ayrton/ayrton/__init__.py", line 191, in polute
# self[std]= getattr (sys, std).buffer
Expand All @@ -12,30 +13,30 @@ all: docs
INSTALL_DIR=$(HOME)/local

tests:
LC_ALL=C $(PYTHON) -m unittest discover $(UNITTEST_OPTS) ayrton
LC_ALL=C $(RUNNER) -m unittest discover $(UNITTEST_OPTS) ayrton

slowtest: debug
# LC_ALL=C $(DEBUG_SIMPLE) $(PYTHON) -m unittest discover --failfast \
# LC_ALL=C $(DEBUG_SIMPLE) $(RUNNER) -m unittest discover --failfast \
# $(UNITTEST_OPTS) ayrton
LC_ALL=C $(DEBUG_MULTI) $(PYTHON) -m unittest discover --failfast \
LC_ALL=C $(DEBUG_MULTI) $(RUNNER) -m unittest discover --failfast \
$(UNITTEST_OPTS) ayrton

quicktest:
LC_ALL=C $(PYTHON) -m unittest discover --failfast $(UNITTEST_OPTS) ayrton
LC_ALL=C $(RUNNER) -m unittest discover --failfast $(UNITTEST_OPTS) ayrton

docs:
PYTHONPATH=${PWD} make -C doc html
RUNNERPATH=${PWD} make -C doc html

install: tests
$(PYTHON) setup.py install --prefix=$(INSTALL_DIR)
install:
$(RUNNER) setup.py install --prefix=$(INSTALL_DIR)

unsafe-install:
@echo "unsafe install, are you sure?"
@read foo
$(PYTHON) setup.py install --prefix=$(INSTALL_DIR)
$(RUNNER) setup.py install --prefix=$(INSTALL_DIR)

upload: tests upload-docs
$(PYTHON) setup.py sdist upload
$(RUNNER) setup.py sdist upload

upload-docs: docs
rsync --archive --verbose --compress --rsh ssh doc/build/html/ www.grulic.org.ar:www/projects/ayrton/
Expand All @@ -47,7 +48,7 @@ check:
flake8 --ignore E201,E211,E225,E221,E226,E202 --show-source --statistics --max-line-length 130 ayrton/*.py

testclean:
rm -f ayrton.*log debug/runner* debug/remote*
rm -f ayrton.*log debug/runner* debug/remote* *.ayrtmp

debug:
mkdir -pv debug
Expand All @@ -58,4 +59,8 @@ rsa_server_key:

debugserver: rsa_server_key
# TODO: discover sshd's path?
# sshd re-exec requires execution with an absolute path
/usr/sbin/sshd -dd -e -h $(shell pwd)/rsa_server_key -p 2244

covreport:
python3-coverage report -m | grep ayrton | egrep -v '/(parser|tests)/'
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ method. Arithmetic expansion can be achieved with normal arithmetic operators.
Process substitution is planned but not yet implemented.

There is no need for a `test`/`[`/`[[` equivalent, but there are for the
operators. As `-`cannot be part of the name of a function, we replaced it with `_`.
So, `-f` became `_f()` and so on. Some of the operators are not implemented yet.
operators. The operators are implemented as functions, so `-f foo` becomes
`-f('foo')`. Some of the operators are not implemented yet.
Of course, string and integer operators are better implemented in Python's `str`,
`int` and, why not, `float` types.

Expand Down
14 changes: 10 additions & 4 deletions TODO.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ Really do:

* https://github.com/amoffat/sh/issues/66

* enable tracing

* see pdb's source

* becareful with buitins, might eclipse valid usages: bash() (exp) blocks /bin/bash
* rename bash() to expand()
* add option _exec=True for actually executing the binary.
Expand All @@ -39,6 +35,8 @@ Really do:
* a setting for making references to unkown envvars as in bash.
* trap?
* executable path caching à la bash.
* with parallel(2):
....

Think deeply about:
-------------------
Expand All @@ -51,3 +49,11 @@ Think deeply about:
* -f vs (-)f vs _f
* commands in keywords should also be _out=Capture
* which is the sanest default, bash (..., single=True) or otherwise

* exec &> ./create.log

* implement -m so we can run ayrton -x -m foo

* check whether we can replace a lot of code with Popen/subprocess

* convert tests to function calls
48 changes: 25 additions & 23 deletions ayrton/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
date_format= "%H:%M:%S"


def set_logging_handler (handler):
def set_logging_handler (handler): # pragma: no cover
# replace the old handler only if there was one to begin with
if len (logging.root.handlers)>0:
# close them so we don't get ResourceWarnings
Expand All @@ -46,12 +46,13 @@ def set_logging_handler (handler):
logging.root.addHandler (handler)


def set_debug (level=logging.DEBUG):
logging.basicConfig(handlers=[ counter_handler () ], level=level,
format=log_format)
def set_debug (level=logging.DEBUG): # pragma: no cover
# logging.basicConfig(handlers=[ counter_handler () ],
logging.basicConfig(handlers=[ logging.FileHandler ('ayrton.log') ],
level=level, format=log_format)


def setup_handler (handler):
def setup_handler (handler): # pragma: no cover
logger= logging.root

# most of the following logging internals were found out by reading
Expand All @@ -67,7 +68,7 @@ def setup_handler (handler):
handler.setFormatter (formatter)


def pid_based_handler ():
def pid_based_handler (): # pragma: no cover
"""When we fork(), a new PID based logger needs to be created
so the child logs to another file."""
handler= logging.FileHandler ('ayrton.%d.log' % os.getpid ())
Expand All @@ -76,14 +77,14 @@ def pid_based_handler ():
return handler


def instance_handler (instance):
def instance_handler (instance): # pragma: no cover
handler= logging.FileHandler ('ayrton.%x.log' % id(instance))
setup_handler (handler)

return handler

instance_count= 0
def counter_handler ():
def counter_handler (): # pragma: no cover
handler= logging.FileHandler ('ayrton.%04d.log' % ayrton.instance_count)
ayrton.instance_count+= 1
setup_handler (handler)
Expand All @@ -94,7 +95,7 @@ def counter_handler ():
# uncomment next line and change level for way too much debugging
# during tests execution
# for running ayrton in the same mode, use the -d options
# set_debug (level=logging.DEBUG)
set_debug (level=logging.DEBUG)

logger= logging.getLogger ('ayrton')

Expand All @@ -108,7 +109,7 @@ def counter_handler ():
from ayrton.parser.astcompiler.astbuilder import ast_from_node
from ayrton.ast_pprinter import pprint

__version__= '0.8.1.0'
__version__= '0.9'


class ExecParams:
Expand Down Expand Up @@ -175,9 +176,9 @@ def polute (self):
'time': [ 'sleep', ],
'sys': [ ], # argv is handled just before execution

'ayrton.file_test': [ '_a', '_b', '_c', '_d', '_e', '_f', '_g', '_h',
'_k', '_p', '_r', '_s', '_u', '_w', '_x', '_L',
'_N', '_S', '_nt', '_ot' ],
'ayrton.file_test': [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'k', 'p', 'r', 's', 'u', 'w', 'x', 'L',
'N', 'S', 'nt', 'ot' ],
'ayrton.expansion': [ 'bash', ],
'ayrton.functions': [ 'cd', ('cd', 'chdir'), 'exit', 'export',
'option', 'run', 'shift', 'unset', ],
Expand Down Expand Up @@ -210,13 +211,14 @@ def __init__ (self, g=None, l=None, polute_globals=True, **kwargs):
# set_logging_handler (instance_handler (self))

# replace the old handler only if there was one to begin with
if len (logging.root.handlers)>0:
if len (logging.root.handlers)>0: # pragma: no cover
# close them so we don't get ResourceWarnings
for handler in logging.root.handlers:
logging.root.removeHandler (handler)
handler.close ()

logging.root.addHandler (counter_handler ())
# logging.root.addHandler (counter_handler ())
logging.root.addHandler (instance_handler (self))

# patch import system after ayrton is loaded but before anything else happens
import ayrton.importer
Expand Down Expand Up @@ -335,7 +337,7 @@ def run_tree (self, tree, file_name, argv=None, params=None):


def run_code (self, code, file_name, argv=None):
if logger.parent.level<=logging.DEBUG2:
if logger.parent.level<=logging.DEBUG2: # pragma: no cover
logger.debug2 ('------------------')
logger.debug2 ('main (gobal) code:')
handler= logger.parent.handlers[0]
Expand Down Expand Up @@ -394,21 +396,21 @@ def run_code (self, code, file_name, argv=None):
result= None
try:
logger.debug3 ('globals for script: %s', ayrton.utils.dump_dict (self.globals))
if self.params.trace:
if self.params.trace: # pragma: no cover
sys.settrace (self.global_tracer)

exec (code, self.globals, self.locals)
result= self.locals.get ('ayrton_return_value', None)
except Exit as e:
result= e.exit_value
except Exception as e:
except Exception as e: # pragma: no cover
if self.params.pdb:
pdb.set_trace ()

logger.debug ('script finished by Exception')
logger.debug (traceback.format_exc ())
error= e
finally:
finally: # pragma: no cover
sys.settrace (None)

logger.debug3 ('globals at script exit: %s', ayrton.utils.dump_dict (self.globals))
Expand All @@ -431,7 +433,7 @@ def wait_for_pending_children (self):
logger.debug ('waiting for %s failed; ignoring', child)


def global_tracer (self, frame, event, arg):
def global_tracer (self, frame, event, arg): # pragma: no cover
""""""
logger.debug2 ('global_tracer: %s', event)
if event in ('call', 'line'):
Expand All @@ -440,7 +442,7 @@ def global_tracer (self, frame, event, arg):
return None


def local_tracer (self, frame, event, arg):
def local_tracer (self, frame, event, arg): # pragma: no cover
if event=='line':
file_name= frame.f_code.co_filename
if self.params.trace_all or file_name==self.file_name:
Expand All @@ -465,15 +467,15 @@ def local_tracer (self, frame, event, arg):
self.trace_line ("+ %s", line)


def trace_line (self, msg, *args):
def trace_line (self, msg, *args): # pragma: no cover
if self.params.debug and False:
logger.debug (msg, *args)
else:
print (msg % args, file=sys.stderr)


def run_tree (tree, g, l):
"""main entry point for remote()"""
"""Main entry point for remote()."""
runner= Ayrton (g=g, l=l)
return runner.run_tree (tree, 'unknown_tree')

Expand Down
Loading

0 comments on commit f9bf855

Please sign in to comment.