~olly/yoyo

1

Re: Use config in a transaction file

Details
Message ID
<20201229193615.on2ka7ifttwmy6lv@hooper>
DKIM signature
missing
Download raw message
On 26/12/2020, Alexander Myltsev wrote:
> 
> $ yoyo apply --config yoyo-dev.ini
> ERROR:yoyo.migrations:Could not import migration from
> '/demo-app/db-migrate/migrations/20201220_01_abcd-test.py':
> ModuleNotFoundError("No module named
> '/demo-app/db-migrate/migrations/20201220_01_abcd-test'")
> Traceback (most recent call last):
>   File "~/Library/Caches/pypoetry/virtualenvs/db-migrate-48SoZt4C-py3.8/lib/python3.8/site-packages/yoyo/migrations.py",
> line 223, in load
>     spec.loader.exec_module(self.module)
>   File "<frozen importlib._bootstrap_external>", line 783, in exec_module
>   File "<frozen importlib._bootstrap>", line 219, in
> _call_with_frames_removed
>   File "/demo-app/db-migrate/migrations/20201220_01_abcd-test.py", line 6,
> in <module>
>     from .config import config
> ModuleNotFoundError: No module named
> '/demo-app/db-migrate/migrations/20201220_01_abcd-test'

It looks like the problem is the relative import (`from .config import
config`) from inside the migration script.

Migration scripts are not loaded as first-class modules and so I don't
think relative imports will work from inside a migration script.

An absolute import should be fine (ie `from config import config`), as
long as the config module is available on sys.path.

Not sure how you would achieve this in poetry, but in a vanilla python
project you would use the `py_modules` parameter of setup.py and then
`python setup.py develop` to install the module in your venv.
Alternatively you could edit your migration script to insert the parent
directory in sys.path before importing the config module.

Olly.

Re: Use config in a transaction file

Details
Message ID
<bb981b6d-a54f-2fe9-7cc3-6befda60973e@phystech.edu>
In-Reply-To
<20201229193615.on2ka7ifttwmy6lv@hooper> (view parent)
DKIM signature
missing
Download raw message
Hi,

Thank you. That worked out.

I added the section as follows to pyproject.toml

packages = [
     { include = "config.py", from = "." },
]

And it worked out with poetry.

A.
Reply to thread Export thread (mbox)