1

In my package setup.py I have

setup(
    ...
    requires=['enum', 'hashlib', ...]
)

I have to edit the requires field manually if I add a dependency in my package and the thing is: I often forget to do that.

Is there an option that can automatically look for imported packages that are not part of the current package?

nowox
  • 25,978
  • 39
  • 143
  • 293
  • Why don't you load and parse the `requirements.txt`? – Laur Ivan Oct 04 '16 at 09:49
  • I am just discovering `requirements.txt`. Does `setuptool` populate this file automatically? – nowox Oct 04 '16 at 09:51
  • 1
    Not afaik. [This question](http://stackoverflow.com/questions/14399534/how-can-i-reference-requirements-txt-for-the-install-requires-kwarg-in-setuptool) has a way to load the data. – Laur Ivan Oct 04 '16 at 09:53

1 Answers1

3

This question is quite old now and I'm sure you managed to find a way around this problem, but anyway. Just to have an answer for this question: I do it the same way as suggested in the comment by just parsing the requirements.txt. Here is the code of one of my packages:

from setuptools import setup

setup(
  name="my_package",
  version="1.0.0",
  description="Just a package",

  ...

  # this will return every module listed in requirements.txt
  install_requires=[line.strip() for line in open("requirements.txt", "r").readlines()],

)

I hope this resolves the question :)

TheClockTwister
  • 819
  • 8
  • 21
  • 1
    In your case you are moving the problem somewhere else. There I still have to manually maintain the list of requirements.txt up to date... – nowox Aug 24 '20 at 21:03
  • 1
    Although there are some scanners that parse your project directory for lines starting with `import ...` and `from ...`, I have no real trust in them since they often mess up things and do the requirements.txt myself. If you are usind PyCharm or a similar IDE, modules which are not im requirements.txt are highlighted in your code. (a very handy feature if you ask me...) – TheClockTwister Aug 24 '20 at 21:34