importing function not in jython library

Post any questions, ideas, or topics related to Jython and Python scripting.
Post Reply
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

importing function not in jython library

Post by joleenf »

Hi,

I am working in current nightly (Version 1.6 beta 2016-01-29), and writing a script. If I want to write a few functions that are linked in the main script, is there a way to import them for use in the main script? Do I have to keep the extra code in my jython shell, should I always include it in the main script even though that mean both a super-huge script and repetition? I would prefer to keep the files separate and linked rather than forcing my colleagues to put support code in their jython shell. Should I create the main script, and put it all in my jython shell and save it as a plugin, that is not very friendly for collaboration.

If I have some code in a file called getFilesNow.py,

Code: Select all

def getGOESRfiles(dir, fileTemplate):

    retrun goesRFilesAvailable


and I have a main script, something like...

Code: Select all

import argparse
parser.add_argument('--fileRegEx', action='store', dest='fileString', \
                  type=str, default=None, \
                  help='filename regular expression string (overrides sector, band, product selections)')
parser.add_argument('--directory', action='store', dest='directory', \
                  type=str, default='None', \
                  help='location of netCDF files')

allFiles=getGOESRfiles(options['directory'], options['fileRegEx'])

print "Continue to display files, etc."
User avatar
bobc
Posts: 990
Joined: Mon Nov 15, 2010 5:57 pm

Re: importing function not in jython library

Post by bobc »

Hi Joleen -

One of our programmers just put in a commit for Inquiry 1480 (Allow a user to create a file in /McIDAS-V/python and have it imported - preferable without a restart). Assuming this change works, if you were to pass a script around that relied on some local functions, you could include a *.py file containing the functions along with it to go in the user's McIDAS-V/python directory.

Note that this is probably not in its final implementation and it is something that our group plans on discussing soon. I'll keep you updated.

Does this sound like it would be something that would address your concerns?

Thanks -
Bob Carp
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: importing function not in jython library

Post by joleenf »

I think this would address my concerns.

Joleen
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: importing function not in jython library

Post by joleenf »

Hi,

I am trying to write instructions for my group. We plan on installing imagery code that I developed on another mac, a linux machine and a few Windows machines. Where are the python directories located for these?

Mac: <user-path>/Documents/McIDAS-V/python/
Windows: ???
Linux: <installation-directory>/McIDAS-V/python/ ???

Joleen
User avatar
jayh
Posts: 424
Joined: Thu Jan 15, 2009 10:34 pm

Re: importing function not in jython library

Post by jayh »

Hi Joleen-

I think something like this would be appropriate for your documentation:

Windows:
C:\Users\username\McIDAS-V\python
Linux:
$HOME/McIDAS-V/python

Thanks, Jay
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: importing function not in jython library

Post by joleenf »

Hi,

I have this jython code located in a git repository. I have been checking out and updating the jython code in an independent directory and then copying to my McIDAS-V/python directory to update in my Jython Library. Occasionally, this means the version I have in my jython library ends up being out of sync with my code in the repository. Is there a way to check out the git repository to the McIDAS-V python directory so that I can check code differences using git?

Thanks,
Joleen
User avatar
Jon
Posts: 192
Joined: Fri Jan 09, 2009 8:44 pm
Location: Madison, WI

Re: importing function not in jython library

Post by Jon »

Hi Joleen,

That's a great idea! Unfortunately, there appear to be issues when a ".git" directory (or essentially any "dot file") is in the McV python directory. We hope to have this fixed immediately after the upcoming 1.6 release!

That said, once this is available, it should be as simple as creating a clone within <MCV USER DIR>/Python.

I've written up http://mcidas.ssec.wisc.edu/inquiry-v/?inquiry=2376 so that we can track this fix.

Jon
User avatar
bobc
Posts: 990
Joined: Mon Nov 15, 2010 5:57 pm

Re: importing function not in jython library

Post by bobc »

Hi Joleen -

Just following up to let you know that today's (06/28) 1.6b1 nightly includes a change made for McIDAS-V to ignore any "dot file" in the McIDAS-V/python directory. If you give this a look and notice any problems, please let me know.

Thanks -
Bob
Post Reply