Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _generate(self):
putup([self.name])
with chdir(self.name):
demoapp_src_dir = path_join(__location__, self.name)
demoapp_dst_root = self.pkg_path
demoapp_dst_pkg = path_join(demoapp_dst_root, "src", self.name)
copyfile(
path_join(demoapp_src_dir, "runner.py"),
path_join(demoapp_dst_pkg, "runner.py"),
)
git("add", path_join(demoapp_dst_pkg, "runner.py"))
copyfile(
path_join(demoapp_src_dir, "setup.cfg"),
path_join(demoapp_dst_root, "setup.cfg"),
)
copyfile(
path_join(demoapp_src_dir, "setup.py"),
path_join(demoapp_dst_root, "setup.py"),
)
def make_commit(self):
with chdir(self.pkg_path):
git("commit", "-a", "-m", "message")
return self
def tag(self, name, message):
with chdir(self.pkg_path):
git("tag", "-a", name, "-m", message)
return self
opts = cli.parse_args([project])
opts = cli.process_opts(opts)
_, opts = api.get_default_options({}, opts)
struct, _ = structure.define_structure({}, opts)
struct, _ = update.apply_update_rules(struct, opts)
structure.create_structure(struct, {})
repo.init_commit_repo(project, struct)
utils.rm_rf(os.path.join("inner_project", ".git"))
shutil.move("inner_project", "main_project/inner_project")
with utils.chdir("main_project"):
main_version = (
subprocess.check_output([sys.executable, "setup.py", "--version"])
.strip()
.splitlines()[-1]
)
with utils.chdir("inner_project"):
inner_version = (
subprocess.check_output([sys.executable, "setup.py", "--version"])
.strip()
.splitlines()[-1]
)
assert main_version.strip() == inner_version.strip()
def test_chdir(caplog, tmpdir, isolated_logger):
caplog.set_level(logging.INFO)
curr_dir = os.getcwd()
dname = uniqstr() # Use a unique name to get easily identifiable logs
temp_dir = str(tmpdir.mkdir(dname))
with utils.chdir(temp_dir, log=True):
new_dir = os.getcwd()
assert new_dir == os.path.realpath(temp_dir)
assert curr_dir == os.getcwd()
assert curr_dir != new_dir
logs = caplog.text
assert re.search("chdir.+" + dname, logs)
def _install_bdist(self):
with chdir("/"):
# Because of the way bdist works, the tar.gz will contain
# the whole path to the current venv, starting from the
# / directory ...
untar(self.dist_file, "--force-local")
# ^ --force-local is required to deal with Windows paths
def test_generated_extension_flake8(tmpfolder, venv_run):
args = [EXT_FLAG, "my_project"]
opts = parse_args(args)
opts = process_opts(opts)
create_project(opts)
with chdir("my_project"):
assert "" == venv_run("flake8")
venv_run("python setup.py install")
venv_run("putup {ext_flag} the_actual_project".format(ext_flag=EXT_FLAG))
assert path_exists("the_actual_project/setup.cfg")
with chdir("the_actual_project"):
assert "" == venv_run("flake8")
def build(self, dist="bdist", cli_opts=()):
with self.guard("built"), chdir(self.pkg_path):
if "wheel" in dist:
self.run("pip", "install", "wheel")
else:
cli_opts = cli_opts or ["--format", "gztar"]
# ^ force tar.gz (Windows defaults to zip)
self.run("python", "setup.py", dist, *cli_opts)
self.dist = dist
return self
def test_pretend_chdir(caplog, tmpdir):
caplog.set_level(logging.INFO)
curr_dir = os.getcwd()
dname = uniqstr() # Use a unique name to get easily identifiable logs
temp_dir = str(tmpdir.mkdir(dname))
with utils.chdir(temp_dir, pretend=True):
new_dir = os.getcwd()
assert new_dir == curr_dir # the directory is not changed
assert curr_dir == os.getcwd()
logs = caplog.text
assert re.search("chdir.+" + dname, logs)
def test_get_git_root(tmpfolder):
project = "my_project"
struct = {
project: {
"my_file": "Some other content",
"my_dir": {"my_file": "Some more content"},
}
}
structure.create_structure(struct, {})
repo.init_commit_repo(project, struct)
with utils.chdir(project):
git_root = repo.get_git_root()
assert os.path.basename(git_root) == project