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

usercustomize.py + middle print statement + sitepackages = True creates error after successful tox run #1570

Closed
Cielquan opened this issue Apr 26, 2020 · 4 comments
Labels
bug:normal affects many people or has quite an impact

Comments

@Cielquan
Copy link

Hi,
this issue is strongly related to #1569 and uses its context as a base for this issue. But its another bug with the same root maybe?

When I set up the usercustomize.py file mentioned in the other issue I not only added a print() at the beginning but also when the import was successful:

try:
    from devtools import debug
except ImportError:
    pass
else:
    print('### devtool\'s debug enabled')
    __builtins__['debug'] = debug

When I now also add devtools to the deps of the env, so that it can be imported successfully I get the traceback shown below.

tox.ini:

[tox]
skipsdist = True

[testenv:dev]
basepython = python3.8
deps = devtools[pygments]>=0.5.1,<0.6
sitepackages = True

Traceback:

$ tox -e dev -r
dev recreate: /home/krys/Python_Projects/.testing/.tox/dev
dev installdeps: devtools[pygments]>=0.5.1,<0.6
_________________________________________________________________ summary __________________________________________________________________
  dev: commands succeeded
  congratulations :)
Traceback (most recent call last):
  File "/home/krys/bin/tox", line 8, in <module>
    sys.exit(cmdline())
  File "/home/krys/.venvs/tox/lib/python3.8/site-packages/tox/session/__init__.py", line 44, in cmdline
    main(args)
  File "/home/krys/.venvs/tox/lib/python3.8/site-packages/tox/session/__init__.py", line 68, in main
    exit_code = session.runcommand()
  File "/home/krys/.venvs/tox/lib/python3.8/site-packages/tox/session/__init__.py", line 194, in runcommand
    return self.subcommand_test()
  File "/home/krys/.venvs/tox/lib/python3.8/site-packages/tox/session/__init__.py", line 222, in subcommand_test
    run_sequential(self.config, self.venv_dict)
  File "/home/krys/.venvs/tox/lib/python3.8/site-packages/tox/session/commands/run/sequential.py", line 9, in run_sequential
    if venv.setupenv():
  File "/home/krys/.venvs/tox/lib/python3.8/site-packages/tox/venv.py", line 621, in setupenv
    envlog.set_python_info(command_path)
  File "/home/krys/.venvs/tox/lib/python3.8/site-packages/tox/logs/env.py", line 18, in set_python_info
    answer["executable"] = python_executable
TypeError: 'NoneType' object does not support item assignment
*** Exit Code: 1 ***

As soon as I remove the print() from the usercustomize.py file everything works just fine.

@JulienPalard
Copy link

Happened to me on Windows (github workflow).

Traceback
Traceback (most recent call last):
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\hostedtoolcache\windows\Python\3.6.8\x64\Scripts\tox.exe\__main__.py", line 7, in <module>
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\tox\session\__init__.py", line 44, in cmdline
    main(args)
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\tox\session\__init__.py", line 69, in main
    exit_code = session.runcommand()
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\tox\session\__init__.py", line 197, in runcommand
    return self.subcommand_test()
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\tox\session\__init__.py", line 213, in subcommand_test
    venv.package = self.hook.tox_package(session=self, venv=venv)
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\pluggy\hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\pluggy\manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\pluggy\manager.py", line 87, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\pluggy\callers.py", line 208, in _multicall
    return outcome.get_result()
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\pluggy\callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\pluggy\callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\tox\package\__init__.py", line 16, in tox_package
    session.package, session.dist = get_package(session)
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\tox\package\__init__.py", line 29, in get_package
    package = acquire_package(config, session)
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\tox\package\__init__.py", line 40, in acquire_package
    path = build_package(config, session)
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\tox\package\builder\__init__.py", line 9, in build_package
    return build(config, session)
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\tox\package\builder\isolated.py", line 32, in build
    if package_venv.setupenv():
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\tox\venv.py", line 645, in setupenv
    envlog.set_python_info(command_path)
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\tox\logs\env.py", line 18, in set_python_info
    answer["executable"] = python_executable
TypeError: 'NoneType' object does not support item assignment

@Cielquan
Copy link
Author

Cielquan commented Dec 10, 2020

In the meantime I switched to another way to add devtools.debug to the python builtins (my original goal).

Now I create a filename.pth file inside the venv's site-packages directory which only imports a filename.py at the same place. The latter one bears the python logic I want to run on python start-up. I just saw that virtualenv uses the same hack.

I also just tested it with a print() and it seems to work for tox. But it fucks poetry up which I run via nox which itself seems to be unaffected.

@JulienPalard
Copy link

Happened to me on Windows (github workflow).

I don't know if github changed something of if tox fixed it, but the traceback I pasted previously does no longer happen.

@gaborbernat
Copy link
Member

This shouldn't be a case anymore in tox 4, no plan to address it from our side unless someone creates a PR for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:normal affects many people or has quite an impact
Projects
None yet
Development

No branches or pull requests

3 participants