Story

Do any languages specify package requirements in import / include statements?

foobarbecue Monday, January 20, 2025

When coding small programs in python, js, java, C++ it often feels to me that the dependency requirements list in pyproject.toml, requirements.json, maven.xml, CMakeLists.txt, contains information that is redundant to the import or include statements at the top of each file.

It seems to me that a reasonable design decision, especially for a scripting language like python, would be to allow specification of versions in the import statement (as pipreqs does) and then have a standard installation process download and install requirements based on those versioned import statements.

I realize there would be downsides to this idea. For example, you have to figure out what happens if different versions of a requrement are specified in different files of the same package (in a sense, the concept of "package" starts to weaken or break down in a case like that). But in some cases, e.g. a single-file python script, it seems like it would be great.

So, are there any languages whose standard installer / dependency resolvers download dependencies based on the import or include statements?

Has anyone hacked or extended python / setuptools to work this way?

3 9
Read on Hacker News Comments 9