Gentoo Archives: gentoo-dev

From: Alec Warner <antarus@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] Locale check in python_pkg_setup()
Date: Sat, 31 Jul 2010 19:50:12
Message-Id: AANLkTi=VT25DP1JsC7mnqN6csVZ_9DZUrFLAV9o=sbJc@mail.gmail.com
In Reply to: Re: [gentoo-dev] Locale check in python_pkg_setup() by Arfrever Frehtes Taifersar Arahesis
1 On Sat, Jul 31, 2010 at 7:44 AM, Arfrever Frehtes Taifersar Arahesis
2 <Arfrever@g.o> wrote:
3 > 2010-07-30 04:36:22 Brian Harring napisał(a):
4 >> On Fri, Jul 30, 2010 at 01:16:42AM +0200, Arfrever Frehtes Taifersar Arahesis wrote:
5 >> > --- python.eclass
6 >> > +++ python.eclass
7 >> > @@ -355,6 +355,8 @@
8 >> >     # Check if phase is pkg_setup().
9 >> >     [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
10 >> >
11 >> > +   local locale
12 >> > +
13 >> >     if [[ "$#" -ne 0 ]]; then
14 >> >             die "${FUNCNAME}() does not accept arguments"
15 >> >     fi
16 >> > @@ -407,6 +409,16 @@
17 >> >             unset -f python_pkg_setup_check_USE_flags
18 >> >     fi
19 >> >
20 >> > +   locale="$(python -c 'import os; print(os.environ.get("LC_ALL", os.environ.get("LC_CTYPE", os.environ.get("LANG", "POSIX"))))')"
21 >>
22 >> You're using python to get the exported env.  Don't.  Use bash (you're
23 >> invoking python from freaking bash after all)...
24 >
25 > Given variable can be set, but not exported.
26
27 If the variable is set but not exported then it is local to the shell
28 env. When bash goes to exec() python the local shell variables are
29 not in the env; so os.environ() will not contain them.
30
31 antarus@kyoto ~ $ foo=BAR
32 antarus@kyoto ~ $ echo $foo
33 BAR
34 antarus@kyoto ~ $ python -c 'import os; print os.environ.get("foo")'
35 None
36 antarus@kyoto ~ $ export foo
37 antarus@kyoto ~ $ python -c 'import os; print os.environ.get("foo")'
38 BAR
39
40 so how is this any different than:
41
42 [[ -n $LC_TYPE ]] && locale=$LC_TYPE
43 [[ -n $LC_ALL ]] && locale=$LC_ALL
44 locale=${locale:-POSIX}
45
46 if you want to keep it short; or the longer version with more ifs and
47 less shell magic. Normally I'm not a big performance man myself; but
48 this is in an eclass used by lots of packages; not just one ebuild.
49
50 >
51 >> bug 328047 is induced by a patch we add (it's not in upstream python).
52 >
53 > This patch comes from upstream.
54 >
55 > --
56 > Arfrever Frehtes Taifersar Arahesis
57 >

Replies

Subject Author
Re: [gentoo-dev] Locale check in python_pkg_setup() Arfrever Frehtes Taifersar Arahesis <Arfrever@g.o>