URL: https://github.com/freeipa/freeipa/pull/169
Author: tiran
 Title: #169: Replace ipaplatform's symlinks with a meta importer
Action: synchronized

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/169/head:pr169
git checkout pr169
From bc506657267095fb2f1b3299e57906b346df1707 Mon Sep 17 00:00:00 2001
From: Christian Heimes <chei...@redhat.com>
Date: Tue, 18 Oct 2016 09:14:31 +0200
Subject: [PATCH] Replace ipaplatform's symlinks with a meta importer

Signed-off-by: Christian Heimes <chei...@redhat.com>
---
 .gitignore                   |  4 ----
 Makefile                     |  5 -----
 ipaplatform/__init__.py.in   | 18 +++++++++++++-----
 ipaplatform/base/services.py |  5 ++++-
 ipaserver/dcerpc.py          |  2 +-
 pylint_plugins.py            | 20 +++++++++++++++++++-
 6 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/.gitignore b/.gitignore
index 61054de..9b15475 100644
--- a/.gitignore
+++ b/.gitignore
@@ -77,7 +77,3 @@ freeipa2-dev-doc
 
 /ipaplatform/__init__.py
 /ipaplatform/setup.py
-/ipaplatform/tasks.py
-/ipaplatform/services.py
-/ipaplatform/paths.py
-/ipaplatform/constants.py
diff --git a/Makefile b/Makefile
index 6324308..0435fe9 100644
--- a/Makefile
+++ b/Makefile
@@ -197,11 +197,6 @@ version-update: release-update
 	if [ "$(SUPPORTED_PLATFORM)" != "" ]; then \
 		sed -e s/__PLATFORM__/$(SUPPORTED_PLATFORM)/ \
 			ipaplatform/__init__.py.in > ipaplatform/__init__.py; \
-		rm -f ipaplatform/paths.py ipaplatform/services.py ipaplatform/tasks.py ipaplatform/constants.py; \
-		ln -s $(SUPPORTED_PLATFORM)/paths.py ipaplatform/paths.py; \
-		ln -s $(SUPPORTED_PLATFORM)/services.py ipaplatform/services.py; \
-		ln -s $(SUPPORTED_PLATFORM)/tasks.py ipaplatform/tasks.py; \
-		ln -s $(SUPPORTED_PLATFORM)/constants.py ipaplatform/constants.py; \
 	fi
 
 	if [ "$(SKIP_API_VERSION_CHECK)" != "yes" ]; then \
diff --git a/ipaplatform/__init__.py.in b/ipaplatform/__init__.py.in
index 61f6f3c..9821bf6 100644
--- a/ipaplatform/__init__.py.in
+++ b/ipaplatform/__init__.py.in
@@ -1,12 +1,20 @@
 #
 # Copyright (C) 2015  FreeIPA Contributors see COPYING for license
 #
+"""Module containing platform-specific functionality.
+
+ipaplatform.constants
+ipaplatform.paths
+ipaplatform.services
+ipaplatform.tasks
+"""
+import os
 
-'''
-Module containing platform-specific functionality for every platform.
-'''
 
 NAME = "__PLATFORM__"
 
-# FIXME: too much cyclic dependencies
-# from __PLATFORM__ import paths, tasks, services
+# Create an alias for platform specific modulues, e.g.
+# 'import ipaplatform.paths' loads 'ipaplatform/NAME/paths.py'.
+
+__path__.append(
+    os.path.join(os.path.dirname(os.path.abspath(__file__)), NAME))
diff --git a/ipaplatform/base/services.py b/ipaplatform/base/services.py
index 750d979..ec38b28 100644
--- a/ipaplatform/base/services.py
+++ b/ipaplatform/base/services.py
@@ -483,7 +483,10 @@ def remove(self):
 
 # Objects below are expected to be exported by platform module
 
-service = None
+def base_service_class_factory(name):
+    raise NotImplementedError
+
+service = base_service_class_factory
 knownservices = None
 
 # System may support more time&date services. FreeIPA supports ntpd only, other
diff --git a/ipaserver/dcerpc.py b/ipaserver/dcerpc.py
index bd1d8c1..a6d10db 100644
--- a/ipaserver/dcerpc.py
+++ b/ipaserver/dcerpc.py
@@ -58,7 +58,7 @@
 import pysss_nss_idmap
 import pysss
 import six
-from ipaplatform.paths import paths
+from ipaplatform.paths import paths  # pylint: disable=import-error
 
 from ldap.filter import escape_filter_chars
 from time import sleep
diff --git a/pylint_plugins.py b/pylint_plugins.py
index bf35773..6273d2c 100644
--- a/pylint_plugins.py
+++ b/pylint_plugins.py
@@ -6,9 +6,11 @@
 
 import copy
 import sys
+import textwrap
 
-from astroid import MANAGER
+from astroid import MANAGER, register_module_extender
 from astroid import scoped_nodes
+from astroid.builder import AstroidBuilder
 
 
 def register(linter):
@@ -255,3 +257,19 @@ def fix_ipa_classes(cls):
         fake_class(cls, ipa_class_members[class_name_with_module])
 
 MANAGER.register_transform(scoped_nodes.Class, fix_ipa_classes)
+
+
+def ipaplatform_transform():
+    """Module aliases for IpaPlatformImporter
+    """
+    return AstroidBuilder(MANAGER).string_build(textwrap.dedent(
+        """
+        from ipaplatform.base import constants
+        from ipaplatform.base import paths
+        from ipaplatform.base import services
+        from ipaplatform.base import tasks
+        """
+    ))
+
+
+register_module_extender(MANAGER, 'ipaplatform', ipaplatform_transform)
-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to