Is there a "default" file name that can be used for importing modules?

280 views Asked by At

What I mean is if there's some standard name that can be used for the primary file in a local Nim module so that when importing by path, we can simply reference the directory?

For example, it seems right now I need to specify both the directory and file name of the local module like this:

import my_module.main

Whereas I was hoping to simply be able to reference the directory if the expected file name was found:

import my_module

Aside from using Nimble or creating a separate --path flag for every module in a nim.cfg file, is there anything that will allow this?

Also, in general, is there a conventional name to use for the main file of a module?


If I have a simple app like this:

myapp--+
       |
       +--myapp.nim
       |
       +--sub--+
               |
               +--sub.nim

In myapp.nim I have to use import sub.sub to load the sub-module. With import sub, I get Error: cannot open sub.

Likewise if I have modules outside the app and set the --path to the parent of those modules, I have to use import my_module.my_module.

1

There are 1 answers

3
def- On

The idea is to have a my_module.nim and sub-modules in a my_module directory. Then you can just import my_module.