Repository: tox-dev/tox (Python)

Issue:
Testing with `--installpkg somewheel.whl` broken (Regression in 3.5.0)
Tox 3.5.0 seems to break my Travis tests for Prequ. I have set the Travis configuration so that it runs `python setup.py bdist_wheel` and then runs as `tox -v --installpkg dist/*.whl`.  This worked fine with earlier Tox versions (<=3.4.0).

With Tox 3.5.0 my Travis job started to break with an exception raised from this line:

https://github.com/tox-dev/tox/blob/5f2535f1a697fe4bfbec571407a742615b410e24/src/tox/package.py#L64

The exception was `AttributeError: 'str' object has no attribute 'basename'`.  Full trace back is available in the build log: https://travis-ci.org/suutari/prequ/jobs/438550460

I think the error happens because `acquire_package` returns a bare `str` if `--instalpkg` is used, but otherwise it seems to return a `_path.local.LocalPath` instance. The failing code in `create_session_view` seems to assume (since commit 6538f74fd7) that the `package` is a a rich `Path` object rather than bare string.


Discussion:
@suutari thanks for pointing this out I'll fix it :+1: 
@gaborbernat thanks for the quick fix!
@suutari https://pypi.org/project/tox/3.5.1/ has been released and should address the issue; thanks for the report and let us know if you bump into any other issues!

<blockquote><img src="https://pypi.org/static/images/twitter.c0030826.jpg" width="48" align="right"><div><img src="/static/images/favicon.6a76275d.ico" height="14"> PyPI</div><div><strong><a href="https://pypi.org/project/tox/3.5.1/">tox</a></strong></div><div>virtualenv-based automation of test activities</div></blockquote>
@gaborbernat Thanks for the fix!

However, even Tox 3.5.1 doesn't work with my use case yet (as 3.4.0 used to). See https://travis-ci.org/suutari/prequ/jobs/438805462

I guess the problem is that the wheel file is renamed to `1-something.whl`, but Pip won't install from a wheel file with that name, since the name of the package doesn't have this `1-` prefix. What's the point of this prefix? Can it be removed? Or maybe a directory could be used instead, e.g. `1/something.whl`, so that the wheel file name could be in correct format.

<blockquote><div><strong><a href="https://travis-ci.org/suutari/prequ/jobs/438805462">Travis CI - Test and Deploy Your Code with Confidence</a></strong></div></blockquote>
https://tox.readthedocs.io/en/latest/changelog.html#features details the goal of adding the hard link. We'll need to change to folder method though indeed, will try to do that tomorrow. If you're available feel free to create a PR doing that.

<blockquote><div><strong><a href="https://tox.readthedocs.io/en/latest/changelog.html#features">Changelog history — tox 3.5.2.dev1 documentation</a></strong></div></blockquote>
Please note that the new hard linking approach (package.py:72) breakes if source path and destination path are on different filesystems. 

Instead of checking if hasattr(os, 'link'), what about trying to os.link and falling back to copying if an Exception is raised?
In theory, both folders should be within ``.tox`` so a very edge case for them to be on a different file system. However, we can be safe by doing so. 
Unfortunately it's my use case, since I'm building with Jenkins and then running tox inside a docker container with --installpkg AND --workdir /tmp/...
Done via https://github.com/tox-dev/tox/pull/1046/commits/46f4e842f49300ac45a38a02f2890ef55990debb
Tox 3.5.2 seems to fix also the second issue with wheels (which was affecting my testing of Prequ). Thanks @gaborbernat!
Great to hear, you're welcome.



Patch:
diff --git a/docs/changelog/1042.bugfix.rst b/docs/changelog/1042.bugfix.rst
new file mode 100644
index 000000000..250208f33
--- /dev/null
+++ b/docs/changelog/1042.bugfix.rst
@@ -0,0 +1,1 @@
+fix regression with ``3.5.0``: specifying ``--installpkg`` raises ``AttributeError: 'str' object has no attribute 'basename'``
diff --git a/src/tox/package.py b/src/tox/package.py
index bbd191fdd..29548c654 100644
--- a/src/tox/package.py
+++ b/src/tox/package.py
@@ -108,9 +108,9 @@ def get_local_package(config, report, session):
     path = config.option.installpkg
     if not path:
         path = config.sdistsrc
-    path = session._resolve_package(path)
-    report.info("using package {!r}, skipping 'sdist' activity ".format(str(path)))
-    return path
+    py_path = py.path.local(session._resolve_package(path))
+    report.info("using package {!r}, skipping 'sdist' activity ".format(str(py_path)))
+    return py_path
 
 
 def build_package(config, report, session):


Test patch:
diff --git a/tests/unit/test_package.py b/tests/unit/test_package.py
index d46d229d8..e4c39a48b 100644
--- a/tests/unit/test_package.py
+++ b/tests/unit/test_package.py
@@ -389,3 +389,18 @@ def build_package(config, report, session):
     assert len(dist_after) == 1
     sdist = dist_after[0]
     assert t1_package != sdist
+
+
+def test_install_via_installpkg(mock_venv, initproj, cmd):
+    base = initproj(
+        "pkg-0.1",
+        filedefs={
+            "tox.ini": """
+                [tox]
+                install_cmd = python -m -c 'print("ok")' -- {opts} {packages}'
+                """
+        },
+    )
+    fake_package = base.ensure(".tox", "dist", "pkg123-0.1.zip")
+    result = cmd("-e", "py", "--notest", "--installpkg", str(fake_package.relto(base)))
+    assert result.ret == 0, result.out