[Fixed]-Packaging a django app with external dependencies

2πŸ‘

βœ…

I nailed it with install_requires option in setup.py

We also have tests_require option and an extras_require directive which all goes to setuptools.setup() if you are using distribute.

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

These are added into distribute in version 0.5a4

Relevant links:

  1. All
    options
  2. extras_require

2πŸ‘

  1. Project A: (with internal app: c and external apps: 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 may be designed as a framework/library without implementation. Thus it does not have wsgi.py, manage.py, etc…. But Project A could provide an example project (sandbox or demo project).

  2. Project D (Django Project): (with app: 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 may contains settings.py, wsgi.py, etc….

πŸ‘€Yeo

Leave a comment