def directory(context, directory, binary): """ Find the virtualenv given the project's path. """ locate = context.obj["locate"] context.exit( locate(directory=directory or Path.cwd(), binary=binary) or 0, )
def test_find_directory_defaults_to_cwd(self): stdout, stderr = self.run_cli(["find", "directory"]) self.assertEqual( (stdout, stderr), ( str(self.locator.for_directory(Path.cwd()).path) + "\n", "", ), )
def main( filesystem, link_dir, name, locator, temporary, installs, links, requirements, recreate, virtualenv_args, persist, ): if name: if temporary: raise click.BadParameter( "specify only one of '-t / --temp / --temporary' or 'name'", ) virtualenv = locator.for_name(name=name) elif temporary: virtualenv = locator.temporary() click.echo(virtualenv.binary("python").dirname()) act = partial(virtualenv.recreate_on, filesystem=filesystem) elif len(installs) == 1: # When there's just one package to install, default to using that name. requirement, = installs name = Requirement(requirement).name virtualenv = locator.for_name(name=name) elif installs: raise click.BadParameter("A name is required.") elif len(links) == 1: # When there's just one binary to link, go for the gold. name, = installs = links virtualenv = locator.for_name(name=name) else: virtualenv = locator.for_directory(directory=Path.cwd()) if recreate or temporary: act = partial(virtualenv.recreate_on, filesystem=filesystem) else: act = virtualenv.create act(arguments=virtualenv_args) virtualenv.install(packages=installs, requirements=requirements) for link in links: filesystem.link(source=virtualenv.binary(name=link), to=link_dir.descendant(link)) if persist: _config.add_virtualenv( filesystem=filesystem, locator=locator, installs=installs, links=links, name=name, )
def test_venvs_default_name(self): """ Just saying ``venvs`` creates an environment based on the current directory's name. """ virtualenv = self.locator.for_directory(Path.cwd()) self.assertFalse(virtualenv.exists_on(self.filesystem)) self.run_cli([]) self.assertTrue(virtualenv.exists_on(self.filesystem))
def test_cwd(self): self.assertEqual(Path.cwd(), Path.from_string(os.getcwd()))
def test_from_relative_string(self): self.assertEqual( Path.from_string("a/b/c"), Path.cwd().descendant("a", "b", "c"), )