Skip to content

Commit

Permalink
Merge pull request #113 from fossology/chore/release-3.x
Browse files Browse the repository at this point in the history
Chore/release 3.x
  • Loading branch information
deveaud-m authored Aug 9, 2023
2 parents c998d61 + 1e639aa commit 16719d1
Show file tree
Hide file tree
Showing 34 changed files with 62 additions and 115 deletions.
39 changes: 0 additions & 39 deletions .github/workflows/foss_cli_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,42 +47,3 @@ jobs:
poetry run coverage run --source=fossology -m pytest tests/test_foss_cli*.py
poetry run coverage report -m
continue-on-error: true

test-last_release:
name: foss_cli tests (Fossology 4.1.0)
runs-on: ubuntu-latest

container:
image: python:3.11-slim
volumes:
- /tmp:/tmp

services:
fossology:
image: fossology/fossology:4.1.0
ports:
- 8081:80
volumes:
- /tmp:/tmp

steps:
- uses: actions/checkout@v1
- name: Install host dependencies
run: |
apt-get -qq update
apt-get install -qq gcc git nmap xz-utils
rm -rf /var/lib/apt/lists/*
- name: Install Python dependencies
run: |
pip install poetry
poetry install --with=dev
- name: Install files in shared volume
run: |
tar xJf tests/files/base-files_11.tar.xz -C /tmp
- name: Check services
run: nmap fossology -p 80
- name: Run tests
run: |
poetry run coverage run --source=fossology -m pytest tests/test_foss_cli*.py
poetry run coverage report -m
14 changes: 3 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,11 @@ A simple wrapper for the Fossology REST API.

See `the OpenAPI specification <https://raw.githubusercontent.com/fossology/fossology/master/src/www/ui/api/documentation/openapi.yaml>`_ used to implement this library.

Compatible API versions:
Current release is compatible with **Fossology version 4.2.1** - API version 1.4.3.

- 1.2.1 (Fossology 3.10.0)
- 1.3.2 (Fossology 3.11.0)
- 1.4.0 (Fossology 4.0.0)
- 1.4.3 (Fossology 4.1.0)
- 1.5.1 (Fossology 4.2.0) - partially covered, see #52 for the list of missing supported API feature
`See release notes <https://github.com/fossology/fossology-python/releases>`_ for all details.

**NOTE**

Version 2.0.0 of `fossology-python` only supports Fossology API version 1.4.3 onwards because of a breaking change in
the version format returned by the API. Other earlier version of the wrapper support a wider range of API versions,
e.g. 1.5.0 supports Fossology API 1.2.1 to 1.4.0.
The list of unsupported API features is documented in `issue #52 <https://github.com/fossology/fossology-python/issues/52>`_.

Documentation
=============
Expand Down
2 changes: 1 addition & 1 deletion docs-source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
copyright = "2021, Siemens AG"

# The full version, including major/minor/patch tags
release = "2.1.0"
release = "3.0.0"


# -- General configuration ---------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions docs-source/sample_workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ Login to the Fossology Server
Create the Fossology Instance.


>>> # The username is only needed for Fossology API version < 1.2.3
>>> foss = Fossology(FOSSOLOGY_SERVER, token, name=os.environ["FOSSOLOGY_USER"])
>>> foss = Fossology(FOSSOLOGY_SERVER, token)
>>> print(f"Logged in as user {foss.user.name}")
Logged in as user fossy

Expand Down
32 changes: 6 additions & 26 deletions fossology/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Copyright 2019-2021 Siemens AG
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT

import logging
import re
from datetime import date, timedelta

import requests
Expand Down Expand Up @@ -68,7 +67,7 @@ def fossology_token(
response = requests.post(url + "/api/v1/tokens", data=data)
if response.status_code == 201:
token = response.json()["Authorization"]
return re.sub("Bearer ", "", token)
return token.replace("Bearer ", "")
elif response.status_code == 404:
description = "Authentication error"
raise AuthenticationError(description, response)
Expand All @@ -88,14 +87,12 @@ class Fossology(Folders, Groups, LicenseEndpoint, Uploads, Jobs, Report, Users,
:Example:
>>> from fossology import Fossology
>>> foss = Fossology(FOSS_URL, FOSS_TOKEN, username) # doctest: +SKIP
>>> foss = Fossology(FOSS_URL, FOSS_TOKEN) # doctest: +SKIP
:param url: URL of the Fossology instance
:param token: The API token generated using the Fossology UI
:param name: The name of the token owner (deprecated since API version 1.2.3)
:type url: str
:type token: str
:type name: str (deprecated since API version 1.2.3)
:raises FossologyApiError: if a REST call failed
:raises AuthenticationError: if the user couldn't be authenticated
"""
Expand All @@ -109,19 +106,18 @@ def __init__(self, url, token, name=None):
self.api = f"{self.host}/api/v1"
self.session = requests.Session()
self.session.headers.update({"Authorization": f"Bearer {self.token}"})
self.version = self.get_version()
self.info = self.get_info()
self.health = self.get_health()
self.user = self.get_self(name)
self.user = self.get_self()
self.name = self.user.name
self.rootFolder = self.detail_folder(self.user.rootFolderId)
self.folders = self.list_folders()

logger.info(
f"Authenticated as {self.user.name} against {self.host} using API version {self.version}"
f"Authenticated as {self.user.name} against {self.host} using API version {self.info.version}"
)

def get_self(self, name=None):
def get_self(self):
"""Perform the first API request and populate user variables
API Endpoint: GET /users/self
Expand All @@ -147,22 +143,6 @@ def get_self(self, name=None):
def close(self):
self.session.close()

def get_version(self):
"""Get API version from the server
API endpoint: GET /version (deprecated since API version 1.3.3)
:return: the API version string
:rtype: string
:raises FossologyApiError: if the REST call failed
"""
response = self.session.get(f"{self.api}/version")
if response.status_code == 200:
return response.json()["version"]
else:
description = "Error while getting API version"
raise FossologyApiError(description, response)

def get_info(self) -> ApiInfo:
"""Get info from the server
Expand Down
3 changes: 3 additions & 0 deletions fossology/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT

__doc__ = """
Allows to run the foss_cli with: python -m fossology
"""
Expand Down
2 changes: 1 addition & 1 deletion fossology/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Siemens AG
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT

from json.decoder import JSONDecodeError
Expand Down
4 changes: 2 additions & 2 deletions fossology/folders.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mypy: disable-error-code="attr-defined"
# Copyright 2019-2021 Siemens AG
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT

import logging
Expand Down Expand Up @@ -99,7 +99,7 @@ def create_folder(
logger.info(
f"Folder '{name}' already exists under the folder {parent.name} ({parent.id})"
)
# Foldernames with similar letter but different cases
# Folder names with similar letter but different cases
# are not allowed in Fossology, compare with lower case
existing_folder = [
folder
Expand Down
21 changes: 6 additions & 15 deletions fossology/foss_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT

__doc__ = """
The foss_cli cmdline interface uses the provided REST-API to communicate
with the Fossology Server.
Expand All @@ -20,11 +23,7 @@
import click

from fossology import Fossology, fossology_token
from fossology.exceptions import (
AuthenticationError,
FossologyApiError,
FossologyUnsupported,
)
from fossology.exceptions import FossologyApiError, FossologyUnsupported
from fossology.obj import AccessLevel, Folder, ReportFormat, Summary, TokenScope

logger = logging.getLogger(__name__)
Expand All @@ -46,7 +45,6 @@
"copyright_email_author": True,
"ecc": True,
"keyword": True,
"monk": True,
"mime": True,
"monk": True,
"nomos": True,
Expand Down Expand Up @@ -219,14 +217,7 @@ def init_foss(ctx: click.Context):
"No Token provided. Either provide FOSS_TOKEN in environment or use the -t option."
)
raise e
try:
foss = Fossology(ctx.obj["SERVER"], ctx.obj["TOKEN"]) # using new API
except AuthenticationError: # API version < 1.2.3 requires a username
foss = Fossology(
ctx.obj["SERVER"],
ctx.obj["TOKEN"],
name=ctx.obj["USERNAME"],
)
foss = Fossology(ctx.obj["SERVER"], ctx.obj["TOKEN"]) # using new API
ctx.obj["FOSS"] = foss
ctx.obj["USER"] = foss.user.name
logger.debug(f"Logged in as user {foss.user.name}")
Expand Down Expand Up @@ -323,7 +314,7 @@ def cli(
logger.debug("Started in debug mode")
if foss_needs_initialization:
logger.debug(
f"Using API: {pprint.pformat(foss.api)} version {pprint.pformat(foss.version)}"
f"Using API: {pprint.pformat(foss.api)} version {pprint.pformat(foss.info.version)}"
)
logger.debug(
f"Running as user {pprint.pformat(foss.user.name)} on {pprint.pformat(foss.host)}"
Expand Down
2 changes: 1 addition & 1 deletion fossology/groups.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mypy: disable-error-code="attr-defined"
# Copyright 2019-2021 Siemens AG
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT

import logging
Expand Down
2 changes: 1 addition & 1 deletion fossology/jobs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mypy: disable-error-code="attr-defined"
# Copyright 2019-2021 Siemens AG
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT

import json
Expand Down
2 changes: 1 addition & 1 deletion fossology/license.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mypy: disable-error-code="attr-defined"
# Copyright 2019-2021 Siemens AG
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT

import json
Expand Down
2 changes: 1 addition & 1 deletion fossology/obj.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mypy: disable-error-code="attr-defined"
# Copyright 2019-2021 Siemens AG
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT

import json
Expand Down
2 changes: 1 addition & 1 deletion fossology/report.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mypy: disable-error-code="attr-defined"
# Copyright 2019-2021 Siemens AG
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT

import logging
Expand Down
2 changes: 1 addition & 1 deletion fossology/uploads.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mypy: disable-error-code="attr-defined"
# Copyright 2019-2021 Siemens AG
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT
import json
import logging
Expand Down
2 changes: 1 addition & 1 deletion fossology/users.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mypy: disable-error-code="attr-defined"
# Copyright 2019-2021 Siemens AG
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT
import logging

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fossology"
version = "2.1.0"
version = "3.0.0"
description = "A library to automate Fossology from Python scripts"
authors = ["Marion Deveaud <[email protected]>"]
license = "MIT License"
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Siemens AG
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT

import logging
Expand Down
2 changes: 1 addition & 1 deletion tests/test_folders.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Siemens AG
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT

import secrets
Expand Down
3 changes: 3 additions & 0 deletions tests/test_foss_cli_create_cmds.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2022 Siemens AG
# SPDX-License-Identifier: MIT

__doc__ = """Test 'create_*' sub commands of foss_cli"""

import time
Expand Down
3 changes: 3 additions & 0 deletions tests/test_foss_cli_flow_cmds.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2022 Siemens AG
# SPDX-License-Identifier: MIT

__doc__ = """Test the "workflow" sub commands of foss_cli"""
import configparser
import os
Expand Down
3 changes: 3 additions & 0 deletions tests/test_foss_cli_help.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2022 Siemens AG
# SPDX-License-Identifier: MIT

__doc__ = """Test the "help" text of the different sub commands of foss_cli"""

from fossology import foss_cli
Expand Down
3 changes: 3 additions & 0 deletions tests/test_foss_cli_logger.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2022 Siemens AG
# SPDX-License-Identifier: MIT

__doc__ = """Test the logging of the foss_cli
foss_cli distinguishes the verbosity levels 0,1,2
defined in foss_cli.py
Expand Down
3 changes: 3 additions & 0 deletions tests/test_foss_cli_start_workflow.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2022 Siemens AG
# SPDX-License-Identifier: MIT

from pathlib import PurePath

from fossology import foss_cli
Expand Down
2 changes: 1 addition & 1 deletion tests/test_groups.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Siemens AG
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT

import secrets
Expand Down
2 changes: 1 addition & 1 deletion tests/test_jobs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Siemens AG
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT

import secrets
Expand Down
2 changes: 1 addition & 1 deletion tests/test_license.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Siemens AG
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT

from unittest.mock import MagicMock
Expand Down
2 changes: 1 addition & 1 deletion tests/test_report.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Siemens AG
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT

import mimetypes
Expand Down
2 changes: 1 addition & 1 deletion tests/test_search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Siemens AG
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT

import secrets
Expand Down
2 changes: 1 addition & 1 deletion tests/test_upload_from.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2021 Siemens AG
# Copyright 2019 Siemens AG
# SPDX-License-Identifier: MIT

from fossology import Fossology
Expand Down
3 changes: 3 additions & 0 deletions tests/test_upload_licenses_copyrights.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2023 Siemens AG
# SPDX-License-Identifier: MIT

import pytest
import responses
from tenacity import RetryError
Expand Down
Loading

0 comments on commit 16719d1

Please sign in to comment.