Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is my custom Django app code?

Tags:

python

pip

django

I built and installed my custom Django app following the official tutorial https://docs.djangoproject.com/en/1.8/intro/reusable-apps/

The installation seems successful.

$ pip install --user ../horizon2fa-0.1.tar.gz

Processing /opt/stack/horizon2fa-0.1.tar.gz
  Requirement already satisfied (use --upgrade to upgrade): horizon2fa==0.1 from file:///opt/stack/horizon2fa-0.1.tar.gz in /opt/stack/.local/lib/python2.7/site-packages
Building wheels for collected packages: horizon2fa
  Running setup.py bdist_wheel for horizon2fa ... done
  Stored in directory: /opt/stack/.cache/pip/wheels/a6/4a/f0/4533f85d90b8f1a274a35d3865a2e0b15ff85f0570a0708679
Successfully built horizon2fa

Where can I find the source code of all my custom classes and methods?

I tried to search it through my system but didn't find them. Is the code compiled?

$ sudo find / -name "*horizon2fa*"

/root/.cache/pip/wheels/a0/9d/24/d8070ea2a01759ce7ebc03c34393db8a5aceccd380e60481c5/horizon2fa-0.1-cp27-none-any.whl
/opt/stack/.cache/pip/wheels/a6/4a/f0/4533f85d90b8f1a274a35d3865a2e0b15ff85f0570a0708679/horizon2fa-0.1-cp27-none-any.whl
/opt/stack/.local/lib/python2.7/site-packages/horizon2fa-0.1.dist-info
/opt/stack/horizon2fa-0.1.tar.gz

The module seems was not installed correctly.

python -c "import horizon2fa; print(horizon2fa.__path__)"

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named horizon2fa

Below, you can see my app directory structure.

trex@trex:~/Development/openstack2FA/horizon2fa$ tree
.
├── admin.py
├── dist
│   └── horizon2fa-0.1.tar.gz
├── enabled
│   └── _31000_myplugin.py
├── horizon2fa.egg-info
│   ├── dependency_links.txt
│   ├── PKG-INFO
│   ├── SOURCES.txt
│   └── top_level.txt
├── __init__.py
├── LICENSE
├── main.py
├── MANIFEST.in
├── migrations
│   ├── 0001_initial.py
│   └── __init__.py
├── models.py
├── panel.py
├── README.rst
├── setup.py
├── templates
│   ├── base.html
│   └── horizon2fa
│       ├── created.html
│       ├── index.html
│       ├── login.html
│       ├── new.html
│       └── view.html
├── tests.py
├── urls.py
├── user.py
└── views.py

And my setup.py script.

import os
from setuptools import find_packages, setup

with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as readme:
    README = readme.read()

# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))

setup(
    name='horizon2fa',
    version='0.1',
    packages=find_packages(),
    include_package_data=True,
    license='BSD License',  # example license
    description='A Django app.',
    long_description=README,
    url='http://www.trex.com/',
    author='trex',
    author_email='[email protected]',
    classifiers=[
        'Environment :: Web Environment',
        'Framework :: Django',
        'Framework :: Django :: X.Y',  # replace "X.Y" as appropriate
        'Intended Audience :: Developers',
        'License :: OSI Approved :: BSD License',  # example license
        'Operating System :: OS Independent',
        'Programming Language :: Python',
        # Replace these appropriately if you are stuck on Python 2.
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Topic :: Internet :: WWW/HTTP',
        'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
    ],
)
like image 779
srgbnd Avatar asked Feb 25 '16 08:02

srgbnd


People also ask

Where is installed apps in Django?

Django projects go in /opt/project/ . PYTHONPATH includes /opt/project . Our settings.py uses apps.

Where can I find app name in Django?

You can get application name from model: Book. _meta. app_label .


1 Answers

Because you used --user, the package is installed for current user (the one who issued pip install --user) and not in system site-packages directory. See the docs for site.USER_BASE. So, you should look in ~/.local/ as said in the docs, probably: /home/%user%/.local/lib/python%version%/site-packages/.

Also, considering, that the package got installed somewhere on PYTHONPATH, you could try to find it by running the following command in your shell:

python -c "import %module%; print(%module%.__path__)"

i.e.

python -c "import horizon2fa; print(horizon2fa.__path__)"

Regarding your question update:

You should create a top level directory, e.g. django-horizon2fa and put setup.py, MANIFEST.in, README.RST, LICENSE.txt and your horizon2fa package directory inside it. So that installation related files are in new dir and all files related to your module are inside a dir in that dir. Current directory setup doesn't allow find_packages() do it's job properly.

django-horizon2fa
│
├── LICENSE
├── MANIFEST.in
├── README.rst
├── setup.py
└── horizon2fa
    ├── __init__.py
    ├── admin.py
    ├── tests.py
    ├── urls.py
    ├── user.py
    ├── views.py
    ├── enabled
    │   └── _31000_myplugin.py
    ├── main.py
    ├── migrations
    │   ├── 0001_initial.py
    │   └── __init__.py
    ├── models.py
    ├── panel.py
    ├── tests.py
    ├── urls.py
    ├── user.py
    ├──  views.py
    └── templates
        ├── base.html
        └── horizon2fa
            ├── created.html
            ├── index.html
            ├── login.html
            ├── new.html
            └── view.html

P.S. Using solely MANIFEST.in, may sometimes lead to problems with inclusion of package data in distribution, e.g. templates. In that case consider providing files from MANIFEST.in in package_data dictionary to setup(), see details in the docs.

like image 155
Nikita Avatar answered Oct 23 '22 23:10

Nikita