我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用setuptools.findall()。
def _get_commands(dist # type: setuptools.dist.Distribution ): # type: (...) -> typing.Dict[str, typing.Set[str]] """Find all commands belonging to the given distribution. Args: dist: The Distribution to search for docopt-compatible docstrings that can be used to generate command entry points. Returns: A dictionary containing a mapping of primary commands to sets of subcommands. """ py_files = (f for f in setuptools.findall() if os.path.splitext(f)[1].lower() == '.py') pkg_files = (f for f in py_files if _get_package_name(f) in dist.packages) commands = {} # type: typing.Dict[str, typing.Set[str]] for file_name in pkg_files: with open(file_name) as py_file: module = typing.cast(ast.Module, ast.parse(py_file.read())) module_name = _get_module_name(file_name) _append_commands(commands, module_name, _get_module_commands(module)) _append_commands(commands, module_name, _get_class_commands(module)) _append_commands(commands, module_name, _get_function_commands(module)) return commands
def patch_all(): # we can't patch distutils.cmd, alas distutils.core.Command = setuptools.Command has_issue_12885 = sys.version_info <= (3, 5, 3) if has_issue_12885: # fix findall bug in distutils (http://bugs.python.org/issue12885) distutils.filelist.findall = setuptools.findall needs_warehouse = ( sys.version_info < (2, 7, 13) or (3, 0) < sys.version_info < (3, 3, 7) or (3, 4) < sys.version_info < (3, 4, 6) or (3, 5) < sys.version_info <= (3, 5, 3) ) if needs_warehouse: warehouse = 'https://upload.pypi.org/legacy/' distutils.config.PyPIRCCommand.DEFAULT_REPOSITORY = warehouse _patch_distribution_metadata_write_pkg_file() _patch_distribution_metadata_write_pkg_info() # Install Distribution throughout the distutils for module in distutils.dist, distutils.core, distutils.cmd: module.Distribution = setuptools.dist.Distribution # Install the patched Extension distutils.core.Extension = setuptools.extension.Extension distutils.extension.Extension = setuptools.extension.Extension if 'distutils.command.build_ext' in sys.modules: sys.modules['distutils.command.build_ext'].Extension = ( setuptools.extension.Extension ) patch_for_msvc_specialized_compiler()
def _find_data_files(): """Traverses the schema directory to identify all XSDs. Returns: A list of (target_directory: [files_list]) tuples. """ data_files = collections.defaultdict(list) for filepath in findall('schemas'): if not filepath.endswith('.xsd'): continue directory, unused_filename = os.path.split(filepath) data_files[os.path.join('dsrf', directory)].append(filepath) return [(k, v) for k, v in data_files.iteritems()]
def egg_info_writer(cmd, basename, filename): # type: (setuptools.command.egg_info.egg_info, str, str) -> None """Read rcli configuration and write it out to the egg info. Args: cmd: An egg info command instance to use for writing. basename: The basename of the file to write. filename: The full path of the file to write into the egg info. """ setupcfg = next((f for f in setuptools.findall() if os.path.basename(f) == 'setup.cfg'), None) if not setupcfg: return parser = six.moves.configparser.ConfigParser() # type: ignore parser.read(setupcfg) if not parser.has_section('rcli') or not parser.items('rcli'): return config = dict(parser.items('rcli')) for k, v in six.iteritems(config): if v.lower() in ('y', 'yes', 'true'): config[k] = True elif v.lower() in ('n', 'no', 'false'): config[k] = False else: try: config[k] = json.loads(v) except ValueError: pass cmd.write_file(basename, filename, json.dumps(config))
def test_findall(example_source): found = list(setuptools.findall(str(example_source))) expected = ['readme.txt', 'foo/bar.py'] expected = [example_source.join(fn) for fn in expected] assert found == expected
def test_findall_curdir(example_source): with example_source.as_cwd(): found = list(setuptools.findall()) expected = ['readme.txt', os.path.join('foo', 'bar.py')] assert found == expected
def test_findall_missing_symlink(tmpdir, can_symlink): with tmpdir.as_cwd(): os.symlink('foo', 'bar') found = list(setuptools.findall()) assert found == []
def findsome(subdir, extensions): """Find files under subdir having specified extensions Leading directory (niceman) gets stripped """ return [ f.split(pathsep, 1)[1] for f in findall(opj('niceman', subdir)) if splitext(f)[-1].lstrip('.') in extensions ] # niceman version to be installed