Packaging a django application with external dependencies

I was thinking of packing one of my django projects in a reusable package.

How to pack is given pretty well at https://docs.djangoproject.com/en/dev/intro/reusable-apps/ and, of course, on many other sites.

All that is offered is to include in the application application INSTALLED_APPS the list of available files in the django project settings.py project.

Cool, but that I have several (third-party) dependencies with the project. Should I list all these packages in the INSTALLED_APPS list in the documentation?

I feel that there should be a better way that you simply enable one application, and all its dependencies are automatically added to the INSTALLED_APPS application.

Now let me give an example of clarity: (you can read here)

  • project A: django reuse application
  • project B and C: are third-party django applications used in project A (e.g. django toolbar, reverse, etc.)
  • Project D: this is your django project and you want to include my project A in your application.

Now:

  • You can add 'A' to your INSTALLED_APPS
  • But you also need to add "B" and "C" as they depend on "A"

My question is: Is there a way in which adding "A" to your project includes "B" and "C" automatically?

As the saying goes, I know how to add custom settings and provide reasonable defaults. It’s just that I can’t think about the problem of dependent applications (maybe because it will be the next day)

+6
source share
2 answers

I attached it using the install_requires parameter in setup.py

We also have the tests_require option and the tests_require directive, which goes to setuptools.setup() if you are using the distribution.

  • install_requires and extras_require are both a list of requirements (packages).
  • extras_require is a dictionary with 'testing', 'doc', etc., are keys and a list of requirements as a list.

They are added to distribute in version 0.5a4

Relevant links:

+1
source
  • Project A: (with internal application: c and external applications: b ):

     # Directory Tree: A β”œβ”€β”€ setup.py β”œβ”€β”€ a β”‚  β”œβ”€β”€ apps # internal dependencies β”‚  β”‚ β”œβ”€β”€ c β”‚ β”‚ β”‚ β”œβ”€β”€ models.py β”‚ β”‚ β”‚ β”œβ”€β”€ ... β”‚ β”‚ β”‚ β”œβ”€β”€ app.py β”‚ β”‚ β”‚ └── __init__.py β”‚  β”‚ └── __init__.py β”‚  β”œβ”€β”€ core # core library β”‚ β”‚ β”œβ”€β”€ __init__.py β”‚ β”‚ └── whatever.py β”‚ β”œβ”€β”€ ... β”‚  └── __init__.py # β”œβ”€β”€ ... └── requirements.pip 
     # File: A/requirements.pip # external dependencies: b b>=0.1,<0.2 
     # File: A/setup.py setup( name="a", install_requires=["B",], # External Dependency ... ) 
     # File: A/a/__init__.py # to be added into INSTALLED_APPS later CORE_APPS = [ "B", # external apps "a.apps.C", # internal apps ] def get_core_apps(): return CORE_APPS 

    Project A can be designed as a structure / library without implementation. Thus, it does not have wsgi.py , manage.py , etc. But Project A can provide an example project (sandbox or demo project).

  • Project D (Django Project): (with attachment: a )

     # File: D/requirements.pip a>=0.1<0.2 
     # File: D/d/settings.py import a INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', # ... ] + a.get_core_apps() 

    Project D is an implementation of project A. Thus, it can contain settings.py , wsgi.py , etc.

+1
source

Source: https://habr.com/ru/post/953952/


All Articles