user202729 / tex-fast-recompile

A Python module to speed up TeX compilation.
LaTeX Project Public License v1.3c
13 stars 0 forks source link

Use TEXINPUTS instead of copying files to temporary output directory when --temp-output-dir is on #8

Closed user202729 closed 1 year ago

user202729 commented 1 year ago

Mentioned in #7.

user202729 commented 1 year ago

Actually the copy forward seems redundant, just copy back is enough???

Will dump some code here just in case

        env=dict(os.environ)

        # https://stackoverflow.com/questions/19023238/why-python-uppercases-all-environment-variables-in-windows
        texinputs: list[str]=[]
        if env.get("TEXINPUTS"):  # exist and nonempty
            texinputs=env["TEXINPUTS"].split(os.pathsep)

        if os.pathsep in str(self.output_directory):
            print(f"Warning: Output directory {self.output_directory} contains invalid character {os.pathsep}")
            # fallback: copy files from real output_directory to temp_output_directory
            # currently sub-aux files are not copied, see https://github.com/user202729/tex-fast-recompile/issues/7
            for extension in ['aux', 'bcf', 'fls', 'idx', 'ind', 'lof', 'lot', 'out', 'toc', 'blg', 'ilg', 'xdv']:
                try:
                    shutil.copyfile(
                        self.output_directory / (self.jobname + '.' + extension),
                        self._temp_output_dir_path / (self.jobname + '.' + extension),
                        )
                except FileNotFoundError:
                    pass

        else:
            #texinputs.insert(0, str(self.output_directory))
            pass

        env["TEXINPUTS"]=os.pathsep.join(texinputs)
user202729 commented 1 year ago

Never mind, issue only happen with nonstandard output_directory.

Implemented in 1f75da7.