Django 1.8: How do I use my first 3rd Party Fork with my current project?
Asked Answered
F

1

6

I'm still very new to development...

I would like to simplify django-friendship and add some different functionality. I've forked it on GitHub. I'm not sure what to do next.

Where should the local copy of my django-friendship repo go? Should I integrate it into my current Django project as an app, or set it up as a separate project? In which case, how do I set my main Django project to use it as an app while developing it?

Any guidance or other resources I can learn from here would be much appreciated.

Thanks!

Flattish answered 10/8, 2015 at 10:14 Comment(3)
How are the dependencies for your project created? Are you running in a virtualenv? You could add that specific GitHub repo to your requirements.txt and install the forked version rather than the original (see e.g. https://mcmap.net/q/21611/-how-to-state-in-requirements-txt-a-direct-github-source/3001761), or add the fork as a submodule.Ampoule
I'm not using virtualenv - I know I should, but I'm only working on the one project and it's just me. If I work with anyone else I'll move to a virtual env in vagrant. Submodule sounds good, but I'm using BitBucket w/SourceTree for my project, and the django-friendship fork is on github. Can I still do that?Flattish
As long as your project is still using git (BitBucket also supports hg, in which case I doubt it's even possible) I think that should be fine. Give it a go and see what happens!Ampoule
R
13

There's a few options open to you:

Install directly from Github

Add the following (replace with your forked repository) to a requirements.txt file or install directly with pip install:

git+git://github.com/revsys/django-friendship.git#egg=django-friendship

This will download a copy of your repository into your python environment. If you make changes to the repository however, you'll need to reinstall this every time you push changes.

Download a local copy and install

This method is much cleaner:

// Clone the repository locally
git clone https://github.com/revsys/django-friendship.git

// cd into the project folder
cd django-friendship

// Install the package into your python environment
// The `-e` tells pip this package is editable
pip install -e .

The project is now linked directly. You can now work on the forked repository locally and the changes will be available to your app straight away.

In your requirements.txt file you'll want to add the following for deployment later:

git+git://github.com/revsys/django-friendship.git#egg=django-friendship

Take a look at the docs for pip for more information on dependency management.

Revolutionize answered 10/8, 2015 at 10:41 Comment(1)
As the project has a setup.py you could also use python setup.py develop in the second example (i.e. replacing pip install -e).Ampoule

© 2022 - 2024 — McMap. All rights reserved.