def clean(ctx, venv=False, extra=''): """Perform house-keeping.""" notify.banner("Cleaning up project files") # Stop any left-over watchdog if os.path.exists(TEST_FOLDER): ctx.run("cd {} && . .env && inv view --kill".format(TEST_FOLDER)) # Add patterns based on given parameters venv_dirs = ['.venv'] patterns = [TEST_FOLDER + '/', 'pip-selfcheck.json', '**/*~'] if venv: patterns.extend([i + '/' for i in venv_dirs]) if extra: patterns.extend(shlex.split(extra)) # Build fileset patterns = [antglob.includes(i) for i in patterns] if not venv: # Do not scan venv dirs when not cleaning them patterns.extend([antglob.excludes(i + '/') for i in venv_dirs]) fileset = antglob.FileSet('.', patterns) # Iterate over matches and remove them for name in fileset: notify.info('rm {0}'.format(name)) if name.endswith('/'): shutil.rmtree(name) else: os.unlink(name)
def clean(ctx, docs=False, venv=False, extra=''): """Perform house-keeping.""" notify.banner("Cleaning up project files") # Add patterns based on given parameters venv_dirs = ['.venv'] patterns = ['new-project/', 'pip-selfcheck.json', '**/*~'] if docs: patterns.append('docs/_build/') if venv: patterns.extend([i + '/' for i in venv_dirs]) if extra: patterns.extend(shlex.split(extra)) # Build fileset patterns = [antglob.includes(i) for i in patterns] if not venv: # Do not scan venv dirs when not cleaning them patterns.extend([antglob.excludes(i + '/') for i in venv_dirs]) fileset = antglob.FileSet('.', patterns) # Iterate over matches and remove them for name in fileset: notify.info('rm {0}'.format(name)) if name.endswith('/'): shutil.rmtree(name) else: os.unlink(name)
def clean(ctx, venv=False, extra=''): """Perform house-keeping.""" notify.banner("Cleaning up project files") ctx.run("invoke view --kill") # Add patterns based on given parameters venv_dirs = ['bin', 'include', 'lib', 'share', 'local', '.venv'] patterns = ['_html/', 'pip-selfcheck.json'] excludes = ['.git/', '.hg/', '.svn/'] if venv: patterns.extend([i + '/' for i in venv_dirs]) if extra: patterns.extend(shlex.split(extra)) # Build fileset patterns = [antglob.includes(i) for i in patterns] + [antglob.excludes(i) for i in excludes] if not venv: # Do not scan venv dirs when not cleaning them patterns.extend([antglob.excludes(i + '/') for i in venv_dirs]) fileset = antglob.FileSet(BASEDIR, patterns) # Iterate over matches and remove them for name in fileset: notify.info('rm {0}'.format(name)) if name.endswith('/'): shutil.rmtree(os.path.join(BASEDIR, name)) else: os.unlink(os.path.join(BASEDIR, name))
def test_directory_patterns_return_matches(root): assert_sets_equal(antglob.FileSet(root, "foo/"), ["foo/"]) assert_sets_equal(antglob.FileSet(root, "**/baz/"), ["foo/bar/baz/"]) assert_sets_equal(antglob.FileSet(root, "**/b*/"), ["foo/bar/", "foo/bar/baz/"]) assert_sets_equal(antglob.FileSet(root, "**/.*/"), ["foo/bar/.hidden/"]) assert_sets_equal(antglob.FileSet(root, "**/.*"), ["foo/bar/baz/..."]) assert_sets_equal(antglob.FileSet(root, "*/"), ["foo/"]) assert_sets_equal(antglob.FileSet(root, "*/*/*/"), ["foo/bar/.hidden/", "foo/bar/baz/"])
def test_lists_of_string_patterns_are_combined(root): patterns = ["*.py", "foo/bar/tw*", "foo/bar/*.py"] assert set(antglob.FileSet(root, patterns[:1])) == set(["zero.py"]) assert set(antglob.FileSet(root, patterns)) == set( ["zero.py", "foo/bar/two", "foo/bar/two.py"])
def test_string_patterns_are_inclusive_by_default(root): assert list(antglob.FileSet(root, "*.py")) == ["zero.py"]
def test_glob_patterns_with_inverted_char_sets(root): assert_sets_equal(antglob.FileSet(root, "**/baz/[^.]*"), ["foo/bar/baz/three", "foo/bar/baz/three.py"]) assert_sets_equal(antglob.FileSet(root, "**/baz/[^t]*"), ["foo/bar/baz/..."])
def test_glob_patterns_with_normal_char_sets(root): assert_sets_equal(antglob.FileSet(root, "**/bar/[.b]*/"), ["foo/bar/.hidden/", "foo/bar/baz/"])
def test_twin_star_pattern_matches_root_files(root): root_py = set(antglob.FileSet(root, [antglob.includes('*.py')])) all_py = set(antglob.FileSet(root, [antglob.includes('**/*.py')])) assert len(root_py) == 1 assert len(all_py) > 1 assert root_py <= all_py
def check_glob(root, pattern, expected): assert_sets_equal(antglob.FileSet(root, [antglob.includes(pattern)]), expected)