Is there an easier way to package with Python?

I tried packing the django application today. This is a big kid, and with the installation file I have to manually write all the packages and subpackages to the "package" parameter. Then I have to find a way to copy fixtures, htmls / css / image files, documentation, etc.

This is a terrible way to work. We are computer scientists, we automate, it does not make sense to do this.

So what when I change the structure of my application? I need to rewrite setup.py.

Is there a better way? Some tool to automate this? I can’t believe the language than the value of development time, for example, Python makes such complex packaging.

I want to ultimately be able to install the application using a simple pip installation. I know how to build, but it is not much simpler and not friendly.

+3
source share
4 answers

At least if you use setuptools(alternative to stdlib distutils), you get an awesome function called find_packages(), which, when launched from the package root, returns a list of package names in dotted notation suitable for the parameter packages.

Here is an example:

# setup.py

from setuptools import find_packages, setup

setup(
    #...
    packages=find_packages(exclude='tests'),
    #...
)

ps Packaging settles in every language and in every system. It sucks no matter how you cut it.

+5
source

. : yoinked Django setup.py, , ( , ):

import os
from distutils.command.install import INSTALL_SCHEMES

def fullsplit(path, result=None):
    """
    Split a pathname into components (the opposite of os.path.join) in a
    platform-neutral way.
    """
    if result is None:
        result = []
    head, tail = os.path.split(path)
    if head == '':
        return [tail] + result
    if head == path:
        return result
    return fullsplit(head, [tail] + result)

# Tell distutils to put the data_files in platform-specific installation
# locations. See here for an explanation:
# http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb
for scheme in INSTALL_SCHEMES.values():
    scheme['data'] = scheme['purelib']

# Compile the list of packages available, because distutils doesn't have
# an easy way to do this.
packages, data_files = [], []
root_dir = os.path.dirname(__file__)
if root_dir != '':
    os.chdir(root_dir)
myapp_dir = 'myapp'

for dirpath, dirnames, filenames in os.walk(myapp_dir):
    # Ignore dirnames that start with '.'
    for i, dirname in enumerate(dirnames):
        if dirname.startswith('.'): del dirnames[i]
    if '__init__.py' in filenames:
        packages.append('.'.join(fullsplit(dirpath)))
    elif filenames:
        data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]])
+1
0

Django.

:

-1
source

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


All Articles