0

Basically i have the project below :

my_pkg
 __init__.py
 \module1
    __init__.py
    scrip1.py
    script2.py
    requirement.txt
 \module2
    _script1.py
    _script2.py
    requirement.txt
 setup.py
 LICENSE
 README.md

I am trying to include the requirement.txt files with the packaging of my library my_pkg

The requirement.txt in module1 folder contains: request

the requirement.txt in module2 folder contains: pdfkit

This is my setup.py file :

import setuptools
from setuptools import setup

with open("README.md", "r") as fh:
    long_description = fh.read()

setup(
    name="im_pkg",
    version="0.0.1",
    author="John Doe",
    description="Shared Python library",
    long_description=long_description,
    license="MIT",
    long_description_content_type="text/markdown",
    packages=setuptools.find_packages(),
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ],
    install_requires=["requests","pdfkit"],
    python_requires='>=3.6'
)

I would like to read my requirement.txt of my subfolder dynamically without having to put it manually in the install_requires= section

FazBen
  • 1
  • The answer is to throw the `requirements.txt` files away. For a library, they serve no purpose. The `install_requires` field in your `setup.py` is the source of truth for project dependencies, and you got that covered already. – Arne Jul 04 '20 at 19:52
  • To be fair, there do exist packaging tools that can bundle `requirements.txt`s and essentially build a `setup.py` or `setup.cfg` for you, most popularly [`pbr`](https://pypi.org/project/pbr/). But they usually expect only a single requirement file, and as I said above, are a little misguided in their approach. See also [this post](https://caremad.io/posts/2013/07/setup-vs-requirement/) from one of the main authors of the python packaging toolchain for some further info. – Arne Jul 05 '20 at 08:12

1 Answers1

0

You should only list primary dependencies alongwith their versions so that it doesn't break. Don't list stuff that was used for developing such as yapf, black, pytest, flake8 etc. Keep the requirements as minimal as possible.

However, if you don't want to that, this is the answer you are looking for.

Example:

    install_requires=[
        "graphene==2.1.8",
        "graphene-django==2.5.0",
        "graphql-core==2.2.1",
        "psycopg2==2.8.3"
    ],
frozenOne
  • 558
  • 2
  • 8