(script=None, outdir=None)
| 102 | # freezing |
| 103 | |
| 104 | def prepare(script=None, outdir=None): |
| 105 | print() |
| 106 | print("cwd:", os.getcwd()) |
| 107 | |
| 108 | if not outdir: |
| 109 | outdir = OUTDIR |
| 110 | os.makedirs(outdir, exist_ok=True) |
| 111 | |
| 112 | # Write the script to disk. |
| 113 | if script: |
| 114 | scriptfile = os.path.join(outdir, 'app.py') |
| 115 | print(f'creating the script to be frozen at {scriptfile}') |
| 116 | with open(scriptfile, 'w', encoding='utf-8') as outfile: |
| 117 | outfile.write(script) |
| 118 | |
| 119 | # Make a copy of the repo to avoid affecting the current build |
| 120 | # (e.g. changing PREFIX). |
| 121 | srcdir = os.path.join(outdir, 'cpython') |
| 122 | copy_source_tree(srcdir, SRCDIR) |
| 123 | |
| 124 | # We use an out-of-tree build (instead of srcdir). |
| 125 | builddir = os.path.join(outdir, 'python-build') |
| 126 | os.makedirs(builddir, exist_ok=True) |
| 127 | |
| 128 | # Run configure. |
| 129 | print(f'configuring python in {builddir}...') |
| 130 | config_args = shlex.split(sysconfig.get_config_var('CONFIG_ARGS') or '') |
| 131 | cmd = [os.path.join(srcdir, 'configure'), *config_args] |
| 132 | ensure_opt(cmd, 'cache-file', os.path.join(outdir, 'python-config.cache')) |
| 133 | prefix = os.path.join(outdir, 'python-installation') |
| 134 | ensure_opt(cmd, 'prefix', prefix) |
| 135 | _run_quiet(cmd, cwd=builddir) |
| 136 | |
| 137 | if not MAKE: |
| 138 | raise UnsupportedError('make') |
| 139 | |
| 140 | cores = os.process_cpu_count() |
| 141 | if cores and cores >= 3: |
| 142 | # this test is most often run as part of the whole suite with a lot |
| 143 | # of other tests running in parallel, from 1-2 vCPU systems up to |
| 144 | # people's NNN core beasts. Don't attempt to use it all. |
| 145 | jobs = cores * 2 // 3 |
| 146 | parallel = f'-j{jobs}' |
| 147 | else: |
| 148 | parallel = '-j2' |
| 149 | |
| 150 | # Build python. |
| 151 | print(f'building python {parallel=} in {builddir}...') |
| 152 | _run_quiet([MAKE, parallel], cwd=builddir) |
| 153 | |
| 154 | # Install the build. |
| 155 | print(f'installing python into {prefix}...') |
| 156 | _run_quiet([MAKE, 'install'], cwd=builddir) |
| 157 | python = os.path.join(prefix, 'bin', 'python3') |
| 158 | |
| 159 | return outdir, scriptfile, python |
| 160 | |
| 161 |
nothing calls this directly
no test coverage detected
searching dependent graphs…