Giter Club home page Giter Club logo

livecoding's Introduction

= livecoding =

== Version ==

2.01

== Licensing and copyright ==

Files declaring other licenses and authors are derivative, and remain under the specified licenses and copyright by the original authors.

All other files are licensed under the BSD license, which is included as the file 'LICENSE'.

== Authors ==

 * Richard Tew <[email protected]>

== Overview ==

This library implements something which is often called live coding or code reloading. It allows an application to have any Python code which might be part of it updated as the files the code is in are changed - while the application is running.

  * No need to restart the application in order to incorporate changes made to Python scripts.
  * No need to execute Python scripts manually each time you want to use the code within them.

The way the library goes about this is by having directories containing Python scripts registered to be monitored so that any time a change is made to a script the code within it can be reloaded and put in place transparently.

Note that these directories should not be those of standard Python modules available for normal import.  The reason for this is that this library manually processes the contents of registered directories and places them so that they can be imported.  By handling this itself, this allows the library to know enough to apply changes to modules as they happen.

== Library Directories ==

 * examples: Example code to illustrate use of this library.
 * filechanges: A library that manages the process of monitoring script files and notifying registrants about modifications to them.
 * scripts: A script directory for use by the unit tests.
 * scripts2: Additional scripts for use by the unit tests.
 * tests: Unit tests for this library.

== Design Decisions ==

There are several noteworthy design decisions which were made during the implementation of this library:

 1. Use of a custom import scheme.
 1. Ignoring removals, whether removal of files or removal of functions or classes from files.

livecoding's People

Watchers

 avatar

livecoding's Issues

Namespace leaks are tracked at the wrong scope

The namespace leak tracking system stores a dictionary on the code
reloader, that uses as a key the attribute name and as the value, a tuple
of script path and script version.  There is no way of knowing in what
namespace the attribute by that name was leaked.

The leaks should be tracked on a per namespace basis.  Either
namespace.__name__ can be used as a key, or some clean way can be found of
storing it on/in the namespace.  In fact, that might be the best solution.

Original issue reported on code.google.com by [email protected] on 13 Feb 2010 at 7:43

Changing Class Definition

What steps will reproduce the problem?

Changing a class definition results in an error

class test(object):pass
to
class test:pass
or
class test(dict):pass 


Original issue reported on code.google.com by [email protected] on 21 Jul 2008 at 11:58

Deleting Class Variables

If you have a class variable, and then you delete it, the following error
appears:


File "livecoding.py", line 368, in ProcessChangedFile
del oldObject[k]

TypeError: 'type' object does not support item deletion 


Original issue reported on code.google.com by [email protected] on 21 Jul 2008 at 11:58

Override functionality needs to be completed

These aspects of the override functionality need to be completed:

 * Ability to specify how the given function is overridden.
   * Replace the original version.
   * Wrap the original version.
   * Chained before the original version.
   * Chained after the original version.
 * Complete the functionality to inject an override.
 * Complete the functionality to remove an override.

Other aspects:

 * Solid error handling.
   * Should be possible to place overrides and wrap them for
     error handling.  Perhaps with the option to restore the
     original version if an override errors, or to remove
     just that override whether it restores the original version
     or leaves a sequence of others.
   * If the error handling is there to ensure the override works
     it might be removal after the first call.  Although perhaps
     it is better that it remains permanently.
 * Duration.
   * An override might be present for N calls.
   * An override might be present for a period of time.

Original issue reported on code.google.com by [email protected] on 28 Dec 2006 at 4:27

Failures in test_reloading.py on py 2.5/2.6 os x leopard

on python 2.5.4, livecoding 0.2, on mac os x leopard:

