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

refactor session #1145

Merged
merged 12 commits into from
Feb 5, 2019
Merged

refactor session #1145

merged 12 commits into from
Feb 5, 2019

Conversation

gaborbernat
Copy link
Member

While looking into doing #998 I realized the concept of env logs and actions have been heavily overlooked, furthermore the reporting should not be tied to the session (as we should report before the session object is constructed). This PR tries to fix all this and split up the longer and longer getting session.py.

@gaborbernat gaborbernat force-pushed the provision branch 2 times, most recently from e656e49 to f9391fc Compare January 20, 2019 19:28
@gaborbernat gaborbernat requested review from obestwalter and asottile and removed request for obestwalter January 21, 2019 09:30
@obestwalter
Copy link
Member

Wow, that's a big one :)

Would you like feedback already about the direction this goes in? I'll have some time tomorrow afternoon to have closer look, if it makes sense already.

@gaborbernat
Copy link
Member Author

gaborbernat commented Jan 21, 2019

@obestwalter yeah hence opening it 👍 even though not 100% ready yet.

@gaborbernat gaborbernat force-pushed the provision branch 2 times, most recently from 8bae2e4 to bbc2c11 Compare January 21, 2019 13:11
Copy link
Contributor

@asottile asottile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't get a chance to read through it all -- got about halfway through and realized github probably doesn't show moves well so I'll probably need to look using the cli

Overall the parts I looked at seemed fine, moving the reporter to a global seems risky, especially now that we;re doing parallel things

src/tox/_pytestplugin.py Outdated Show resolved Hide resolved


@pytest.fixture
def newmocksession(mocksession, newconfig):
def newmocksession_(args, source, plugins=()):
mocksession.config = newconfig(args, source, plugins=plugins)
config = newconfig(args, source, plugins=plugins)
mocksession.__init__(config)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, I've never seen this before -- I assume it just re-initializes the object? is this well defined?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a function call AFAIK 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite get, why this change is necessary at all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we want to reset the report, calculated session venvs when a new config is loaded 👍 can use the _reset path though.

src/tox/_pytestplugin.py Show resolved Hide resolved
src/tox/action.py Outdated Show resolved Hide resolved
src/tox/config/__init__.py Show resolved Hide resolved
src/tox/helper/build_isolated.py Outdated Show resolved Hide resolved
src/tox/package/__init__.py Show resolved Hide resolved
src/tox/package/local.py Show resolved Hide resolved
src/tox/reporter.py Show resolved Hide resolved
src/tox/session/__init__.py Show resolved Hide resolved
@obestwalter
Copy link
Member

I only had time to skim through, but I like the general direction of it. I'll try to carve out some more time tomorrow to play with it.

@obestwalter
Copy link
Member

I'd say let's run with this after the comments are addressed and test failures are fixed.

Stripping down the several __init__.py modules to what really hast to be there can be also done in a later PR.

Main thing is we keep backwards compatibility regarding the main objects that people use from other tools / plugins.

@gaborbernat gaborbernat changed the title [WIP] Refactor session refactor session Feb 5, 2019
@gaborbernat
Copy link
Member Author

This looks OK for now. I'm not 100% settled on the reporting thing, but we can take it for a test drive. Maybe instead we should just use the logging framework which we kinda mimic. But this can be a subsequent PR to migrate to that.

@gaborbernat gaborbernat merged commit 984ce02 into tox-dev:master Feb 5, 2019
@gaborbernat gaborbernat deleted the provision branch February 5, 2019 18:20
@cjerdonek
Copy link

cjerdonek commented Mar 28, 2019

It looks like this PR causes pip's CI to fail. Here is the traceback:

  File "/home/travis/virtualenv/python3.6.7/bin/tox", line 11, in <module>
    sys.exit(cmdline())
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/tox/session/__init__.py", line 42, in cmdline
    main(args)
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/tox/session/__init__.py", line 63, in main
    retcode = session.runcommand()
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/tox/session/__init__.py", line 187, in runcommand
    return self.subcommand_test()
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/tox/session/__init__.py", line 215, in subcommand_test
    run_sequential(self.config, self.venv_dict)
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/tox/session/commands/run/sequential.py", line 9, in run_sequential
    if venv.setupenv():
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/tox/venv.py", line 582, in setupenv
    status = self.update(action=action)
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/tox/venv.py", line 240, in update
    self.hook.tox_testenv_create(action=action, venv=self)
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pluggy/hooks.py", line 284, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/tox_venv/hooks.py", line 99, in tox_testenv_create
    venv.session.make_emptydir(venv.path)
AttributeError: 'VirtualEnv' object has no attribute 'session'

Apparently this is because tox-venv relies on the VirtualEnv object's session attribute, which this PR removes: https://github.com/tox-dev/tox-venv/blob/31b874292ed3da5fee701d2a048db4c8b1ad8cae/src/tox_venv/hooks.py#L99

@cjerdonek
Copy link

Also, tox-venv's setup.py says:

install_requires=['tox>=2.0'],

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

Successfully merging this pull request may close these issues.

4 participants