def __init__(self, vcs=None): os.environ["ZESTRELEASER"] = "We are called from within zest.releaser" # ^^^ Env variable so called tools can detect us. Don't depend on the # actual text, just on the variable's name. if vcs is None: self.vcs = choose.version_control() else: # In a fullrelease, we share the determined vcs between # prerelease, release and postrelease. self.vcs = vcs self.data = { 'name': self.vcs.name, 'nothing_changed_yet': NOTHING_CHANGED_YET, 'reporoot': self.vcs.reporoot, 'workingdir': self.vcs.workingdir, } self.setup_cfg = pypi.SetupConfig() if utils.TESTMODE: pypirc_old = pkg_resources.resource_filename( 'zest.releaser.tests', 'pypirc_old.txt') self.pypiconfig = pypi.PypiConfig(pypirc_old) else: self.pypiconfig = pypi.PypiConfig() if self.pypiconfig.no_input(): utils.AUTO_RESPONSE = True
def _update_version(self, version): """Find out where to change the version and change it. There are three places where the version can be defined. The first one is an explicitly defined Python file with a ``__version__`` attribute. The second one is some version.txt that gets read by setup.py. The third is directly in setup.py. """ if self.get_python_file_version(): setup_cfg = pypi.SetupConfig() filename = setup_cfg.python_file_with_version() lines = open(filename).read().split('\n') for index, line in enumerate(lines): match = UNDERSCORED_VERSION_PATTERN.search(line) if match: lines[index] = "__version__ = '%s'" % version contents = '\n'.join(lines) open(filename, 'w').write(contents) logger.info("Set __version__ in %s to %r", filename, version) return version_filenames = ['version'] for extension in TXT_EXTENSIONS: version_filenames.append('.'.join(['version', extension])) versionfile = self.filefind(version_filenames) if versionfile: # We have a version.txt file but does it match the setup.py # version (if any)? setup_version = self.get_setup_py_version() if not setup_version or (setup_version == self.get_version_txt_version()): open(versionfile, 'w').write(version + '\n') logger.info("Changed %s to %r", versionfile, version) return good_version = "version = '%s'" % version line_number = 0 setup_lines = open('setup.py').read().split('\n') for line in setup_lines: match = VERSION_PATTERN.search(line) if match: logger.debug("Matching version line found: %r", line) if line.startswith(' '): # oh, probably ' version = 1.0,' line. indentation = line.split('version')[0] # Note: no spaces around the '='. good_version = indentation + "version='%s'," % version setup_lines[line_number] = good_version break line_number += 1 contents = '\n'.join(setup_lines) open('setup.py', 'w').write(contents) logger.info("Set setup.py's version to %r", version)
def _update_python_file_version(self, version): setup_cfg = pypi.SetupConfig() filename = setup_cfg.python_file_with_version() lines, encoding = utils.read_text_file(filename) lines = lines.split('\n') for index, line in enumerate(lines): match = UNDERSCORED_VERSION_PATTERN.search(line) if match: lines[index] = "__version__ = '%s'" % version contents = '\n'.join(lines) utils.write_text_file(filename, contents, encoding) logger.info("Set __version__ in %s to %r", filename, version)
def get_python_file_version(self): setup_cfg = pypi.SetupConfig() if not setup_cfg.python_file_with_version(): return lines = open(setup_cfg.python_file_with_version()).read().split('\n') for line in lines: match = UNDERSCORED_VERSION_PATTERN.search(line) if match: logger.debug("Matching __version__ line found: %r", line) line = line.lstrip('__version__').strip() line = line.lstrip('=').strip() line = line.replace('"', '').replace("'", "") return utils.strip_version(line)
def __init__(self, reporoot=None): self.workingdir = os.getcwd() if reporoot is None: self.reporoot = self.workingdir self.relative_path_in_repo = '' else: self.reporoot = reporoot # Determine relative path from root of repo. self.relative_path_in_repo = os.path.relpath( self.workingdir, reporoot) self.setup_cfg = pypi.SetupConfig() pypi_cfg = pypi.PypiConfig() self.fallback_encoding = pypi_cfg.encoding()
def get_python_file_version(self): setup_cfg = pypi.SetupConfig() if not setup_cfg.python_file_with_version(): return lines, encoding = utils.read_text_file( setup_cfg.python_file_with_version()) encoding # noqa, unused variable lines = lines.splitlines() for line in lines: match = UNDERSCORED_VERSION_PATTERN.search(line) if match: logger.debug("Matching __version__ line found: %r", line) line = line.lstrip('__version__').strip() line = line.lstrip('=').strip() line = line.replace('"', '').replace("'", "") return utils.strip_version(line)
def __init__(self, vcs=None): if vcs is None: self.vcs = choose.version_control() else: # In a fullrelease, we share the determined vcs between # prerelease, release and postrelease. self.vcs = vcs self.data = {'workingdir': self.vcs.workingdir, 'reporoot': self.vcs.reporoot, 'name': self.vcs.name} self.setup_cfg = pypi.SetupConfig() if self.setup_cfg.no_input(): utils.AUTO_RESPONSE = True if utils.TESTMODE: pypirc_old = pkg_resources.resource_filename( 'zest.releaser.tests', 'pypirc_old.txt') self.pypiconfig = pypi.PypiConfig(pypirc_old) else: self.pypiconfig = pypi.PypiConfig()
def _update_version(self, version): """Find out where to change the version and change it. There are three places where the version can be defined. The first one is an explicitly defined Python file with a ``__version__`` attribute. The second one is some version.txt that gets read by setup.py. The third is directly in setup.py. """ if self.get_python_file_version(): setup_cfg = pypi.SetupConfig() filename = setup_cfg.python_file_with_version() lines, encoding = utils.read_text_file(filename) lines = lines.split('\n') for index, line in enumerate(lines): match = UNDERSCORED_VERSION_PATTERN.search(line) if match: lines[index] = "__version__ = '%s'" % version contents = '\n'.join(lines) utils.write_text_file(filename, contents, encoding) logger.info("Set __version__ in %s to %r", filename, version) return version_filenames = ['version'] for extension in TXT_EXTENSIONS: version_filenames.append('.'.join(['version', extension])) versionfile = self.filefind(version_filenames) if versionfile: # We have a version.txt file but does it match the setup.py # version (if any)? setup_version = self.get_setup_py_version() if not setup_version or (setup_version == self.get_version_txt_version()): with open(versionfile, 'w') as f: f.write(version + '\n') logger.info("Changed %s to %r", versionfile, version) return good_version = "version = '%s'" % version line_number = 0 setup_lines, encoding = utils.read_text_file('setup.py') setup_lines = setup_lines.split('\n') for line_number, line in enumerate(setup_lines): match = VERSION_PATTERN.search(line) if match: logger.debug("Matching version line found: %r", line) if line.startswith(' '): # oh, probably ' version = 1.0,' line. indentation = line.split('version')[0] # Note: no spaces around the '='. good_version = indentation + "version='%s'," % version setup_lines[line_number] = good_version contents = '\n'.join(setup_lines) utils.write_text_file('setup.py', contents, encoding) logger.info("Set setup.py's version to %r", version) return logger.error( "We could read a version from setup.py, but could not write it " + "back. See " + "http://zestreleaser.readthedocs.io/en/latest/versions.html " + "for hints.") raise RuntimeError("Cannot set version")
def __init__(self): self.vcs = choose.version_control() self.data = {'workingdir': self.vcs.workingdir, 'name': self.vcs.name} self.setup_cfg = pypi.SetupConfig() if self.setup_cfg.no_input(): utils.AUTO_RESPONSE = True