Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
38 changes: 38 additions & 0 deletions .github/workflows/pypi-release-aboutcode-federatedcode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build aboutcode.federatedcode Python distributions and publish on PyPI

on:
workflow_dispatch:
push:
tags:
- "aboutcode.federatedcode/*"

jobs:
build-and-publish:
name: Build and publish library to PyPI
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Install flot
run: python -m pip install flot --user

- name: Build binary wheel and source tarball
run: python -m flot --pyproject pyproject-aboutcode.federatedcode.toml --sdist --wheel --output-dir dist/

- name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN_ABOUTCODE_FEDERATEDCODE }}

- name: Upload built archives
uses: actions/upload-artifact@v4
with:
name: pypi_archives
path: dist/*
12 changes: 12 additions & 0 deletions aboutcode/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# FederatedCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/nexB/federatedcode for support or download.
# See https://aboutcode.org for more information about AboutCode.org OSS projects.
#

import pkgutil

__path__ = pkgutil.extend_path(__path__, __name__)
9 changes: 9 additions & 0 deletions aboutcode/federatedcode/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Changelog
=============



v0.1.0 (December 13, 2024)
---------------------------

- Initial release of the ``aboutcode.federatedcode`` library.
60 changes: 57 additions & 3 deletions aboutcode/federatedcode/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,70 @@
aboutcode.federatedcode
=======================

|license| |build|
|license| |build| |release|

.. |license| image:: https://img.shields.io/badge/License-Apache--2.0-blue.svg?style=for-the-badge
:target: https://opensource.org/licenses/Apache-2.0

.. |build| image:: https://img.shields.io/github/actions/workflow/status/aboutcode-org/federatedcode/main.yml?style=for-the-badge&logo=github
.. |build| image:: https://img.shields.io/github/actions/workflow/status/aboutcode-org/federatedcode/pypi-release-aboutcode-federatedcode.yml?style=for-the-badge&logo=github

This is a library of FederatedCode client utilities to fetch and subscribe package metadata.
.. |release| image:: https://img.shields.io/pypi/v/aboutcode.federatedcode?style=for-the-badge&logo=pypi&color=%23a569bd
:target: https://pypi.org/project/aboutcode.federatedcode/
:alt: PyPI - Version


This is a CLI and library of FederatedCode client utilities for fetching and subscribing to package metadata, and utilities for managing activity streams.

Installation
============

To install the FederatedCode client, use the following command:

.. code-block:: bash

pip install aboutcode.federatedcode


CLI Usage
=========

Use the ``federatedcode`` CLI to discover and fetch scans using the PURL:

.. code-block:: bash

# Display the general help for federatedcode
federatedcode --help

# Display help for a specific command
federatedcode [command] --help

Example
-------

Discover a PURL in the FederatedCode AP Server:

.. code-block:: bash

❯ federatedcode discover pkg:npm/%40angular/animation
http://<Your-FederatedCode-Host>/purls/@pkg:npm/%2540angular/animation


Library Usage
=============

Use the ``client`` module to fetch scan results, subscribe to packages, or discover packages
in the AP server.

.. code-block:: python

from aboutcode.federatedcode import client

Use the ``contrib`` module to get the Django mixin and various utilities to manage activity streams.

.. code-block:: python

from aboutcode.federatedcode.contrib import django

License
=======

Expand Down
10 changes: 10 additions & 0 deletions aboutcode/federatedcode/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# FederatedCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/nexB/federatedcode for support or download.
# See https://aboutcode.org for more information about AboutCode.org OSS projects.
#

__version__ = "0.1.0"
3 changes: 2 additions & 1 deletion aboutcode/federatedcode/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
from urllib.parse import urljoin

import requests
from aboutcode.hashid import get_package_base_dir
from dotenv import load_dotenv
from packageurl import PackageURL

from aboutcode.hashid import get_package_base_dir

load_dotenv()

FEDERATEDCODE_GIT_RAW_URL = os.getenv(
Expand Down
22 changes: 22 additions & 0 deletions aboutcode/federatedcode/tests/test_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# FederatedCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/nexB/federatedcode for support or download.
# See https://aboutcode.org for more information about AboutCode.org OSS projects.
#

from unittest.mock import patch

from aboutcode.federatedcode.client import discover_package_in_ap_server


def test_discover_package_in_ap_server():
with patch("requests.head") as mock_head:
mock_response = mock_head.return_value
mock_response.status_code = 200

result = discover_package_in_ap_server("pkg:foo/bar")
expected = "http://localhost:8000/purls/@pkg:npm/foo/bar"
result == expected
1 change: 0 additions & 1 deletion fedcode/pipelines/sync_scancode_scans.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from traceback import format_exc as traceback_format_exc

from aboutcode.pipeline import LoopProgress

from fedcode.models import Package
from fedcode.models import Repository
from fedcode.pipelines import FederatedCodePipeline
Expand Down
2 changes: 1 addition & 1 deletion fedcode/pipelines/sync_vulnerablecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from itertools import zip_longest

import saneyaml
from aboutcode.pipeline import LoopProgress

from aboutcode.pipeline import LoopProgress
from fedcode.activitypub import Activity
from fedcode.activitypub import UpdateActivity
from fedcode.models import Note
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ addopts = [
[tool.black]
line-length = 100
include = '\.pyi?$'
skip_gitignore = true
# 'extend-exclude' excludes files or directories in addition to the defaults
extend-exclude = "venv|fedcode/migrations"

Expand Down