From 2b39f1e8997401cbc89cf2f3a771e0348bf956b3 Mon Sep 17 00:00:00 2001 From: Nikita Shulga Date: Mon, 9 Nov 2020 01:51:53 -0800 Subject: [PATCH] Do not build unless setup.py is top-level scope (#2969) I.e. put all file system altering operations under `if __name__ == "__main__":` --- setup.py | 67 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/setup.py b/setup.py index 093307ab612..291523c03c1 100644 --- a/setup.py +++ b/setup.py @@ -44,7 +44,6 @@ def get_dist(pkgname): version = os.getenv('BUILD_VERSION') elif sha != 'Unknown': version += '+' + sha[:7] -print("Building wheel {}-{}".format(package_name, version)) def write_version_file(): @@ -57,10 +56,6 @@ def write_version_file(): f.write(" cuda = _check_cuda_version()\n") -write_version_file() - -readme = open('README.rst').read() - pytorch_dep = 'torch' if os.getenv('PYTORCH_VERSION'): pytorch_dep += "==" + os.getenv('PYTORCH_VERSION') @@ -397,30 +392,38 @@ def run(self): distutils.command.clean.clean.run(self) -setup( - # Metadata - name=package_name, - version=version, - author='PyTorch Core Team', - author_email='soumith@pytorch.org', - url='https://github.com/pytorch/vision', - description='image and video datasets and models for torch deep learning', - long_description=readme, - license='BSD', - - # Package info - packages=find_packages(exclude=('test',)), - package_data={ - package_name: ['*.dll', '*.dylib', '*.so'] - }, - zip_safe=False, - install_requires=requirements, - extras_require={ - "scipy": ["scipy"], - }, - ext_modules=get_extensions(), - cmdclass={ - 'build_ext': BuildExtension.with_options(no_python_abi_suffix=True), - 'clean': clean, - } -) +if __name__ == "__main__": + print("Building wheel {}-{}".format(package_name, version)) + + write_version_file() + + with open('README.rst') as f: + readme = f.read() + + setup( + # Metadata + name=package_name, + version=version, + author='PyTorch Core Team', + author_email='soumith@pytorch.org', + url='https://github.com/pytorch/vision', + description='image and video datasets and models for torch deep learning', + long_description=readme, + license='BSD', + + # Package info + packages=find_packages(exclude=('test',)), + package_data={ + package_name: ['*.dll', '*.dylib', '*.so'] + }, + zip_safe=False, + install_requires=requirements, + extras_require={ + "scipy": ["scipy"], + }, + ext_modules=get_extensions(), + cmdclass={ + 'build_ext': BuildExtension.with_options(no_python_abi_suffix=True), + 'clean': clean, + } + )