Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def read(*names, **kwargs):
'packageurl-python >= 0.7.0',
'xmltodict >= 0.11.0',
'javaproperties >= 0.5',
'toml >= 0.10.0',

# scancode
'click >= 6.0.0, < 7.0.0',
Expand Down
2 changes: 2 additions & 0 deletions src/packagedcode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from __future__ import unicode_literals

from packagedcode import models
from packagedcode import cargo
from packagedcode import freebsd
from packagedcode import haxe
from packagedcode import maven
Expand Down Expand Up @@ -54,6 +55,7 @@
npm.NpmPackage,
phpcomposer.PHPComposerPackage,
haxe.HaxePackage,
cargo.RustCargoCrate,
models.MeteorPackage,
models.BowerPackage,
freebsd.FreeBSDPackage,
Expand Down
113 changes: 113 additions & 0 deletions src/packagedcode/cargo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

# Copyright (c) 2019 nexB Inc. and others. All rights reserved.
# http://nexb.com and https://github.com/nexB/scancode-toolkit/
# The ScanCode software is licensed under the Apache License version 2.0.
# Data generated with ScanCode require an acknowledgment.
# ScanCode is a trademark of nexB Inc.
#
# You may not use this software except in compliance with the License.
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
# When you publish or redistribute any data created with ScanCode or any ScanCode
# derivative work, you must accompany this data with the following acknowledgment:
#
# Generated with ScanCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
# ScanCode should be considered or used as legal advice. Consult an Attorney
# for any legal advice.
# ScanCode is a free software code scanning tool from nexB Inc. and others.
# Visit https://github.com/nexB/scancode-toolkit/ for support and download.

from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals

import io
import toml
import logging

import attr

from commoncode import filetype
from commoncode import fileutils
from packagedcode import models


"""
Handle Rust cargo crates
"""

TRACE = False

logger = logging.getLogger(__name__)

if TRACE:
import sys
logging.basicConfig(stream=sys.stdout)
logger.setLevel(logging.DEBUG)


@attr.s()
class RustCargoCrate(models.Package):
metafiles = ('Cargo.toml',)
default_type = 'cargo'
default_primary_language = 'Rust'
default_web_baseurl = "https://crates.io/"
default_download_baseurl = "https://crates.io/api/v1/"
default_api_baseurl = "https://crates.io/api/v1/"

@classmethod
def recognize(cls, location):
return parse(location)

@classmethod
def get_package_root(cls, manifest_resource, codebase):
return manifest_resource.parent(codebase)

def repository_homepage_url(self, baseurl=default_web_baseurl):
return '{}/crates/{}'.format(baseurl, self.name)

def repository_download_url(self, baseurl=default_download_baseurl):
return '{}/crates/{}/{}/download'.format(baseurl, self.name, self.version)

def api_data_url(self, baseurl=default_api_baseurl):
return '{}/crates/{}'.format(baseurl, self.name)

def compute_normalized_license(self):
return models.compute_normalized_license(self.declared_license)


def is_cargo_toml(location):
return (filetype.is_file(location) and fileutils.file_name(location).lower() == 'cargo.toml')


def parse(location):
"""
Return a Package object from a Cargo.toml file or None.
"""
if not is_cargo_toml(location):
return

with io.open(location, encoding='utf-8') as loc:
package_data = toml.load(location)

return build_package(package_data)


def build_package(package_data):
"""
Return a Pacakge object from a package data mapping or None.
"""

name = package_data.get('package').get('name')
version = package_data.get('package').get('version')
package = RustCargoCrate(
name=name,
version=version,
)

return package
2 changes: 1 addition & 1 deletion src/packagedcode/npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def build_package(package_data):
if homepage:
homepage = homepage[0]
else:
homepage =''
homepage = ''
namespace, name = split_scoped_package_name(name)
package = NpmPackage(
namespace=namespace or None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32785,6 +32785,9 @@
"thirdparty/text_unidecode-1.2-py2.py3-none-any.whl",
"thirdparty/text_unidecode-1.2-py2.py3-none-any.whl.ABOUT",
"thirdparty/text_unidecode-1.2-py2.py3-none-any.whl.NOTICE",
"thirdparty/toml-0.10.0-py2.py3-none-any.whl",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not your making but this is a weird test that I will need to fix.

"thirdparty/toml-0.10.0-py2.py3-none-any.whl.ABOUT",
"thirdparty/toml-0.10.0-py2.py3-none-any.whl.LICENSE",
"thirdparty/typecode_libmagic-5.22-py2-none-manylinux1_x86_64.whl",
"thirdparty/typecode_libmagic-5.22-py2-none-win32.whl",
"thirdparty/typecode_libmagic-5.22-py2-none-win_amd64.whl",
Expand Down Expand Up @@ -32840,4 +32843,4 @@
"original_platform": null,
"new_platform": "ruby",
"specification_version": 4
}
}
Binary file added thirdparty/toml-0.10.0-py2.py3-none-any.whl
Binary file not shown.
15 changes: 15 additions & 0 deletions thirdparty/toml-0.10.0-py2.py3-none-any.whl.ABOUT
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
about_resource: toml-0.10.0-py2.py3-none-any.whl
checksum_md5: 70f2a3ce1fc099c20702b55f44f0b130
checksum_sha1: 5a6d4ad5089719e4f567997a24da13204db2eb28
contact: [email protected]
copyright: Copyright 2013-2018 William Pearson
description: Python Library for Tom's Obvious, Minimal Language
download_url: https://files.pythonhosted.org/packages/b9/19/5cbd78eac8b1783671c40e34bb0fa83133a06d340a38b55c645076d40094/toml-0.10.0.tar.gz
homepage_url: https://github.com/uiri/toml
license_expression: mit
name: toml
notes: Used for parsing for TOML configuration files.
owner: Willam Pearson
owner_url: https://github.com/uiri
vcs_url: https://github.com/uiri/toml
version: 0.10.0
Binary file added thirdparty/toml-0.10.0.tar.gz
Binary file not shown.
26 changes: 26 additions & 0 deletions thirdparty/toml.LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
The MIT License

Copyright 2013-2018 William Pearson
Copyright 2015-2016 Julien Enselme
Copyright 2016 Google Inc.
Copyright 2017 Samuel Vasko
Copyright 2017 Nate Prewitt
Copyright 2017 Jack Evans

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.