Skip to content

Commit

Permalink
Validate filenames in builder
Browse files Browse the repository at this point in the history
This moves the logic for checking filenames closer to where it's
actually used.

Signed-off-by: Stephen Finucane <stephen@that.guru>
  • Loading branch information
stephenfin authored and AA-Turner committed Sep 26, 2022
1 parent 9ab21ce commit 49eeb0e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
10 changes: 5 additions & 5 deletions sphinx/builders/__init__.py
Expand Up @@ -275,16 +275,16 @@ def build_specific(self, filenames: List[str]) -> None:
for filename in filenames:
filename = path.normpath(path.abspath(filename))

if not path.isfile(filename):
logger.warning(__('file %r given on command line does not exist, '),
filename)
continue

if not filename.startswith(self.srcdir):
logger.warning(__('file %r given on command line is not under the '
'source directory, ignoring'), filename)
continue

if not path.isfile(filename):
logger.warning(__('file %r given on command line does not exist, '
'ignoring'), filename)
continue

docname = self.env.path2doc(filename)
if not docname:
logger.warning(__('file %r given on command line is not a valid '
Expand Down
13 changes: 2 additions & 11 deletions sphinx/cmd/build.py
Expand Up @@ -209,16 +209,7 @@ def build_main(argv: List[str] = sys.argv[1:]) -> int:
if not args.doctreedir:
args.doctreedir = os.path.join(args.outputdir, '.doctrees')

# handle remaining filename arguments
filenames = args.filenames
missing_files = []
for filename in filenames:
if not os.path.isfile(filename):
missing_files.append(filename)
if missing_files:
parser.error(__('cannot find files %r') % missing_files)

if args.force_all and filenames:
if args.force_all and args.filenames:
parser.error(__('cannot combine -a option and filenames'))

if args.color == 'no' or (args.color == 'auto' and not color_terminal()):
Expand Down Expand Up @@ -276,7 +267,7 @@ def build_main(argv: List[str] = sys.argv[1:]) -> int:
warning, args.freshenv, args.warningiserror,
args.tags, args.verbosity, args.jobs, args.keep_going,
args.pdb)
app.build(args.force_all, filenames)
app.build(args.force_all, args.filenames)
return app.statuscode
except (Exception, KeyboardInterrupt) as exc:
handle_exception(app, args, exc, error)
Expand Down

0 comments on commit 49eeb0e

Please sign in to comment.