drno-reg
@drno-reg
см не кратко

Может ли python собрать пакет таким образом чтобы в него можно было добавить не python файлы которые лежат за пределами папки с исходниками?

У меня есть проект в котором есть пакет файлов на python и отличные от python файлы

у меня есть такая иерархия питоно-проекта

app
| - configus.yml
| - postgresql_node_exporter.py
requirements.txt

setup.py
import os
from pathlib import Path
from setuptools import find_packages, setup, Command
from typing import List, Tuple
import json

import _version


DIRECTORY = Path(__file__).absolute().parent
REQUIREMENTS = DIRECTORY.joinpath("requirements.txt")
README = DIRECTORY.joinpath("README.md")


class CleanCommand(Command):
    """Custom clean command to tidy up the project root."""
    user_options = []

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def run(self):
        os.system('rm -vrf ./build ./dist ./*.pyc ./*.tgz ./*.egg-info ./*/*.egg-info .eggs')


def read_requirements(file_name: str, exclude: Tuple) -> List[str]:
    result = []

    with open(file_name, "r") as reader:
        for line in reader:
            trimmed_line = line.strip()
            if not trimmed_line.startswith(exclude):
                result.append(trimmed_line)

    return result


requirements = read_requirements("requirements.txt", ("#", "--"))


with open(README, "r", encoding="utf-8") as readme_reader:
    long_description = readme_reader.read()

setup(
    name="postgresql_exporter",
    version=_version.get_version(),
    author="",
    author_email="",
    description="",
    long_description=long_description,
    long_description_content_type="text/markdown",
    url="",
    packages=find_packages(),
    include_package_data=True,
    install_requires=requirements,
    setup_requires=['pytest-runner'],
    tests_require=['pytest', 'setuptools_scm<=6.4.2'],
    test_suite='test',
    cmdclass={
        'clean': CleanCommand,
    },
)


MANIFEST.in
include requirements.txt
graft app/


запускаю build
python setup.py bdist_wheel bdist

в результате получаются в папке ./dist 2 файла
postgresql_exporter-1.0.0-py3-none-any.whl
postgresql_exporter-1.0.0.macosx-12-x86_64.tar.gz


потом в локальное окружение ставлю пакет

pip3 install --no-index --no-deps -f ./dist postgresql_exporter


в итоге все есть кроме requirements.txt

% ls -las venv/lib/python3.10/site-packages/app 
 __init__.py
 __pycache__
 configus.yml
 postgresql_node_exporter.py


где requirements.txt его искать и почему pip его не установил?
  • Вопрос задан
  • 110 просмотров
Пригласить эксперта
Ответы на вопрос 1
TalismanChet
@TalismanChet
Лицо зла
забросьте requirements.txt внутрь папки с исходниками.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы