3

Suppose I have a project that will be using some of the Google APIs. In order for me to make it easier to work with the API, I want to use the PHP library that Google provides (https://github.com/google/google-api-php-client) Should I just clone it into my current project, and add it to .gitignore? Should I clone it, and start using git modules, or should I just copy the files that I need, and add them to .gitignore?

Another scenario would be when I'm working with libraries that I've created, and that I have locally. Should I clone them into the current project? Should I create symlinks to the files that I need?

Finally, there are some libraries that aside from having the code hosted in github, also provide 'stand alone' files. Think for example of jQuery. In these cases, is it better to just download the file they provide? Or is it better to clone the repository into the current project?

I'm guessing this all has to do with software architecture. Any book recommendations in that topic?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Buzu
  • 1,059
  • 2
  • 8
  • 15
  • Since you're using PHP, https://packagist.org/ for the PHP packages, and http://bower.io/ for the JavaScript. – ceejayoz Jun 12 '14 at 20:35
  • Thanks, but that does not consider cases where the dependencies are not in either of those, or other package/dependency manages, such as when you are working with private libraries, or public libraries that are not in those systems. – Buzu Jun 12 '14 at 21:04
  • 1
    Both trivially accomodated. Using composer with an arbitrary repository: https://getcomposer.org/doc/05-repositories.md#loading-a-package-from-a-vcs-repository Using composer with private repositories: https://getcomposer.org/doc/05-repositories.md#using-private-repositories Bower also supports private repositories. Both package managers will allow people other than the author to publish a package, as well. – ceejayoz Jun 12 '14 at 21:09
  • That sounds much better :D I will make sure to check out composer. I've heard of it before, but never really took the time to take a close look. – Buzu Jun 12 '14 at 21:11
  • Doing it with Bower: http://stackoverflow.com/questions/20196707/can-i-add-a-git-repository-to-my-bower-json – ceejayoz Jun 12 '14 at 21:11

2 Answers2

1

Package managers were made for this use case.

In PHP, the main package manager is Composer, for which packages can be found on Packagist.org. Per the composer.json file in the Google API PHP client repository, its package is https://packagist.org/packages/google/apiclient.

Composer will install these libraries (along with an autoload file) in a directory called vendor, which you'd add to .gitignore so their contents don't get committed. Composer handles the installation and updates of the dependencies based on your composer.json file.

For JavaScript libraries, http://bower.io/ is frequently used (although many JS libraries are also available via Composer/Packagist).

Both tools allow arbitrary and/or private repositories to be used.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • 1
    Great, thanks for making this into an answer. It is basically the same as the comments, but I can mark it as accepted answer. As I previously said, I know of the two package manages, but never really looked at them for more than 5 minutes. I think I will take a closer look, and start using them. In the case of bower, I may stick to npm, and use bower only if the libraries are not already in npm. Also, when I need to use private projects, I will use bower. Thanks. – Buzu Jun 13 '14 at 20:09
  • Glad I could help. I didn't realize jQuery/Bootstrap/et al. were in NPM, so that's another good solution. I suspect NPM can handle arbitrary repos too. As a PHP dev, Composer will make you very happy in the long run. – ceejayoz Jun 13 '14 at 20:22
  • I've been reluctant to use composer for who knows what reason. I just haven't done it, but I definitely will now. – Buzu Jun 13 '14 at 20:57
0

My way:

  • Install all code you want to modify as "editable" (git/hb/bzr clone).
  • All other libraries are installed as packages
  • Every system gets an own linux user (user name scheme: coreapp_customer_stage)
  • Each linux user has its own virtualenv (Python)
  • the virtualenv gets automatically entered if you ssh to the account.
  • automate the setup of new development accounts.
  • do version pinning if all tests pass (pip freeze).

For your example: jquery: Do you want to modify jquery? I guess not: Don't clone it.

guettli
  • 25,042
  • 81
  • 346
  • 663
  • That works well in environments such as python, where you install packages globally, and include them from a common location, but not with environments like php, or js where dependencies are usually installed within the project's directory. It does make sense not to clone something I don't want to edit though. – Buzu Jun 12 '14 at 21:09
  • @Buzu today most python people use virtualenv. That is an isolated environment where you **don't** install packages globally. With "global" I mean "/usr/lib.." (root level). – guettli Jun 13 '14 at 07:27
  • OH, I was not aware of that. I will check it out. Thanks – Buzu Jun 13 '14 at 14:17