how python circuits components loading process works - circuits-framework

python circuits is a great framework, I am not familiar with its component
loading machanism
apart from loads from the /site-data folder for installed python modules through pip, I guess thats where the PYTHONPATH is set
is it loads from else where? e.g the current path when I do invoke python app.py?

It uses safe_import which ultimately uses __import__ from the Python builtins. This means your components have to be importable via the normal Python import paths.

Related

How to import a sass theming module from node_modules folder

I created a small vue.js library that is using scss for styling and published that as npm package. It works well with a default theme included into the package. But what if I would like to provide a custom theme from the application that consumes that npm package, how would you do that?
The source for a very basic version of the library is here: https://github.com/gwildu/gwi-vue-components
The idea is, that you would copy paste the styling folder somewhere (e.g., into your application directory or into another npm package) and configure the library package to import from that copyied directory.
I did some investigation myself and found that there is a big discussion about having dynamic imports in sass since years. This issue (open since 2013) claims to add such a feature (they call it load). Not sure, how actively sass is still developed and when this feature will be supported. For now I see 3 possible solutions:
move to LESS as it supports dynamic imports. Semantic UI gives you a hint about how theming could be done in LESS
It is possible to import from relative paths in SASS. That way you are also able to import from a parent directory of your package root directory (your application directory) like, e.g., #import '../../theme/index';. You would support somewhere in your package an example of a theme that the consumer then would have to copy to, e.g., the root directory of his application and adjust it to his needs. In your package you would then import the theme from that directory in the consumers application folder. The downside is, that the package would not work out of the box
You have a default theme in your package and you add some instructions into the readme how the user can override that theme in a build script. The consumer would have to copy the default theme to his application directory, adjust it to his needs and in the build script he would replace the theme in, e.g., node_modules/your-library-package-folder/theme/ by the theme in your application folder.
To be complete here is the approach with a dynamic import (that is not yet supported by SASS):
In your main theme file in the library package (that would be imported by the components) you would do a relative import of kind of a config file from the consumers application folder like in approach 2 (see above) but that config file yould not contain the theme but only the import path of the theme in a variable. that variable then would be used by the package main theme file to import the theme. For making the library work out of the box, I guess there would be a way to have a default theme as backup if the config file in the consumers directory would not exist (not tested)
Update:
I tried approach 3 but failed to get something useful. The issue with that approach is that you would have to somehow sync your custome theme with the default theme when you update the library to a higher version which might get too complex to handle in a reasonable way. Then I tried to use the overwrite feature of SASS as described here: How to overwrite SCSS variables when compiling to CSS which led me to approach
In your library component you first import a file with possible custom variables and you declare your variables in the library as default.
The issue with that approach is that SASS does not support optional imports. The file with the custom variables have to exist somewhere. So if the library updates you again have to sync your custom theme files for each component / file that was changed in the library. Apparently SASS also don't want to support such a feature in the future: https://github.com/sass/sass/issues/779 which is sad, as it seems to me an essential feature for being able to do theming without a highly complex build step.
Overall, it seems SASS itself is making every effort to prevent a simple theming approach which makes me think of moving back to LESS again. Not having a simple way for static theming in SASS in my opinion outweight the cons of not having an easy way to define custom functions in LESS.

Embedded Python 3 not creating .pyc files when using importlib

I'm trying to embed a Python 3 interpreter in an Objective C Cocoa app on a Mac, following instructions in this answer (which extends this article) and building Python and PyObjC by hand.
I'd like to be able to run Python code as plugins. I specifically don't want to rely on the stock Apple Python (v2.7). I have most of it working but can't seem to reliably load the plugin scripts. It looks like the embedded Python interpreter is unable to create the __pycache__/*.pyc files. This may be a symptom, or a cause. If I import the plugin file manually from the Python3 REPL (via import or the imp or importlib modules) the .pyc is generated and the plugin then loads correctly. If I don't do this manually the .pyc is not created and I receive a ValueError "Unmarshallable object".
I've tried loosening permissions on the script directory to no avail. The cache_tag looks OK, both from the REPL and from within the bouncer script:
>>> sys.implementation.cache_tag
'cpython-35'
py_compile raises a Cocoa exception if I try and compile the plugin file manually (I'm still digging into that).
I'm using the following:
OS X 10.11.5 (El Capitan)
XCode 7.2.1
Python v3.5.2
PyObjC v3.11
I had to make a couple of necessary tweaks to the process outlined in the linked SO answer:
Compiling Python 3 required Homebrew versions of OpenSSL and zlib, and appropriate LDFLAGS and CPPFLAGS:
export CPPFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix zlib)/include"
export LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix zlib)/lib"
I also ensure pip is installed OK when configuring Python to build:
./configure --prefix="/path/to/python/devbuild/python3.5.2" --with-ensurepip=install
There is a fork of the original article source (which uses the stock Python2) that works fine here, so I suspect I'm not too far off the mark. Any idea what I've missed? Do I need to sign, or otherwise give permission to, the embedded Python? Are there complilation/configuration options I've neglected to set?
TIA
Typical. It's always the last thing you try, isn't it? Adding the directory containing the plugin scripts to sys.path seems to do the trick, although I'm not sure why importlib needs this (I thought the point was to allow you to circumvent the normal import mechanism). Perhaps it's to do with the way the default importlib.machinery.SourceFileLoader is implemented?
Something like:
sys.path.append(os.path.abspath("/path/to/plugin/scripts"))
makes the "Unmarshallable object" problem go away. The cache directory and .pyc files are created correctly.

