0

I have plenty of home-developed packages on Gitlab. Many of these package have setup.py but many of them don't.

I also have projects on Gitlab that use these packages.

My duty is to map the imports in all of these projects to the corresponding package. The problem is that most of the time, the packages that don't have setup.py have a project name slightly different from the statement used in the import

Example:

  • project called: abc-def, or abc def
  • when installing: pip install company-name-abc-def
  • when importing: abc_def

Sometimes the name could be further (not only a dash or space)

Is there a way to know the import name for each project? or the project name from the import statement?

Could it be something set in the pyproject.toml? I read these files but there wasn't something obvious of this.

sinoroc
  • 18,409
  • 2
  • 39
  • 70
The Maestro
  • 659
  • 1
  • 5
  • 21
  • yea that is true. but actually I asked the question in a revered way to make it easier. I actually have the imports, and trying to map them to the projects and packages we have on Gitlab. Maybe it is better to edit the question to make it more clear – The Maestro Jul 21 '23 at 18:47
  • Does this answer your question? [Given the name of a Python package, what is the name of the module to import?](https://stackoverflow.com/questions/11453866/given-the-name-of-a-python-package-what-is-the-name-of-the-module-to-import) – mkrieger1 Jul 21 '23 at 19:01
  • You're talking about the difference between [distributions (distribution packages)](https://packaging.python.org/en/latest/glossary/#term-Distribution-Package) and [import packages](https://packaging.python.org/en/latest/glossary/#term-Import-Package). The names of the two are _completely unrelated_. There's no way to derive one from the other, unless a project decides to make them similar. Also note that distributions can include any number of import packages. – Brian61354270 Jul 21 '23 at 19:18
  • I tried the suggested solution in the second answer, but it didn't work for me :/ – The Maestro Jul 21 '23 at 19:18
  • @Brian61354270 I think you are right! apparently the only way is to use a tool like FuzzyWuzzy to get the closest project name to the imported statement :/ – The Maestro Jul 21 '23 at 19:20

1 Answers1

0

You're talking about the difference between distributions (distribution packages) and import packages. The names of the two are completely unrelated. There's no way to derive one from the other, unless a project decides to make them similar. Also note that a distribution can contain any number of import packages, which makes deriving a mapping between the two more challenging.

Broadly speaking, the distribution name is what you specify in your build system metadata (e.g. a name = "my-distribution" line in pyproject.toml) while the import package name is determined by the actual directory / file name in your package's source tree.

The distribution name is used when specifying dependencies to your build system (e.g. when invoking pip install or in your build system's dependencies table in pyproject.toml) while the import package name only appears in import statements.

Brian61354270
  • 8,690
  • 4
  • 21
  • 43