def test_dir_in_package_data(self): """ A directory in package_data should not be added to the filelist. """ # See bug 19286 sources = self.mkdtemp() pkg_dir = os.path.join(sources, "pkg") os.mkdir(pkg_dir) open(os.path.join(pkg_dir, "__init__.py"), "w").close() docdir = os.path.join(pkg_dir, "doc") os.mkdir(docdir) open(os.path.join(docdir, "testfile"), "w").close() # create the directory that could be incorrectly detected as a file os.mkdir(os.path.join(docdir, 'otherdir')) os.chdir(sources) dist = Distribution({"packages": ["pkg"], "package_data": {"pkg": ["doc/*"]}}) # script_name need not exist, it just need to be initialized dist.script_name = os.path.join(sources, "setup.py") dist.script_args = ["build"] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail("failed package_data when data dir includes a dir")
def test_empty_package_dir(self): cwd = os.getcwd() sources = self.mkdtemp() open(os.path.join(sources, '__init__.py'), 'w').close() testdir = os.path.join(sources, 'doc') os.mkdir(testdir) open(os.path.join(testdir, 'testfile'), 'w').close() os.chdir(sources) old_stdout = sys.stdout sys.stdout = StringIO.StringIO() try: dist = Distribution({'packages': ['pkg'], 'package_dir': {'pkg': ''}, 'package_data': {'pkg': ['doc/*']}}) dist.script_name = os.path.join(sources, 'setup.py') dist.script_args = ['build'] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail("failed package_data test when package_dir is ''") finally: os.chdir(cwd) sys.stdout = old_stdout
def test_empty_package_dir (self): # See SF 1668596/1720897. cwd = os.getcwd() # create the distribution files. sources = self.mkdtemp() open(os.path.join(sources, "__init__.py"), "w").close() testdir = os.path.join(sources, "doc") os.mkdir(testdir) open(os.path.join(testdir, "testfile"), "w").close() os.chdir(sources) old_stdout = sys.stdout sys.stdout = StringIO.StringIO() try: dist = Distribution({"packages": ["pkg"], "package_dir": {"pkg": ""}, "package_data": {"pkg": ["doc/*"]}}) # script_name need not exist, it just need to be initialized dist.script_name = os.path.join(sources, "setup.py") dist.script_args = ["build"] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail("failed package_data test when package_dir is ''") finally: # Restore state. os.chdir(cwd) sys.stdout = old_stdout
def test_empty_package_dir(self): cwd = os.getcwd() sources = self.mkdtemp() open(os.path.join(sources, '__init__.py'), 'w').close() testdir = os.path.join(sources, 'doc') os.mkdir(testdir) open(os.path.join(testdir, 'testfile'), 'w').close() os.chdir(sources) old_stdout = sys.stdout sys.stdout = StringIO.StringIO() try: dist = Distribution({ 'packages': ['pkg'], 'package_dir': { 'pkg': '' }, 'package_data': { 'pkg': ['doc/*'] } }) dist.script_name = os.path.join(sources, 'setup.py') dist.script_args = ['build'] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail("failed package_data test when package_dir is ''") finally: os.chdir(cwd) sys.stdout = old_stdout
def test_dir_in_package_data(self): """ A directory in package_data should not be added to the filelist. """ sources = self.mkdtemp() pkg_dir = os.path.join(sources, 'pkg') os.mkdir(pkg_dir) open(os.path.join(pkg_dir, '__init__.py'), 'w').close() docdir = os.path.join(pkg_dir, 'doc') os.mkdir(docdir) open(os.path.join(docdir, 'testfile'), 'w').close() os.mkdir(os.path.join(docdir, 'otherdir')) os.chdir(sources) dist = Distribution({ 'packages': ['pkg'], 'package_data': { 'pkg': ['doc/*'] } }) dist.script_name = os.path.join(sources, 'setup.py') dist.script_args = ['build'] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail('failed package_data when data dir includes a dir')
def test_empty_package_dir(self): # See bugs #1668596/#1720897 sources = self.mkdtemp() open(os.path.join(sources, "__init__.py"), "w").close() testdir = os.path.join(sources, "doc") os.mkdir(testdir) open(os.path.join(testdir, "testfile"), "w").close() os.chdir(sources) dist = Distribution({ "packages": ["pkg"], "package_dir": { "pkg": "" }, "package_data": { "pkg": ["doc/*"] } }) # script_name need not exist, it just need to be initialized dist.script_name = os.path.join(sources, "setup.py") dist.script_args = ["build"] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail("failed package_data test when package_dir is ''")
def test_dir_in_package_data(self): """ A directory in package_data should not be added to the filelist. """ # See bug 19286 sources = self.mkdtemp() pkg_dir = os.path.join(sources, "pkg") os.mkdir(pkg_dir) open(os.path.join(pkg_dir, "__init__.py"), "w").close() docdir = os.path.join(pkg_dir, "doc") os.mkdir(docdir) open(os.path.join(docdir, "testfile"), "w").close() # create the directory that could be incorrectly detected as a file os.mkdir(os.path.join(docdir, 'otherdir')) os.chdir(sources) dist = Distribution({ "packages": ["pkg"], "package_data": { "pkg": ["doc/*"] } }) # script_name need not exist, it just need to be initialized dist.script_name = os.path.join(sources, "setup.py") dist.script_args = ["build"] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail("failed package_data when data dir includes a dir")
def BuildExtension(sources, output_dir, extension_name): from distutils import log from distutils.core import Distribution, Extension import os import tempfile build_dir = tempfile.mkdtemp() # Source file paths must be relative to current path. cwd = os.getcwd() src_files = [os.path.relpath(filename, cwd) for filename in sources] ext = Extension(extension_name, src_files) if os.name == 'nt': _FixDistutilsMsvcCompiler() # VS 2010 does not generate manifest, see http://bugs.python.org/issue4431 ext.extra_link_args = ['/MANIFEST'] dist = Distribution({ 'ext_modules': [ext] }) dist.script_args = ['build_ext', '--build-temp', build_dir, '--build-lib', output_dir] dist.parse_command_line() log.set_threshold(log.DEBUG) dist.run_commands() dist.script_args = ['clean', '--build-temp', build_dir, '--all'] dist.parse_command_line() log.set_threshold(log.DEBUG) dist.run_commands()
def test_dir_in_package_data(self): """ A directory in package_data should not be added to the filelist. """ sources = self.mkdtemp() pkg_dir = os.path.join(sources, 'pkg') os.mkdir(pkg_dir) open(os.path.join(pkg_dir, '__init__.py'), 'w').close() docdir = os.path.join(pkg_dir, 'doc') os.mkdir(docdir) open(os.path.join(docdir, 'testfile'), 'w').close() os.mkdir(os.path.join(docdir, 'otherdir')) os.chdir(sources) dist = Distribution({'packages': ['pkg'], 'package_data': {'pkg': ['doc/*']}}) dist.script_name = os.path.join(sources, 'setup.py') dist.script_args = ['build'] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail('failed package_data when data dir includes a dir')
def test_empty_package_dir(self): # See bugs #1668596/#1720897 sources = self.mkdtemp() open(os.path.join(sources, "__init__.py"), "w").close() testdir = os.path.join(sources, "doc") os.mkdir(testdir) open(os.path.join(testdir, "testfile"), "w").close() os.chdir(sources) dist = Distribution({"packages": ["pkg"], "package_dir": {"pkg": ""}, "package_data": {"pkg": ["doc/*"]}}) # script_name need not exist, it just need to be initialized dist.script_name = os.path.join(sources, "setup.py") dist.script_args = ["build"] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail("failed package_data test when package_dir is ''")
lines = msg.split('\n') size = max(len(l) + 1 for l in lines) print('-' * (size + 2)) for l in lines: print('|{}{}|'.format(l, ' ' * (size - len(l)))) print('-' * (size + 2)) if __name__ == '__main__': # Parse the command line and check the arguments # before we proceed with building deps and setup dist = Distribution() dist.script_name = sys.argv[0] dist.script_args = sys.argv[1:] try: ok = dist.parse_command_line() except DistutilsArgError as msg: raise SystemExit( core.gen_usage(dist.script_name) + "\nerror: %s" % msg) if not ok: sys.exit() if RUN_BUILD_DEPS: build_deps() extensions, cmdclass, packages, entry_points = configure_extension_build() setup( name=package_name, version=version, description=("Tensors and Dynamic neural networks in "
def parse_command_line(self): """Process features after parsing command line options""" result = _Distribution.parse_command_line(self) if self.features: self._finalize_features() return result
path = os.path.dirname(os.path.realpath(__file__)) os.system("chmod a+r -R %s"%join(path, "smc_pyutil", "templates")) def readme(): with open('README.md') as f: return f.read() from setuptools import setup, find_packages # This checks, if setup.py is run with 'install --user' # in that case we assume it is installed for development and do NOT change the python executable. # Therefore we want to load the local library via the site.py mechanism. # (this mimics http://svn.python.org/projects/python/trunk/Lib/distutils/dist.py, called in setup behind the scenes) from distutils.core import Distribution d = Distribution() d.parse_command_line() # CRITICAL! # Uses a wrapped python executable to not load the user's "site" packages in ~/.local. # Otherwise, setuptool's startup scripts do not work, if there is a conflicting # setuptools version in .local/lib/python-packages (or, any other locally installed python lib) # setting sys.executable changes the she-bang #!... at the top of these scripts # credits to http://stackoverflow.com/a/17329493 python2_nosite = '/usr/local/bin/python2-nosite' # don't overwrite for local smc-in-smc development if 'user' not in d.command_options.get("install", {}).keys(): # check, if python2_nosite exists and is executable if os.path.isfile(python2_nosite) and os.access(python2_nosite, os.X_OK): import sys sys.executable = python2_nosite
def readme(): with open('README.md') as f: return f.read() # from https://github.com/ninjaaron/fast-entry_points/ issue https://github.com/sagemathinc/cocalc/issues/2259 import fastentrypoints from setuptools import setup, find_packages # This checks, if setup.py is run with 'install --user' # in that case we assume it is installed for development and do NOT change the python executable. # Therefore we want to load the local library via the site.py mechanism. # (this mimics http://svn.python.org/projects/python/trunk/Lib/distutils/dist.py, called in setup behind the scenes) from distutils.core import Distribution d = Distribution() d.parse_command_line() # CRITICAL! # Uses a wrapped python executable to not load the user's "site" packages in ~/.local. # Otherwise, setuptool's startup scripts do not work, if there is a conflicting # setuptools version in .local/lib/python-packages (or, any other locally installed python lib) # setting sys.executable changes the she-bang #!... at the top of these scripts # credits to http://stackoverflow.com/a/17329493 python2_nosite = '/usr/local/bin/python2-nosite' # don't overwrite for local smc-in-smc development if 'user' not in d.command_options.get("install", {}).keys(): # check, if python2_nosite exists and is executable if os.path.isfile(python2_nosite) and os.access(python2_nosite, os.X_OK): import sys sys.executable = python2_nosite
try: sha = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=cwd).decode("ascii").strip() except Exception: pass if sha != "Unknown": version += "+" + sha[:7] return sha if __name__ == '__main__': dist = Distribution() dist.script_name = sys.argv[0] dist.script_args = sys.argv[1:] try: is_valid_args = dist.parse_command_line() except DistutilsArgError as msg: raise SystemExit(f"{core.gen_usage(dist.script_name)}\nerror:{msg}") if not is_valid_args: sys.exit() check_env_args() extensions, cmdclass, install_requires = build_config_setup() cwd = os.path.dirname(os.path.abspath(__file__)) sha = get_version() version_path = os.path.join(cwd, "pytorch_nndct", "version.py") with open(version_path, "w") as f: f.write(f"__version__ = '{version}'\n") f.write(f"git_version = '{sha}'\n")