mirror of https://github.com/explosion/spaCy.git
Support option to not depend on parent package in spacy package
This commit is contained in:
parent
5010fcbd3a
commit
6fa0d709d5
|
@ -30,6 +30,7 @@ def package_cli(
|
||||||
version: Optional[str] = Opt(None, "--version", "-v", help="Package version to override meta"),
|
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."),
|
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"),
|
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
|
# fmt: on
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
|
@ -60,6 +61,7 @@ def package_cli(
|
||||||
create_sdist=create_sdist,
|
create_sdist=create_sdist,
|
||||||
create_wheel=create_wheel,
|
create_wheel=create_wheel,
|
||||||
force=force,
|
force=force,
|
||||||
|
no_require_parent=no_require_parent
|
||||||
silent=False,
|
silent=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -74,6 +76,7 @@ def package(
|
||||||
create_meta: bool = False,
|
create_meta: bool = False,
|
||||||
create_sdist: bool = True,
|
create_sdist: bool = True,
|
||||||
create_wheel: bool = False,
|
create_wheel: bool = False,
|
||||||
|
no_require_parent: bool = False,
|
||||||
force: bool = False,
|
force: bool = False,
|
||||||
silent: bool = True,
|
silent: bool = True,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -114,6 +117,8 @@ def package(
|
||||||
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)
|
||||||
|
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 "
|
||||||
|
@ -186,7 +191,8 @@ def package(
|
||||||
imports.append(code_path.stem)
|
imports.append(code_path.stem)
|
||||||
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)
|
|
||||||
|
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)
|
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)
|
||||||
|
@ -302,6 +308,8 @@ def get_third_party_dependencies(
|
||||||
modules.add(func_info["module"].split(".")[0]) # type: ignore[union-attr]
|
modules.add(func_info["module"].split(".")[0]) # type: ignore[union-attr]
|
||||||
dependencies = []
|
dependencies = []
|
||||||
for module_name in modules:
|
for module_name in modules:
|
||||||
|
if no_depend_on_spacy and module_name == "spacy":
|
||||||
|
continue
|
||||||
if module_name in distributions:
|
if module_name in distributions:
|
||||||
dist = distributions.get(module_name)
|
dist = distributions.get(module_name)
|
||||||
if dist:
|
if dist:
|
||||||
|
@ -511,6 +519,9 @@ from shutil import copy
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
|
|
||||||
|
REQUIRE_PARENT_PACKAGE = {require_parent}
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
|
@ -536,7 +547,10 @@ def list_files(data_dir):
|
||||||
|
|
||||||
def list_requirements(meta):
|
def list_requirements(meta):
|
||||||
parent_package = meta.get('parent_package', 'spacy')
|
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:
|
if 'setup_requires' in meta:
|
||||||
requirements += meta['setup_requires']
|
requirements += meta['setup_requires']
|
||||||
if 'requirements' in meta:
|
if 'requirements' in meta:
|
||||||
|
|
Loading…
Reference in New Issue