Library manager, git(hub) and subdirectories

As the title hints, I’m trying to work out if it is possible for the PIO library manager to treat the subdirectory of a GitHub repo as the source for library files… I’ve been using a local copy of the libraries (pural) in \lib just fine, but wanted to use the GitHub versions directly if possible, especially as it already includes the fix I’ve been copying across manually. The lib_deps examples nor the lib install syntax don’t look promising, so I fully understand if this won’t work without some weirdo scripting, as this does appear to be an odd edge case.

https://github.com/OttoDIY/DIY/tree/master/libraries

It’s very easy to resolve

  1. Extra script which pulls GIT data to $PROJECT_DIR/diylibs
  2. lib_extra_dirs with diylibs value.
1 Like

Fantastic! :smiley:

EDIT: Snippets updated due to subsequent tips, and it works just fine now! :slight_smile:

In my particular case, I did the following in platformio.ini

extra_scripts = pre:get_libs.py
lib_extra_dirs = diylibs/libraries

and after some farting around, put together this for the get_libs.py extra_script

import os

Import("env")

DIYLIBS_DIR = env.subst("$PROJECT_DIR/diylibs")

if not os.path.exists(DIYLIBS_DIR):
    print "Cloning OttoDIY/DIY repo ... "
    env.Execute("git clone --depth 100 https://github.com/OttoDIY/DIY $PROJECT_DIR/diylibs")
else:
    print "Checking for OttoDIY/DIY repo updates ... "
    env.Execute("git --work-tree=$PROJECT_DIR\diylibs --git-dir=$PROJECT_DIR\diylibs\.git pull origin master --depth 100")

And it seems to be working perfectly… it either clones the diylibs folder if it is not present or pulls it to make sure it’s up to date. Not necessary but it might as well for now, and I needed to make sure the clone was a one-shot affair.

Is it possible to make this fire before the LDF scan runs? Just wondering as presently if this was to be run on a new project and the repo needed to be cloned, since it runs after LM/LDF scan, but at the start of the build, the first build attempt will fail as the LDF correctly sees that the libraries were missing, and fails the build.

1 Like

Do you mean PRE scripting? extra_scripts = pre:get_libs.py :slight_smile:

1 Like

It’s better to use

DIYLIBS_DIR = env.subst("$PROJECT_DIR/diylibs")
1 Like

Thanks, and thanks! :smiley: pre: does indeed get it to happen before the LM scan, and ensures the libraries exist if not present on the first build. And env.subst was exactly what I needed… I was going cross-eyed going through the SCons documentation looking for some way to get variables out of it! :laughing:

Code snippets updated above to suit.

1 Like