Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaks when noxfile is not in normal location #819

Open
SwampFalc opened this issue Jul 25, 2022 · 0 comments
Open

Breaks when noxfile is not in normal location #819

SwampFalc opened this issue Jul 25, 2022 · 0 comments

Comments

@SwampFalc
Copy link

SwampFalc commented Jul 25, 2022

I have just moved my noxfile from my project root into my "tests" folder, and so I now call nox providing the full path to the noxfile (--noxfile <path>).

However, as the nox documentation indicates at https://nox.thea.codes/en/stable/config.html#nox.sessions.Session.invoked_from, if the given noxfile is in a different folder, then nox will cwd into that folder. This will then break the relative path used in _PoetrySession.export_requirements:

lockdata = Path("poetry.lock").read_bytes()

Now, looking at the code some more, this seems like it's just the first error I encounter using my noxfile, I would assume that all of _PoetrySession.poetry is going to be broken since Poetry.config also assumes a correct cwd:

@property
def config(self) -> Config:
    """Return the package configuration."""
    if self._config is None:
        self._config = Config(Path.cwd())
    return self._config

So the best fix would be, I believe, to implement a more solid way for your Poetry class to detect the exact project root. This could then be used in export_requirements (and probably some other places too).

I have some code from an internal tool I made, that seems to work:

path = Path.cwd()
# Find the project root path by locating the pyproject.toml file
root = Path("/")
while not (path / "pyproject.toml").exists():
    path = path.parent
    if path == root:
        raise RuntimeError("This tool only works in a development folder.")

At the end of this, path should be the actual root of the project, where you can find all of poetry's files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant