SOLVED Working with modules
-
Hi, I have a question about working in modules—specifically where the generated .pyc files are (if anywhere).
For example: I import a module of helper functions into my main script and test the script in RF. And then when I have to edit one of the helper functions, RF isn't "aware" of the changes. I usually quit and re-open RF and then it'll work fine.
My understanding is that .pyc files are created on import, at runtime, and I assume this is why RF doesn't see the changes in the imported module, but I don't see those files (or a
__pycache__
) folder in my dev folder. Are they stored somewhere in Application Support?
-
@gferreira Ah! Ok, thank you. Very helpful! :+1:
-
when an extension is installed, its
lib
folder is added to thesys.path
. and since it’s a shared namespace, there is a conflict if two modules have the same name.the recommendation is to use reverse domain names (without dots) to create unique names for extension modules:
comJesentanadiExtensionNameUtils
(Extension1)comJesentanadiAnotherExtensionUtils
(Extension2)
see the note in Extension File Specification > lib
-
@frederik One more question.
Another problem I'm having is that if I have 2 extensions with some helper functions in a
utils
directory, when I try to run the second one, I get aModuleNotFoundError
for something in theutils
directory.For example:
Extension1.roboFontExt └── lib ├── extensionName.py └── utils ├── __init__.py └── helperFunctions.py Extension2.roboFontExt └── lib ├── anotherExtension.py └── utils ├── __init__.py └── calculations.py
When I have Extension1 installed and I try to run Extension2 from the scripting window, I'll get something like
ModuleNotFoundError: No module named utils.calculations
.Should I treat each extension like a package and put an
__init__.py
in thelib
folder of each extension?Extension1.roboFontExt └── lib ├── __init__.py ├── extensionName.py └── utils ├── __init__.py └── helperFunctions.py Extension2.roboFontExt └── lib ├── __init__.py ├── anotherExtension.py └── utils ├── __init__.py └── calculations.py
-
If you have the extension installed RoboFont copies during installing the extension to
<user>/Libary/Application Support/RoboFont/plugins
and there you will find your.pyc
orpycache
.For development I would recommend to have a
main.py
that load the extension so you can run this directly in the scripting window.good luck!
-
This post is deleted!
-
@frederik Thanks. Is it possible to delete
.pyc
files of__pycache__
folder? I don't know where RoboFont puts those.
-
.pyc
or__pychache__
are indeed made during runtime on import of the requested module. To reload a py file in python3 you can use:import module import importlib importlib.reload(module)
You will have to do this for each ‘file’ in your module.
Be careful with subclasses of NSObjects.