Commit 16d7da6b authored by Jason R. Coombs's avatar Jason R. Coombs

Use native decorator syntax in pkg_resources

parent 40a5af7a
"""Package resource API """
Package resource API
-------------------- --------------------
A resource is a logical file contained within a package, or a logical A resource is a logical file contained within a package, or a logical
...@@ -2039,7 +2040,7 @@ class EntryPoint(object): ...@@ -2039,7 +2040,7 @@ class EntryPoint(object):
list(map(working_set.add, list(map(working_set.add,
working_set.resolve(self.dist.requires(self.extras),env,installer))) working_set.resolve(self.dist.requires(self.extras),env,installer)))
#@classmethod @classmethod
def parse(cls, src, dist=None): def parse(cls, src, dist=None):
"""Parse a single entry point from string `src` """Parse a single entry point from string `src`
...@@ -2071,9 +2072,7 @@ class EntryPoint(object): ...@@ -2071,9 +2072,7 @@ class EntryPoint(object):
else: else:
return cls(name.strip(), value.strip(), attrs, extras, dist) return cls(name.strip(), value.strip(), attrs, extras, dist)
parse = classmethod(parse) @classmethod
#@classmethod
def parse_group(cls, group, lines, dist=None): def parse_group(cls, group, lines, dist=None):
"""Parse an entry point group""" """Parse an entry point group"""
if not MODULE(group): if not MODULE(group):
...@@ -2086,9 +2085,7 @@ class EntryPoint(object): ...@@ -2086,9 +2085,7 @@ class EntryPoint(object):
this[ep.name]=ep this[ep.name]=ep
return this return this
parse_group = classmethod(parse_group) @classmethod
#@classmethod
def parse_map(cls, data, dist=None): def parse_map(cls, data, dist=None):
"""Parse a map of entry point groups""" """Parse a map of entry point groups"""
if isinstance(data,dict): if isinstance(data,dict):
...@@ -2107,8 +2104,6 @@ class EntryPoint(object): ...@@ -2107,8 +2104,6 @@ class EntryPoint(object):
maps[group] = cls.parse_group(group, lines, dist) maps[group] = cls.parse_group(group, lines, dist)
return maps return maps
parse_map = classmethod(parse_map)
def _remove_md5_fragment(location): def _remove_md5_fragment(location):
if not location: if not location:
...@@ -2135,7 +2130,7 @@ class Distribution(object): ...@@ -2135,7 +2130,7 @@ class Distribution(object):
self.precedence = precedence self.precedence = precedence
self._provider = metadata or empty_provider self._provider = metadata or empty_provider
#@classmethod @classmethod
def from_location(cls,location,basename,metadata=None,**kw): def from_location(cls,location,basename,metadata=None,**kw):
project_name, version, py_version, platform = [None]*4 project_name, version, py_version, platform = [None]*4
basename, ext = os.path.splitext(basename) basename, ext = os.path.splitext(basename)
...@@ -2151,7 +2146,6 @@ class Distribution(object): ...@@ -2151,7 +2146,6 @@ class Distribution(object):
location, metadata, project_name=project_name, version=version, location, metadata, project_name=project_name, version=version,
py_version=py_version, platform=platform, **kw py_version=py_version, platform=platform, **kw
) )
from_location = classmethod(from_location)
hashcmp = property( hashcmp = property(
lambda self: ( lambda self: (
...@@ -2184,16 +2178,15 @@ class Distribution(object): ...@@ -2184,16 +2178,15 @@ class Distribution(object):
# metadata until/unless it's actually needed. (i.e., some distributions # metadata until/unless it's actually needed. (i.e., some distributions
# may not know their name or version without loading PKG-INFO) # may not know their name or version without loading PKG-INFO)
#@property @property
def key(self): def key(self):
try: try:
return self._key return self._key
except AttributeError: except AttributeError:
self._key = key = self.project_name.lower() self._key = key = self.project_name.lower()
return key return key
key = property(key)
#@property @property
def parsed_version(self): def parsed_version(self):
try: try:
return self._parsed_version return self._parsed_version
...@@ -2201,9 +2194,7 @@ class Distribution(object): ...@@ -2201,9 +2194,7 @@ class Distribution(object):
self._parsed_version = pv = parse_version(self.version) self._parsed_version = pv = parse_version(self.version)
return pv return pv
parsed_version = property(parsed_version) @property
#@property
def version(self): def version(self):
try: try:
return self._version return self._version
...@@ -2216,9 +2207,8 @@ class Distribution(object): ...@@ -2216,9 +2207,8 @@ class Distribution(object):
raise ValueError( raise ValueError(
"Missing 'Version:' header and/or %s file" % self.PKG_INFO, self "Missing 'Version:' header and/or %s file" % self.PKG_INFO, self
) )
version = property(version)
#@property @property
def _dep_map(self): def _dep_map(self):
try: try:
return self.__dep_map return self.__dep_map
...@@ -2236,7 +2226,6 @@ class Distribution(object): ...@@ -2236,7 +2226,6 @@ class Distribution(object):
extra = safe_extra(extra) or None extra = safe_extra(extra) or None
dm.setdefault(extra,[]).extend(parse_requirements(reqs)) dm.setdefault(extra,[]).extend(parse_requirements(reqs))
return dm return dm
_dep_map = property(_dep_map)
def requires(self,extras=()): def requires(self,extras=()):
"""List of Requirements needed for this distro if `extras` are used""" """List of Requirements needed for this distro if `extras` are used"""
...@@ -2294,13 +2283,12 @@ class Distribution(object): ...@@ -2294,13 +2283,12 @@ class Distribution(object):
raise AttributeError(attr) raise AttributeError(attr)
return getattr(self._provider, attr) return getattr(self._provider, attr)
#@classmethod @classmethod
def from_filename(cls,filename,metadata=None, **kw): def from_filename(cls,filename,metadata=None, **kw):
return cls.from_location( return cls.from_location(
_normalize_cached(filename), os.path.basename(filename), metadata, _normalize_cached(filename), os.path.basename(filename), metadata,
**kw **kw
) )
from_filename = classmethod(from_filename)
def as_requirement(self): def as_requirement(self):
"""Return a ``Requirement`` that matches this distribution exactly""" """Return a ``Requirement`` that matches this distribution exactly"""
...@@ -2407,10 +2395,9 @@ class Distribution(object): ...@@ -2407,10 +2395,9 @@ class Distribution(object):
kw.setdefault('metadata', self._provider) kw.setdefault('metadata', self._provider)
return self.__class__(**kw) return self.__class__(**kw)
#@property @property
def extras(self): def extras(self):
return [dep for dep in self._dep_map if dep] return [dep for dep in self._dep_map if dep]
extras = property(extras)
class DistInfoDistribution(Distribution): class DistInfoDistribution(Distribution):
...@@ -2614,7 +2601,7 @@ class Requirement: ...@@ -2614,7 +2601,7 @@ class Requirement:
def __repr__(self): return "Requirement.parse(%r)" % str(self) def __repr__(self): return "Requirement.parse(%r)" % str(self)
#@staticmethod @staticmethod
def parse(s): def parse(s):
reqs = list(parse_requirements(s)) reqs = list(parse_requirements(s))
if reqs: if reqs:
...@@ -2623,8 +2610,6 @@ class Requirement: ...@@ -2623,8 +2610,6 @@ class Requirement:
raise ValueError("Expected only one requirement", s) raise ValueError("Expected only one requirement", s)
raise ValueError("No requirements found", s) raise ValueError("No requirements found", s)
parse = staticmethod(parse)
state_machine = { state_machine = {
# =>< # =><
'<': '--T', '<': '--T',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment