Example #1
0
 def _get_license(self, value):
     if not is_dict_like(value):
         return ""
     if "file" in value and "text" in value:
         raise ProjectError("license table shouldn't specify both 'file' "
                            "and 'text' at the same time")
     return (Path(value["file"]).read_text(encoding=self.DEFAULT_ENCODING)
             if "file" in value else value.get("text"))
Example #2
0
 def _get_readme_content(self, value):
     if is_dict_like(value):
         if "file" in value and "text" in value:
             raise ProjectError(
                 "readme table shouldn't specify both 'file' "
                 "and 'text' at the same time")
         if "text" in value:
             return value["text"]
         file_path = value.get("file")
         encoding = value.get("charset", self.DEFAULT_ENCODING)
         return Path(file_path).read_text(encoding=encoding)
     return Path(value).read_text(encoding=self.DEFAULT_ENCODING)
Example #3
0
 def _get_content_type(self, value):
     if is_dict_like(value):
         content_type = value.get("content-type")
         if not content_type:
             raise ProjectError(
                 "'content-type' is missing in the readme table")
         if content_type not in self.SUPPORTED_CONTENT_TYPES:
             raise ProjectError(
                 f"Unsupported readme content-type: {content_type}")
         return content_type
     if value.lower().endswith(".md"):
         return "text/markdown"
     elif value.lower().endswith(".rst"):
         return "text/x-rst"
     raise ProjectError(f"Unsupported readme suffix: {value}")
Example #4
0
 def _get_license_type(self, value):
     if is_dict_like(value):
         if value.get("text", "") in license_lookup:
             return value.get("text")
     else:
         return value
Example #5
0
 def _get_readme_file(self, value):
     if is_dict_like(value):
         return value.get("file")
     return value