diff options
| author | jwansek <eddie.atten.ea29@gmail.com> | 2022-01-21 20:00:38 +0000 | 
|---|---|---|
| committer | jwansek <eddie.atten.ea29@gmail.com> | 2022-01-21 20:00:38 +0000 | 
| commit | 4f0dde8e96bf504887cfa4cc6b3c1df85364a329 (patch) | |
| tree | 2412812eefc7805db1e60f119862292a07ab39b2 | |
| parent | 593124e9db06ff7a1621c62129ef9fcdbc692c43 (diff) | |
| download | Smarker-4f0dde8e96bf504887cfa4cc6b3c1df85364a329.tar.gz Smarker-4f0dde8e96bf504887cfa4cc6b3c1df85364a329.zip | |
did some more work on rendering txt reports
| -rw-r--r-- | jinja_helpers.py | 37 | ||||
| -rw-r--r-- | mark.py | 2 | ||||
| -rw-r--r-- | reflect.py | 21 | ||||
| -rw-r--r-- | smarker.conf | 7 | ||||
| -rw-r--r-- | templates/txt.jinja2 | 47 | 
5 files changed, 95 insertions, 19 deletions
| diff --git a/jinja_helpers.py b/jinja_helpers.py index af91786..cf68748 100644 --- a/jinja_helpers.py +++ b/jinja_helpers.py @@ -1,5 +1,6 @@  """Functions in this module will be avaliable to call in jinja templates"""  import yaml +import re  def recurse_class_tree_text(tree, indent = 4):      return yaml.dump(tree, indent = indent).replace(": {}", "") @@ -19,12 +20,40 @@ def _get_helpers():      r.import_module("jinja_helpers")      return {k: v[0] for k, v in r.get_functions("jinja_helpers").items()} +def get_required_num_args(funcname): +    return int(re.findall(r"(?<=\()(\d+)(?=\))", funcname)[0]) + +def bool_to_yesno(b:bool): +    if b: +        return "YES" +    else: +        return "NO" + +def len_documentation(comments, docs): +    """This function isn't in jinja""" +    if comments == "None": +        commentlen = 0 +    else: +        commentlen = len(comments) + +    if docs == "None": +        docslen = 0 +    else: +        docslen = len(docs) + +    return commentlen + docslen + +def get_source_numlines(source): +    return "%d lines (%d characters)" % (source.count("\n"), len(source)) +  if __name__ == "__main__": -    import json -    with open("100301654_report.json", "r") as f: -        init_struct = json.load(f)["files"] +    # import json +    # with open("100301654_report.json", "r") as f: +    #     init_struct = json.load(f)["files"] + +    # print(flatten_struct(flatten_struct(init_struct)["example.py"]["functions"])) -    print(flatten_struct(flatten_struct(init_struct)["example.py"]["functions"])) +    print(get_required_num_args("aFunctionThatIsntThere(2)"))      
\ No newline at end of file @@ -38,7 +38,7 @@ def main(**kwargs):              with open(os.path.join("templates", "%s.jinja2" % kwargs["format"]), "r") as f:                  jinja_template = jinja2.Template(f.read()) -            strout = jinja_template.render(**output, **jinja_helpers._get_helpers()) +            strout = jinja_template.render(**output, **jinja_helpers._get_helpers(), **kwargs)          if output_file == "stdout":              print(strout) @@ -51,8 +51,8 @@ class Reflect:              str: Provided documentation          """          return { -            "comments": inspect.getcomments(self.imported_modules[module_name]),  -            "doc": inspect.getdoc(self.imported_modules[module_name]) +            "comments": self.__format_doc(inspect.getcomments(self.imported_modules[module_name])),  +            "doc": self.__format_doc(inspect.getdoc(self.imported_modules[module_name]))          }      def get_classes(self, module_name): @@ -66,7 +66,7 @@ class Reflect:              a tuple containing the class object and the classes' documentation.          """          return { -            i[0]: (i[1], {"comments": inspect.getcomments(i[1]), "doc": inspect.getdoc(i[1])})  +            i[0]: (i[1], {"comments": self.__format_doc(inspect.getcomments(i[1])), "doc": self.__format_doc(inspect.getdoc(i[1]))})               for i in inspect.getmembers(self.imported_modules[module_name])               if inspect.isclass(i[1]) and self.get_class_full_name(i[1]).split(".")[0] in self.imported_modules.keys()          } @@ -85,9 +85,9 @@ class Reflect:          return {              i[0]: (                  i[1],  -                {"comments": inspect.getcomments(i[1]), "doc": inspect.getdoc(i[1])},  +                {"comments": self.__format_doc(inspect.getcomments(i[1])), "doc": self.__format_doc(inspect.getdoc(i[1]))},                   str(inspect.signature(i[1])), -                inspect.getsource(i[1])  +                inspect.getsource(i[1]).rstrip()              )              for i in inspect.getmembers(                  self.get_classes(module_name)[class_name][0],  @@ -99,9 +99,9 @@ class Reflect:          return {              i[0]: (                  i[1],  -                {"comments": inspect.getcomments(i[1]), "doc": inspect.getdoc(i[1])},  +                {"comments": self.__format_doc(inspect.getcomments(i[1])), "doc": self.__format_doc(inspect.getdoc(i[1]))},                   str(inspect.signature(i[1])), -                inspect.getsource(i[1])  +                inspect.getsource(i[1]).rstrip()               )              for i in inspect.getmembers(self.imported_modules[module_name])               if inspect.isfunction(i[1]) @@ -214,6 +214,9 @@ class Reflect:              subprocess.run(cmd)          return test_results + +    def __format_doc(*doc): +        return str(doc[1]).rstrip()  def gen_reflection_report(client_code_path, assessment_struct, student_no, configuration):      # print(configuration) @@ -292,7 +295,7 @@ def gen_reflection_report(client_code_path, assessment_struct, student_no, confi                  out["files"][i][required_file]["functions"][j][required_function]["documentation"] = present_functions[function_name][-3]                      out["files"][i][required_file]["functions"][j][required_function]["arguments"] = present_functions[function_name][-2]                      out["files"][i][required_file]["functions"][j][required_function]["minimum_arguments"] = present_functions[function_name][-2].count(",") + 1     -                out["files"][i][required_file]["functions"][j][required_function]["source_code"] = present_functions[function_name][-2] +                out["files"][i][required_file]["functions"][j][required_function]["source_code"] = present_functions[function_name][-1]          if "tests" in required_files_features.keys():              filename = list(assessment_struct["files"][i].keys())[0] @@ -319,4 +322,4 @@ if __name__ == "__main__":      reflect = Reflect(os.getcwd())      print(reflect.client_modules)      reflect.import_module("jinja_helpers") -    print({k: v[0] for k, v in reflect.get_functions("jinja_helpers").items()})
\ No newline at end of file +    print({k: v for k, v in reflect.get_functions("jinja_helpers").items()})
\ No newline at end of file diff --git a/smarker.conf b/smarker.conf index 180b8cf..523f892 100644 --- a/smarker.conf +++ b/smarker.conf @@ -4,7 +4,12 @@ port = 3306  user = smarker
  passwd = smarkerPassword
 -[.md]
 +[md]
 +show_full_docs = True
 +show_source = True
 +show_numlines = True
 +
 +[txt]
  show_full_docs = True
  show_source = True
  show_numlines = True
\ No newline at end of file diff --git a/templates/txt.jinja2 b/templates/txt.jinja2 index 1daf52a..d6a0c16 100644 --- a/templates/txt.jinja2 +++ b/templates/txt.jinja2 @@ -18,12 +18,51 @@      {%- endif -%}      {% if "functions" in files_contents.keys() %}          Functions: -        {%- set flat_functions = flatten_struct(files_contents["functions"]) -%} -        {% for function_name, function_contents in flat_functions.items() %} -            {{ function_name }} +        {%- set flat_functions = flatten_struct(files_contents["functions"]) %} +        {%- for function_name, function_contents in flat_functions.items() %} +            {{ function_name + ":" }} +            {%- if function_contents["present"] %} +                Arguments: +                    {{ function_contents["arguments"] }} +                    Enough? {{ bool_to_yesno(function_contents["minimum_arguments"] >= get_required_num_args(function_name)) }} +                Documentation: +                    {{ len_documentation(function_contents["documentation"]["comments"], function_contents["documentation"]["doc"]) }} characters long +                    {%- if txt_show_full_docs == "True" %} +                    Comments: +                        {%- if function_contents["documentation"]["comments"] == "None" %} +                        *** No comments present *** +                        {%- else %} +``` +{{ function_contents["documentation"]["comments"] }} +``` +                        {%- endif %} +                    Docstring: +                        {%- if function_contents["documentation"]["doc"] == "None" %} +                        *** No docstring present *** +                        {%- else %} +``` +{{ function_contents["documentation"]["doc"] }} +``` +                        {%- endif -%} +                    {%- endif %} +                    Source: +                        {{ get_source_numlines(function_contents["source_code"]) }} +                        {%- if txt_show_source == "True" %} +                        Code: +``` +{{ function_contents["source_code"] }} +``` +                        {%- endif %} +            {%- else %} +                *** Function not present *** +            {%- endif %}          {%- endfor -%}      {%- endif -%}      {% else %}          *** File not present ***      {% endif %} -{% endfor %}
\ No newline at end of file +{% endfor %} + +{% if out != "stdout" -%} +{{ test_results["pytest_report"] }} +{%- endif -%}
\ No newline at end of file | 
