Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash if pants.ini is missing in the buildroot (#7452)
### Problem If `pants.ini` is not present, then Pants will crash with this error: ``` timestamp: 2019-03-28T18:16:34.356612 Exception caught: (exceptions.IOError) File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/bin/pants", line 10, in <module> sys.exit(main()) File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/bin/pants_loader.py", line 85, in main PantsLoader.run() File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/bin/pants_loader.py", line 81, in run cls.load_and_execute(entrypoint) File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/bin/pants_loader.py", line 74, in load_and_execute entrypoint_main() File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/bin/pants_exe.py", line 39, in main PantsRunner(exiter, start_time=start_time).run() File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/bin/pants_runner.py", line 39, in run options_bootstrapper = OptionsBootstrapper.create(env=self._env, args=self._args) File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/option/options_bootstrapper.py", line 133, in create config_files_products = [filecontent_for(p) for p in config_file_paths] File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/option/options_bootstrapper.py", line 106, in filecontent_for return FileContent(ensure_text(path), read_file(path)) File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/util/dirutil.py", line 155, in read_file with open(filename, mode) as f: Exception message: [Errno 2] No such file or directory: '/Users/eric/DocsLocal/code/projects/setup/pants.ini' ``` This does not appear to be by design. Notably, we allow an empty `pants.ini` without any issue. There is no meaningful difference between an empty `pants.ini` from a non-existent `pants.ini`, so this seems to be a bug. ### Solution First check if `pants.ini` exists before adding it to the list of config files. This also allows us to refactor `./pants generate-pants-ini` from #7448 to create a new `pants.ini`, rather than requiring the user to make it. This allows us to simplify our setup instructions even more by removing the `touch pants.ini` instruction.
- Loading branch information