Repository: spack/spack

Issue:
Spack fails to install when cwd does not exist
### Steps to reproduce

```
harmen-desktop julia-1.7.2-7xre62gf3wq2jlnjwkgdxqbxfjhvzphs $ spack -d install -v julia@:1.7.1
sh: 0: getcwd() failed: No such file or directory
==> [2022-03-26-10:32:12.152463] Reading config file /home/harmen/spack/etc/spack/defaults/config.yaml
==> [2022-03-26-10:32:12.164657] Reading config file /home/harmen/.spack/config.yaml
Traceback (most recent call last):
  File "/home/harmen/spack/bin/spack", line 98, in <module>
    sys.exit(spack.main.main())
  File "/home/harmen/spack/lib/spack/spack/main.py", line 916, in main
    return _main(argv)
  File "/home/harmen/spack/lib/spack/spack/main.py", line 871, in _main
    return finish_parse_and_run(parser, cmd_name, env_format_error)
  File "/home/harmen/spack/lib/spack/spack/main.py", line 877, in finish_parse_and_run
    command = parser.add_command(cmd_name)
  File "/home/harmen/spack/lib/spack/spack/main.py", line 334, in add_command
    module = spack.cmd.get_module(cmd_name)
  File "/home/harmen/spack/lib/spack/spack/cmd/__init__.py", line 120, in get_module
    module = __import__(module_name,
  File "/home/harmen/spack/lib/spack/spack/cmd/install.py", line 22, in <module>
    import spack.report
  File "/home/harmen/spack/lib/spack/spack/report.py", line 235, in <module>
    class collect_info(object):
  File "/home/harmen/spack/lib/spack/spack/report.py", line 285, in collect_info
    def __call__(self, type, dir=os.getcwd()):
FileNotFoundError: [Errno 2] No such file or directory
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 76, in apport_excepthook
    binary = os.path.realpath(os.path.join(os.getcwd(), sys.argv[0]))
FileNotFoundError: [Errno 2] No such file or directory

Original exception was:
Traceback (most recent call last):
  File "/home/harmen/spack/bin/spack", line 98, in <module>
    sys.exit(spack.main.main())
  File "/home/harmen/spack/lib/spack/spack/main.py", line 916, in main
    return _main(argv)
  File "/home/harmen/spack/lib/spack/spack/main.py", line 871, in _main
    return finish_parse_and_run(parser, cmd_name, env_format_error)
  File "/home/harmen/spack/lib/spack/spack/main.py", line 877, in finish_parse_and_run
    command = parser.add_command(cmd_name)
  File "/home/harmen/spack/lib/spack/spack/main.py", line 334, in add_command
    module = spack.cmd.get_module(cmd_name)
  File "/home/harmen/spack/lib/spack/spack/cmd/__init__.py", line 120, in get_module
    module = __import__(module_name,
  File "/home/harmen/spack/lib/spack/spack/cmd/install.py", line 22, in <module>
    import spack.report
  File "/home/harmen/spack/lib/spack/spack/report.py", line 235, in <module>
    class collect_info(object):
  File "/home/harmen/spack/lib/spack/spack/report.py", line 285, in collect_info
    def __call__(self, type, dir=os.getcwd()):
FileNotFoundError: [Errno 2] No such file or directory
```

### Error message

_No response_

### Information on your system

.

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have searched the issues of this repo and believe this is not a duplicate
- [X] I have run the failing commands in debug mode and reported the output


Discussion:

Resolving patch:
diff --git a/lib/spack/spack/report.py b/lib/spack/spack/report.py
--- a/lib/spack/spack/report.py
+++ b/lib/spack/spack/report.py
@@ -2,7 +2,6 @@
 # Spack Project Developers. See the top-level COPYRIGHT file for details.
 #
 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
-
 """Tools to produce reports of spec installations"""
 import codecs
 import collections
@@ -281,9 +280,9 @@ def __init__(self, cls, function, format_name, args):
                              .format(self.format_name))
         self.report_writer = report_writers[self.format_name](args)
 
-    def __call__(self, type, dir=os.getcwd()):
+    def __call__(self, type, dir=None):
         self.type = type
-        self.dir = dir
+        self.dir = dir or os.getcwd()
         return self
 
     def concretization_report(self, msg):


Test patch: