Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if not commit:
print("Not committing bump, use --commit to commit")
if not push:
print("Not pushing bump, use --push to push")
vdefs = self.meta.definitions.get("version")
if vdefs:
self.update_sources(next_version, commit, push, vdefs)
self.scm.apply_tag(commit, push, next_version, branch)
if not self.strategy.hook:
return
hook = setupmeta.project_path(self.strategy.hook)
if setupmeta.is_executable(hook):
setupmeta.run_program(hook, self.meta.name, branch, next_version, fatal=True, dryrun=not commit, cwd=setupmeta.project_path())
self.auto_fill("name", title.value, source=title.source)
if "--name" in sys.argv[1:3]:
# No need to waste time auto-filling anything if all we need to show is package name
return self
packages = self.attrs.get("packages", [])
py_modules = self.attrs.get("py_modules", [])
if not packages and not py_modules and self.name:
# Try to auto-determine a good default from 'self.name'
name = self.pythonified_name
src_folder = project_path("src")
if os.path.isdir(src_folder):
packages = setuptools.find_packages(where=src_folder)
if os.path.isfile(project_path("src", "%s.py" % name)):
py_modules = [name]
if packages or py_modules:
self.auto_fill("package_dir", {"": "src"})
else:
src_folder = project_path()
packages = setuptools.find_packages(where=src_folder)
if packages:
# Take only found packages that start with the expected name
# For any other use-case, user must explicitly list their packages
packages = [p for p in packages if p.startswith(name)]
if os.path.isfile(project_path("%s.py" % name)):
py_modules = [name]
def clean(self, *relative_paths):
for relative_path in relative_paths:
path = setupmeta.project_path(relative_path)
if not os.path.exists(path):
continue
if self.commit:
print("Deleting %s..." % path)
shutil.rmtree(path)
else:
print("Would delete %s" % path)
packages = setuptools.find_packages(where=src_folder)
if os.path.isfile(project_path("src", "%s.py" % name)):
py_modules = [name]
if packages or py_modules:
self.auto_fill("package_dir", {"": "src"})
else:
src_folder = project_path()
packages = setuptools.find_packages(where=src_folder)
if packages:
# Take only found packages that start with the expected name
# For any other use-case, user must explicitly list their packages
packages = [p for p in packages if p.startswith(name)]
if os.path.isfile(project_path("%s.py" % name)):
py_modules = [name]
if packages:
self.auto_fill("packages", sorted(packages))
if py_modules:
self.auto_fill("py_modules", py_modules)
# Scan the usual/conventional places
for py_module in py_modules:
self.merge(SimpleModule("%s.py" % py_module))
for package in packages:
if package and "." not in package:
# Look at top level modules only
self.merge(
def find_venv():
venv = os.environ.get("VIRTUAL_ENV")
if venv:
return venv
for folder in (".venv", "venv"):
fpath = setupmeta.project_path(folder)
if os.path.isdir(fpath):
return fpath
def clean_direct(self):
for target in self.direct:
full_path = setupmeta.project_path(target)
if os.path.exists(full_path):
self.delete(full_path)
def resolved_paths(relative_paths):
"""
:param list(str) relative_paths: Ex: "README.rst", "README*"
:return str|None: Contents of the first non-empty file found
"""
candidates = []
for path in relative_paths:
# De-dupe and respect order (especially for globbed paths)
if "*" in path:
full_path = setupmeta.project_path(path)
for expanded in sorted(glob.glob(full_path)):
relative_path = os.path.basename(expanded)
if relative_path not in candidates:
candidates.append(relative_path)
continue
if path not in candidates:
candidates.append(path)
return candidates
abort("twine command not supported on %s" % platform.python_implementation())
if not self.egg and not self.sdist and not self.wheel:
abort("Specify at least one of: --egg, --dist or --wheel")
# Env var SETUPMETA_TWINE primarily used to allow for flexible testing
# Can be set to instruct setupmeta to use a particular twine executable as well
# Use absolute path, of filename (for example: "my-twine-wrapper")
twine = setupmeta.which(os.environ.get("SETUPMETA_TWINE", "twine"))
if not twine:
abort("twine is not installed")
if not self.commit:
print("Dryrun, use --commit to effectively build/publish")
dist = setupmeta.project_path("dist")
self.clean("dist", "build")
try:
if self.should_run(self.egg):
self.run_command("build egg distribution", sys.executable, "setup.py", "bdist_egg")
if self.should_run(self.sdist):
self.run_command("build source distribution", sys.executable, "setup.py", "sdist")
if self.should_run(self.wheel):
self.run_command("build wheel distribution", sys.executable, "setup.py", "bdist_wheel", "--universal")
if self.commit and not os.path.exists(dist):
abort("No files found in %s" % dist)
files = [os.path.join(dist, name) for name in sorted(os.listdir(dist))] if self.commit else ["dist/*"]
return
cv = vdef.sources[0].value if vdef and vdef.sources else None
if self.problem:
if not cv:
self.meta.auto_fill("version", "0.0.0", "missing")
if self.strategy:
setupmeta.warn(self.problem)
setupmeta.trace("not auto-filling version due to problem: [%s]" % self.problem)
return
gv = self.scm.get_version()
if self.generate_version_file:
path = setupmeta.project_path(setupmeta.VERSION_FILE)
with open(path, "w") as fh:
fh.write("%s" % gv)
if gv.patch and "patch" not in self.strategy.bumpable:
msg = "patch version component should be .0 for versioning strategy '%s', " % self.strategy
msg += "'.%s' from current version tag '%s' will be ignored" % (gv.patch, gv)
setupmeta.warn(msg)
rendered = self.strategy.rendered(gv)
if cv and gv:
cvc = setupmeta.version_components(cv)
cvv = Version(main="%s.%s.%s" % cvc[:3], distance=cvc[4], commitid=gv.commitid, dirty=cvc[5])
actual = self.strategy.rendered(cvv, auto_bumped=False)
cleaned = self.strategy.rendered(gv.non_dirty)
if actual not in (cleaned, rendered):
source = vdef.sources[0].source