Opening source file causes File not found exception

Hi, I just started using guild and I’m trying to integrate it with an existing project.
I have the following directory structure:

├─ configs/
│  ├─
│  ├─
│  ├─
├─ utils/
│  ├─

Where the config files contain something similar to

from utils.base_config import BaseConfig

class Config(BaseConfig):
    class Model:
        architecture: MLP
        class Parameters:

if __name__ == "__main__":

and among other things does this

import __main__

class BaseConfig:
    def init(cls):
        with Path('configs/').open('w+') as f:
            f.writelines([f'from .{Path(str(__main__)).stem } import Config'])

Now, when I run guild run configs/ I get the following error:

Traceback (most recent call last):
  File "C:\Users\username\PycharmProjects\project\configs\", line 56, in <module>
  File "C:\Users\username\PycharmProjects\project\utils\", line 13, in init
    with Path('configs/').open('w+') as f:
  File "C:\Users\username\.conda\envs\project_env\lib\", line 1252, in open
    return, mode, buffering, encoding, errors, newline,
  File "C:\Users\username\.conda\envs\project_env\lib\", line 1120, in _opener
    return, flags, mode)
FileNotFoundError: [Errno 2] No such file or directory: 'configs\\'

Then, when I look into the sourcecode directory of the run I see that only, and cfg2.pyare present and the directory structure is not preserved (i.e. the three files are not under configs). Any idea on how to solve this?

Also, I was wondering how I could log the configuration file. I tried playing with flag-dest:config but couldn’t manage to make it work.

Thanks for the detailed report and my apologies for the very late reply here!

I believe this issue is related to this problem — Guild is not correctly running as a module inside the configs package but rather as a top-level script inside a subdirectory.

You can create a Guild file in your project root that looks like this:

# guild.yml

  main: configs.cfg1

This tells Guild that the cf1 script is actually a module inside configs. Guild uses this to configure the Python system path as needed.

The behavior you’re seeing is by design, but I think this design is bad! Guild should spot that is inside a package (indicated by the presence of and do the right thing there.

I’ll make sure this is fixed and lands in the next release. In the meantime, using the Guild file there should work or you.

Sorry again!