Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing support #25

Merged
merged 4 commits into from
Dec 8, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Test.tar.gz
Test_file.zip
test_all_components.json
test_all_releases.json
real_instance_tests.py

# test coverage
htmlcov/
Expand Down
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

# SW360 Base Library for Python

## V1.3.2

* have type hints.
* drop support for Python 3.7

## V1.3.1

* dependency updates to fix security vulnerabilities.
Expand Down
23 changes: 15 additions & 8 deletions check_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
import argparse
import os
import sys
from typing import Any, Dict, List, Optional
from typing import Any, Dict, Optional

from colorama import init, Fore, Style
import requests
from colorama import Fore, Style, init

import sw360

# Do you use an oauth flow? This is usually False if you get your SW360 token
Expand All @@ -54,10 +55,9 @@
class CheckProject():
"""Check a project on SW360, display component clearing status"""
def __init__(self) -> None:
self.client = None
self.project_id = ""
self.project = None
self.sw360_url = "https://sw360.siemens.com"
self.client: sw360.SW360
self.project_id: str = ""
self.sw360_url: str = "https://sw360.siemens.com"

@classmethod
def get_clearing_state(cls, proj: Dict[Any, Any], href: str) -> str | None:
Expand All @@ -75,6 +75,9 @@ def get_clearing_state(cls, proj: Dict[Any, Any], href: str) -> str | None:
def has_source_code(self, href: str) -> bool:
"""Returns true if a source code attachment is available"""
rel = self.client.get_release_by_url(href)
if not rel:
return False

if "_embedded" not in rel:
return False

Expand Down Expand Up @@ -136,6 +139,10 @@ def show_project_status(self, project_id: str) -> None:
print(Fore.LIGHTRED_EX + " ERROR: unable to access project!")
sys.exit(" " + str(swex) + Style.RESET_ALL)

if not project:
print(" Project not found!")
return

print(" Project name: " + project["name"] + ", " + project["version"])
if "projectResponsible" in project:
print(" Project responsible: " + project["projectResponsible"])
Expand Down Expand Up @@ -178,7 +185,7 @@ def login(self, token: Optional[str] = None, url: Optional[str] = None) -> bool
" Error authorizing user!" +
Style.RESET_ALL)

def find_project(self, name: str, version: str) -> Optional[List[Dict[Any, Any]]]:
def find_project(self, name: str, version: str) -> str:
"""Find the project with the matching name and version on SW360"""
projects = self.client.get_projects_by_name(name)
if not projects:
Expand Down Expand Up @@ -207,7 +214,7 @@ def find_project(self, name: str, version: str) -> Optional[List[Dict[Any, Any]]
if project["version"].lower() == version:
return pid

return None
return ""

@classmethod
def parse_commandline(cls) -> Any:
Expand Down
3 changes: 2 additions & 1 deletion docs-source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#
import os
import sys

current_dir = os.path.dirname(__file__)
target_dir = os.path.abspath(os.path.join(current_dir, "../sw360"))
sys.path.insert(0, target_dir)
Expand Down Expand Up @@ -42,7 +43,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []
exclude_patterns = [] # type: ignore


# -- Options for HTML output -------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ types-urllib3 = "^1.26.25.14"
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

[tool.mypy]
mypy_path = "stubs"
exclude = [
'/tests',
]
Loading
Loading