Sublime Forum

General method to add a pypi package as ST dependency?

#1

What are the generic steps you need to follow to add a pypi package as a ST dependency?

Asking this cos yesterday I was trying to use html5print in one Sublime plugin so the first idea was just copying html5print\html5print folder directly into my plugin folder to see whether that’d work out of the box… unfortunately it didn’t, one dependency would be missing… so i tried to solve that missing dependency error by repeating the procedure, so I’ve cloned the github repo of this missing dependency and manually but then a new dependency would miss again, and so on… Didn’t take me time to know this method was error proof and a total wrong way to use pypi packages on ST.

I mean, the above method would be good enough if the package is just flat and self-contained but it will fail miserably if it has several recursive dependencies.

So my question is, assuming you’ve got an existing system-wide python3.3 where you’ve installed and tested succesfully through pip a package… how would you use that same package in SublimeText?

0 Likes

#2

ST started to provide a Data/Lib/python3.3 for python libraries/packages since 3141 or so, but this is not yet supported by Package Control and therefore not useful for dependencies you want to publish. Not sure if it was possible to create a patched pip, which downloads to that directory. But as most py33 packages disappeared from pypi it wouldn’t be worth the effort, I guess.

The official way is to create a package containing folders like [all|st2|st3]_[windows|linux|osx]_[x86|x64] which themselfs contain the folder of the pyi package.

Just have a look into some existing dependencies to learn about the required file structure.

By placing a .sublime-dependency file into the root of your package, it is marked as dependencies and picked up by Package Control, which will then add it to the sys.path to make in globally available.

To publish it you’ll need to create a github repo of exactly that file/folder structure and create a pull-request to add it to the https://github.com/wbond/package_control_channel/blob/master/repository/dependencies.json

In order to use the dependency, you need to add a dependencies.json to the package which uses it.

See https://packagecontrol.io/docs/dependencies for details.

1 Like

#3

You need to find each package that was installed, and extract them into the necessary folder structure for an ST dependency - https://packagecontrol.io/docs/dependencies. The folder structure depends on whether or not the package includes any shared libraries. If not, you use the all folder like requests. If there are shared libraries, they need to be added in the architecture-specific folder like _ssl.

Once you’ve created a repo, you need to add the dependency to the list of available dependencies at https://github.com/wbond/package_control_channel/blob/master/repository/dependencies.json. You’ll need to specify the load order so that dependencies required by other dependencies are loaded first by Package Control.

There is no recursive dependency handling, so each package that uses a dependency will need to know the full graph of dependencies to include in the list. You can see how to specify dependencies by platform/arch/st version at https://github.com/wbond/package_control/blob/master/dependencies.json.

1 Like

#4

There is a lot of room for improvements to dependencies like @deathaxe mentioned. Here are things that should be improved, if someone has time and is so inclined to work on it:

  • Rip out support for Sublime Text 2 from Package Control - the next version will be 4.0.0 and only support ST3
  • Get rid of 0_package_control_loader and move over to Data/Lib/python3.3/ since that is in sys.path by default
  • Improve handling of dependency install order - right now there is a bug where they aren’t installed in load order
  • Support the concept of a dependency having a dependency
  • Maybe(?) support the idea of package requiring another package
3 Likes

#5

Seems it could remove a lot of hassle from Package Control. Maybe worth a ‘next’ branch to place pull requests to which start with removing ST2 stuff?

5 Likes

#6

As I was curious about @deathaxe previous comment today I’ve decided to install&test ST3143. This new concept of having Data/Lib/python3.3 is just brilliant, my first thought to make my life easier would be creating a virtualenv and replacing that python3.3 folder with a shortcut to lib/site-packages, it seems this is just not posible because if you try to remove the folder ST will create it again. It looks to me you need to copy manually the virtualenv packages installed by pip into that folder, which is not that bad… although is not ideal.

Any workaround about it so you can use pip to populate that folder with pypi packages? Other than that, this feature is a reason enough to upgrade to this new version of ST, thanks guys, good job :wink:

1 Like