add/remove components in noflo-ui

I've cloned noflo-ui from github and am running locally but cannot figure out how to add/remove components from the noflo-search box. Ideally, I would like to remove all components from the search results and show only a the ones from my component libraries.
The readme states that libraries can be added by modifying preview/component.json, but removing libraries seems to have no effect. After reading through the docs on components and the spec for component.js I tried editing /component.json, and was also unable to change the results which show in the search box. Furthermore, I can't find any documentation on the .noflo property used in components.json.
Am I doing something wrong or is removing default components not an option?
I assume you are using the bundled noflo-browser runtime (iframe). Did you rebuild after editing preview/components.json?
An easier way to use custom component libraries is to do a custom runtime build, for instance based on noflo-app, host it locally, and switch the runtime URL to point there.
This also works with app.flowhub.io so no need to build & run noflo-ui locally.
In addition to editing preview/component.json, you also have to rebuild the iframe runtime components. To do that, run:
$ grunt build
Note that with newer noflo-ui/Flowhub there is actually no need to build the full UI locally. You can use the hosted Flowhub or even the Chrome app, and simply connect it to an iframe runtime you're running somewhere else:
The noflo-browser-app repo gives a nice base to build these from.

Visualworks mcz packages import with Monticello

I'm trying to program a client for multitouch gestures using TUIO under SmallTalk/Visualworks.
In order to get the mcz package for TUIO, I'm using Monticello.
The problem is that whenever i try to load a package with Monticello, i always end receiving this error message :
I can show you the Stack if anyone is inerested in it.
Thank's in advance.
A mcz package is essentially a compressed zip file. The current implementation of Monticello in VisualWorks uses external shell programs to uncompress and compress the source code to a Monticello mcz file.
When porting packages from Monticello to VisualWorks under Windows, there is usually a problem finding the corresponding zip.exe/unzip.exe. To solve your problem, try to set your PATH variable to your zip.exe/unzip.exe.
Another approach is to download the Info-ZIP package from the web. Place it into a subfolder in the image directory and change the execution logic of the VisualWorks Monticello Package. Browse for senders of shOne: in the VisualWorks Monticello Package and change the call.
The next thing to keep in mind when porting packages from Squeak or Pharo is to always define a Namespace which is named extactly after the first word of the monticello package name (upTo: $-). Define the namespace before loading the package.
i.e. JQueryMobile-Libraries-NickAger.10.mcz -> Define a Namespace JQueryMobile
Don't forget to import necessary Namespaces that the imported code requires to resolve the superclass names.
i.e. JQueryMobile needs Seaside.*, Javascript.*, JQuery.*, Grease.*, Smalltalk.*

Jython ImportError when embedding into Java on 'xml.dom.minidom'

I have a python script which is processing XML using xml.dom.minidom.
When I executed it with Jython by command line (jython myfile.py), everything was fine.
But when I tried to do the same thing embedding it into a java application, (I mean reading it as an java string then passing this string for evaluation) I got:
import xml.dom.minidom
ImportError: No module named xml
Which is driving me crazy. I tried to use different jython version (2.2, 2.5), to clear the cache, but nothing works!
Jython's Documentation tells me that we can use this module without any particular remarks.
Some people had the same problem on the internet but never got any replies. Except this:
here but still nothing work. I think I have the correct values in my jython registry, because it's working using the command line! It's just the embedding which fails everything.
I'm using a full install of Jython.
Why so much trouble, so?
Thanks in advance.
i've never done this before, but are you trying to embed jython like they did here or here? do you know where you got the jython.jar in your java classpath from? if you know where your jython module is located on disc then you might be able to just add that path as they did at the bottom of this page. To find the location of your module, load up jython and look in sys.path for a path that ends in Lib. that location should have a directory named xml (the xml package) which contains a directory named dom (the dom package), which contains a file minidom.py (the minidom module).
The xml module (jython) isn't on the the python-path of your embedded jython.
This may help:
use a jython-jar which contains the Lib (and all the Batteries :-)
put the Libs on the classpath of your java app
to help debug:
log "sys.path" in your embedded jython