pip install ignoring child directories on install with django project - python

I am writing a Django application and am very new to the framework and python. I am following the tutorial here: https://docs.djangoproject.com/en/1.9/intro/reusable-apps/ and am currently at packaging and installing the application created from this tutorial: https://docs.djangoproject.com/en/1.9/intro/tutorial01/
This is my first Django application and my first time using Python.
Currently my setup.py file looks like this:
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= 'django-polls',
version='0.1',
packages=find_packages(),
include_package_date=True,
license='BSD License', #example license
description = 'A simple Django app to conduct Web-based polls.',
long_description = README,
url='https://www.example.com',
author='Your Name',
author_email='yourname#example.com',
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Django :: 1.9.6', # 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 :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
)
my MANIFEST.in file looks like this:
include LICENSE
include README.rst
recursive-include polls/static *
recursive-include polls/templates *
recursive-include docs *
my file directory is as follows:
|polls
|__init.py__
|admin.py
|apps.py
|models.py
|tests.py
|urls.py
|views.py
|__pychache__
|# pycachestuff
|migrations
|# migrations stuff
|static
|polls
|images
|background.gif
|style.css
|templates
|polls
|detail.html
|index.html
|results.html
|docs
|
When I run the setup, the produced .zip works great, all the directories are included. However, when I run
pip install C:\Path\To\dist\django-polls-0.1.zip -t C:\Path\To\Package
It only installs what is immediately under the primary polls directory and migrations. It ignores the subdirectories static and templates. It also ignores docs, but the folder is empty and the tutorial has led me to believe empty directories are ignored.
Does anyone know how I can fix this? A few answers I have seen suggest using package_data or data_files, but I'm very new to python and I can't seem to get the syntax right (or those answers are wrong).
Thank you for your time

Related

How to add submodules in a Python Library?

I have created a python library whose structure looks like this.
|/library_name
| |__init__.py
| |/subpackage
| | |__init__.py
| | |
|setup.py
|setup.cfg
|LICENSE
Now when i published in pypi, I couldn't see the inner subpackages installed along with it. What should I do? What should be in outer __init__.py. Assume inner __init__.py has classes which I have written. Somebody please help how to add subpackages to the python library.
Here's the setup.py format
setup(
name = 'package',
packages = ['package'],
version = '1.0.1',
license='GNU General Public Version 3',
description = 'Package is the open source Python Library for solving various AI needs',
long_description = long_description,
long_description_content_type = "text/markdown",
author = ['Vigneshwar K R'],
author_email = 'mymail#gmail.com',
url = 'https://github.com/ToastCoder/repo',
download_url = 'https://github.com/ToastCoder/repo/archive/master.zip',
keywords = ['ARTIFICIAL INTELLIGENCE', 'TENSORFLOW'],
install_requires=['tensorflow'],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'Intended Audience :: Education',
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9'
],
)
Could you share said setup.py & __init__.py codes please ?
I see two ways to deal with this :
make the content from lib/submodule available from the top level : in lib/__init__.py add from submodule import *, then add every imported name in __all__. As far as i know, this is bad practice everywhere BUT inside of __init__.pys
add the submodule directory to setup.py's packages parameter : packages=["lib", "lib.submodule"]
edit: as i expected, submodule is missing from the packages parameter, so it is not considered needed.
the find_packages option commented about has the same effect as adding lib.submodule to the packages list, it is mainly used in large libraries where adding every single module manually would be a pain.

Something is breaking my package deployment

I use setuptools and a requirements file to satisfy dependencies for my open source module.
Example setup.py:
from setuptools import setup, find_packages
from pip.req import parse_requirements
# parse_requirements() returns generator of
# pip.req.InstallRequirement objects
install_reqs = parse_requirements('requirements.txt',
session=False)
# reqs is a list of requirement
reqs = [str(ir.req) for ir in install_reqs]
setup(
name='python-symphony',
version='0.1.5',
description='python module for symphony chat',
author='Matt Joyce',
author_email='matt#joyce.nyc',
url='https://github.com/symphonyoss/python-symphony',
license='Apache 2.0',
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
],
keywords='symphony chat api python module',
# install dependencies from requirements.txt
install_requires=reqs,
packages=find_packages(),
# bin files / python standalone executable scripts
include_package_data=True,
zip_safe=False,
)
This has worked for some time. However, recently my builds have been breaking. I believe there is a bug in setuptools, possibly related to pygments.
There are two (thus far) identified failure states:
It results in the package being installed as a binary wheel (despite no such package existing in PyPI).
It results in the package installing in site-packages seemingly correctly, but none of the subclasses can be called from the module.
I can get it to work manually by removing the package from site packages and running:
pip install --isolated --no-cache-dir python-symphony
but this results in pygments getting messed up somehow. (I noticed this when trying to debug the module in bpython).
Trying to run this stuff from a venv (wrapped with a Bash script) tends to still fail.
Is anyone aware of a new / recent issue in setuptools that could be responsible for this sort of breakage?
setuptools version: setuptools-33.1.1.dist-info and newer
Ref:
github: https://github.com/symphonyoss/python-symphony
pypi: https://pypi.python.org/pypi/python-symphony/

My setup.py is not working -- install fails

