Pebaz / nimporter

Compile Nim Extensions for Python On Import!
MIT License
824 stars 33 forks source link

When srcDir = "src", package name should not be prefixed by "src." #29

Closed phdye closed 4 years ago

phdye commented 4 years ago

When the .nimble specifies a srcDir, the package name should not include the directory name.

Pebaz commented 4 years ago

Unfortunately, this is expected behavior for Nimporter.

What is happening is that the auto-discovery mechanism of Nimporter finds that the src dir contains a Nim file and does not contain a Nimble file which means it will treat it as an extension Module rather than an extension Library.

Extension modules are single Nim files. Extension libraries are folders that contain both a Nim file + Nimble file of the same name as the folder.

In essence, a separate src dir is not supported by Nimporter.

To achieve the same effect, place a single Nim file adjacent to the Nimble file and this will cause Nimporter to use the Nimble file and honor the srcDir setting.

To reduce the complexity of bundling Nim code along with Python code in a cross-platform and simple way, some concessions had to be made which restricted project structure.

Let me know if I can explain further!

phdye commented 4 years ago

I realize that is how Nimporter is documented to work. However, should not nimporter construct package names and locate source files in the same manner that nimble does ?

https://nim-lang.org/docs/nimscript.html#srcDir

Sent from Mail for Windows 10

From: Pebaz Sent: Sunday, June 14, 2020 3:57 PM To: Pebaz/nimporter Cc: phdye; Author Subject: Re: [Pebaz/nimporter] When srcDir = "src", package name should not beprefixed by "src." (#29)

Unfortunately, this is expected behavior for Nimporter. What is happening is that the auto-discovery mechanism of Nimporter finds that the src dir contains a Nim file and does not contain a Nimble file which means it will treat it as an extension Module rather than an extension Library. Extension modules are single Nim files. Extension libraries are folders that contain both a Nim file + Nimble file of the same name as the folder. In essence, a separate src dir is not supported by Nimporter. To achieve the same effect, place a single Nim file adjacent to the Nimble file and this will cause Nimporter to use the Nimble file and honor the srcDir setting. Let me know if I can explain further! — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

Pebaz commented 4 years ago

Not exactly. Nimporter was designed for simplicity first.

Nimble is a fully-capable build tool that can understand the entirety of the Nim programming language, run NimScripts, and understand config files.

Nimporter literally just finds Nim files or folders containing a Nim file and a Nimble file of the same name as the containing folder.

Furthermore, Nimporter was not designed to house a complete Nim project unless it adheres to the above rules (folder.nim and folder.nimble in folder/).

Why wasn't Nimporter designed to understand directives within .nimble files?

I actually considered this. However, there are just too many different options and by making (relatively unobtrusive) concessions like the one mentioned above, Nimporter can automatically discover, build, bundle, and ship Nim code along with Python code by adding 1 line of code to a setup.py.

Once I figured out what types of interactions Nimporter was going to allow, it made Nimporter much simpler and I got automatic discovery for free! 😀

I would be more than happy to help with creating a project structure that is Python/Nim/Nimporter friendly if you would like! If so, you can reopen this issue, if not, I'll go ahead and close it for now.