Support option to not depend on parent package in spacy package

This commit is contained in:
Matthew Honnibal 2024-09-29 13:51:04 +02:00
parent 5010fcbd3a
commit 6fa0d709d5
1 changed files with 16 additions and 2 deletions

View File

@ -30,6 +30,7 @@ def package_cli(
version: Optional[str] = Opt(None, "--version", "-v", help="Package version to override meta"),
build: str = Opt("sdist", "--build", "-b", help="Comma-separated formats to build: sdist and/or wheel, or none."),
force: bool = Opt(False, "--force", "-f", "-F", help="Force overwriting existing data in output directory"),
no_require_parent: bool = Opt(False, "--no-require-parent", "-R", "-R", help="Don't include the parent package (e.g. spacy) in the requirements"),
# fmt: on
):
"""
@ -60,6 +61,7 @@ def package_cli(
create_sdist=create_sdist,
create_wheel=create_wheel,
force=force,
no_require_parent=no_require_parent
silent=False,
)
@ -74,6 +76,7 @@ def package(
create_meta: bool = False,
create_sdist: bool = True,
create_wheel: bool = False,
no_require_parent: bool = False,
force: bool = False,
silent: bool = True,
) -> None:
@ -114,6 +117,8 @@ def package(
msg.fail("Can't load pipeline meta.json", meta_path, exits=1)
meta = srsly.read_json(meta_path)
meta = get_meta(input_dir, meta)
if no_require_parent:
msg.info("Excluding parent package {about.__title__} from requirements")
if meta["requirements"]:
msg.good(
f"Including {len(meta['requirements'])} package requirement(s) from "
@ -186,7 +191,8 @@ def package(
imports.append(code_path.stem)
shutil.copy(str(code_path), str(package_path))
create_file(main_path / "meta.json", srsly.json_dumps(meta, indent=2))
create_file(main_path / "setup.py", TEMPLATE_SETUP)
create_file(main_path / "setup.py", TEMPLATE_SETUP.format(require_parent="False" if no_require_parent else "True"))
create_file(main_path / "MANIFEST.in", TEMPLATE_MANIFEST)
init_py = TEMPLATE_INIT.format(
imports="\n".join(f"from . import {m}" for m in imports)
@ -302,6 +308,8 @@ def get_third_party_dependencies(
modules.add(func_info["module"].split(".")[0]) # type: ignore[union-attr]
dependencies = []
for module_name in modules:
if no_depend_on_spacy and module_name == "spacy":
continue
if module_name in distributions:
dist = distributions.get(module_name)
if dist:
@ -511,6 +519,9 @@ from shutil import copy
from setuptools import setup
REQUIRE_PARENT_PACKAGE = {require_parent}
def load_meta(fp):
with io.open(fp, encoding='utf8') as f:
return json.load(f)
@ -536,7 +547,10 @@ def list_files(data_dir):
def list_requirements(meta):
parent_package = meta.get('parent_package', 'spacy')
requirements = [parent_package + meta['spacy_version']]
if REQUIRE_PARENT_PACKAGE:
requirements = [parent_package]
else:
requirements = []
if 'setup_requires' in meta:
requirements += meta['setup_requires']
if 'requirements' in meta: