Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] [PATCH] Generate soname dependency metadata (282639)
Date: Fri, 30 Jan 2015 06:01:58
Message-Id: 54CB1E4F.9080109@gentoo.org
In Reply to: Re: [gentoo-portage-dev] [PATCH] Generate soname dependency metadata (282639) by "Michał Górny"
1 On 01/29/2015 09:00 PM, Michał Górny wrote:
2 > Dnia 2015-01-26, o godz. 19:16:28
3 > Zac Medico <zmedico@g.o> napisał(a):
4 >> +from ...util.elf.constants import (
5 >
6 > Please do not use relative imports. Almost all code is using absolute
7 > imports so if we're going to change that, we should get a proper
8 > discussion first.
9
10 Well, is anyone else here opposed to using relative imports? They are
11 supported since python 2.5, and I don't see anything wrong with them.
12
13 >> + needed_file.close()
14 >
15 > Looks like you really want 'with ... as needed_file:' here :).
16
17 That's an instance of atomic_ofstream, and it's designed to leave the
18 original file in place if the close call isn't reached. I did this on
19 purpose, so that the existing NEEDED.ELF.2 file is left intact if the
20 code is interrupted for some reason (such as with ^C). I think that's
21 better than leaving a partial/corrupt NEEDED.ELF.2 file there if it's
22 interrupted. Plus, adding "with" block makes it harder to see what's
23 changed in the patch, because I'll have to indent a bunch of existing code.
24
25 >> + def __str__(self):
26 >> + """
27 >> + Format this entry for writing to a NEEDED.ELF.2 file.
28 >> + """
29 >> + return (
30 >> + self.arch + ";" +
31 >> + self.filename + ";" +
32 >> + self.soname + ";" +
33 >> + ":".join(self.runpaths) + ";" +
34 >> + ",".join(self.needed) +
35 >> + (";" + self.multilib_category if self.multilib_category
36 >> + is not None else "") +
37 >> + "\n"
38 >
39 > How about using ';'.join? Would be definitely clearer in the intention.
40
41 Like this?
42
43 ";".join(
44 self.arch,
45 self.filename,
46 self.soname,
47 ":".join(self.runpaths),
48 ",".join(self.needed),
49 (self.multilib_category if self.multilib_category
50 is not None else "")
51 ) + "\n"
52
53 That would be fine with me.
54
55 >> diff --git a/pym/portage/util/elf/constants.py b/pym/portage/util/elf/constants.py
56 >> new file mode 100644
57 >> index 0000000..3857b71
58 >> --- /dev/null
59 >> +++ b/pym/portage/util/elf/constants.py
60 >> @@ -0,0 +1,36 @@
61 >> +# Copyright 2015 Gentoo Foundation
62 >> +# Distributed under the terms of the GNU General Public License v2
63 >
64 > I think you could mention here where those constants come from so that
65 > others can easily find them and update for new arches. Then it would be
66 > probably good to note what else needs to be updated :).
67
68 Honestly, I don't know where they originally come from, but we can just
69 say that they come from elfutils as suggested by Anthony.
70
71 >> +def decode_uint32_le(data):
72 >> + """
73 >> + Decode an unsigned 32-bit integer with little-endian encoding.
74 >> +
75 >> + @param data: string of bytes of length 4
76 >> + @type data: bytes
77 >> + @rtype: int
78 >> + @return: unsigned integer value of the decoded data
79 >> + """
80 >> + return (
81 >> + ord(data[0:1]) +
82 >> + (ord(data[1:2]) << 8) +
83 >> + (ord(data[2:3]) << 16) +
84 >> + (ord(data[3:4]) << 24)
85 >> + )
86 >
87 > How about using the struct module instead of reinventing the wheel?
88
89 Well the versions that I wrote seem a lot more readable to me than they
90 would be if written using things like struct.unpack_from("<L", data)[0].
91 Either way is fine with me, though. Google seems to show some issues
92 with struct import failing for broken python installations, but that
93 should not be an issue in practice.
94 --
95 Thanks,
96 Zac

Replies