Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-7185: Python 3 #2

Merged
merged 6 commits into from Sep 20, 2016
Merged

DM-7185: Python 3 #2

merged 6 commits into from Sep 20, 2016

Conversation

timj
Copy link
Member

@timj timj commented Sep 19, 2016

No description provided.

autopep8 {{package_dir}} --in-place --recursive --ignore E26,E133,E226,E228,N802,N803 --max-line-length 110
Copy link
Member Author

@timj timj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. There are some issues that need resolving.

if os.path.exists(filename) == False:
print "file %s not found" % filename

if os.path.exists(filename) is False:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that os.path.exists() returns a boolean I think it would be clearer as:

if not os.path.exists(filename):

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

UNKNOWN_PLATFORM_EXIT_CODE = 10
MISSING_PBS_CONFIG_EXIT_CODE = 20
# UNKNOWN_PLATFORM_EXIT_CODE = 10
# MISSING_PBS_CONFIG_EXIT_CODE = 20
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these not being used then? Are they informational?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are intended to be used at a later date when we have severity levels. I'm looking into this later this month.

@@ -55,7 +56,7 @@ def main():
sys.stdin.close()
sys.stdout.close()
sys.stderr.close()
if creator.isVerbose == False:
if creator.isVerbose is False:
Copy link
Member Author

@timj timj Sep 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not creator.isVerbose:

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

try:
from shlex import split as cmd_split
except ImportError:
from pipes import split as cmd_split
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this because shlex has the split function in python 2 and 3 and pipes never seems to have it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to look at this again.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what happened there. Must have been a copy buffer paste. Thanks for catching that.

# If there is no space, the dataid is something simple like a skytile id
newData=myData
# If there is no space, the dataid is something simple like a skytile id
newData = myData
visit = str(int(count / 100))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

visit = str(count // 100)

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -38,7 +42,7 @@ def nextSeq(self):
@return a sequence number
"""
seq = 0
if os.path.exists(self.fileName) == False:
if os.path.exists(self.fileName) is False:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not os.path.exists():

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -37,16 +46,26 @@ def test1(self):
filename = os.path.join("tests", "testfiles", "test.diamond.dag")

stdout = self.executeCommand("%s %s A1 %s" % (exe, execPath, filename))
self.assertTrue(stdout == "run=1033 filter=r camcol=2 field=229\n")
stdout = bytes(stdout)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make more sense for executeCommand to use decode() to decode the output from the command and convert it to a real string. Then drop all this bytes stuff.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absolutely. don't know what I was thinking.

filename = os.path.join("/tmp",username+"_"+str(os.getpid())+".seq")
if os.path.exists(filename) == True:
filename = os.path.join("/tmp", username+"_"+str(os.getpid())+".seq")
if os.path.exists(filename) is True:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop the is True.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced that test

def test1(self):
username = pwd.getpwuid(os.geteuid()).pw_name
filename = os.path.join("/tmp",username+"_"+str(os.getpid())+".seq")
if os.path.exists(filename) == True:
filename = os.path.join("/tmp", username+"_"+str(os.getpid())+".seq")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use lsst.utils.tests.getTempFilePath() here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely so. I'll check. This code pre-dates that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Replaced that code to use getTempFilePath().

def test1(self):
pairs = {}
pairs["TEST1"] = "Hello"
pairs["TEST2"] = "Goodbye"
infile = os.path.join("tests", "testfiles", "templateWriter.template")
compare = os.path.join("tests", "testfiles", "templateWriter.txt")
username = pwd.getpwuid(os.geteuid()).pw_name
outfile = os.path.join("/tmp",username+"_"+str(os.getpid())+"_template.txt")
outfile = os.path.join("/tmp", username+"_"+str(os.getpid())+"_template.txt")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lsst.utils.tests.getTempFilePath()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. Replaced that code to use getTempFilePath()

Copy link

@hsinfang hsinfang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About the commit messages, our Developer Guide asks us to write commit messages in the imperative tense.


def test1(self):
username = pwd.getpwuid(os.geteuid()).pw_name
filename = os.path.join("/tmp", username+"_"+str(os.getpid())+".seq")
if os.path.exists(filename) == True:
if os.path.exists(filename) is True:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is Ture not needed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -222,7 +221,7 @@ def createConfiguration(self, input):
@return the newly created Orca configuration file
"""
resolvedInputName = envString.resolve(input)
if self.opts.verbose == True:
if self.opts.verbose is True:
print("creating configuration using ", resolvedInputName)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is True not needed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

self.outputFileName = os.path.join(configDir, "%s_config.py" % (self.runid))
if self.opts.verbose == True:
self.outputFileName = os.path.join(configDir, "%s.config" % (self.runid))
if self.opts.verbose is True:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is True not needed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -234,10 +233,10 @@ def createConfiguration(self, input):
substitutes["CTRL_EXECUTE_SETUP_PACKAGES"] = self.getSetupPackages()

configDir = os.path.join(substitutes["LOCAL_SCRATCH"], "configs")
if os.path.exists(configDir) == False:
if os.path.exists(configDir) is False:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not os.path.exists(configDir):?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -38,7 +38,7 @@
dagNode = sys.argv[1]
filename = sys.argv[2]

if os.path.exists(filename) == False:
if os.path.exists(filename) is False:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not os.path.exists(filename)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -23,30 +23,40 @@
import unittest
import os.path
from lsst.ctrl.execute.allocationConfig import AllocationConfig
import lsst.utils.tests

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume these changes in tests/ are not done by flake8; the commit message "flake8 code cleanup" is then confusing..

@@ -61,5 +61,5 @@ class CondorInfoConfig(pexConfig.Config):
filename = envString.resolve(filename)
config.load(filename)

for i in config.platform.keys():
for i in list(config.platform.keys()):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as the other list()+keys()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Removed redundant references using list(keys())
@srp3rd srp3rd merged commit c7bc58c into master Sep 20, 2016
@ktlim ktlim deleted the tickets/DM-7185 branch August 25, 2018 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants