[PATCH] pynfs: Avoid changing sys.path in generated code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Previously importing the rpc module had side effects on sys.path which
is not preferable when using the it in larger projects. This has now
been fixed by removing the code modifying sys.path and using relative
over absolute imports in the impacted files.

Signed-off-by: William Sjöblom <wilsj@xxxxxxxxxx>
---
 rpc/rpc.py      | 10 +++++-----
 rpc/rpclib.py   |  4 ++--
 rpc/security.py | 16 ++++++++--------
 xdr/xdrgen.py   |  7 +++----
 4 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/rpc/rpc.py b/rpc/rpc.py
index 4d1eb09..b7f906c 100644
--- a/rpc/rpc.py
+++ b/rpc/rpc.py
@@ -8,12 +8,12 @@ import logging
 from collections import deque as Deque
 from errno import EINPROGRESS, EWOULDBLOCK

-import rpc.rpc_pack as rpc_pack
-from rpc_const import *
-from rpc_type import *
+from . import rpc_pack
+from .rpc_const import *
+from .rpc_type import *

-import security
-import rpclib
+from . import security
+from . import rpclib
 import random

 log_p = logging.getLogger("rpc.poll") # polling loop thread
diff --git a/rpc/rpclib.py b/rpc/rpclib.py
index 0e8e8e5..23458bf 100644
--- a/rpc/rpclib.py
+++ b/rpc/rpclib.py
@@ -1,5 +1,5 @@
-from rpc_const import *
-from rpc_type import *
+from .rpc_const import *
+from .rpc_type import *

 import logging
 log = logging.getLogger("rpc.lib")
diff --git a/rpc/security.py b/rpc/security.py
index 0ebb923..fe4390c 100644
--- a/rpc/security.py
+++ b/rpc/security.py
@@ -1,13 +1,13 @@
-from rpc_const import AUTH_NONE, AUTH_SYS, RPCSEC_GSS, SUCCESS, CALL, \
+from .rpc_const import AUTH_NONE, AUTH_SYS, RPCSEC_GSS, SUCCESS, CALL, \
     MSG_ACCEPTED
-from rpc_type import opaque_auth, authsys_parms
-from rpc_pack import RPCPacker, RPCUnpacker
-from gss_pack import GSSPacker, GSSUnpacker
+from .rpc_type import opaque_auth, authsys_parms
+from .rpc_pack import RPCPacker, RPCUnpacker
+from .gss_pack import GSSPacker, GSSUnpacker
 from xdrlib import Packer, Unpacker
-import rpclib
-from gss_const import *
-import gss_type
-from gss_type import rpc_gss_init_res
+from . import rpclib
+from .gss_const import *
+from . import gss_type
+from .gss_type import rpc_gss_init_res
 try:
     import gssapi
 except ImportError:
diff --git a/xdr/xdrgen.py b/xdr/xdrgen.py
index 6064586..b472e50 100755
--- a/xdr/xdrgen.py
+++ b/xdr/xdrgen.py
@@ -1355,9 +1355,8 @@ allow_attr_passthrough = True # Option which allows substructure attrs to
                               # is a unique substructure to search.
 pack_header = """\
 import sys,os
-sys.path.append(os.path.dirname(__file__))
-import %s as const
-import %s as types
+from . import %s as const
+from . import %s as types
 import xdrlib
 from xdrlib import Error as XDRError

@@ -1440,7 +1439,7 @@ def run(infile, filters=True, pass_attrs=True, debug=False):
     const_fd.write(comment_string)
     type_fd = open(types_file + ".py", "w")
     type_fd.write(comment_string)
-    type_fd.write("import sys,os\nsys.path.append(os.path.dirname(__file__))\nimport %s as const\n" % constants_file) +    type_fd.write("import sys,os\nfrom . import %s as const\n" % constants_file)
     pack_fd = open(packer_file + ".py", "w")
     pack_fd.write(comment_string)
     pack_fd.write(pack_header % (constants_file, types_file))
--
2.31.1





[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux