Search code examples
pythonbuildpip

Use config file for pip within build


I am building a package from source files.

If I run with the argument

--no-isolation

It successfully builds. However, if I try to build in an isolated environment it fails trying to install packages [SSLCertVerificationError]. I have solved in my normal environment by adding the following to pip.ini

[global]
trusted-host = pypi.org
               files.pythonhosted.org
               pypi.python.org

What can I add to the command so that PIP within the Build process will use this config file.

python -m build [WHAT GOES HERE]

The particular line that it is failing at is:

subprocess.CalledProcessError: 
Command '['\\Temp\\build-env-zu51awtu\\Scripts\\python.exe', '-Im', 'pip', 'install', '--use-pep517', '--no-warn-script-location', '-r', '\\Local\\Temp\\build-reqs-7xyim3xs.txt']' returned non-zero exit status 1.

Solution

  • There doesn't appear to be a direct way to apply a config file to pip in this process.

    Looking at the source code in build/env, line 228-238

    cmd = [
                    self.executable,
                    '-Im',
                    'pip',
                    'install',
                    '--use-pep517',
                    '--no-warn-script-location',
                    '-r',
                    os.path.abspath(req_file.name),
                ]
                _subprocess(cmd)
    
    

    This could either be modified directly by adding additional arguments to this list, or, by executing earlier in the program

            popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
            for stdout_line in iter(popen.stdout.readline, ""):
                print(stdout_line)
    

    you will be able to see where pip is looking for config files and save a config file with the required options there.