Simplify setting to require parent package

This commit is contained in:
Matthew Honnibal 2024-09-29 14:19:10 +02:00
parent 969832f5d6
commit 3b165a8716

View File

@ -116,9 +116,7 @@ def package(
if not meta_path.exists() or not meta_path.is_file(): if not meta_path.exists() or not meta_path.is_file():
msg.fail("Can't load pipeline meta.json", meta_path, exits=1) msg.fail("Can't load pipeline meta.json", meta_path, exits=1)
meta = srsly.read_json(meta_path) meta = srsly.read_json(meta_path)
meta = get_meta(input_dir, meta) meta = get_meta(input_dir, meta, require_parent=not no_require_parent)
if no_require_parent:
msg.info("Excluding parent package {about.__title__} from requirements")
if meta["requirements"]: if meta["requirements"]:
msg.good( msg.good(
f"Including {len(meta['requirements'])} package requirement(s) from " f"Including {len(meta['requirements'])} package requirement(s) from "
@ -192,7 +190,7 @@ def package(
shutil.copy(str(code_path), str(package_path)) shutil.copy(str(code_path), str(package_path))
create_file(main_path / "meta.json", srsly.json_dumps(meta, indent=2)) create_file(main_path / "meta.json", srsly.json_dumps(meta, indent=2))
create_file(main_path / "setup.py", TEMPLATE_SETUP % ("False" if no_require_parent else "True")) create_file(main_path / "setup.py", TEMPLATE_SETUP)
create_file(main_path / "MANIFEST.in", TEMPLATE_MANIFEST) create_file(main_path / "MANIFEST.in", TEMPLATE_MANIFEST)
init_py = TEMPLATE_INIT.format( init_py = TEMPLATE_INIT.format(
imports="\n".join(f"from . import {m}" for m in imports) imports="\n".join(f"from . import {m}" for m in imports)
@ -340,7 +338,9 @@ def create_file(file_path: Path, contents: str) -> None:
def get_meta( def get_meta(
model_path: Union[str, Path], existing_meta: Dict[str, Any] model_path: Union[str, Path],
existing_meta: Dict[str, Any],
require_parent: bool = False,
) -> Dict[str, Any]: ) -> Dict[str, Any]:
meta: Dict[str, Any] = { meta: Dict[str, Any] = {
"lang": "en", "lang": "en",
@ -369,6 +369,8 @@ def get_meta(
existing_reqs = [util.split_requirement(req)[0] for req in meta["requirements"]] existing_reqs = [util.split_requirement(req)[0] for req in meta["requirements"]]
reqs = get_third_party_dependencies(nlp.config, exclude=existing_reqs) reqs = get_third_party_dependencies(nlp.config, exclude=existing_reqs)
meta["requirements"].extend(reqs) meta["requirements"].extend(reqs)
if require_parent and about.__title__ not in meta["requirements"]:
meta["requirements"].append(about.__title__)
return meta return meta
@ -519,9 +521,6 @@ from shutil import copy
from setuptools import setup from setuptools import setup
REQUIRE_PARENT_PACKAGE = %s
def load_meta(fp): def load_meta(fp):
with io.open(fp, encoding='utf8') as f: with io.open(fp, encoding='utf8') as f:
return json.load(f) return json.load(f)
@ -546,11 +545,11 @@ def list_files(data_dir):
def list_requirements(meta): def list_requirements(meta):
parent_package = meta.get('parent_package', 'spacy') # Up to version 3.7, we included the parent package
if REQUIRE_PARENT_PACKAGE: # in requirements by default. This behaviour is removed
requirements = [parent_package] # in 3.8, with a setting to include the parent package in
else: # the requirements list in the meta if desired.
requirements = [] requirements = []
if 'setup_requires' in meta: if 'setup_requires' in meta:
requirements += meta['setup_requires'] requirements += meta['setup_requires']
if 'requirements' in meta: if 'requirements' in meta: