pytask-dev / pytask

pytask is a workflow management system that facilitates reproducible data analyses.
https://pytask-dev.readthedocs.io/en/stable
Other
114 stars 10 forks source link

QST: Why does `import config` not work? #339

Closed augustebaum closed 1 year ago

augustebaum commented 1 year ago

Question about pytask

I created a project using a cookiecutter template and used conda to create an environment. My project is structured as follows:

my_project
├── src
│   ├── __init__.py
│   ├── config.py
│   ├── tasks
│   └── my_project
├── setup.cfg
├── pyproject.toml
├── environment.yml
└── tests

so that tasks contains all the tasks and my_project contains all the reusable code that might be released as a package. There are __init__.py files in all directories within src.

However, when I run pytask in the root directory, while in my conda environment, collection of any task fails because import config fails. When I print sys.path I get this:

['<conda-env-directory>/bin',
'<conda-env-directory>/lib/python310.zip',
'<conda-env-directory>/lib/python3.10',
'<conda-env-directory>/lib/python3.10/lib-dynload',
'<conda-env-directory>/lib/python3.10/site-packages',
'<some-temp-dir>']

So it doesn't contain my_project/src. Does it make sense to anyone why this doesn't work, and how I can make it work?

In pyproject.toml I have:

[build-system]
requires = ["poetry-core", "setuptools>=45", "wheel", "setuptools_scm[toml]>=6.0"]
build-backend = "poetry.core.masonry.api"

as I used poetry before changing to conda.

In setup.cfg I have:

[options]
packages = find:
install_requires =
    pytask
python_requires = >=3.8
include_package_data = True
package_dir =
    =src
zip_safe = False

[options.packages.find]
where = src

as I didn't change anything from the cookiecutter template.

Any help or support would be very much appreciated. In any case, thanks for your attention and have a great day.

tobiasraabe commented 1 year ago

Hi @augustebaum! I have questions and notes but no definitive answer.

If you want to be closer to the pytask cookiecutter and solve your issue, do this:

  1. Remove poetry from the pyproject.toml.
  2. Nest the content of src in another folder as explained above.

I hope it helps!

augustebaum commented 1 year ago

Thanks for the quick answer. I trouble-shooted this with a friend and they taught me about the pip install -e . technique whereby you install your own codebase as a package, so that the path to src is included in sys.path. This suffices to make my tasks run properly and it is already included in the environment.yml file from the template so I'll leave it at that, but yeah my next step would have been to fit the template structure more strictly.

Thanks again!