Comments (18)
I'm currently experiencing a cold so my thought might be squishy...
ximport
should allow for .bot files and distingish between .py and .bot.
if extension == .bot
add SB/NB functions
Perhaps we run into another problem of compiled libs. Are .bot files compiled and if yes, how?
from shoebot.
There's no compilation of .bot files (beyond py->pyc, and I'd need to double check that).
I need to think about the other bit; it sounds reasonable ?
Apart from .bot extensions, it makes me wonder if we should support shebangs and have that as a way of telling something is a nodebox/shoebot file, and what they'd look like, for instance
#!/bin/env nodebox
#!/bin/env sbot
from shoebot.
I've just looked at the objects in Context.namespace, all the commands, constants etc that are loaded into the script namespace. That's about 230 entries. About 150 if I ignore the special "_" stuff.
In my opinion that's too much to include in a lib automatically.
from shoebot.
Started building a test for this + realised loading .bot files + fixing up the namespace should probably be implemented with importlib + a finder and loader.
from shoebot.
In my opinion that's too much to include in a lib automatically.
But there should be an option to deliberately do so.
from shoebot.
I wonder if it's possible to add them lazily ?
Ultimately it's something like dict.update() once a frame so it may not be the worst.
I'll experiment with it in shoebot, with .py import at first (since that doesn't need extra work compared to .bot to import), and benchmark.
import in python can be a little heavy anyway, let's see if this adds anything noticeable.
from shoebot.
Realised a lot of that won't be needed, it should matter of passing the right dict to the importer.
from shoebot.
Made a rough proof of concept -
This uses a finder / loader - but would need some issues resolved
- caching the module in sys.modules needs to be implemented
- no pyc compilation happens; this is the same for shoebot code itself, where exec(...) is used.
from shoebot.
I am new to importlib so I used the smallest change that would make it run.
def ximport(self, libName):
lib = importlib.__import__( libName )
for name in self._ns:
if name[0] != '_':
lib.__dict__[name] = self._ns[name]
self._ns[libName] = lib
lib._ctx = self
return lib
If that proves useful, I'll add a param loadContext=False
to default to old behaviour. For testing I copied the Supershape lib and removed the "_ctx.".
from shoebot.
Problems:
- libraries defining functions with names from the namespace. Currently these get overwritten.
- checking if a name already exists collides with module caching on following scripts.
from shoebot.
Doesn't the library get exec'd during import though ?
So may calls to the API in the body of the module it will fail I think?
I thought that passing globals() to import would help, but it doesn't - the importer just uses that to grab __path__
and a couple of other variables.
You might be able to use __dict__.setdefault
to work around the issue of overwriting.
from shoebot.
I filtered for names. That's only half the work. Must check for the right instance of Context and before copying check the target lib for conflicts.
from shoebot.
Doesn't the library get exec'd during import though ?
That step happens probably in importlib.import()
from shoebot.
Yep...
I guess it means that you can't have a library with this fill
and friends in the body, since that would fail during the __import__
line ?
I wonder if some of this would go away if we had a step that transformed the code in the same way as processing does ?
https://happycoding.io/tutorials/java/processing-in-java#processing-is-java
Under the hood adding imports and changing fill
etc to context.fill
.
from shoebot.
I guess it means that you can't have a library with this
fill
and friends in the body, since that would fail during the__import__
line ?
It does not fail. Since the lib is already imported, copying the attributes overwrites the lib.fill with Context.fill.
I think the problem is that I try to manipulate attributes in a highly caching environment.
I am looking for a solution that does not involve storing namelists from first import to distinguish between imported and attribute copied names in the lib.
Perhaps my first idea is better: from nodebox.bowels import line,transform,path
.
from shoebot.
The first idea is definitely the most sensible one, in the context of ordinary python.
I think something is wrong in my assumptions, I need to poke this with a debugger, I thought __import__
execs everything in the body, so fill
and friends don't exist yet.
Though - to be fair, maybe there are enough differences in shoebot + nodebox to make this tricky.
I'm not in front of my own computer right now so can't test anuthing.
from shoebot.
After some contemplating:
- I let the replace
_ctx
idea drop. _ctx is ugly and cheap and does the job - perhaps I'll revive it by introducing an extension for NB/SB Library files like .nblib which won't have a _ctx but a selection of the NodeBox grammar included. Deciding behaviour on import.
from shoebot.
Only populating the namespace for some file extension seems sane (implementing a custom file encoding is another option)
I'm going to see if I can replace the shoebot core before coming back to this, the architecture makes it too hard to do this in a nice way at the moment.
from shoebot.
Related Issues (20)
- Option for text() to be drawn with (x,y) being the top left corner, not baseline
- Socket control and puredata example fixes. HOT 2
- Saving a snapshot of a script with draw() repeats more than 300 times HOT 4
- Variables window only shows when the --window option is used
- Broken links on front page HOT 2
- Support miter limits on stroke joins HOT 2
- Include pprint() in utility functions HOT 3
- The text() width property does nothing, same with align() HOT 1
- Could not build wheels for pygobject which use PEP 517 and cannot be installed directly HOT 1
- Python 3.10 - collections.Mapping moved to collections.abc.Mapping HOT 2
- GUI tests freeze HOT 1
- release 1.4
- Update our setup.py ..
- Nodebox compatibility - does scale() affect the origin of shapes ? HOT 19
- Release 1.4.2
- Can't install gedit plugin now gedit has versions > 40.0
- Test wrapper - del some variables to give allow objects to be destroyed at test tear down.
- collections.Mapping not supported anymore in Python 3.10 HOT 1
- Docs fixes HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shoebot.