$ python test_reloading.py 
WARNING:root:TODO, implement leakage compatibility case
............E.E
======================================================================
ERROR: testUpdateSameFileReload_ClassFunctionUpdate
(__main__.CodeReloadingObstacleTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_reloading.py", line 451, in
testUpdateSameFileReload_ClassFunctionUpdate
    self.failUnless(ret.defaults == (True,), "Function argument default
value not updated")
AttributeError: 'tuple' object has no attribute 'defaults'

======================================================================
ERROR: testUpdateSameFileReload_FunctionUpdate
(__main__.CodeReloadingObstacleTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_reloading.py", line 551, in
testUpdateSameFileReload_FunctionUpdate
    newScriptFile = self.ReloadScriptFile(scriptDirectory, scriptDirPath,
"functions.py", mangleCallback=cb)
  File "test_reloading.py", line 100, in ReloadScriptFile
    result = self.codeReloader.ReloadScript(oldScriptFile)
  File "/Library/Python/2.5/site-packages/livecoding/reloader.py", line
126, in ReloadScript
    newScriptFile = self.CreateNewScript(oldScriptFile)
  File "/Library/Python/2.5/site-packages/livecoding/reloader.py", line
142, in CreateNewScript
    newScriptFile = scriptDirectory.LoadScript(filePath, namespacePath)
  File "/Library/Python/2.5/site-packages/livecoding/namespace.py", line
316, in LoadScript
    return self.scriptFileClass(filePath, namespacePath)
  File "/Library/Python/2.5/site-packages/livecoding/namespace.py", line
29, in __init__
    self.Load(filePath)
  File "/Library/Python/2.5/site-packages/livecoding/namespace.py", line
38, in Load
    self.codeObject = compile(script, self.filePath, "exec")
  File "/Users/sa/Code/src/livecoding/scripts/functions.py", line 2

   ^
SyntaxError: invalid syntax

----------------------------------------------------------------------
Ran 15 tests in 0.379s


on python 2.6.2, livecoding 0.2, on mac os x leopard:

$ python2.6 test_reloading.py 
WARNING:root:TODO, implement leakage compatibility case
..F...........E
======================================================================
ERROR: testUpdateSameFileReload_FunctionUpdate
(__main__.CodeReloadingObstacleTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_reloading.py", line 551, in
testUpdateSameFileReload_FunctionUpdate
    newScriptFile = self.ReloadScriptFile(scriptDirectory, scriptDirPath,
"functions.py", mangleCallback=cb)
  File "test_reloading.py", line 100, in ReloadScriptFile
    result = self.codeReloader.ReloadScript(oldScriptFile)
  File "/Users/sa/Code/src/livecoding/reloader.py", line 126, in ReloadScript
    newScriptFile = self.CreateNewScript(oldScriptFile)
  File "/Users/sa/Code/src/livecoding/reloader.py", line 142, in
CreateNewScript
    newScriptFile = scriptDirectory.LoadScript(filePath, namespacePath)
  File "/Users/sa/Code/src/livecoding/namespace.py", line 316, in LoadScript
    return self.scriptFileClass(filePath, namespacePath)
  File "/Users/sa/Code/src/livecoding/namespace.py", line 29, in __init__
    self.Load(filePath)
  File "/Users/sa/Code/src/livecoding/namespace.py", line 38, in Load
    self.codeObject = compile(script, self.filePath, "exec")
  File "/Users/sa/Code/src/livecoding/scripts/functions.py", line 2

   ^
SyntaxError: invalid syntax

======================================================================
FAIL: testFileChangeDetection (__main__.CodeReloaderSupportTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_reloading.py", line 788, in testFileChangeDetection
    self.failUnless(game.FileChangeFunction.__doc__ == " new version ",
"Updated function doc string value still the original one")
AssertionError: Updated function doc string value still the original one

----------------------------------------------------------------------
Ran 15 tests in 0.416s

FAILED (failures=1, errors=1)



Original issue reported on code.google.com by [email protected] on 20 Apr 2009 at 8:46

pip install livecoding fails

There is no setup.py, so things fail.

'/home/stuaxo/.virtualenvs/tmp/build/livecoding/setup.py'


Might also need to reorged a little.

Original issue reported on code.google.com by [email protected] on 14 Nov 2013 at 11:35

MODE_UPDATE leaks old classes

MODE_UPDATE works by executing a changed script file into a custom globals
dictionary, then processing what is in there, transferring the interesting
bits over to the first loaded version of that script.

However, in my usage of it, I am seeing the classes in the changed script
file hanging around.  So if I look up all the subclasses of a given base
class, I will find any version of those subclasses which has ever existed.

This appears to be because of the circular reference between a class and
the func_globals variable on the functions defined on it.  But this does
not seem like it should be a problem.

For now, I clear the globals dictionary for a script (which is what
func_globals on every class function within that script points to) when
that script is garbage collected.  Which works as a workaround.

Original issue reported on code.google.com by [email protected] on 21 Jan 2010 at 1:59

Inconsistent exception logging

Exceptions when import dependencies cannot be resolved are logged line by
line.  Exceptions when unit tests fail are logged within one log line.

The former is noisy and unreadable.  The latter is clear and readable.  All
exception logging should be done in the way the latter uses.

Original issue reported on code.google.com by [email protected] on 8 Jan 2010 at 8:59

Script directory dependency resolution sub-optimal

The script directory dependency resolution has N number of attempts to
execute the scripts it has to load.  This works fine, but there is
potential to make it optimal.

This could be by having it consider what it has left, and to only do as
many further attempts as are necessary to determine that everything can be
loaded or that everything cannot be loaded.

Original issue reported on code.google.com by [email protected] on 13 Feb 2010 at 12:35

python 2.5 compatibility

On python 2.5.4, livecoding 0.2, on mac os x leopard,

With the simple example:

$ python run.py 
Traceback (most recent call last):
  File "run.py", line 31, in <module>
    Run()
  File "run.py", line 11, in Run
    cr.AddDirectory("base", "scripts")
  File "/Library/Python/2.5/site-packages/livecoding/reloader.py", line 51,
in AddDirectory
    if handler.Load():
  File "/Library/Python/2.5/site-packages/livecoding/namespace.py", line
175, in Load
    self.LoadDirectory(self.baseDirPath)
  File "/Library/Python/2.5/site-packages/livecoding/namespace.py", line
207, in LoadDirectory
    namespace = self.GetNamespacePath(dirPath)
  File "/Library/Python/2.5/site-packages/livecoding/namespace.py", line
168, in GetNamespacePath
    relativeDirPath = os.path.relpath(dirPath, self.baseDirPath)
AttributeError: 'module' object has no attribute 'relpath'




Original issue reported on code.google.com by [email protected] on 20 Apr 2009 at 8:42

UpdateModuleAttributes incomplete / leaked attribute confusion

Looking at UpdateModuleAttributes, it is clear that this function has a few
issues.

* Why is 'overwritableAttributes' passed in?
* Why are the leaked attributes collected in 'leakedAttributes' unused?

And finally, with collection of leaked and contributed attributes, who
removes leaked attributes that have been replaced?

Original issue reported on code.google.com by [email protected] on 13 Feb 2010 at 12:45

testUpdateSameFileReload_FunctionUpdate failure on os x leopard py2.5 on rev118

What steps will reproduce the problem?


$ python test_reloading.py
WARNING:root:TODO, implement leakage compatibility case
..............F
======================================================================
FAIL: testUpdateSameFileReload_FunctionUpdate
(__main__.CodeReloadingObstacleTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_reloading.py", line 554, in
testUpdateSameFileReload_FunctionUpdate
    self.failUnless(testFunction is not game.TestFunction, "Function not
updated by reload")
AssertionError: Function not updated by reload

----------------------------------------------------------------------
Ran 15 tests in 0.836s

FAILED (failures=1)



Original issue reported on code.google.com by [email protected] on 26 Apr 2009 at 5:39

MODE_OVERWRITE may not work

I switched to MOVE_UPDATE because it didn't seem to.  George Oliver is
using MODE_UPDATE, and has resorted to doing 'instance.__class__ =
namespace.class'.

Original issue reported on code.google.com by [email protected] on 9 Jan 2010 at 3:53

follow PEP 8 naming conventions

The code seems to follow the C# naming conventions of using camel case with
leading caps for methods and leading lowercase for instance variables.  The
PEP 8 style guide for Python recommends using the
lowercase_with_underscores style for both methods and instance variables. 
Following this will keep the code consistent with the prevailing style for
Python naming.

See http://www.python.org/dev/peps/pep-0008/

Original issue reported on code.google.com by [email protected] on 10 Apr 2007 at 6:49

Consider license change to GPL

I thought this project was licensed under the GPL, but as pointed out on
Reddit it is not.  I need to consider changing from BSD to GPL.

Original issue reported on code.google.com by [email protected] on 21 Jan 2010 at 8:27

MODE_UPDATE and base classes

MODE_UPDATE does not update the base classes of a changed class.  This
definitely needs to be fixed.  If it is not possible to change the base
class of an object, like from object to type, then this should be a logged
warning or error with an understandable description of the reason for it.

Original issue reported on code.google.com by [email protected] on 23 Feb 2010 at 1:27

Importing wiki page needs a rewrite

Should have a clearer distinction between automatic and user driven updates.

  Which gives the following two categories:

  - Automatic updating (have to be using threads).
  - User driven updates.

  The user can also choose how updates are detected.

  - Inline when polling.
  - Accrued in a thread.  These would be acquired from a queue.

  This is still quite confused.  But it would all be hidden away in
filechanges.

Original issue reported on code.google.com by [email protected] on 28 Dec 2006 at 3:37

Objects with __slots__ set, are not updated properly

What steps will reproduce the problem?
1. Run the MUD framework.
2. Edit a slots based class that has instances.
3. Save the file.

What is the expected output? What do you see instead?

The expected output is that all instances are updated and continue to work.  

Instead..

Traceback (most recent call last):
  File "D:\SVN\_googlecode\sorrows-mudlib\trunk\contrib\uthread.py", line 95, in newFunction
    oldFunction(*args, **kwargs)
  File "D:\SVN\_googlecode\sorrows-mudlib\trunk\games\roguelike\services\world.py", line 340, in RunNPC
    matches = self.FindMovementDirections(body.position)
  File "D:\SVN\_googlecode\sorrows-mudlib\trunk\games\roguelike\services\world.py", line 315, in FindMovementDirections
    if self.IsTileUnoccupied(tile):
  File "D:\SVN\_googlecode\sorrows-mudlib\trunk\games\roguelike\services\world.py", line 285, in IsTileUnoccupied
    return tile.isPassable
  File "D:\SVN\_googlecode\sorrows-mudlib\trunk\games\roguelike\services\world.py", line 43, in isPassable
    return self.flags & FLAG_PASSABLE
TypeError: descriptor 'flags' for 'Tile' objects doesn't apply to 'Tile' object

Please use labels and text to provide additional information.

Original issue reported on code.google.com by [email protected] on 6 Sep 2010 at 10:30

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.