jython/python for McV in git

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

jython/python for McV in git

Post by joleenf »

I have quite a bit of McV jython code, some of which doubles as independent python code. I need some advice on rethinking the git repository.

The code was developed as part of a project, initially is was in a project repository sub-directory, to which, I would soft link from my McIDAS-V/python directory to the project repo subdirectory. This caused problems when the link target would disappear. I decided it would be best to sparse-checkout the jython code into the McIDAS-V/python directory. At that point, I found that using sub-directories did not work. Unfortunately, I did not find a way to sparse-checkout a git repo sub-directory without inheriting the directory tree. Therefore, I put all the jython code in the top level of git project repository, which I dislike immensely.

I will need some of the code that I use regularly in my jython library in another project which would probably just use python 2.7 or higher. In that case, I usually add a "if __name__ == '__main__’:”
In that location, I usually initialize a logger and argparse. In this case, McV will periodically start a new logger and this is not a great thing.

Therefore, I am thinking that I probably need to write independent python code initializes the logger and argparse and calls the needed routines, which could then be used in either McV or python. I am thinking I should probably separate my McIDAS-V jython code into a different repository and then fork(???) the necessary pieces into the python project repository?

What would you do in this situation?

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

Re: jython/python for McV in git

Post by Jon »

Hi Joleen,

Rather than using a soft/symbolic link, you could create a "hard" link to the file within your local repository (an unfortunate limitation is that you can't create a hard link to a directory):

Code: Select all

ln /path/to/repo/file.py ~/Documents/McIDAS-V/python/

When you run "ls -l ~/Documents/McIDAS-V/python", the second column should now be at least two. That number is the number of links to the file's inode. Note: if you were to remove the file from your repository, it will still be in ~/Documents/McIDAS-V/python.

Another idea, especially if you have a directory like /path/to/repo/mymcvstuff, would be to create a shell script similar to the following (be sure to read the comments about rsync's "--delete" flag!):

Code: Select all


# note: the trailing slash in the source directory matters!
# if not present, you would wind up with "$HOME/McIDAS-V/python/foo"
export SOURCE="$HOME/repos/work/mcvjython/"
export DEST="$HOME/McIDAS-V/python/"

export RUN_MCV="$HOME/mcidasv/nightly/runMcV"

# the "--delete" flag will delete any files that are in the destination
# that *are not ALSO in the source directory*.
# when a file is removed from the source directory, --delete will also
# delete it from the destination.
rsync -avh \
      --exclude 'default.py*' \
      --delete \
      "$SOURCE" \

Post Reply