gowerc
gowerc

Reputation: 1099

How does pip determine a module's dependencies?

This is likely an issue with my understanding of how python modules are packaged but I am confused as to how pip determines what a modules dependencies are when it installs a module. It appears that different build tools have their own way of specifying dependencies for example in poetry it is:

[tool.poetry.dependencies]
requests = "^2.13.0"

Where as under setuptools it is:

[project]
dependencies = [
    "docutils",
    "BazSpam == 1.1",
]

So yer I'm confused as to how pip can determine what are a module's dependencies if each build system has its own unique specification within the pyproject.toml file. I'm guess theres some standard format in the built tar.gz file but if thats the case then how does pip know what to install if its installing from source like from a GitHub repo ?

Upvotes: 1

Views: 99

Answers (1)

atline
atline

Reputation: 31584

In fact, the setup.py is the configure for pip to determine the dependency.

  • For local packages, you should have setup.py in it.
  • For github, the address also require a setup.py in that github repo.
  • For poetry, although we explicitly define all dependency in pyproject.toml, the poetry will automatically generate a setup.py to the tar.gz after you input poetry build.

So, for any high level build tool, if we use pip to install the built out, the pip will all use install_requires settings in setup.py, no matter the setup.py generated explicitly or implicitly.

Update:

It looks the new pip version already could recognize the pyproject.toml, so in fact the setup.py auto generated is for low version pip compatibility use I think.

Upvotes: 1

Related Questions