2

In my pyinvoke task library, I would like to know the project directory so I can derive default locations for the directories like src, test, and dist.

Currently, the only way I can see to do this is from context.config._project_prefix.

Is there a better way to get the project directory? One that doesn't require the use of an underscore-prefixed (private, subject to change) attribute? Alternatively, what's the reason for why no such public attribute exists?

davidrmcharles
  • 1,923
  • 2
  • 20
  • 33

1 Answers1

0

What I've often done is to use __file__ in my tasks.py and find the project root relative to that.

For example:

myproject
    dist
    src
    test
    tasks.py
# In tasks.py

from pathlib import Path

project_dir = Path(__file__).parent.absolute()
Eric Smith
  • 2,739
  • 2
  • 30
  • 29