Пример #1
0
def get_entrypoints(filename):
    if not os.path.exists(filename):
        return {}, {}

    # This is done because you can pass a string to entry_points wrappers which
    # means that they may or may not be valid INI files. The attempt here is to
    # strip leading and trailing whitespace in order to make them valid INI
    # files.
    with open(filename) as fp:
        data = StringIO()
        for line in fp:
            data.write(line.strip())
            data.write("\n")
        data.seek(0)

    cp = configparser.RawConfigParser()
    cp.readfp(data)

    console = {}
    gui = {}
    if cp.has_section('console_scripts'):
        console = dict(cp.items('console_scripts'))
    if cp.has_section('gui_scripts'):
        gui = dict(cp.items('gui_scripts'))
    return console, gui
Пример #2
0
 def _construct_parser(self, fname):
     # type: (str) -> RawConfigParser
     parser = configparser.RawConfigParser()
     # If there is no such file, don't bother reading it but create the
     # parser anyway, to hold the data.
     # Doing this is useful when modifying and saving files, where we don't
     # need to construct a parser.
     if os.path.exists(fname):
Пример #3
0
 def __init__(self, *args, **kwargs):
     self.config = configparser.RawConfigParser()
     self.name = kwargs.pop('name')
     self.isolated = kwargs.pop("isolated", False)
     self.files = self.get_config_files()
     if self.files:
         self.config.read(self.files)
     assert self.name
     optparse.OptionParser.__init__(self, *args, **kwargs)
Пример #4
0
 def switch(self, dest, url, rev_options):
     # type: (str, HiddenText, RevOptions) -> None
     repo_config = os.path.join(dest, self.dirname, "hgrc")
     config = configparser.RawConfigParser()
     try:
         config.read(repo_config)
         config.set("paths", "default", url.secret)
         with open(repo_config, "w") as config_file:
             config.write(config_file)
     except (OSError, configparser.NoSectionError) as exc:
         logger.warning("Could not switch Mercurial repository to %s: %s", url, exc)
     else:
         cmd_args = make_command("update", "-q", rev_options.to_args())
         self.run_command(cmd_args, cwd=dest)
Пример #5
0
 def switch(self, dest, url, rev_options):
     repo_config = os.path.join(dest, self.dirname, 'hgrc')
     config = configparser.RawConfigParser()
     try:
         config.read(repo_config)
         config.set('paths', 'default', url)
         with open(repo_config, 'w') as config_file:
             config.write(config_file)
     except (OSError, configparser.NoSectionError) as exc:
         logger.warning(
             'Could not switch Mercurial repository to %s: %s',
             url,
             exc,
         )
     else:
         cmd_args = ['update', '-q'] + rev_options.to_args()
         self.run_command(cmd_args, cwd=dest)
Пример #6
0
 def _construct_parser(self, fname):
     # type: (str) -> RawConfigParser
     parser = configparser.RawConfigParser()
     # If there is no such file, don't bother reading it but create the
     # parser anyway, to hold the data.
     # Doing this is useful when modifying and saving files, where we don't
     # need to construct a parser.
     if os.path.exists(fname):
         try:
             parser.read(fname)
         except UnicodeDecodeError:
             raise ConfigurationError(
                 ("ERROR: "
                  "Configuration file contains invalid %s characters.\n"
                  "Please fix your configuration, located at %s\n") %
                 (locale.getpreferredencoding(False), fname))
     return parser
 def switch(self, dest, url, rev_options):
     # type: (str, HiddenText, RevOptions) -> None
     repo_config = os.path.join(dest, dirname, 'hgrc')
     config = configparser.RawConfigParser()
     try:
         config.read(repo_config)
         config.set('paths', 'default', url.secret)
         with open(repo_config, 'w') as config_file:
             config.write(config_file)
     except (OSError, configparser.NoSectionError) as exc:
         logger.warning(
             'Could not switch Mercurial repository to %s: %s',
             url,
             exc,
         )
     else:
         cmd_args = make_command('update', '-q', rev_options.to_args())
         run_command(cmd_args, cwd=dest)
Пример #8
0
def test_mercurial_switch_updates_config_file_when_found(tmpdir):
    hg = Mercurial()
    options = hg.make_rev_options()
    hg_dir = os.path.join(tmpdir, '.hg')
    os.mkdir(hg_dir)

    config = configparser.RawConfigParser()
    config.add_section('paths')
    config.set('paths', 'default', 'old_url')

    hgrc_path = os.path.join(hg_dir, 'hgrc')
    with open(hgrc_path, 'w') as f:
        config.write(f)
    hg.switch(tmpdir, hide_url('new_url'), options)

    config.read(hgrc_path)

    default_path = config.get('paths', 'default')
    assert default_path == 'new_url'
Пример #9
0
 def _construct_parser(self, fname):
     # type: (str) -> RawConfigParser
     parser = configparser.RawConfigParser()
     # If there is no such file, don't bother reading it but create the
     # parser anyway, to hold the data.
     # Doing this is useful when modifying and saving files, where we don't
     # need to construct a parser.
     if os.path.exists(fname):
         try:
             parser.read(fname)
         except UnicodeDecodeError:
             # See https://github.com/pypa/pip/issues/4963
             raise ConfigurationFileCouldNotBeLoaded(
                 reason="contains invalid {} characters".format(
                     locale.getpreferredencoding(False)),
                 fname=fname,
             )
         except configparser.Error as error:
             # See https://github.com/pypa/pip/issues/4893
             raise ConfigurationFileCouldNotBeLoaded(error=error)
     return parser
Пример #10
0
 def __init__(self, isolated):
     self._configparser = configparser.RawConfigParser()
     self._config = {}
     self.isolated = isolated
Пример #11
0
 def __init__(self):
     self._configparser = configparser.RawConfigParser()
     self._config = {}