3939 b) with a parameterization build desired packages in to standard `dist/` folder
4040 c) validate packages and publish to PyPI
4141"""
42- import contextlib
4342import os
44- import tempfile
4543from importlib .util import module_from_spec , spec_from_file_location
4644from types import ModuleType
47- from typing import Generator , Optional
4845
49- import setuptools
50- import setuptools .command .egg_info
46+ from setuptools import setup
5147
5248_PACKAGE_NAME = os .environ .get ("PACKAGE_NAME" )
5349_PACKAGE_MAPPING = {
@@ -73,43 +69,6 @@ def _load_py_module(name: str, location: str) -> ModuleType:
7369 return py
7470
7571
76- def _named_temporary_file (directory : Optional [str ] = None ) -> str :
77- # `tempfile.NamedTemporaryFile` has issues in Windows
78- # https://github.com/deepchem/deepchem/issues/707#issuecomment-556002823
79- if directory is None :
80- directory = tempfile .gettempdir ()
81- return os .path .join (directory , os .urandom (24 ).hex ())
82-
83-
84- @contextlib .contextmanager
85- def _set_manifest_path (manifest_dir : str , aggregate : bool = False ) -> Generator :
86- if aggregate :
87- # aggregate all MANIFEST.in contents into a single temporary file
88- manifest_path = _named_temporary_file (manifest_dir )
89- mapping = _PACKAGE_MAPPING .copy ()
90- del mapping ["lightning" ]
91- lines = []
92- for pkg in mapping .values ():
93- with open (os .path .join (_PATH_SRC , pkg , "MANIFEST.in" )) as fh :
94- lines .extend (fh .readlines ())
95- # convert lightning_foo to lightning/foo
96- for new , old in mapping .items ():
97- lines = [line .replace (old , f"lightning/{ new } " ) for line in lines ]
98- with open (manifest_path , mode = "w" ) as fp :
99- fp .writelines (lines )
100- else :
101- manifest_path = os .path .join (manifest_dir , "MANIFEST.in" )
102- assert os .path .exists (manifest_path )
103- # avoid error: setup script specifies an absolute path
104- manifest_path = os .path .relpath (manifest_path , _PATH_ROOT )
105- setuptools .command .egg_info .manifest_maker .template = manifest_path
106- yield
107- # cleanup
108- setuptools .command .egg_info .manifest_maker .template = "MANIFEST.in"
109- if aggregate :
110- os .remove (manifest_path )
111-
112-
11372if __name__ == "__main__" :
11473 setup_tools = _load_py_module (name = "setup_tools" , location = os .path .join (_PATH_ROOT , ".actions" , "setup_tools.py" ))
11574 assistant = _load_py_module (name = "assistant" , location = os .path .join (_PATH_ROOT , ".actions" , "assistant.py" ))
@@ -129,19 +88,13 @@ def _set_manifest_path(manifest_dir: str, aggregate: bool = False) -> Generator:
12988 # should have included only the relevant files of the package to install
13089 possible_packages = _PACKAGE_MAPPING .values () if _PACKAGE_NAME is None else [_PACKAGE_MAPPING [_PACKAGE_NAME ]]
13190 for pkg in possible_packages :
132- pkg_path = os .path .join (_PATH_SRC , pkg )
133- pkg_setup = os .path .join (pkg_path , "__setup__.py" )
91+ pkg_setup = os .path .join (_PATH_SRC , pkg , "__setup__.py" )
13492 if os .path .exists (pkg_setup ):
13593 print (f"{ pkg_setup } exists. Running `setuptools.setup`" )
13694 setup_module = _load_py_module (name = f"{ pkg } _setup" , location = pkg_setup )
137- setup_args = setup_module ._setup_args ()
138- if _PACKAGE_NAME is None :
139- # we are installing a wheel, no need for MANIFEST.in things
140- setuptools .setup (** setup_args )
141- else :
142- # we are installing from source, set the correct manifest path
143- with _set_manifest_path (pkg_path , aggregate = pkg == "lightning" ):
144- setuptools .setup (** setup_args )
95+ setup_module ._adjust_manifest (pkg_name = pkg )
96+ setup_args = setup_module ._setup_args (pkg_name = pkg )
97+ setup (** setup_args )
14598 break
14699 else :
147100 raise RuntimeError (f"Something's wrong, no package was installed. Package name: { _PACKAGE_NAME } " )
0 commit comments