0

I am using an IDE so hacks like sys.path.append() are somewhat undesirable, because static type checker can hardy see modules imported like this, so I was wondering what is a conventional way of referring to and managing your personal library of small utility scripts that are shared among a bunch of different projects. I can think of following:

  1. Using a git submodule that reffers to a git repo with 'personal utils shared among projects'
  2. A symlink to a shared project, though it leads to duplicate code in github
  3. A proper package with setup and everything, but it seems like an overkill to me in terms of the amount of work required to maintain and sync versions between projects, even if that is just a folder with a setup.py script
  4. Copy-pasting scripts between project utils subfolders on demand - that is what I do now, but it leads to some weird conflicting version of same utils in different projects

A bit of context: I am the only person who actively makes changes to these projects, so trickery with git might be okay, though other people might also need to have to run that code at some point in the future.

Ben Usman
  • 7,969
  • 6
  • 46
  • 66
  • You can add py files into your current import lib folder (ie, look at your `sys.path` list for a `lib` directory and add any py files you want to be checked as modules) – R Nar Nov 03 '17 at 22:48
  • @RNar not sure whether directly editing something in `lib` is a good idea. I am personally using an environment, so it might work, but for those using system-wide python this might be an issue. Moreover, these changes are still hard to sync between multiple environments. – Ben Usman Nov 03 '17 at 22:53
  • you are not editing anything, just having the py file in the directory allows it to be imported by whatever instance of python checks that lib folder. If you are going to be distributing these util files to other people, then a proper package seems well worth the extra effort of making 1 or 2 small files – R Nar Nov 03 '17 at 23:02
  • @RNar *"Best practices to maintain **often changing** set of utils within multiple projects?"* :) if these were some static files then yes, packaging seems like a reasonable solution, but considering that they are edited and extended from time to time, editing them directly in `lib` or assigning new package version number to every minor change seems tedious (though I never built a package myself); and, again, if you have multiple envs on same machine, editing `lib` corresponding to one of them does not seem to effect other – Ben Usman Nov 03 '17 at 23:12
  • 1
    Are you currently using any tools for managing your environments? If not, `conda` is my go-to; you can supply `pth` files that essentially has a list of addititional directories that should be included in your search path. (Here's a a [reference](https://stackoverflow.com/questions/37006114/anaconda-permanently-include-external-packages-like-in-pythonpath).) Looks to me like something that would work for you – R Nar Nov 04 '17 at 01:35
  • @RNar Interesting, did not know about `.pth` files! It is still little hacky, but pycharm seems to recognize these files well, so I will give it a try! Thank you. – Ben Usman Nov 04 '17 at 01:57

0 Answers0