Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flit_core/flit_core/build_thyself.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def build_sdist(sdist_directory, config_settings=None):

sb = SdistBuilder(
module, metadata, cwd, reqs_by_extra, entrypoints={},
extra_files=['pyproject.toml', 'build_dists.py']
extra_files=['pyproject.toml', 'build_dists.py', 'install_bootstrap.py']
)
path = sb.build(Path(sdist_directory))
return path.name
Expand Down
37 changes: 37 additions & 0 deletions flit_core/install_bootstrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Install flit_core without using any other tools.

Normally, you would install flit_core with pip like any other Python package.
This script is meant to help with 'bootstrapping' other packaging
systems, where you may need flit_core to build other packaging tools.

Pass a path to the site-packages directory or equivalent where the package
should be placed. If omitted, this defaults to the site-packages directory
of the Python running the script.
"""
import os
import sys
import sysconfig
from tempfile import TemporaryDirectory
from zipfile import ZipFile

from flit_core import build_thyself

os.chdir(os.path.dirname(os.path.abspath(__file__)))

if len(sys.argv) == 2:
dest = sys.argv[1]
if not os.path.isdir(dest):
sys.exit("Destination path must already be a directory")
elif len(sys.argv) == 1:
dest = sysconfig.get_path('purelib')
else:
sys.exit("Specify 0 or 1 arguments (destination directory)")

with TemporaryDirectory(prefix='flit_core-bootstrap-') as td:
print("Building wheel")
whl_fname = build_thyself.build_wheel(td)
whl_path = os.path.join(td, whl_fname)

print("Installing to", dest)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have argparse arguments that split the build and install stages up? It would also be handy to have a --root flag along the lines of ensurepip/distutils/setuptools since we need to redirect the install location when cross compiling.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nothing to actually do with --root here - that only matters if you install scripts, which this doesn't. For this scenario, you'd just prefix it to the target path, e.g. ${ROOT}/usr/lib/pythonX.Y/site-packages.

The commands to do this in separate build & install steps already exist 😉 :

# Build
rm -rf dist
python build_dists.py

# Install
unzip dist/*.whl -d /path/to/whatever/site-packages

The only real difference in this new script is that it skips building the sdist. The Python zipfile module also has a CLI if that's easier than using the unzip command.

with ZipFile(whl_path) as zf:
zf.extractall(dest)