From 6af800b515f7392504bd1844cc544ee349bde11a Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Thu, 26 May 2016 03:11:00 -0500 Subject: [PATCH 1/9] fix comments in configs tests --- tests/test_config.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/test_config.py b/tests/test_config.py index 3c62ff6c..852dacf0 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -38,7 +38,7 @@ def sample_json_config(config_dir): def test_dict_equals_yaml(): - """Verify that example YAML is returning expected dict format.""" + # Verify that example YAML is returning expected dict format. config = kaptan.Kaptan(handler='yaml').import_config( loadfixture('example1.yaml')) @@ -100,15 +100,14 @@ def test_scan_config(tmpdir): def test_expand_shell_command_after(): - """Expand configuration into full form.""" - # Expand shell commands from string to list.""" + # Expand shell commands from string to list. config = expand_config(fixtures.config_dict) assert config, fixtures.config_dict_expanded def test_expandenv_and_homevars(): - """Assure ~ tildes and environment template vars expand.""" + # Assure ~ tildes and environment template vars expand. expanduser = os.path.expanduser expandvars = os.path.expandvars @@ -136,7 +135,7 @@ def test_expandenv_and_homevars(): def test_find_config_files(tmpdir): - """Test find_config_files in home directory.""" + # Test find_config_files in home directory. tmpdir.join('.vcspull.yaml').write('') with EnvironmentVarGuard() as env: @@ -418,7 +417,7 @@ def test_merge_nested_dict(tmpdir, config_dir): assert 'vcsOn2' not in config3_dict[str(tmpdir.join('test/')) + '/'] assert 'vcsOn2' in config4_dict[str(tmpdir.join('test/')) + '/'] - """Duplicate path + name with different repo URL / remotes raises.""" + # Duplicate path + name with different repo URL / remotes raises. configs = config.find_config_files( path=str(config_dir), match="repoduplicate[1-2]" From 4c340493e45a90673fd25c5dd2b213b613f95d55 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Thu, 26 May 2016 04:27:32 -0500 Subject: [PATCH 2/9] Simply repo duplicate test --- tests/fixtures/repoduplicate1.yaml | 8 +++--- tests/fixtures/repoduplicate2.yaml | 8 +++--- tests/test_config.py | 41 ++++++++++-------------------- 3 files changed, 21 insertions(+), 36 deletions(-) diff --git a/tests/fixtures/repoduplicate1.yaml b/tests/fixtures/repoduplicate1.yaml index 09a6465d..a69c6cad 100644 --- a/tests/fixtures/repoduplicate1.yaml +++ b/tests/fixtures/repoduplicate1.yaml @@ -1,5 +1,5 @@ -{TMP_DIR}/test/: +/path/to/test/: subRepoDiffVCS: - url: svn+file://${svn_repo_path} - subRepoSameVCS: git+file://${git_repo_path} - vcsOn1: svn+file://${svn_repo_path} + url: svn+file:///path/to/svnrepo + subRepoSameVCS: git+file://path/to/gitrepo + vcsOn1: svn+file:///path/to/another/svn diff --git a/tests/fixtures/repoduplicate2.yaml b/tests/fixtures/repoduplicate2.yaml index 0e8ec738..35df77f9 100644 --- a/tests/fixtures/repoduplicate2.yaml +++ b/tests/fixtures/repoduplicate2.yaml @@ -1,5 +1,5 @@ -{TMP_DIR}/test/: +/path/to/test/: subRepoDiffVCS: - url: git+file://${git_repo_path} - subRepoSameVCS: git+file://${git_repo_path} - vcsOn2: svn+file://${svn_repo_path} + url: git+file:///path/to/diffrepo + subRepoSameVCS: git+file:///path/to/gitrepo + vcsOn2: svn+file:///path/to/another/svn diff --git a/tests/test_config.py b/tests/test_config.py index 852dacf0..e0e6836f 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -385,37 +385,22 @@ def test_find_config_include_home_configs( def test_merge_nested_dict(tmpdir, config_dir): - # remnants of RepoIntegrationTest", todo: remove this style of templating - config_yaml3 = loadfixture('repoduplicate1.yaml').format( - svn_repo_path='lol', - hg_repo_path='lol2', - git_repo_path='lol3', - TMP_DIR=str(tmpdir) - ) - - config_yaml4 = loadfixture('repoduplicate2.yaml').format( - svn_repo_path='lol', - hg_repo_path='lol2', - git_repo_path='lol3', - TMP_DIR=str(tmpdir) - ) - - config3 = config_dir.join('repoduplicate1.yaml') - config3.write(config_yaml3) + config1 = config_dir.join('repoduplicate1.yaml') + config1.write(loadfixture(r'repoduplicate1.yaml')) - conf = kaptan.Kaptan(handler='yaml').import_config(str(config3)) - config3_dict = conf.export('dict') + conf = kaptan.Kaptan(handler='yaml').import_config(str(config1)) + config1_dict = conf.export('dict') - config4 = config_dir.join('repoduplicate2.yaml') - config4.write(config_yaml4) + config2 = config_dir.join('repoduplicate2.yaml') + config2.write(loadfixture('repoduplicate2.yaml')) - conf = kaptan.Kaptan(handler='yaml').import_config(str(config4)) - config4_dict = conf.export('dict') + conf = kaptan.Kaptan(handler='yaml').import_config(str(config2)) + config2_dict = conf.export('dict') # validate export of multiple configs + nested dirs - assert 'vcsOn1' in config3_dict[str(tmpdir.join('test/')) + '/'] - assert 'vcsOn2' not in config3_dict[str(tmpdir.join('test/')) + '/'] - assert 'vcsOn2' in config4_dict[str(tmpdir.join('test/')) + '/'] + assert 'vcsOn1' in config1_dict['/path/to/test/'] + assert 'vcsOn2' not in config1_dict['/path/to/test/'] + assert 'vcsOn2' in config2_dict['/path/to/test/'] # Duplicate path + name with different repo URL / remotes raises. configs = config.find_config_files( @@ -423,7 +408,7 @@ def test_merge_nested_dict(tmpdir, config_dir): match="repoduplicate[1-2]" ) - assert str(config3) in configs - assert str(config4) in configs + assert str(config1) in configs + assert str(config2) in configs with pytest.raises(Exception): config.load_configs(configs) From c49122cb49ea729cd010ec70dd75ef78a6578881 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Thu, 26 May 2016 04:31:00 -0500 Subject: [PATCH 3/9] simplify config tests more --- tests/test_config.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/test_config.py b/tests/test_config.py index e0e6836f..3f1172e3 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -148,7 +148,6 @@ def test_find_config_files(tmpdir): def test_multiple_configs_raises_exception(tmpdir): - tmpdir.join('.vcspull.json').write('') tmpdir.join('.vcspull.yaml').write('') with EnvironmentVarGuard() as env: @@ -388,20 +387,9 @@ def test_merge_nested_dict(tmpdir, config_dir): config1 = config_dir.join('repoduplicate1.yaml') config1.write(loadfixture(r'repoduplicate1.yaml')) - conf = kaptan.Kaptan(handler='yaml').import_config(str(config1)) - config1_dict = conf.export('dict') - config2 = config_dir.join('repoduplicate2.yaml') config2.write(loadfixture('repoduplicate2.yaml')) - conf = kaptan.Kaptan(handler='yaml').import_config(str(config2)) - config2_dict = conf.export('dict') - - # validate export of multiple configs + nested dirs - assert 'vcsOn1' in config1_dict['/path/to/test/'] - assert 'vcsOn2' not in config1_dict['/path/to/test/'] - assert 'vcsOn2' in config2_dict['/path/to/test/'] - # Duplicate path + name with different repo URL / remotes raises. configs = config.find_config_files( path=str(config_dir), From b277926bc23ec68e4869c7ce9b9b780da8ae6a49 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Thu, 26 May 2016 04:32:30 -0500 Subject: [PATCH 4/9] remove unused r string --- tests/test_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_config.py b/tests/test_config.py index 3f1172e3..a8e51bf2 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -385,7 +385,7 @@ def test_find_config_include_home_configs( def test_merge_nested_dict(tmpdir, config_dir): config1 = config_dir.join('repoduplicate1.yaml') - config1.write(loadfixture(r'repoduplicate1.yaml')) + config1.write(loadfixture('repoduplicate1.yaml')) config2 = config_dir.join('repoduplicate2.yaml') config2.write(loadfixture('repoduplicate2.yaml')) From be24de041f7b7135ad8798e99fc7ab57b529bc75 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Thu, 26 May 2016 04:50:24 -0500 Subject: [PATCH 5/9] Relative dir test midway --- tests/test_config.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_config.py b/tests/test_config.py index a8e51bf2..cebfc125 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -400,3 +400,18 @@ def test_merge_nested_dict(tmpdir, config_dir): assert str(config2) in configs with pytest.raises(Exception): config.load_configs(configs) + + +def test_relative_dir(tmpdir): + arbitrary_dir = tmpdir.join('moo') + arbitrary_dir.mkdir() + + arbitrary_dir.join('rel.yaml').write(""" +./relativedir: + docutils: svn+http://svn.code.sf.net/p/docutils/code/trunk + """) + + configs = config.find_config_files( + path=str(arbitrary_dir) + ) + repos = config.load_configs(configs) From 1a11e92da2bff57081223036d169bd95a94dac3c Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Thu, 26 May 2016 04:52:45 -0500 Subject: [PATCH 6/9] refactor names of some internal functions --- vcspull/config.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/vcspull/config.py b/vcspull/config.py index fa17a80a..ed0f3134 100644 --- a/vcspull/config.py +++ b/vcspull/config.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- """Config utility functions for vcspull. - vcspull.config ~~~~~~~~~~~~~~ @@ -217,8 +216,8 @@ def find_config_files( return configs -def load_configs(configs): - """Return repos from a directory and fnmatch. Not recursive. +def load_configs(files): + """Return repos from a list of files. :todo: Validate scheme, check for duplciate destinations, VCS urls @@ -226,33 +225,31 @@ def load_configs(configs): :type path: list :returns: expanded config dict item :rtype: list of dict - """ - configlist = [] - for config in configs: - fName, fExt = os.path.splitext(config) - conf = kaptan.Kaptan(handler=fExt.lstrip('.')) - conf.import_config(config) + repos = [] + for f in files: + _, ext = os.path.splitext(f) + conf = kaptan.Kaptan(handler=ext.lstrip('.')).import_config(f) - newconfigs = expand_config(conf.export('dict')) + newrepos = expand_config(conf.export('dict')) - if not configlist: - configlist.extend(newconfigs) + if not repos: + repos.extend(newrepos) continue - dupes = find_dupes(configlist, newconfigs) + dupes = detect_duplicate_repos(repos, newrepos) if dupes: msg = ( 'repos with same path + different VCS detected!', dupes ) raise Exception(msg) - configlist.extend(newconfigs) + repos.extend(newrepos) - return configlist + return repos -def find_dupes(repos1, repos2): +def detect_duplicate_repos(repos1, repos2): """Return duplicate repos dict if repo_dir same and vcs different. :param repos1: list of repo expanded dicts From 55f4e4d6c2a45d64e5c629279ded95ab18a03b6b Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Thu, 26 May 2016 05:03:23 -0500 Subject: [PATCH 7/9] Refactor config / repo loading to go in config module --- tests/test_config.py | 8 +-- tests/test_repo_object.py | 5 +- vcspull/__init__.py | 6 +- vcspull/cli.py | 3 +- vcspull/config.py | 123 +++++++++++++++++++++++++------------- vcspull/util.py | 81 ------------------------- 6 files changed, 93 insertions(+), 133 deletions(-) diff --git a/tests/test_config.py b/tests/test_config.py index cebfc125..a34b5d12 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -9,7 +9,7 @@ import pytest from vcspull import config, exc -from vcspull.config import expand_config +from vcspull.config import extract_repos from .fixtures import example as fixtures from .fixtures._util import loadfixture @@ -101,7 +101,7 @@ def test_scan_config(tmpdir): def test_expand_shell_command_after(): # Expand shell commands from string to list. - config = expand_config(fixtures.config_dict) + config = extract_repos(fixtures.config_dict) assert config, fixtures.config_dict_expanded @@ -121,8 +121,8 @@ def test_expandenv_and_homevars(): config2 = kaptan.Kaptan(handler='json') \ .import_config(config_json).export('dict') - config1_expanded = expand_config(config1) - config2_expanded = expand_config(config2) + config1_expanded = extract_repos(config1) + config2_expanded = extract_repos(config2) paths = [r['parent_dir'] for r in config1_expanded] assert expanduser(expandvars('${HOME}/github_projects/')) in paths diff --git a/tests/test_repo_object.py b/tests/test_repo_object.py index 6f2ac1f3..bc1bd7cb 100644 --- a/tests/test_repo_object.py +++ b/tests/test_repo_object.py @@ -7,10 +7,9 @@ import kaptan -from vcspull.config import expand_config +from vcspull.config import extract_repos, filter_repos from vcspull.repo import (BaseRepo, GitRepo, MercurialRepo, SubversionRepo, create_repo) -from vcspull.util import filter_repos from .fixtures import example as fixtures @@ -147,7 +146,7 @@ def test_makes_recursive(tmpdir, git_dummy_repo_dir): conf = kaptan.Kaptan(handler='yaml') conf.import_config(YAML_CONFIG) conf = conf.export('dict') - repos = expand_config(conf) + repos = extract_repos(conf) for r in filter_repos(repos): repo = create_repo(**r) diff --git a/vcspull/__init__.py b/vcspull/__init__.py index 7329dfa8..702d0cce 100644 --- a/vcspull/__init__.py +++ b/vcspull/__init__.py @@ -17,9 +17,10 @@ import logging from .cli import setup_logger -from .config import expand_config, is_config_file, load_configs +from .config import (extract_repos, filter_repos, in_dir, is_config_file, + load_configs) from .log import DebugLogFormatter, LogFormatter, RepoFilter, RepoLogFormatter -from .util import in_dir, filter_repos, mkdir_p, run, update_dict, which +from .util import mkdir_p, run, update_dict, which try: # Python 2.7+ from logging import NullHandler @@ -29,4 +30,3 @@ def emit(self, record): pass logging.getLogger(__name__).addHandler(NullHandler()) - diff --git a/vcspull/cli.py b/vcspull/cli.py index 2c946111..34d7cce6 100644 --- a/vcspull/cli.py +++ b/vcspull/cli.py @@ -14,10 +14,9 @@ import click from .__about__ import __version__ -from .config import find_config_files, load_configs +from .config import find_config_files, load_configs, filter_repos from .log import DebugLogFormatter from .repo import create_repo -from .util import filter_repos MIN_ASYNC = 3 # minimum amount of repos to sync concurrently diff --git a/vcspull/config.py b/vcspull/config.py index ed0f3134..8b754432 100644 --- a/vcspull/config.py +++ b/vcspull/config.py @@ -13,6 +13,7 @@ import glob import logging import os +import fnmatch import kaptan @@ -23,29 +24,6 @@ log = logging.getLogger(__name__) -def in_dir( - config_dir=CONFIG_DIR, - extensions=['.yml', '.yaml', '.json'] -): - """Return a list of configs in ``config_dir``. - - :param config_dir: directory to search - :type config_dir: string - :param extensions: filetypes to check (e.g. ``['.yaml', '.json']``). - :type extensions: list - :rtype: list - - """ - configs = [] - - for filename in os.listdir(config_dir): - if is_config_file(filename, extensions) and \ - not filename.startswith('.'): - configs.append(filename) - - return configs - - def expand_dir(_dir): """Return path with environmental variables and tilde ~ expanded. @@ -56,7 +34,7 @@ def expand_dir(_dir): return os.path.expanduser(os.path.expandvars(_dir)) -def expand_config(config): +def extract_repos(config): """Return expanded configuration. end-user configuration permit inline configuration shortcuts, expand to @@ -120,21 +98,6 @@ def expand_config(config): return configs -def is_config_file(filename, extensions=['.yml', '.yaml', '.json']): - """Return True if file has a valid config file type. - - :param filename: filename to check (e.g. ``mysession.json``). - :type filename: string - :param extensions: filetypes to check (e.g. ``['.yaml', '.json']``). - :type extensions: list or string - :rtype: bool - - """ - extensions = [extensions] if isinstance( - extensions, string_types) else extensions - return any(filename.endswith(e) for e in extensions) - - def find_home_config_files(filetype=['json', 'yaml']): """Return configs of ``.vcspull.{yaml,json}`` in user's home directory.""" configs = [] @@ -231,7 +194,7 @@ def load_configs(files): _, ext = os.path.splitext(f) conf = kaptan.Kaptan(handler=ext.lstrip('.')).import_config(f) - newrepos = expand_config(conf.export('dict')) + newrepos = extract_repos(conf.export('dict')) if not repos: repos.extend(newrepos) @@ -285,3 +248,83 @@ def detect_duplicate_repos(repos1, repos2): if n['url'] != currepo['url']: dupes += (n, currepo,) return dupes + + +def in_dir( + config_dir=CONFIG_DIR, + extensions=['.yml', '.yaml', '.json'] +): + """Return a list of configs in ``config_dir``. + + :param config_dir: directory to search + :type config_dir: string + :param extensions: filetypes to check (e.g. ``['.yaml', '.json']``). + :type extensions: list + :rtype: list + + """ + configs = [] + + for filename in os.listdir(config_dir): + if is_config_file(filename, extensions) and \ + not filename.startswith('.'): + configs.append(filename) + + return configs + + +def filter_repos(config, repo_dir=None, vcs_url=None, name=None): + """Return a :py:obj:`list` list of repos from (expanded) config file. + + repo_dir, vcs_url and name all support fnmatch. + + :param config: the expanded repo config in :py:class:`dict` format. + :type config: dict + :param repo_dir: directory of checkout location, fnmatch pattern supported + :type repo_dir: str or None + :param vcs_url: url of vcs remote, fn match pattern supported + :type vcs_url: str or None + :param name: project name, fnmatch pattern supported + :type name: str or None + :rtype: list + + """ + repo_list = [] + + if repo_dir: + repo_list.extend( + [r for r in config if fnmatch.fnmatch(r['parent_dir'], repo_dir)] + ) + + if vcs_url: + repo_list.extend( + r for r in config if fnmatch.fnmatch( + r.get('url', r.get('repo')), + vcs_url + ) + ) + + if name: + repo_list.extend( + [r for r in config if fnmatch.fnmatch( + r.get('name'), + name + )] + ) + + return repo_list + + +def is_config_file(filename, extensions=['.yml', '.yaml', '.json']): + """Return True if file has a valid config file type. + + :param filename: filename to check (e.g. ``mysession.json``). + :type filename: string + :param extensions: filetypes to check (e.g. ``['.yaml', '.json']``). + :type extensions: list or string + :rtype: bool + + """ + extensions = [extensions] if isinstance( + extensions, string_types) else extensions + return any(filename.endswith(e) for e in extensions) diff --git a/vcspull/util.py b/vcspull/util.py index ba87523d..6dfab119 100644 --- a/vcspull/util.py +++ b/vcspull/util.py @@ -11,7 +11,6 @@ import collections import errno -import fnmatch import logging import os import subprocess @@ -24,71 +23,6 @@ logger = logging.getLogger(__name__) -def in_dir( - config_dir=CONFIG_DIR, - extensions=['.yml', '.yaml', '.json'] -): - """Return a list of configs in ``config_dir``. - - :param config_dir: directory to search - :type config_dir: string - :param extensions: filetypes to check (e.g. ``['.yaml', '.json']``). - :type extensions: list - :rtype: list - - """ - configs = [] - - for filename in os.listdir(config_dir): - if is_config_file(filename, extensions) and \ - not filename.startswith('.'): - configs.append(filename) - - return configs - - -def filter_repos(config, repo_dir=None, vcs_url=None, name=None): - """Return a :py:obj:`list` list of repos from (expanded) config file. - - repo_dir, vcs_url and name all support fnmatch. - - :param config: the expanded repo config in :py:class:`dict` format. - :type config: dict - :param repo_dir: directory of checkout location, fnmatch pattern supported - :type repo_dir: str or None - :param vcs_url: url of vcs remote, fn match pattern supported - :type vcs_url: str or None - :param name: project name, fnmatch pattern supported - :type name: str or None - :rtype: list - - """ - repo_list = [] - - if repo_dir: - repo_list.extend( - [r for r in config if fnmatch.fnmatch(r['parent_dir'], repo_dir)] - ) - - if vcs_url: - repo_list.extend( - r for r in config if fnmatch.fnmatch( - r.get('url', r.get('repo')), - vcs_url - ) - ) - - if name: - repo_list.extend( - [r for r in config if fnmatch.fnmatch( - r.get('name'), - name - )] - ) - - return repo_list - - def run( cmd, cwd=None, @@ -211,18 +145,3 @@ def update_dict(d, u): else: d[k] = u[k] return d - - -def is_config_file(filename, extensions=['.yml', '.yaml', '.json']): - """Return True if file has a valid config file type. - - :param filename: filename to check (e.g. ``mysession.json``). - :type filename: string - :param extensions: filetypes to check (e.g. ``['.yaml', '.json']``). - :type extensions: list or string - :rtype: bool - - """ - extensions = [extensions] if isinstance( - extensions, string_types) else extensions - return any(filename.endswith(e) for e in extensions) From c2f41c51046cd6ff59eacb9f70610fe8ae782476 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Thu, 26 May 2016 05:39:06 -0500 Subject: [PATCH 8/9] groundwork for handling relative dirs #28 --- tests/test_config.py | 22 +++++++++++----------- vcspull/config.py | 25 ++++++++++++++----------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/tests/test_config.py b/tests/test_config.py index a34b5d12..b4fcaba0 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -9,7 +9,7 @@ import pytest from vcspull import config, exc -from vcspull.config import extract_repos +from vcspull.config import extract_repos, expand_dir from .fixtures import example as fixtures from .fixtures._util import loadfixture @@ -108,10 +108,6 @@ def test_expand_shell_command_after(): def test_expandenv_and_homevars(): # Assure ~ tildes and environment template vars expand. - - expanduser = os.path.expanduser - expandvars = os.path.expandvars - config_yaml = loadfixture('expand.yaml') config_json = loadfixture("expand.json") @@ -125,13 +121,13 @@ def test_expandenv_and_homevars(): config2_expanded = extract_repos(config2) paths = [r['parent_dir'] for r in config1_expanded] - assert expanduser(expandvars('${HOME}/github_projects/')) in paths - assert expanduser('~/study/') in paths - assert expanduser('~') in paths + assert expand_dir('${HOME}/github_projects/') in paths + assert expand_dir('~/study/') in paths + assert expand_dir('~') in paths paths = [r['parent_dir'] for r in config2_expanded] - assert expandvars('${HOME}/github_projects/') in paths - assert expanduser('~/study/') in paths + assert expand_dir('${HOME}/github_projects/') in paths + assert expand_dir('~/study/') in paths def test_find_config_files(tmpdir): @@ -414,4 +410,8 @@ def test_relative_dir(tmpdir): configs = config.find_config_files( path=str(arbitrary_dir) ) - repos = config.load_configs(configs) + repos = config.load_configs(configs, str(arbitrary_dir)) + + assert str(arbitrary_dir.join('relativedir')) == repos[0]['parent_dir'] + assert str(arbitrary_dir.join('relativedir', 'docutils')) == \ + repos[0]['repo_dir'] diff --git a/vcspull/config.py b/vcspull/config.py index 8b754432..fc84c0d3 100644 --- a/vcspull/config.py +++ b/vcspull/config.py @@ -7,34 +7,36 @@ """ -from __future__ import (absolute_import, division, print_function, - unicode_literals, with_statement) +from __future__ import (absolute_import, print_function, unicode_literals, + with_statement) +import fnmatch import glob import logging import os -import fnmatch import kaptan from . import exc from ._compat import string_types -from .util import update_dict, CONFIG_DIR +from .util import CONFIG_DIR, update_dict log = logging.getLogger(__name__) -def expand_dir(_dir): +def expand_dir(_dir, cwd=os.getcwd()): """Return path with environmental variables and tilde ~ expanded. :param dir: :type dir: string :rtype; string """ + if not os.path.isabs(_dir): + _dir = os.path.normpath(os.path.join(cwd, _dir)) return os.path.expanduser(os.path.expandvars(_dir)) -def extract_repos(config): +def extract_repos(config, cwd=os.getcwd()): """Return expanded configuration. end-user configuration permit inline configuration shortcuts, expand to @@ -62,7 +64,7 @@ def extract_repos(config): ''' if isinstance(repo_data, string_types): - conf['url'] = expand_dir(repo_data) + conf['url'] = repo_data, cwd else: conf = update_dict(conf, repo_data) @@ -78,10 +80,11 @@ def extract_repos(config): if 'name' not in conf: conf['name'] = repo if 'parent_dir' not in conf: - conf['parent_dir'] = expand_dir(directory) + conf['parent_dir'] = expand_dir(directory, cwd) + if 'repo_dir' not in conf: conf['repo_dir'] = expand_dir( - os.path.join(conf['parent_dir'], conf['name']) + os.path.join(conf['parent_dir'], conf['name']), cwd ) if 'remotes' in conf: remotes = [] @@ -179,7 +182,7 @@ def find_config_files( return configs -def load_configs(files): +def load_configs(files, cwd=os.getcwd()): """Return repos from a list of files. :todo: Validate scheme, check for duplciate destinations, VCS urls @@ -194,7 +197,7 @@ def load_configs(files): _, ext = os.path.splitext(f) conf = kaptan.Kaptan(handler=ext.lstrip('.')).import_config(f) - newrepos = extract_repos(conf.export('dict')) + newrepos = extract_repos(conf.export('dict'), cwd) if not repos: repos.extend(newrepos) From a1cc7ce5939c68aceb29f6b86231c99386ad4f72 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Thu, 26 May 2016 05:59:12 -0500 Subject: [PATCH 9/9] Update more readthedocs.io links --- bootstrap_env.py | 2 +- doc/conf.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bootstrap_env.py b/bootstrap_env.py index 94af4ddc..62f9b765 100755 --- a/bootstrap_env.py +++ b/bootstrap_env.py @@ -103,7 +103,7 @@ def which(exe=None, throw=True): message = ( 'pip is required for this bootstrap to run.\n' 'Find instructions on how to install at: %s' % - 'http://pip.readthedocs.org/en/latest/installing.html' + 'http://pip.readthedocs.io/en/latest/installing.html' ) fail(message) diff --git a/doc/conf.py b/doc/conf.py index da599016..7a6a68c8 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -280,4 +280,4 @@ #texinfo_no_detailmenu = false # example configuration for intersphinx: refer to the python standard library. -intersphinx_mapping = {'http://docs.python.org/': None, 'pip': ('http://sphinx.readthedocs.org/en/latest/', None)} +intersphinx_mapping = {'http://docs.python.org/': None, 'pip': ('http://sphinx.readthedocs.io/en/latest/', None)}