How to use Python modules in custom RV packages

Hi everyone!

This is actually the same question that @Fabian asked here a long time ago. Since he didn’t get any answer, I’m going to explain my case (and I wonder if @Fabian addressed the problem).

I have built a plugin with this structure:

The main file is the MTP_Review.py file. The rest are used with import statements. For example:

As you can see, I have created a Python module called rv_review and I need it copied in the RV support path.

To achieve this, I created the following PACKAGE file which looks like this:

package: MTP Review
version: 0.1
rv: 2022.3.1
hidden: false
system: true
optional: false

modes:
  - file: MTP_Review.py
    menu: 'MTP'
    shortcut: 'alt+w+z'
    event: ''
    load: immediate
    icon: ''
    requires: ''

files:
  - file: QLauncherDialog.py
    location: Python/$PACKAGE/rv_review
  - file: flag.svg
    location: SupportFiles/$PACKAGE

So, I define only one mode with the main file, MTP_Review.py . I guess I have to include the rest of the files in the files key. For now, I’m just testing with a Python file and a file of something else, to see if they are copied to the RV support path.

Then, I created a zip file called vfx_rv_review-0.1.rvpkg with all these files in the root:

Finally, I run: rvpkg -force -install -add. However, if I check the RV support path, I cannot see the Python files copied:

So, how can I define non-mode Python files in the PACKAGE file to be copied/populated with the same module in the RV support path?

I hope I was able to explain!

Hi @daniel_mepathysic !

I basically defined my extra python files like you did with your flag.svg and added this to the top of my main python file:

sys.path.append(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'SupportFiles', 'name_of_my_rv_package'))

This works but feels super hacky and I hope/wish there is an intended way to handle this. So hopefully someone else can enlighten us both :slight_smile:

Cheers,
Fabian

1 Like

Oh, thank you for your very quick reply @Fabian!

I wonder if adding the files as I did with my flag.svg and updating the PYTHONPATH variable instead of adding what you said might work.

I’ll test it and get back to you with an answer.

1 Like

Ok, let me show you what I have found out:

You cannot define subfolders in the location of the files in the PACKAGE file. If you do it, the file won’t be copied when you run rvpkg -force -install -add. And if you want to use the Python folder, you cannot even use the $PACKAGE variable.

So, having these values in the PACKAGE file:

files:
  - file: MTP_RvUtilities.py
    location: SupportFiles
  - file: MTP_SessionData.py
    location: SupportFiles/$PACKAGE
  - file: MTP_ShotImporter.py
    location: SupportFiles/rv_review
  - file: QLauncherDialog.py
    location: SupportFiles/$PACKAGE/rv_review
  - file: QNotesWidget.py
    location: Python
  - file: QTimeline.py
    location: Python/$PACKAGE
  - file: QTimelineGrid.py
    location: Python/rv_review
  - file: QVersionLabelWidget.py
    location: Python/$PACKAGE/rv_review
  - file: flag.svg
    location: SupportFiles/$PACKAGE/icons

only MTP_RvUtilities.py, MTP_SessionData.py and QNotesWidget.py are copied (apart from MTP_Review.py which is the main mode file):

I wonder why it’s required to specify all the files used by the plugin in the PACKAGE file. Apart from being really annoying, the module structure is not preserved so all the import statements will fail.

So my next test will be remove all the file fields and copy manually, without rvpkg, to one of the folders of the RV support path, keeping the module structure. Then, I’ll update the PYTHONPATH with this path.

This should work. My only concern is what is the risk of having these module files outside of PACKAGE.

If anyone knows the answer, I’d really appreciate it.

1 Like