Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
Explain why we import at run-time for each method.
  • Loading branch information
jnmclarty committed Oct 8, 2018
1 parent e2b5c7c commit 61b4430
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion pyenvdiff/collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def diff(self, oth):
left = str(self)
right = str(oth)

#pyenvdiff is designed to be dependency free, so we put import statements for a few dependencies in nice-to-have features.
import ghdiff

out = ghdiff.diff(left, right)
Expand Down Expand Up @@ -123,6 +124,10 @@ class Platform(Collector):

@staticmethod
def from_env():

# pyenvdiff is designed to be dependency free.
# Each collector will return an error if its required dependency isn't available.
# ...but allows other collectors to continue on.
import platform as p
return [p.platform(), p.processor()] + list(p.architecture())

Expand All @@ -139,6 +144,10 @@ class PkgutilModules(Collector):

@staticmethod
def from_env():

# pyenvdiff is designed to be dependency free.
# Each collector will return an error if its required dependency isn't available.
# ...but allows other collectors to continue on.
import pkgutil
info = [m for i, m, p in pkgutil.iter_modules() if p]
info.sort()
Expand All @@ -159,7 +168,10 @@ class PipDistributions(Collector):

@staticmethod
def from_env():


# pyenvdiff is designed to be dependency free.
# Each collector will return an error if its required dependency isn't available.
# ...but allows other collectors to continue on.
import pip

# pip ~9
Expand Down Expand Up @@ -268,6 +280,9 @@ class SysFloatInfo(Collector):

@staticmethod
def from_env():
# pyenvdiff is designed to be dependency free. Yes, even sys.
# Each collector will return an error if its required dependency isn't available.
# ...but allows other collectors to continue on.
import sys
return list(map(str, sys.float_info))

Expand All @@ -284,6 +299,10 @@ class SysExecutable(Collector):

@staticmethod
def from_env():

# pyenvdiff is designed to be dependency free. Yes, even sys.
# Each collector will return an error if its required dependency isn't available.
# ...but allows other collectors to continue on.
import sys
return sys.executable or "None Found"

Expand All @@ -297,6 +316,9 @@ class SysPrefix(Collector):

@staticmethod
def from_env():
# pyenvdiff is designed to be dependency free. Yes, even sys.
# Each collector will return an error if its required dependency isn't available.
# ...but allows other collectors to continue on.
import sys

out = []
Expand All @@ -321,6 +343,10 @@ class SysByteOrder(Collector):

@staticmethod
def from_env():

# pyenvdiff is designed to be dependency free. Yes, even sys.
# Each collector will return an error if its required dependency isn't available.
# ...but allows other collectors to continue on.
import sys
return sys.byteorder

Expand All @@ -333,6 +359,10 @@ class OSUname(Collector):

@staticmethod
def from_env():

# pyenvdiff is designed to be dependency free. Yes, even os, because some builds might omit.
# Each collector will return an error if its required dependency isn't available.
# ...but allows other collectors to continue on.
import os
return " ".join(os.uname()) # Unix only

Expand All @@ -357,6 +387,9 @@ class SysVersion(Collector):

@staticmethod
def from_env():
# pyenvdiff is designed to be dependency free. Yes, even os, because some builds might omit.
# Each collector will return an error if its required dependency isn't available.
# ...but allows other collectors to continue on.
import sys
return sys.version

Expand All @@ -369,6 +402,9 @@ class SysApiVersion(Collector):

@staticmethod
def from_env():
# pyenvdiff is designed to be dependency free. Yes, even sys, because some builds might omit.
# Each collector will return an error if its required dependency isn't available.
# ...but allows other collectors to continue on.
import sys
return sys.api_version

Expand All @@ -382,6 +418,9 @@ class SysVersionInfo(Collector):

@staticmethod
def from_env():
# pyenvdiff is designed to be dependency free. Yes, even sys, because some builds might omit.
# Each collector will return an error if its required dependency isn't available.
# ...but allows other collectors to continue on.
import sys
info = {}
for i, attr in enumerate(SysVersionInfo.attrs):
Expand All @@ -401,6 +440,9 @@ class TimeZone(Collector):

@staticmethod
def from_env():
# pyenvdiff is designed to be dependency free. Yes, even time, because some builds might omit.
# Each collector will return an error if its required dependency isn't available.
# ...but allows other collectors to continue on.
import time
return [str(time.timezone)] + list(time.tzname)

Expand All @@ -418,6 +460,10 @@ class OSEnviron(Collector):

@staticmethod
def from_env():

# pyenvdiff is designed to be dependency free. Yes, even os, because some builds might omit.
# Each collector will return an error if its required dependency isn't available.
# ...but allows other collectors to continue on.
import os
environ = dict(os.environ)
keys = list(environ.keys())
Expand All @@ -441,6 +487,11 @@ class UserName(Collector):

@staticmethod
def from_env():

# pyenvdiff is designed to be dependency free. Yes, even os, because some builds might omit.
# Each collector will return an error if its required dependency isn't available.
# ...but allows other collectors to continue on.

# Note this only works on linux-based systems
import pwd, os
return pwd.getpwuid(os.getuid())[0]
Expand All @@ -453,6 +504,10 @@ class HomeDirectory(Collector):

@staticmethod
def from_env():

# pyenvdiff is designed to be dependency free. Yes, even os, because some builds might omit.
# Each collector will return an error if its required dependency isn't available.
# ...but allows other collectors to continue on.
import os
return os.path.expanduser('~')

Expand Down

0 comments on commit 61b4430

Please sign in to comment.