So, I've been trying this whole week to write a proper setup.py, and ended up with something like this:
#!/usr/bin/env python
from setuptools import setup
from codecs import open
from os import path
# Get the version number
from sql_tools2 import __version__
__author__ = 'Pandu POLUAN (pepoluan)'
__copyright__ = '(C) 2015, Pandu POLUAN'
__maintainer__ = 'pepoluan'
__email__ = 'pepoluan#gmail.com'
__status__ = 'Development'
__credits__ = ['pepoluan']
here = path.abspath(path.dirname(__file__))
# Get the long description from the README file
with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
long_description = f.read()
setup(
name='sql_tools2',
version=__version__,
description='Tools to manipulate and analyze SQL Queries before execution.',
long_description=long_description,
url='https://bitbucket.org/pepoluan/sqltools2',
author='Pandu POLUAN',
author_email='pepoluan#gmail.com',
license='MPL 2.0',
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'Programming Language :: SQL',
'Topic :: Software Development :: Quality Assurance',
'Topic :: Database',
'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7'
],
keywords='sql subquery',
packages=['sql_tools2'],
install_requires=['sqlparse'],
extras_require={
'dev': ['pytest'],
'test': ['pytest'],
},
zip_safe=False
)
Now if I execute setup.py install, I see the module being installed.
However, another Python program (same virtualenv) cannot import:
>>> import sql_tools2
ImportError: no module named sql_tools2
I am using PyCharm as the IDE. Interestingly, if I type import and wait for auto-completion, PyCharm indeed offered sql_tools2 as one of the modules it recognized.
Where did I go wrong?

After installing app TemplateDoesNotExist error

In virtualenv defaulting python3:
First I removed my app myapp from project. And I created a new folder called django-myapp next main django project directory.
Inside django-myapp I copied the myapp to this folder and created all needed files for making python package.
And I ran python setup.py sdist. Until now everything is ok.
My template and css files are included in django-myapp-0.1.tar.gz file. But when I installed this app with pip install django-myapp/dist/django-myapp-0.1.tar.gz, the app is installed. But when I run server and go to main page TemplateDoesNotExist error happens.
My admin page works, and then I checked /env/alis5/lib/python3.4/site-packages/myapp/ there is no templates directory in it.
What is the problem. I followed django tutorial: https://docs.djangoproject.com/en/1.7/intro/reusable-apps/
here is my MANIFEST.in:
include LICENSE
include README.rst
recursive-include polls/static *
recursive-include polls/templates *
recursive-include docs *
and here is also my setup.py:
setup(
name='django-polls',
version='0.1',
packages=['polls'],
include_package_date=True,
license='BSD License', # example license
description='A simple Django app to conduct Web-based polls.',
long_description=README,
url='http://www.example.com/',
author='Maksat Yalkabov',
author_email='yalkabovmaksat#gmail.com',
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
'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 :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
)
You said you followed the tutorial, but I have to ask, did you create the manifest file? You didn't mention it, and only Python is included by default.
Create myapp/MANIFEST.in and inside it add recursive-include myapp/templates *
That should ensure that python setup.py sdist creates the package with your templates directory recursively.
edit
Ok, so I've just tested this on a project of mine.
- proj
- setup.py
- MANIFEST.in
- injurytracker
- init.py
- templates
- etc
In setup.py I've got packages=['injurytracker'], to include my package, and in MANIFEST.in I've got recursive-include injurytracker/templates * And when I check the dist.gz I've got my templates included.
As you've mentioned include_package_data, setting that either way, doesn't effect the template directory inclusion.
In your setup.py also import find_packages from setuptools, and in your setup method add somthing like this;
packages=find_packages(exclude=["project", "project.*"]),
For me that picks out all my python modules & files that I expect, migrations included.
Do you have this in your settings.py?
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader', # <--
)

Pip django app installation

I am currently working on an internal ad manager as a django app! It is called "glinks" which basically means graphical link. Kinda makes sense I guess. I wanted to make it available through pip so I went through all the steps and it can now be found here:
https://pypi.python.org/pypi/django-glinks/
For some reason when I install it straight from the tar file on the page i get the proper folder/file structure.
django-glinks
*files needed
glinks
*files needed
templatetags
*files needed
BUT! When I used pip install django-glinks i dont get the templatetags directory or files with it! so instead i get this:
django-glinks
*files needed
glinks
*files needed
I am pretty new to this so it would be great if someone could help me out. Here is my setup.py file:
from distutils.core import setup
import os
README = open(os.path.join(os.path.dirname(__file__), 'README.txt')).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='django-glinks',
version='0.1.4',
author='Shawn Simon',
author_email='shawn.simon.developer#gmail.com',
packages=['glinks'],
url='http://pypi.python.org/pypi/django-glinks/',
license='LICENSE.txt',
description='Interal add manager for django sites.',
long_description=open('README.txt').read(),
install_requires=[
"Django >= 1.6.0",
],
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License', # example license
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
)
and here is my manafest.in :
include *.txt
recursive-include docs *.txt
recursive-include docs *.py
recursive-include docs *.rst
recursive-include docs Makefile
recursive-include pypiuploader *.py
recursive-include tests *.py
include glinks/templatetags/*.py
include *.py
Correcting setup - completing packages var
Good you show the setup.py. It is missing the reference to the glingks.templatetags package.
If you add this package into packages as shown below, it will work. For me, I was after this modification ïmporting not only glinks, but also glinks.templatetags.
setup(
name='django-glinks',
version='0.1.4',
author='Shawn Simon',
author_email='shawn.simon.developer#gmail.com',
packages=['glinks', "glinks.templatetags"],
url='http://pypi.python.org/pypi/django-glinks/',
license='LICENSE.txt',
description='Interal add manager for django sites.',
long_description=open('README.txt').read(),
install_requires=[
"Django >= 1.6.0",
],
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License', # example license
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
)

Categories

Resources