使用setup.py自定义python软件包目录布局 [英] Customizing python package directory layout with setup.py

查看:73
本文介绍了使用setup.py自定义python软件包目录布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我具有以下目录结构:

Suppose I have the following directory structure:

src/
└── python/
    └── generated/
        ├── __init__.py
        ├── a.py
        └── lib/
            ├── __init__.py
            └── b.py

我的 setup.py 需要什么样子才能创建具有如下目录布局的dist:

What does my setup.py need to look like in order to create a dist with a directory layout like:

src/
└── python/
    ├── __init__.py
    ├── a.py
    └── lib/
        ├── __init__.py
        └── b.py

目标是简单地消除 generate 文件夹.我用 package_dir 尝试了无尽的变化,除了原始目录结构之外,什么也无法产生.

The goal is to simply eliminate the generated folder. I've tried endless variations with package_dir and can't get anything produced other than the original directory structure.

推荐答案

您的 setup.py 应该放在您的 src 目录中,并且应如下所示:

Your setup.py should be placed in your src directory and should look like this:

#!/usr/bin/env python3

import setuptools

setuptools.setup(
    name='Thing',
    version='1.2.3',
    packages=[
        'python',
        'python.lib',
    ],
    package_dir={
        'python': 'python/generated',
    },
)

请注意 package_dir 设置.它指示 setuptools 从目录 python/generated 中获取 python 包的代码.在内置发行版中,您将找到正确的目录结构.

Note the package_dir setting. It instructs setuptools to get the code for the python package from the directory python/generated. In the built distributions you will then find the right directory structure.

这篇关于使用setup.py自定义python软件包目录布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