Skip to content

Remove os.getcwd from function signature#31480

Merged
alalazo merged 1 commit intospack:developfrom
alalazo:bugfix/no_os_getcwd_in_func_signature
Jul 12, 2022
Merged

Remove os.getcwd from function signature#31480
alalazo merged 1 commit intospack:developfrom
alalazo:bugfix/no_os_getcwd_in_func_signature

Conversation

@alalazo
Copy link
Copy Markdown
Member

@alalazo alalazo commented Jul 7, 2022

fixes #29730

This is also wrong since it binds the directory at the time of module import, rather than the one at the time of function call.

fixes spack#29730

This is also wrong since it binds the directory at the time
of module import, rather than the one at the time of function
call.
@alalazo alalazo requested a review from haampie July 7, 2022 15:30
@alalazo alalazo added the bugfix Something wasn't working, here's a fix label Jul 7, 2022
@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Jul 7, 2022

Not sure it's worth a test, but in case this ought to be tested with an integration test, since the error happens at import time and multiprocessing has the same errors as here when using spawn (which makes me think this is a fix only for linux).

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Jul 7, 2022

For reference, here's what happens when trying to spawn a clean process to test this:

tmpdir = local('/tmp/pytest-of-culpo/pytest-5/test_installing_when_cwd_does_0'), install_mockery = None, mock_fetch = None
mock_packages = <spack.repo.RepoPath object at 0x7f670d2dd8e0>

    @pytest.mark.regression('29730')
    def test_installing_when_cwd_does_not_exist(
            tmpdir, install_mockery, mock_fetch, mock_packages
    ):
        deleted_dir = tmpdir.ensure_dir('local')
        # Execute with spawn to force a new import
        ctx = multiprocessing.get_context('spawn')
        p = ctx.Process(target=install, args=('trivial-install-test-package',))
        with deleted_dir.as_cwd():
            deleted_dir.remove(rec=1)
            # Ensure this doesn't raise.
>           p.start()

lib/spack/spack/test/cmd/install.py:1075: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib/python3.8/multiprocessing/process.py:121: in start
    self._popen = self._Popen(self)
/usr/lib/python3.8/multiprocessing/context.py:284: in _Popen
    return Popen(process_obj)
/usr/lib/python3.8/multiprocessing/popen_spawn_posix.py:32: in __init__
    super().__init__(process_obj)
/usr/lib/python3.8/multiprocessing/popen_fork.py:19: in __init__
    self._launch(process_obj)
/usr/lib/python3.8/multiprocessing/popen_spawn_posix.py:42: in _launch
    prep_data = spawn.get_preparation_data(process_obj._name)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'SpawnProcess-1'

    def get_preparation_data(name):
        '''
        Return info about parent needed by child to unpickle process object
        '''
        _check_not_importing_main()
        d = dict(
            log_to_stderr=util._log_to_stderr,
            authkey=process.current_process().authkey,
            )
    
        if util._logger is not None:
            d['log_level'] = util._logger.getEffectiveLevel()
    
        sys_path=sys.path.copy()
        try:
            i = sys_path.index('')
        except ValueError:
            pass
        else:
            sys_path[i] = process.ORIGINAL_DIR
    
        d.update(
            name=name,
            sys_path=sys_path,
            sys_argv=sys.argv,
            orig_dir=process.ORIGINAL_DIR,
>           dir=os.getcwd(),
            start_method=get_start_method(),
            )
E       FileNotFoundError: [Errno 2] No such file or directory

/usr/lib/python3.8/multiprocessing/spawn.py:176: FileNotFoundError
==================================================================== slowest 30 durations ====================================================================
0.02s setup    lib/spack/spack/test/cmd/install.py::test_installing_when_cwd_does_not_exist[mock_archive0]
0.02s call     lib/spack/spack/test/cmd/install.py::test_installing_when_cwd_does_not_exist[mock_archive0]

(1 durations < 0.005s hidden.  Use -vv to show these durations.)
================================================================== short test summary info ===================================================================
FAILED lib/spack/spack/test/cmd/install.py::test_installing_when_cwd_does_not_exist[mock_archive0] - FileNotFoundError: [Errno 2] No such file or directory
===================================================================== 1 failed in 0.25s ======================================================================

@alalazo alalazo merged commit 89b8d33 into spack:develop Jul 12, 2022
@alalazo alalazo deleted the bugfix/no_os_getcwd_in_func_signature branch July 12, 2022 08:08
bhatiaharsh pushed a commit to bhatiaharsh/spack that referenced this pull request Aug 8, 2022
fixes spack#29730

This is also wrong since it binds the directory at the time
of module import, rather than the one at the time of function
call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Something wasn't working, here's a fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spack fails to install when cwd does not exist

2 participants