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

Crash when using PassthroughEnv #347

Closed
drhagen opened this issue Apr 25, 2021 · 4 comments · Fixed by #354
Closed

Crash when using PassthroughEnv #347

drhagen opened this issue Apr 25, 2021 · 4 comments · Fixed by #354
Labels
bug Something isn't working

Comments

@drhagen
Copy link
Contributor

drhagen commented Apr 25, 2021

Starting in v0.8.2, using @nox_poetry.session(venv_backend='none') causes a crash. This was introduced in #298 and is caused by accessing the nonexistant location attribute of the PassthroughEnv object in _PoetrySession.export_requirements.

Example script:

import nox_poetry

@nox_poetry.session(venv_backend='none')
def lint(session: nox_poetry.Session):
    session.install('flakehell', 'flake8', 'pep8-naming', 'flake8-quotes')
    session.run('flakehell', 'lint', 'src', 'tests', 'examples')

Example error message:

nox > Running session lint
nox > Session lint raised exception AttributeError("'PassthroughEnv' object has no attribute 'location'")
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.9.4/x64/lib/python3.9/site-packages/nox/sessions.py", line 549, in execute
    self.func(session)
  File "/opt/hostedtoolcache/Python/3.9.4/x64/lib/python3.9/site-packages/nox/_decorators.py", line 53, in __call__
    return self.func(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.9.4/x64/lib/python3.9/site-packages/nox_poetry/sessions.py", line 42, in wrapper
    function(proxy, *_args, **_kwargs)
  File "/home/runner/work/parsita/parsita/noxfile.py", line 22, in lint
    session.install('flakehell', 'flake8', 'pep8-naming', 'flake8-quotes')
  File "/opt/hostedtoolcache/Python/3.9.4/x64/lib/python3.9/site-packages/nox_poetry/sessions.py", line 276, in install
    return self.poetry.install(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.9.4/x64/lib/python3.9/site-packages/nox_poetry/sessions.py", line 144, in install
    requirements = self.export_requirements()
  File "/opt/hostedtoolcache/Python/3.9.4/x64/lib/python3.9/site-packages/nox_poetry/sessions.py", line 200, in export_requirements
    tmpdir = Path(self.session.virtualenv.location) / "tmp"
AttributeError: 'PassthroughEnv' object has no attribute 'location'
drhagen added a commit to drhagen/parsita that referenced this issue Apr 25, 2021
@cjolowicz
Copy link
Owner

cjolowicz commented Apr 25, 2021

Thank you for catching this!

The idea in #298 was to, essentially, do what session.create_tmp does but without setting TMPDIR. Instead of session._runner.envdir we're using session.virtualenv.location because it's a public API. It was an oversight that this does not work for PassthroughEnv.

The fix would be here:

tmpdir = Path(self.session.virtualenv.location) / "tmp"
tmpdir.mkdir(exist_ok=True)

I'd be fine with switching to the private API, and passing parents=True to ensure the directory can be created. This would be emulating session.create_tmp.

There have also been thoughts about using just a single requirements file for all sessions. I think we don't need per-session requirements files anymore. Edit: Opened #350 for this.

@cjolowicz
Copy link
Owner

Fix released in 0.8.5, could you give it a spin?

@drhagen
Copy link
Contributor Author

drhagen commented Apr 29, 2021

I have confirmed that this is fixed.

@cjolowicz
Copy link
Owner

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants