Skip to content

Commit

Permalink
Add parse with dparse #253
Browse files Browse the repository at this point in the history
Signed-off-by: Li <[email protected]>
  • Loading branch information
Li committed Jun 11, 2019
1 parent 0f4bdae commit c64548e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/packagedcode/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@
from pkginfo import UnpackedSDist
from pkginfo import Wheel

import dparse
from dparse import filetypes

from commoncode import filetype
from commoncode import fileutils
from packagedcode import models
from packagedcode.utils import build_description
from packagedcode.utils import combine_expressions
from packageurl import PackageURL


"""
Expand Down Expand Up @@ -420,6 +424,34 @@ def parse_with_pkginfo(object):
return package


def parse_with_dparse(location):
file_name = fileutils.file_name(location)
if file_name not in (filetypes.requirements_txt,
filetypes.conda_yml,
filetypes.tox_ini,
filetypes.pipfile,
filetypes.pipfile_lock):
return
with open(location, 'rb') as f:
content = f.read()
df = dparse.parse(content, file_type=file_name)
df_dependencies = df.dependencies
if not df_dependencies:
return
package_dependencies = []
for df_dependency in df_dependencies:
package_dependencies.append(
models.DependentPackage(
purl=PackageURL(
type='pypi', name=df_dependency.name).to_string(),
scope='dependencies',
is_runtime=True,
is_optional=False,
)
)
return package_dependencies


def build_package(package_data):
"""
Yield Package object from a package_data mapping json file.
Expand Down

0 comments on commit c64548e

Please sign in to comment.