Skip to content

Commit 0943842

Browse files
authored
Merge branch 'main' into sync-scancode-scan
2 parents c9ce4f1 + 365bf5e commit 0943842

File tree

5 files changed

+175
-4
lines changed

5 files changed

+175
-4
lines changed

aboutcode/federatedcode/README.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
=======================
2+
aboutcode.federatedcode
3+
=======================
4+
5+
|license| |build|
6+
7+
.. |license| image:: https://img.shields.io/badge/License-Apache--2.0-blue.svg?style=for-the-badge
8+
:target: https://opensource.org/licenses/Apache-2.0
9+
10+
.. |build| image:: https://img.shields.io/github/actions/workflow/status/aboutcode-org/federatedcode/main.yml?style=for-the-badge&logo=github
11+
12+
This is a library of FederatedCode client utilities to fetch and subscribe package metadata.
13+
14+
15+
License
16+
=======
17+
18+
Copyright (c) nexB Inc. and others. All rights reserved.
19+
20+
SPDX-License-Identifier: Apache-2.0
21+
22+
See https://aboutcode.org for more information about AboutCode OSS projects.
23+
24+
.. code-block:: none
25+
26+
You may not use this software except in compliance with the License.
27+
You may obtain a copy of the License at
28+
29+
http://www.apache.org/licenses/LICENSE-2.0
30+
31+
Unless required by applicable law or agreed to in writing, software
32+
distributed under the License is distributed on an "AS IS" BASIS,
33+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34+
See the License for the specific language governing permissions and
35+
limitations under the License.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# FederatedCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/nexB/federatedcode for support or download.
7+
# See https://aboutcode.org for more information about AboutCode.org OSS projects.
8+
#
9+
10+
import os
11+
from typing import Union
12+
from urllib.parse import urljoin
13+
14+
import requests
15+
from aboutcode.hashid import get_package_base_dir
16+
from dotenv import load_dotenv
17+
from packageurl import PackageURL
18+
19+
load_dotenv()
20+
21+
FEDERATEDCODE_GITHUB_ACCOUNT_NAME = os.getenv("FEDERATEDCODE_GITHUB_ACCOUNT_NAME")
22+
23+
24+
class ScanNotAvailableError(Exception):
25+
pass
26+
27+
28+
def get_package_scan(purl: Union[PackageURL, str]):
29+
"""Return the package scan result for a PURL from the FederatedCode Git repository."""
30+
31+
if not FEDERATEDCODE_GITHUB_ACCOUNT_NAME:
32+
raise ValueError("Provide ``FEDERATEDCODE_GITHUB_ACCOUNT_NAME`` in .env file.")
33+
34+
if isinstance(purl, str):
35+
purl = PackageURL.from_string(purl)
36+
37+
if not purl.version:
38+
raise ValueError("Missing version in PURL.")
39+
40+
package_path = get_package_base_dir(purl=purl)
41+
package_path_parts = package_path.parts
42+
43+
repo_name = f"{package_path_parts[0]}/refs/heads/main"
44+
package_dir_path = "/".join(package_path_parts[1:])
45+
version = purl.version
46+
file_name = "scancodeio.json"
47+
48+
url_parts = [FEDERATEDCODE_GITHUB_ACCOUNT_NAME, repo_name, package_dir_path, version, file_name]
49+
50+
file_url = urljoin("https://raw.githubusercontent.com", "/".join(url_parts))
51+
52+
try:
53+
response = requests.get(file_url)
54+
response.raise_for_status()
55+
return response.json()
56+
except requests.exceptions.HTTPError as err:
57+
if response.status_code == 404:
58+
raise ScanNotAvailableError(f"No scan available for {purl!s}")
59+
raise err
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[build-system]
2+
requires = [ "flot>=0.7.0" ]
3+
build-backend = "flot.buildapi"
4+
5+
[project]
6+
name = "aboutcode.federatedcode"
7+
version = "0.1.0"
8+
description = "A library for FederatedCode client"
9+
readme = "aboutcode/federatedcode/README.rst"
10+
license = { text = "Apache-2.0 AND Python-2.0" }
11+
requires-python = ">=3.9"
12+
13+
authors = [
14+
{ name = "AboutCode, nexB Inc. and others", email = "info@aboutcode.org" },
15+
]
16+
17+
keywords = [
18+
"purl",
19+
"Package-URL",
20+
"open source",
21+
"package",
22+
"sca",
23+
"scan",
24+
"activitypub",
25+
"dependencies",
26+
]
27+
28+
classifiers = [
29+
"Development Status :: 5 - Production/Stable",
30+
"Intended Audience :: Developers",
31+
"Programming Language :: Python :: 3",
32+
"Programming Language :: Python :: 3 :: Only",
33+
"Topic :: Software Development",
34+
"Topic :: Utilities",
35+
]
36+
37+
dependencies = [
38+
"packageurl_python >= 0.15.6",
39+
"aboutcode.hashid>=0.1.0",
40+
"python-dotenv>=1.0.1",
41+
]
42+
43+
urls = { Homepage = "https://github.com/aboutcode-org/federatedcode" }
44+
45+
46+
[tool.bumpversion]
47+
current_version = "0.1.0"
48+
allow_dirty = true
49+
50+
files = [
51+
{ filename = "pyproject-aboutcode.federatedcode.toml" },
52+
]
53+
54+
[tool.flot]
55+
includes = [
56+
"aboutcode/**/*",
57+
]
58+
59+
excludes = [
60+
# Python compiled files
61+
"**/*.py[cod]",
62+
"**/*.egg-info",
63+
# Various junk and temp files
64+
"**/.DS_Store",
65+
"**/*~",
66+
"**/.*.sw[po]",
67+
"**/.ve",
68+
"**/*.bak",
69+
"**/.ipynb_checkpoints",
70+
"aboutcode/federatedcode/tests/**/*",
71+
]
72+
73+
metadata_files = ["apache-2.0.LICENSE", "NOTICE"]
74+
editable_paths = ["aboutcode"]

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ mypy-extensions==1.0.0
5252
nh3==0.2.15
5353
oauthlib==3.2.2
5454
openpyxl==3.1.2
55-
packageurl-python==0.11.1
55+
packageurl-python==0.15.6
5656
packaging==23.1
5757
pathspec==0.11.2
5858
Pillow==9.5.0

setup.cfg

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ install_requires =
8080
jwcrypto>=1.5.0
8181
mypy-extensions>=1.0.0
8282
oauthlib>=3.2.2
83-
packageurl-python>=0.11.1
83+
packageurl-python>=0.15.6
8484
packaging>=23.1
8585
pathspec>=0.11.2
8686

@@ -107,13 +107,16 @@ install_requires =
107107
urllib3>=2.0.3
108108
wrapt>=1.15.0
109109

110-
#schema
110+
# Schema
111111
django-ninja>=1.2.1
112112
pydantic>=2.8.2
113113

114-
#pipeline
114+
# Pipeline
115115
aboutcode.pipeline>=0.1.0
116116

117+
# aboutcode.federatedcode.client
118+
aboutcode.hashid>=0.1.0
119+
python-dotenv>=1.0.1
117120

118121
[options.extras_require]
119122
testing =

0 commit comments

Comments
 (0)