Exemple #1
0
def __get_dirs():
    ws_path = workspace.get_path()

    if ws_path is None:
        return __overlay_paths
    else:
        return __overlay_paths + [ws_path]
Exemple #2
0
    def run(self, argv):
        task_snake_case_name = argv[0]
        task_camel_case_name = util.to_camel_case(
            task_snake_case_name) + "Task"
        workspace_path = workspace.get_path()

        if workspace_path is None:
            raise RuntimeError(
                "Not currently in a workspace: running a task generator requires being in a workspace"
            )

        ws_package_name = workspace.get_package_name(workspace_path)

        self.render_template(source="task.py.jinja2",
                             destination=os.path.join(
                                 ws_package_name, "tasks",
                                 task_snake_case_name + ".py"),
                             env={"task_classname": task_camel_case_name})

        self.render_template(source="test_task.py.jinja2",
                             destination=os.path.join(
                                 "tests", "tasks",
                                 "test_" + task_snake_case_name + ".py"),
                             env={
                                 "workspace_pkg": ws_package_name,
                                 "task_module":
                                 "lor.tasks." + task_snake_case_name,
                                 "task_classname": task_camel_case_name,
                             })
Exemple #3
0
    def test_get_path_returns_manually_set_path(self):
        ws_path = os.path.join(tempfile.mkdtemp(), "ws")
        workspace_generator.create(ws_path)
        workspace._set_path(ws_path)

        returned_path = workspace.get_path()

        self.assertEqual(ws_path, returned_path)
Exemple #4
0
    def test_get_path_returns_cwd_if_cwd_is_workspace_and_no_manual_override_set(
            self):
        ws_path = os.path.join(tempfile.mkdtemp(), "ws")
        workspace_generator.create(ws_path)

        workspace._set_path(None)

        returned_path = workspace.get_path(ws_path)

        self.assertEqual(ws_path, returned_path)
Exemple #5
0
def bootstrap_globals(prop_overrides):
    """
    Bootstrap global variables.

    Used by LoR CLI to bootstrap CLI overrides (variable vals etc.)

    :param prop_overrides:
    :return:
    :raises RuntimeError: If not in a workspace
    :raises FileNotFoundError: If workspace properties.yml file is missing
    """
    workspace_path = workspace.get_path()

    if workspace_path is None:
        raise RuntimeError(
            "Not currently in a workspace (or cannot locate one)")

    workspace._set_path(workspace_path)

    path._set_overlay_paths([])  # Not using overlay paths yet

    prop_file_path = os.path.join(workspace.get_path(),
                                  lor._constants.WORKSPACE_PROPS)

    if not os.path.exists(prop_file_path):
        raise FileNotFoundError(
            "{prop_file_path}: No such file: a properties file is *required* in the workspace when running LoR"
        )

    loaders = [props.DictPropertyLoader("cli-overrides", prop_overrides)
               ] + props.get_loaders()
    props._set_loaders(loaders)

    # This allows workspaces to be loaded dynamically at runtime by LoR and Luigi
    # (the Luigi docs get clients to set PYTHONPATH explicitly)
    sys.path.insert(0, workspace.get_path())
Exemple #6
0
    def destination_root(self):
        """
        Returns the destination root directory.

        Relative destination paths are resolved relative to this root. By default, the destination root is the current
        workspace if a current workspace can be established; otherwise, an AssertionError is raised.

        :return: The destination root directory as a string
        """
        maybe_workspace_path = workspace.get_path()

        if maybe_workspace_path is None:
            raise AssertionError(
                "Not currently in a workspace: by default, generators write to a workspace"
            )
        else:
            return maybe_workspace_path
Exemple #7
0
    def __find_generators(self):
        generators_in_lor = self.__list_of_generators_to_dict_of_generator_commands(reflection.subclasses_in_pkg(lor.generators, Generator))

        ws_path = workspace.get_path()

        if ws_path is not None:
            ws_package = workspace.get_package_name(ws_path)
            sys.path.insert(0, ws_path)
            try:
                generator_pkg = importlib.import_module(ws_package + ".generators")
                generators_in_ws = self.__list_of_generators_to_dict_of_generator_commands(reflection.subclasses_in_pkg(generator_pkg, Generator))
            except ImportError as ex:
                generators_in_ws = {}
        else:
            generators_in_ws = {}

        return util.merge(generators_in_lor, generators_in_ws)
Exemple #8
0
    def run(self, argv):
        parser = ArgumentParser(description=self.description())
        parser.add_argument("generator_name")

        generator_name = parser.parse_args(argv).generator_name

        ws_path = workspace.get_path()
        if ws_path is None:
            parser.error("Not currently in a workspace")

        ws_package = workspace.get_package_name(ws_path)
        generator_dir = os.path.join(ws_package, "generators", generator_name)

        self.mkdir(generator_dir)
        self.create_file("", os.path.join(generator_dir, "__init__.py"))
        self.mkdir(os.path.join(generator_dir, "templates"))
        generator_modname = generator_name + "_generator.py"
        generator_classname = util.to_camel_case(generator_name)
        self.render_template(
            "generator.py.jinja2",
            os.path.join(generator_dir, generator_modname),
            {
                "generator_classname": generator_classname
            })
Exemple #9
0
 def __enter__(self):
     self.existing = workspace.get_path()
     ws_path = os.path.join(tempfile.mkdtemp(), "ws")
     ws = workspace_generator.create(ws_path)
     workspace._set_path(ws)
     return ws
Exemple #10
0
 def __enter__(self):
     self.existing = workspace.get_path()
     workspace._set_path(self.ws_path)
     return self.ws_path
Exemple #11
0
 def test_get_path_returns_None_if_manual_ws_set_is_None_and_cwd_is_not_a_workspace(
         self):
     some_dir = tempfile.mkdtemp()
     workspace._set_path(None)
     self.assertIsNone(workspace.get_path(some_dir))