signalpillar / tox-battery

Experiments with Tox plugin system
MIT License
33 stars 3 forks source link

Parser fails on "-r" in requirements file #3

Closed divergentdave closed 7 years ago

divergentdave commented 8 years ago

I have a project where tox.ini includes "-r{toxinidir}/requirements-test.txt", and requirements-test.txt includes "-r requirements.txt". When I try to run tox with tox-battery installed, I get the following error.

Traceback (most recent call last):
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 90, in __init__
    req = REQUIREMENT.parseString(requirement_string)
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/pkg_resources/_vendor/pyparsing.py", line 1137, in parseString
    raise exc
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/pkg_resources/_vendor/pyparsing.py", line 1127, in parseString
    loc, tokens = self._parse( instring, 0 )
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/pkg_resources/_vendor/pyparsing.py", line 1001, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/pkg_resources/_vendor/pyparsing.py", line 2412, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/pkg_resources/_vendor/pyparsing.py", line 1001, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/pkg_resources/_vendor/pyparsing.py", line 2669, in parseImpl
    return self.expr._parse( instring, loc, doActions, callPreParse=False )
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/pkg_resources/_vendor/pyparsing.py", line 1001, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/pkg_resources/_vendor/pyparsing.py", line 2395, in parseImpl
    loc, resultlist = self.exprs[0]._parse( instring, loc, doActions, callPreParse=False )
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/pkg_resources/_vendor/pyparsing.py", line 1005, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/pkg_resources/_vendor/pyparsing.py", line 1785, in parseImpl
    raise ParseException(instring, loc, self.errmsg, self)
pkg_resources._vendor.pyparsing.ParseException: Expected W:(abcd...) (at char 0), (line:1, col:1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2788, in __init__
    super(Requirement, self).__init__(requirement_string)
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 94, in __init__
    requirement_string[e.loc:e.loc + 8]))
pkg_resources.extern.packaging.requirements.InvalidRequirement: Invalid requirement, parse error at "'-r requi'"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/david/callisto/.venv/bin/tox", line 11, in <module>
    sys.exit(cmdline())
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/tox/session.py", line 38, in main
    config = prepare(args)
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/tox/session.py", line 26, in prepare
    config = parseconfig(args)
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/tox/config.py", line 236, in parseconfig
    pm.hook.tox_configure(config=config)
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/pluggy.py", line 724, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/pluggy.py", line 338, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/pluggy.py", line 333, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/pluggy.py", line 596, in execute
    res = hook_impl.function(*args)
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/toxbat/requirements.py", line 36, in tox_configure
    return _ensure_envs_recreated_on_requirements_update(config)
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/toxbat/requirements.py", line 46, in _ensure_envs_recreated_on_requirements_update
    requires_recreation = are_requirements_changed(env)
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/toxbat/requirements.py", line 69, in are_requirements_changed
    for reqfile in requirement_files
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/toxbat/requirements.py", line 70, in <genexpr>
    if reqfile and os.path.isfile(reqfile)
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/toxbat/requirements.py", line 89, in is_changed
    changed = not are_equal_requirement_files(fpath, prev_version_fpath)
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/toxbat/requirements.py", line 101, in are_equal_requirement_files
    reqs1 = sorted(parse_requirements(content_of(fpath1)), key=hash_cmp)
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/toxbat/requirements.py", line 111, in parse_requirements
    return list(pkg_resources.parse_requirements(file_content))
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2781, in parse_requirements
    yield Requirement(line)
  File "/home/david/callisto/.venv/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2790, in __init__
    raise RequirementParseError(str(e))
pkg_resources.RequirementParseError: Invalid requirement, parse error at "'-r requi'"
signalpillar commented 8 years ago

@divergentdave thanks for reporting this issue. Solution will be very simple - do not parse requirements file at all. The format is defined by pip and pip position itself as a tool not API.

I started to work on it.

signalpillar commented 8 years ago

I've published version 0.2 with aforementioned fix. If it is not late could you please let me know whether it helps you. Thanks.

Solved in https://github.com/signalpillar/tox-battery/pull/4