Skip to content

Commit

Permalink
Make sure setuptools itself can be installed with editable_wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Jun 15, 2022
1 parent 5bb97d0 commit 3e9f441
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
1 change: 1 addition & 0 deletions bootstrap.egg-info/entry_points.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
egg_info = setuptools.command.egg_info:egg_info
build_py = setuptools.command.build_py:build_py
sdist = setuptools.command.sdist:sdist
editable_wheel = setuptools.command.editable_wheel:editable_wheel

[distutils.setup_keywords]
include_package_data = setuptools.dist:assert_bool
Expand Down
48 changes: 16 additions & 32 deletions setuptools/command/editable_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@
from pathlib import Path

from distutils.core import Command
from distutils.errors import DistutilsError
from zipfile import ZIP_DEFLATED, ZipFile, ZipInfo

import pkg_resources
from setuptools import __version__

SOURCE_EPOCH_ZIP = 499162860

WHEEL_FILE = f"""\
Wheel-Version: 1.0
Generator: setuptools ({__version__})
Root-Is-Purelib: false
Tag: py3-none-any
Tag: ed-none-any
"""


class editable_wheel(Command):
"""Build 'editable' wheel for development"""
Expand All @@ -38,20 +46,10 @@ def initialize_options(self):
self.dist_dir = None

def finalize_options(self):
# is this part of the 'develop' command needed?
ei = self.get_finalized_command("egg_info")
if ei.broken_egg_info:
template = "Please rename %r to %r before using 'develop'"
args = ei.egg_info, ei.broken_egg_info
raise DistutilsError(template % args)
self.args = [ei.egg_name]

# the .pth file should point to target
self.egg_base = ei.egg_base
self.dist_info = self.get_finalized_command("dist_info")
self.egg_base = self.dist_info.egg_base
self.dist_info_dir = Path(self.dist_info.dist_info_dir)
self.target = pkg_resources.normalize_path(self.egg_base)
self.dist_info_dir = Path(
(ei.egg_info[: -len(".egg-info")] + ".dist-info").rpartition("/")[-1]
)

def build_editable_wheel(self):
if getattr(self.distribution, "use_2to3", False):
Expand All @@ -66,10 +64,6 @@ def build_editable_wheel(self):
self.reinitialize_command("build_ext", inplace=1)
self.run_command("build_ext")

# now build the wheel
# with the dist-info directory and .pth from 'editables' library
# ...

mtime = time.gmtime(SOURCE_EPOCH_ZIP)[:6]

dist_dir = Path(self.dist_dir)
Expand All @@ -80,8 +74,6 @@ def build_editable_wheel(self):
wheel_name = f"{fullname}-ed.py3-none-any.whl"
wheel_path = dist_dir / wheel_name

wheelmeta_builder(dist_dir / dist_info_dir / "WHEEL")

if wheel_path.exists():
wheel_path.unlink()

Expand All @@ -96,6 +88,10 @@ def build_editable_wheel(self):
info = ZipInfo(str(dist_info_dir / f), mtime)
archive.writestr(info, metadata.read())

# Add WHEEL file
info = ZipInfo(str(dist_info_dir / "WHEEL"), mtime)
archive.writestr(info, WHEEL_FILE)

add_manifest(archive, dist_info_dir)


Expand Down Expand Up @@ -127,15 +123,3 @@ def add_manifest(archive, dist_info_dir):
zipfile.ZipInfo(str(record_path), time.gmtime(SOURCE_EPOCH_ZIP)[:6]), RECORD
)
archive.close()


def wheelmeta_builder(target):
with open(target, "w+") as f:
f.write(
"""Wheel-Version: 1.0
Generator: setuptools_pep660 (0.1)
Root-Is-Purelib: false
Tag: py3-none-any
Tag: ed-none-any
"""
)

0 comments on commit 3e9f441

Please sign in to comment.