Skip to content

Commit

Permalink
Extract name/version functionality from egg_info to be re-used by a d…
Browse files Browse the repository at this point in the history
…ist-info command. Ref #1386.
  • Loading branch information
jaraco committed Jul 13, 2018
1 parent 89155ab commit e9bdeda
Showing 1 changed file with 35 additions and 26 deletions.
61 changes: 35 additions & 26 deletions setuptools/command/egg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,33 @@ def translate_pattern(glob):
return re.compile(pat, flags=re.MULTILINE|re.DOTALL)


class egg_info(Command):
class InfoCommon:
tag_build = None
tag_date = None

@property
def name(self):
return safe_name(self.distribution.get_name())

def tagged_version(self):
version = self.distribution.get_version()
# egg_info may be called more than once for a distribution,
# in which case the version string already contains all tags.
if self.vtags and version.endswith(self.vtags):
return safe_version(version)
return safe_version(version + self.vtags)

def tags(self):
version = ''
if self.tag_build:
version += self.tag_build
if self.tag_date:
version += time.strftime("-%Y%m%d")
return version
vtags = property(tags)


class egg_info(InfoCommon, Command):
description = "create a distribution's .egg-info directory"

user_options = [
Expand All @@ -133,14 +159,9 @@ class egg_info(Command):
}

def initialize_options(self):
self.egg_name = None
self.egg_version = None
self.egg_base = None
self.egg_info = None
self.tag_build = None
self.tag_date = 0
self.broken_egg_info = False
self.vtags = None

####################################
# allow the 'tag_svn_revision' to be detected and
Expand All @@ -167,11 +188,15 @@ def save_version_info(self, filename):
egg_info['tag_date'] = 0
edit_config(filename, dict(egg_info=egg_info))

def finalize_options(self):
self.egg_name = safe_name(self.distribution.get_name())
self.vtags = self.tags()
self.egg_version = self.tagged_version()
@property
def egg_name(self):
return self.name

@property
def egg_version(self):
return self.tagged_version()

def finalize_options(self):
parsed_version = parse_version(self.egg_version)

try:
Expand Down Expand Up @@ -254,14 +279,6 @@ def delete_file(self, filename):
if not self.dry_run:
os.unlink(filename)

def tagged_version(self):
version = self.distribution.get_version()
# egg_info may be called more than once for a distribution,
# in which case the version string already contains all tags.
if self.vtags and version.endswith(self.vtags):
return safe_version(version)
return safe_version(version + self.vtags)

def run(self):
self.mkpath(self.egg_info)
installer = self.distribution.fetch_build_egg
Expand All @@ -277,14 +294,6 @@ def run(self):

self.find_sources()

def tags(self):
version = ''
if self.tag_build:
version += self.tag_build
if self.tag_date:
version += time.strftime("-%Y%m%d")
return version

def find_sources(self):
"""Generate SOURCES.txt manifest file"""
manifest_filename = os.path.join(self.egg_info, "SOURCES.txt")
Expand Down

0 comments on commit e9bdeda

Please sign in to comment.