Sublime Forum

How to Add a Python Package to an ST Package

#1

If I am developing an ST package and need a custom (or 3rd-party) Python package to go with it, by looking at some of the existing ST packages, it LOOKS like the correct way to do that is to include the Python package in a subdirectory below the ST package root, and to make it “look” like a Python package by having a __init__.py file in there. Then importing uses the standard Python package “pathing”. Example:

<st_data>/Packages/MyPackage/my_python_lib_dir/__init__.py

…and other Python package files there. Then

from .my_python_lib_dir import module_name

Is this the correct (ST-designer-intended) way to do it?

(I looked and didn’t find any other Forum topics on this, nor have I found any documentation on it.)

0 Likes

#2

Not answering your specific question, but looking at the problem ffrom a different perspective. Is the 3rd party library available here, by chance?

packagecontrol/channel: Package Control Libraries Channel then look to the repository.json file.

If so, you can import it, without having to incorporate the codebase into your own plugin. There are a few steps:

  1. Add the additional channel to ‘Package Control.sublime-settings’ (as shown in the GitHub readme above)
  2. Ensure your plugin is configure for python 3.8 by creating a file called .python-version that contains the text ‘3.8’ in the root of your plugin
  3. create a dependencies.json file that lists the libraries you wish to import

eg:

{ "*": { "*": [ "bs4","soupsieve","lxml"] } }
0 Likes