Struggling with git submodule and django - django

I have a django project A which contains an app App1. I also have a django project B in which I'd like to have the same App1. Then, when I edit App1 in my project A, I'd like to update App1 and be able to pull changes in project B.
A and B are under separate git repository.
What should be my workflow?
Should I create a submodule and a new git repo for the App1 I want to duplicate? I read a lot about people struggling with submodules and tricking git...
I don't want to break anything...
Cheers

Okay, my question was pretty stupid. I created a separate git repo for App1. I create a new directory on my computer where I copy/paste my App1 then sync it to git. Then, for each of my django project, I created git submodule and here it is!

Related

How to ship migrations in a Django reusable app?

I can create migrations for my reusable application from a minimal test project, but that would install the migrations in -
/usr/local/lib/python3.5/dist-packages/django_app-0.1-py3.5.egg/django_app/migrations/0001_initial.py
I wanna ship the migrations with the reusable app, Do I just copy the file or is there any other method?
A couple of options:
1) Add the test project to your reusable app's repo for the purposes of creating migrations and perhaps as a usage example, as django-allauth does.
2) Keep your test project as a separate repo, and symlink the reusable app repo into the test project's directory as a dependency. Create migrations using the test project and the migration files will be created in your reusable app's repo directory, ready to be committed.
Keen to hear what other people are doing!

Git - How to commit a local repository to a subfolder of another local repository?

I have a Django project that I've started some time ago and I was hosting it at bitbucket. Now I need to host it at openshift, and the way to do that is that they provide you with a git repository and every time you push they deploy automatically. The problem is that the repository comes with several top-level folder for configuration and setup, and the effective django project must be inside a subfolder called wsig/openshift.
My question is, how can I commit my changes from my local django repository to the wsig/openshift subfolder of my local openshift repository? Because I intend to continue to develop on the bitbucket/local repository
You are probably looking for submodules. From the docs:
Submodules allow foreign repositories to be embedded within a
dedicated subdirectory of the source tree, always pointed at a
particular commit.
So you would do and would have the bitbucket repository as a seperate repository embedded in a subfolder of the openshift repository by running
git submodule add path_to_bitbucket folder/in/openshift
in the openshift repository.
You will have to run an occaisonal git submodule update to keep openshift up to date but you probably already expected extra work of that sort.
I had the exact same problem too! Is highly annoying but I took another road:
Why don't you create a Python 2.7 project from scratch? Current Django structure is honestly annoying. The way I did was:
Create an openshift project which was in that annoying structure.
Copy, preserve (in my local FS, not in Openshift) a copy of settings.py and wsgi.py.
Discard that project, and start a bare Python 2.7 project.
Check it out to my local FS, create a Django project in my local fs.
Replace the contents of wsgi and settings accordingly (adapting any possible misplaced paths - it's easier than it looks).
Commit/push (this new structure).
You will do differently in point 4: you will checkout that remote branch (bitbucket) as well, merge it on the openshift branch, change accordingly those files in point 5, and push the openshift branch.
There you have a brand-new project, matching your structure (perhaps you want to configure both remote branches in your environment: openshift and bitbucket).
That's the way I did and honestly I have nothing to regret.
Offtopic, but perhaps would be useful since you're using Django: This is specially important if you want to -also- use (gunicorn|uwsgi)+nginx (with a custom cart. which does not provide apache but nginx, and python), and so cannot use the default Django cart.

Best way to (git) clone app into Django project directory

I want to clone (via GIT) an external app into my project directory. Unfortunately there is one folder on top of the project that makes Django not see the cloned folder as an app.
For example see allauth. After cloning the app itself is in allauth/allauth resp. from the project view my_project/allauth/allauth. If just adding allauth to INSTALLED_APPS, the app is not found by the server. I also tried adding allauth.allauth, which also doesn't work.
What is the recommended way to clone an external app into a Django project folder (and manage it as submodule for example)?
you can clone it into a vendor/ directory and then symlink it's app folder into your project, but I'd recommend against that.
A better way would be to use a virtual environment, and install the application as an editable package.
$ pip install -e git+https://github.com.au/person/project#v0.1.1#egg=project
This will clone the repo into the src/ folder in your virualenv and set up the paths correctly such that it can be loaded normally with django.

Same Django project different GIT repositories

Which is the best way to have two different repositories on the same Django project?
I started developing a project months ago and I have the whole folder in the repository. I want to reuse some apps in the project and I would like to create a different repository for them since they will be spin-offs project. But I want to keep it updated.
Which is the best workflow, methodology, etc... to achieve this? Or is it a bad approuch?
Thanks!
Xavi
You can wrap each app as a python package, which has its own GIT repo. And save all your packages in some private (or public?) python packages repository (like Gemfury).
Then, in your projects, just use the app as you install django itself.. pip install myapp
This way the apps a reusable and decoupled from any project.
(This works very well for myself.. perhaps there is a better way)
You can use submodule,
$git submodule add git://github.com/yourusername/project2.git project2
$cat .gitmodules
.gitmodules output:
[submodule "project2"]
path = project2
url = git://github.com/yourusername/project2.git
If you want to Clone some git project like submodule,
git clone git://github.com/yourusername/project2.git
cd project2
git submodule init

Cloning a django project from hg using buildout and using it for development

I have a django project sitting in a bitbucket repository. Is it possible to automate using buildout, the following process:
1. Install django
2. clone the django project from hg repository
3. install the dependency modules of the django project
Update: I have achieved what I wanted to, with the help of mr.developer extension as suggested by Ross.
While doing that I had another question popping up. Which is the best place to specify the dependencies - in the buildout.cfg or in the setup.py of the 'develop' modules? For now I have duplicated the specification.
Generally, you make your checkout the buildout itself, so you'd place buildout.cfg and bootstrap.py in your project root. That way when someone checks out/clones your project, they just do the bootstrap/buildout dannce and they're up and running.
If you have multiple checkouts, then look into mr.developer.