tag:infinitekind.tenderapp.com,2009-01-14:/discussions/general-questions/102914-how-to-test-python-scripts-with-moneydanceInfinite Kind: Discussion 2021-01-16T08:40:26Ztag:infinitekind.tenderapp.com,2009-01-14:Comment/486311372020-09-24T17:20:31Z2020-09-24T17:20:31ZHow to test Python scripts with Moneydance<div><p>Hi, I am a user and quite new to Python. As I understand it:<br>
- Moneydance MoneyBot uses Jython 2.7 - i.e. Java base - and is the latest available for now - No - you have to run these scripts within the MD environment/console. - I believe you can run a Java IDE to run Java (from within MD), but others will have to explain that.</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/486311372020-09-24T18:29:20Z2020-09-24T18:29:46ZHow to test Python scripts with Moneydance<div><p>Thanks!<br>
That does sound like a path to explore. I'll check out Jython.</p>
<p>Cheers.</p></div>dvillamil+infinitekindtag:infinitekind.tenderapp.com,2009-01-14:Comment/486311372020-10-17T01:30:22Z2020-10-17T01:30:22ZHow to test Python scripts with Moneydance<div><p>Hi Diego,</p>
<p>It seems weened to run under the MoneyBot Console only, as explained in my earlier post: <strong>jython access to md outside MoneyBot Console</strong>.</p></div>davidcullentag:infinitekind.tenderapp.com,2009-01-14:Comment/486311372020-10-17T08:38:14Z2020-10-17T08:38:14ZHow to test Python scripts with Moneydance<div><p>Further followup..</p>
<p>I see no practical way to test Python scripts ‘outside’ Moneydance…. I.e. how would they work as they rely on MD?</p>
<p>Further the moneydance (and _ui and _data) variables are created by the Moneydance>MoneyBot>Python console, so again, these can only exist when MD is running the scripts.</p>
<p>I can see conceptually that a Python script could open the MD data file itself, and then go from there calling the APIs, but (understandably) I don’t see an API method to actually open the MD data file… So no dice there..</p>
<p>FYI - whilst you need nothing other than a text editor to create MD Python scripts, I do now have IntelliJ IDE(A) configured to properly ‘manage’ Python(Jython) MD scripts - as follows:</p>
<p>(IntelliJ seems more capable than PyCharm, but is from the same company)</p>
<p>Rough steps</p>
<p>Download/install IntelliJ (IJ)<br>
- add the Python addin (which is actually based on PyCharm) - add the Python 2.7 SDK into Platform settings - add(download) Adopt OpenJDK 14 (Hotspot) into IJ (this is what MD is built on) - open the MoneyDance application file / package contents and copy the contents somewhere for your project dev work - create a new project >> base it on Python 2.7 - add a library (Java) and select all the .jar files within the application files you just copied from Contents/Java. - create/add a module called MoneyDanceApp</p>
<blockquote>
<blockquote>
<p>select Java base it on OpenAdoptJDK 14 in dependancies</p>
<blockquote>
<blockquote>
<p>add/link to the library above you just created (as runtime) make sure adopt open JDK is listed add/link the contents directory from the MD contents you saved above and select classes and sources make sure the dependancy list is the MD Library, adoptJDK, module source, contents...</p>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<ul>
<li>create another module called scripts >> based on Python 2.7 >> in dependancies, add/link the MoneyDanceApp module you created above</li>
</ul>
<p>Now your code should recognise MD and resolve most references (not all).<br>
- It won’t resolve moneydance (and _ui and _data) - It won’t resolve the odd item within MD - It won’t resolve the odd Java item</p>
<p>NOTE: We are using here the AdoptOpenJDK 14 which is what MD is built upon, but not the actual Java JRE that’s bundled with MD (I’ve found no way to do that, but not sure it matters too much).</p>
<p>BUT on the whole it will help you manage your script better and look for errors.</p>
<p>In addition, you can now create a debug/run configuration to run Moneydance within your IDE (it’s neat, but of no real use at the moment)</p>
<blockquote>
<blockquote>
<p>Click add, application Main Class, type Moneydance (if you’ve done it right then this will resolve) Prog Args -d Working Dir = your MD data directory Use ClassPath of = MoneyDanceApp (that you created above) tick include dependancies with provided scope JRE = adopt-openJDK 14</p>
</blockquote>
</blockquote>
<p>Then you can click RUN and MD will load. NOTE - make sure all other instances of MD are closed, also that it will not load your settings (due to sandboxing).. But all you need to do is copy config.dict<br>
From: /Users/xxx/Library/Containers/com.infinitekind.MoneydanceOSX/Data/Library/Application Support/Moneydance<br>
To /Users/xx/Library/Application Support/Moneydance<br>
Or wherever your system is storing its settings<br>
—</p>
<p>I’m now trying to workout how to go further, but that’s all for now…</p>
<p>It has been suggested that: “you could write a java wrapper that launches moneydance... calling the com.moneydance.apps.md.controller.Main.main(argv) method. Then when that main method returns you could access the Main.mainObj static variable and get the python interpreter using Main.mainObj.getPythonInterpreter()” but I haven’t worked out how to do that yet, or what that would give me….</p>
<p>If anyone improves the above setup, or go further, do shout..?</p>
<p>It’s quite funny that you can create scripts with a plain text editor, or do all the above and get the same result…!!!</p></div>Stuart Beesley (Mr Toolbox)