Return a mapping of data parsed from a podspec/gemspec/Pofile/Gemfile file at ``location``. Use ``package_type`` a Package URL type for dependencies. dependencies is a list of DependentPackage.
(location, package_type)
| 134 | |
| 135 | |
| 136 | def parse_spec(location, package_type): |
| 137 | """ |
| 138 | Return a mapping of data parsed from a podspec/gemspec/Pofile/Gemfile file |
| 139 | at ``location``. Use ``package_type`` a Package URL type for dependencies. |
| 140 | dependencies is a list of DependentPackage. |
| 141 | """ |
| 142 | spec_data = {} |
| 143 | with open(location) as spec: |
| 144 | content = spec.read() |
| 145 | |
| 146 | lines = content.splitlines() |
| 147 | for line in lines: |
| 148 | line = pre_process(line) |
| 149 | |
| 150 | for attribute_name, parser in PARSER_BY_NAME.items(): |
| 151 | parsed = parser(line=line) |
| 152 | if parsed: |
| 153 | spec_data[attribute_name] = parsed |
| 154 | |
| 155 | # description can be in single or multi-lines |
| 156 | # There are many different ways to write description. |
| 157 | # we reparse for multline |
| 158 | description = spec_data.get("description") |
| 159 | if description: |
| 160 | if '<<-' in description: |
| 161 | # a Ruby multiline text |
| 162 | spec_data['description'] = get_multiline_description( |
| 163 | description_start=description, |
| 164 | lines=lines, |
| 165 | ) |
| 166 | else: |
| 167 | # a single quoted description |
| 168 | spec_data['description'] = get_cleaned_string(description) |
| 169 | |
| 170 | # We avoid reloading twice the file but we are still parsing twice: need to |
| 171 | # merge all in gemfileparser or write a better parser. |
| 172 | spec_data['dependencies'] = list(get_dependent_packages( |
| 173 | lines=lines, |
| 174 | location=location, |
| 175 | package_type=package_type, |
| 176 | )) |
| 177 | |
| 178 | return spec_data |
| 179 | |
| 180 | |
| 181 | def get_dependent_packages(lines, location, package_type): |
nothing calls this directly
no test coverage detected