Как упаковать несколько функций в один пакет Python и загрузить его в PyPI - PullRequest
0 голосов
/ 26 сентября 2018

Я создал пакет Python, theanwer.Вот это на PyPI и GitHub .Он имеет только одну функцию, theanswer().После установки:

import theanswer
theanswer.theanswer()

возвращает 42, как и ожидалось.

Структура каталогов:

theanwer/
    theanswer/
        __init__.py
    setup.py

__init__.py содержит:

def theanswer():
    return 42

if __name__ == "__main__":
    theanswer()

setup.py содержит:

setup(name='theanswer',
      version='0.1',
      description='answer to the ultimate question',
      url='https://github.com/zabop/PyPIattempt',
      author='Pal Szabo',
      author_email='szabopal96@gmail.com',
      license='MIT',
      packages=['theanswer'],
      zip_safe=False)

Я следовал инструкциям здесь и здесь , чтобы сделать это.

Теперь, еслиЯ хочу иметь этот код в пакете theanswer:

def returnthis(this)
    return this

, и я хочу использовать его как:

theanswer.returnthis(this)

, возвращая this.Как я могу добиться этого?Как должен выглядеть файл setup.py и какую структуру каталогов мне нужно использовать (чтобы иметь возможность загрузить его в PyPI)?


Моя идея для дерева каталогов:

theanwer/
    theanswer/
        __init__.py # containing the function theanswer
    returnthis/
        __init__.py # containing the function returnthis

и в файле setup.py пакеты должны быть packages=['theanswer','returnthis'].

Это способ сделать это?

...