Skip to contentSkip to conversation

patman: Don't run patman when it is imported as a module

PATCH New Simon Glass 2 participants 6 messages Jul 30, 2015 – Aug 7, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 patman: Don't run patman when it is imported as a module

Commit 488d19c (patman: add distutils based installer) has the side effect of making patman run twice with each invocation. Fix this by checking for 'main program' invocation in patman.py. This is good practice in any case.

---

 tools/patman/patman.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/patman/patman.py +4 -1
index e76fc42..6fe8fe0 100755
@@ -74,8 +74,11 @@ specified by tags you place in the commits. Use -n to do a dry run first."""
 settings.Setup(parser, options.project, '')
 (options, args) = parser.parse_args()
 
+if __name__ != "__main__":
+    pass
+
 # Run our meagre tests
-if options.test:
+elif options.test:
     import doctest
 
     sys.argv = [sys.argv[0]]
Signature · 1 line
2.5.0.rc2.392.g76e840b
#1 lore raw

PATCH 1/1 patman: Don't run patman when it is imported as a module

Hi Simon,

Quoted 6 lines · Simon Glass

Commit 488d19c (patman: add distutils based installer) has the side effect of making patman run twice with each invocation. Fix this by checking for 'main program' invocation in patman.py. This is good practice in any case.

---

I did (kind of) think about that at the time when I had to handle the in-tree vs out-of-tree usage. One solution would have been to move most of the code to a module ("patch-manager" say) and have the patman script import that. The same would work for anything else that wanted to bring in bits of patman (buildman perhaps?).

Quoted 24 lines
 tools/patman/patman.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/patman/patman.py +4 -2
index e76fc42..6fe8fe0 100755
@@ -74,8 +74,11 @@ specified by tags you place in the commits. Use -n to do a dry run first."""
 settings.Setup(parser, options.project, '')
 (options, args) = parser.parse_args()
 
+if __name__ != "__main__":
+    pass
+
 # Run our meagre tests
-if options.test:
+elif options.test:
     import doctest
 
     sys.argv = [sys.argv[0]]
--

2.5.0.rc2.392.g76e840b

#2 lore raw

PATCH 1/1 patman: Don't run patman when it is imported as a module

Hi Chris,

Quoted 10 lines · Chris Packham

Hi Simon,

Quoted 6 lines · Simon Glass

Commit 488d19c (patman: add distutils based installer) has the side effect of making patman run twice with each invocation. Fix this by checking for 'main program' invocation in patman.py. This is good practice in any case.

---

Quoted 7 lines

I did (kind of) think about that at the time when I had to handle the in-tree vs out-of-tree usage. One solution would have been to move most of the code to a module ("patch-manager" say) and have the patman script import that. The same would work for anything else that wanted to bring in bits of patman (buildman perhaps?).

Ah OK. We could do this, but what is the benefit? Buildman currently imports the particular modules it needs and doesn't use the top-level tool.

[snip]

Regards,
Simon

#3 lore raw

PATCH 1/1 patman: Don't run patman when it is imported as a module

Quoted 21 lines · Simon Glass

Hi Chris,

Quoted 10 lines · Chris Packham

Hi Simon,

Quoted 6 lines · Simon Glass

Commit 488d19c (patman: add distutils based installer) has the side effect of making patman run twice with each invocation. Fix this by checking for 'main program' invocation in patman.py. This is good practice in any case.

---

Quoted 7 lines

I did (kind of) think about that at the time when I had to handle the in-tree vs out-of-tree usage. One solution would have been to move most of the code to a module ("patch-manager" say) and have the patman script import that. The same would work for anything else that wanted to bring in bits of patman (buildman perhaps?).

Quoted 4 lines

Ah OK. We could do this, but what is the benefit? Buildman currently imports the particular modules it needs and doesn't use the top-level tool.

That may play into the de-coupling of u-boot and patman. Some of these common bits could be yet another re-usable component that both patman and buildman use. But then you'd have to come up with a name for such a component which we all know is a NP-hard problem :).

I haven't really looked at buildman and only have a vague understanding of what it does. Do you think it too would be useful outside of u-boot?

Quoted 4 lines

[snip]

Regards,
Simon

#4 lore raw

PATCH 1/1 patman: Don't run patman when it is imported as a module

Hi Chris,

Quoted 27 lines · Chris Packham
Quoted 21 lines · Simon Glass

Hi Chris,

Quoted 10 lines · Chris Packham

Hi Simon,

Quoted 6 lines · Simon Glass

Commit 488d19c (patman: add distutils based installer) has the side effect of making patman run twice with each invocation. Fix this by checking for 'main program' invocation in patman.py. This is good practice in any case.

---

Quoted 7 lines

I did (kind of) think about that at the time when I had to handle the in-tree vs out-of-tree usage. One solution would have been to move most of the code to a module ("patch-manager" say) and have the patman script import that. The same would work for anything else that wanted to bring in bits of patman (buildman perhaps?).

Quoted 4 lines

Ah OK. We could do this, but what is the benefit? Buildman currently imports the particular modules it needs and doesn't use the top-level tool.

Quoted 8 lines

That may play into the de-coupling of u-boot and patman. Some of these common bits could be yet another re-usable component that both patman and buildman use. But then you'd have to come up with a name for such a component which we all know is a NP-hard problem :).

I haven't really looked at buildman and only have a vague understanding of what it does. Do you think it too would be useful outside of u-boot?

Potentially although it would be a bit of work. How many projects build for 1000 boards and want to collate common bisectability errors between them?

Regards,
Simon

#5 lore raw

PATCH 1/1 patman: Don't run patman when it is imported as a module

In reply to Chris Packham
Quoted 11 lines · Chris Packham

Hi Simon,

Quoted 6 lines · Simon Glass

Commit 488d19c (patman: add distutils based installer) has the side effect of making patman run twice with each invocation. Fix this by checking for 'main program' invocation in patman.py. This is good practice in any case.

---

Applied to u-boot-x86 and now in mainline.