Bug 269458 - devel/py-virtualenv: 'make stage' fails with Permission Denied
Summary: devel/py-virtualenv: 'make stage' fails with Permission Denied
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Nicola Vitale
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-10 12:10 UTC by John Hein
Modified: 2023-02-12 09:55 UTC (History)
2 users (show)

See Also:
bugzilla: maintainer-feedback? (nivit)


Attachments
Fix build when a previous version of virtualenv is installed (811 bytes, patch)
2023-02-10 14:56 UTC, Nicola Vitale
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John Hein 2023-02-10 12:10:52 UTC
'make -C devel/py-virtualenv stage' (as non-root) fails with 'Permission Denied' after update to 20.18.0 and USE_PYTHON=pep517.

======================
 .
 .
===>  Staging for py39-virtualenv-20.18.0
===>   Generating temporary packing list
done with bpm generate-plist
Using pip 22.3.1 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
Processing ./dist/virtualenv-20.18.0-py3-none-any.whl
Installing collected packages: virtualenv
  Attempting uninstall: virtualenv
    Found existing installation: virtualenv 20.17.0
    Uninstalling virtualenv-20.17.0:
ERROR: Could not install packages due to an OSError.
Consider using the `--user` option or check the permissions.
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/shutil.py", line 825, in move
    os.rename(src, real_dst)
PermissionError: [Errno 13] Permission denied: '/usr/local/bin/virtualenv' -> '/tmp/jhein/pip-uninstall-87hvxxnm/virtualenv'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/commands/install.py", line 494, in run
    installed = install_given_reqs(
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/req/__init__.py", line 68, in install_given_reqs
    uninstalled_pathset = requirement.uninstall(auto_confirm=True)
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/req/req_install.py", line 660, in uninstall
    uninstalled_pathset.remove(auto_confirm, verbose)
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/req/req_uninstall.py", line 373, in remove
    moved.stash(path)
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/req/req_uninstall.py", line 271, in stash
    renames(path, new_path)
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/utils/misc.py", line 311, in renames
    shutil.move(old, new)
  File "/usr/local/lib/python3.9/shutil.py", line 830, in move
    os.unlink(src)
PermissionError: [Errno 13] Permission denied: '/usr/local/bin/virtualenv'
*** Error code 1

Stop.
make[1]: stopped in /usr/ports/devel/py-virtualenv
======================
Comment 1 Nicola Vitale freebsd_committer freebsd_triage 2023-02-10 14:56:53 UTC
Created attachment 240045 [details]
Fix build when a previous version of virtualenv is installed

Hi, can you try this patch, please?
Comment 2 commit-hook freebsd_committer freebsd_triage 2023-02-10 16:32:15 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=a4431f26f3a69c55d0785aeb349f070c8bea1321

commit a4431f26f3a69c55d0785aeb349f070c8bea1321
Author:     Nicola Vitale <nivit@FreeBSD.org>
AuthorDate: 2023-02-10 16:25:04 +0000
Commit:     Nicola Vitale <nivit@FreeBSD.org>
CommitDate: 2023-02-10 16:31:02 +0000

    devel/py-virtualenv: Fix build when a previous version is installed

    - Pass the option --ignore-installed to pip(1), because it tries to deinstall
      the  previous version when installing the new one. This is safe because we
      install it in the stage dir. [1]

    - Fix build with Python < 3.9.
      Replace the switch -s (strip) with -d (destination dir), passed to module
      compileall.py, because the first is available only with Python 3.9+. [2]

      Reported error:

    ===>  Staging for py38-virtualenv-20.18.0
    ===>   Generating temporary packing list
    Using pip 22.3.1 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)
    Processing ./dist/virtualenv-20.18.0-py3-none-any.whl
    Installing collected packages: virtualenv
      changing mode of /wrkdirs/usr/ports/devel/py-virtualenv/work-py38/stage/usr/local/bin/virtualenv to 755
    Successfully installed virtualenv-20.18.0
    WARNING: There was an error checking the latest version of pip.
    /usr/local/bin/python3.8 /usr/local/lib/python3.8/compileall.py -s /wrkdirs/usr/ports/devel/py-virtualenv/work-py38/stage -f /wrkdirs/usr/ports/devel/py-virtualenv/work-py38/stage/usr/local/lib/python3.8/site
    -packages
    usage: compileall.py [-h] [-l] [-r RECURSION] [-f] [-q] [-b] [-d DESTDIR]
                         [-x REGEXP] [-i FILE] [-j WORKERS]
                         [--invalidation-mode {checked-hash,timestamp,unchecked-hash}]
                         [FILE|DIR [FILE|DIR ...]]
    compileall.py: error: unrecognized arguments: -s /wrkdirs/usr/ports/devel/py-virtualenv/work-py38/stage/usr/local/lib/python3.8/site-packages
    *** Error code 2

    PR:             269458 [1]
    Reported by:    John Hein <jcfyecrayz@liamekaens.com> [1]
    Reported by:    Кирилл Варнаков <kirill@varnakov.com> (via email) [2]

 devel/py-virtualenv/Makefile | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Comment 3 John Hein 2023-02-10 16:44:06 UTC
That seems to work in a quick test.

I'm curious, however... why redefine all the PEP517_* values?  What is wrong with the current default PEP517_*CMD for this port?
Comment 4 Nicola Vitale freebsd_committer freebsd_triage 2023-02-10 20:42:17 UTC
I redefine PEP517_BUILD_*, because the virtualenv project use devel/py-hatchling to build, so, with the default variables, we would have one more (unnecessary) dependency (devel/py-build).

About PEP517_INSTALL_*, the starting point is that I want to install the bytecode (al least until a definitive decision is made, see https://reviews.freebsd.org/D38429 ), but the default installer (devel/py-installer) does not record .pyc files in the RECORD file (they are optional after all - see https://peps.python.org/pep-0627/ ). The problem is that python.mk uses that file to create the PLIST file of the port (see https://github.com/freebsd/freebsd-ports/blob/b81b1236109378963da7ed1ada0e343e58aaeefb/Mk/Uses/python.mk#L861 ) and so the package is created without those bytecode files.

That's all. :)