Skip to content

Commit

Permalink
pre-commit and friends
Browse files Browse the repository at this point in the history
  • Loading branch information
FredHappyface committed Oct 8, 2024
1 parent 6564798 commit 89240b9
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 91 deletions.
2 changes: 1 addition & 1 deletion documentation/reference/licensecheck/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def cli() -> None: ...

## main

[Show source in cli.py:89](../../../licensecheck/cli.py#L89)
[Show source in cli.py:101](../../../licensecheck/cli.py#L101)

Test entry point.

Expand Down
82 changes: 20 additions & 62 deletions documentation/reference/licensecheck/get_deps.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,88 +5,46 @@
> Auto-generated documentation for [licensecheck.get_deps](../../../licensecheck/get_deps.py) module.
- [Get Deps](#get-deps)
- [getDepsWithLicenses](#getdepswithlicenses)
- [getReqs](#getreqs)
- [check](#check)
- [resolve_requirements](#resolve_requirements)

## getDepsWithLicenses
## check

[Show source in get_deps.py:75](../../../licensecheck/get_deps.py#L75)

Get a set of dependencies with licenses and determine license compatibility.

#### Arguments

----
- `using` *str* - use requirements or poetry
- `myLice` *License* - user license
- `ignorePackages` *list[ucstr]* - a list of packages to ignore (compat=True)
- `failPackages` *list[ucstr]* - a list of packages to fail (compat=False)
- `ignoreLicenses` *list[ucstr]* - a list of licenses to ignore (skipped, compat may still be
False)
- `failLicenses` *list[ucstr]* - a list of licenses to fail (compat=False)
- `onlyLicenses` *list[ucstr]* - a list of allowed licenses (any other license will fail)
- `skipDependencies` *list[ucstr]* - a list of dependencies to skip (compat=False)

#### Returns

-------
- `tuple[License,` *set[PackageInfo]]* - tuple of
my package license
set of updated dependencies with licenseCompat set
[Show source in get_deps.py:41](../../../licensecheck/get_deps.py#L41)

#### Signature

```python
def getDepsWithLicenses(
using: str,
myLice: License,
ignorePackages: list[ucstr],
failPackages: list[ucstr],
ignoreLicenses: list[ucstr],
failLicenses: list[ucstr],
onlyLicenses: list[ucstr],
skipDependencies: list[ucstr],
) -> set[PackageInfo]: ...
def check(
requirements_paths: list[str],
groups: list[str],
this_license: License,
ignore_packages: list[ucstr] | None = None,
fail_packages: list[ucstr] | None = None,
ignore_licenses: list[ucstr] | None = None,
fail_licenses: list[ucstr] | None = None,
only_licenses: list[ucstr] | None = None,
skip_dependencies: list[ucstr] | None = None,
) -> tuple[bool, set[PackageInfo]]: ...
```

#### See also

- [License](./types.md#license)
- [PackageInfo](./types.md#packageinfo)
- [ucstr](./types.md#ucstr)



## getReqs

[Show source in get_deps.py:17](../../../licensecheck/get_deps.py#L17)

Get requirements for the end user project/ lib.

```python
>>> getReqs("poetry")
>>> getReqs("poetry:dev")
>>> getReqs("requirements")
>>> getReqs("requirements:requirements.txt;requirements-dev.txt")
>>> getReqs("PEP631")
>>> getReqs("PEP631:tests")
```

#### Arguments

----
- `using` *str* - use requirements, poetry or PEP631.
- `skipDependencies` *list[str]* - list of dependencies to skip.

#### Returns
## resolve_requirements

-------
- `set[str]` - set of requirement packages
[Show source in get_deps.py:15](../../../licensecheck/get_deps.py#L15)

#### Signature

```python
def getReqs(using: str, skipDependencies: list[ucstr]) -> set[ucstr]: ...
def resolve_requirements(
requirements_paths: list[str], groups: list[str], skip_dependencies: list[ucstr]
) -> set[ucstr]: ...
```

#### See also
Expand Down
28 changes: 25 additions & 3 deletions documentation/reference/licensecheck/resolvers/native.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
> Auto-generated documentation for [licensecheck.resolvers.native](../../../../licensecheck/resolvers/native.py) module.
- [Native](#native)
- [do_get_reqs](#do_get_reqs)
- [get_reqs](#get_reqs)

## get_reqs
## do_get_reqs

[Show source in native.py:16](../../../../licensecheck/resolvers/native.py#L16)
[Show source in native.py:46](../../../../licensecheck/resolvers/native.py#L46)

Underlying machineary to get requirements.

Expand All @@ -30,7 +31,7 @@ Underlying machineary to get requirements.
#### Signature

```python
def get_reqs(
def do_get_reqs(
using: str,
skipDependencies: list[ucstr],
extras: list[str],
Expand All @@ -41,4 +42,25 @@ def get_reqs(

#### See also

- [ucstr](../types.md#ucstr)



## get_reqs

[Show source in native.py:17](../../../../licensecheck/resolvers/native.py#L17)

#### Signature

```python
def get_reqs(
skipDependencies: list[ucstr],
extras: list[str],
requirementsPaths: list[Path],
pyproject: dict[str, Any],
) -> set[ucstr]: ...
```

#### See also

- [ucstr](../types.md#ucstr)
5 changes: 1 addition & 4 deletions documentation/reference/licensecheck/resolvers/uv.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@

```python
def get_reqs(
using: str,
skipDependencies: list[ucstr],
extras: list[str],
requirementsPaths: list[str],
skipDependencies: list[ucstr], extras: list[str], requirementsPaths: list[str]
) -> set[ucstr]: ...
```

Expand Down
11 changes: 5 additions & 6 deletions licensecheck/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from dataclasses import fields
from pathlib import Path
from sys import exit as sysexit
from sys import stdout, stdin
from typing import TextIO
from sys import stdin, stdout

from fhconfparser import FHConfParser, SimpleConf

Expand Down Expand Up @@ -123,17 +122,17 @@ def main(args: dict) -> int:
simpleConf = SimpleConf(configparser, "licensecheck", args)

# File
requirements_paths = (
simpleConf.get("requirements_paths") or ["__stdin__"]
)
requirements_paths = simpleConf.get("requirements_paths") or ["__stdin__"]
output_file = (
stdout
if simpleConf.get("file") is None
else Path(simpleConf.get("file")).open("w", encoding="utf-8")
)

# Get my license
this_license_text = args["license"] if args.get("license") else packageinfo.getMyPackageLicense()
this_license_text = (
args["license"] if args.get("license") else packageinfo.getMyPackageLicense()
)
this_license = license_matrix.licenseType(this_license_text)[0]

def getFromConfig(key: str) -> list[types.ucstr]:
Expand Down
7 changes: 1 addition & 6 deletions licensecheck/get_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@
from licensecheck.types import JOINS, License, PackageInfo, ucstr



def resolve_requirements(
requirements_paths: list[str],
groups: list[str],
skip_dependencies: list[ucstr],
) -> set[ucstr]:


) -> set[ucstr]:
try:
return res_uv.get_reqs(
skipDependencies=skip_dependencies,
Expand Down Expand Up @@ -52,7 +49,6 @@ def check(
only_licenses: list[ucstr] | None = None,
skip_dependencies: list[ucstr] | None = None,
) -> tuple[bool, set[PackageInfo]]:

# Def values
ignore_packages = ignore_packages or []
fail_packages = fail_packages or []
Expand All @@ -61,7 +57,6 @@ def check(
only_licenses = only_licenses or []
skip_dependencies = skip_dependencies or []


requirements = resolve_requirements(requirements_paths, groups, skip_dependencies)

ignoreLicensesType = license_matrix.licenseType(
Expand Down
13 changes: 8 additions & 5 deletions licensecheck/resolvers/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from pathlib import Path
from typing import Any

import tomli
from packaging.requirements import Requirement
from packaging.utils import canonicalize_name
import tomli

from licensecheck.session import session
from licensecheck.types import ucstr
Expand All @@ -20,7 +20,6 @@ def get_reqs(
requirementsPaths: list[Path],
pyproject: dict[str, Any],
) -> set[ucstr]:

using = "[unknown]"

# determine using based on file type
Expand All @@ -35,9 +34,13 @@ def get_reqs(
except tomli.TOMLDecodeError:
using = "requirements"


return do_get_reqs(using=using, skipDependencies=skipDependencies, extras=extras, pyproject=pyproject, requirementsPaths=requirementsPaths)

return do_get_reqs(
using=using,
skipDependencies=skipDependencies,
extras=extras,
pyproject=pyproject,
requirementsPaths=requirementsPaths,
)


def do_get_reqs(
Expand Down
1 change: 0 additions & 1 deletion licensecheck/resolvers/uv.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def get_reqs(
extras: list[str],
requirementsPaths: list[str],
) -> set[ucstr]:

for idx, requirement in enumerate(requirementsPaths):
if not Path(requirement).exists():
msg = f"Could not find specification of requirements ({requirement})."
Expand Down
14 changes: 12 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from __future__ import annotations

from pathlib import Path
from typing import Any

import pytest

Expand All @@ -19,7 +22,14 @@ def aux_file(file: str) -> str:


test_data = [
({"license": "MIT", "file": aux_file("test_main_tc1.txt"), "requirements_paths": ["pyproject.toml"]}, 0),
(
{
"license": "MIT",
"file": aux_file("test_main_tc1.txt"),
"requirements_paths": ["pyproject.toml"],
},
0,
),
(
{
"license": "BSD",
Expand All @@ -44,7 +54,7 @@ def aux_file(file: str) -> str:


@pytest.mark.parametrize(("args", "expected_exit_code"), test_data)
def test_main(args, expected_exit_code) -> None:
def test_main(args: dict[str, Any], expected_exit_code: int) -> None:
exit_code = main(args)
assert exit_code == expected_exit_code
assert aux_get_text(args["file"]).replace(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_resolvers_uv.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_issue_81() -> None:
requirementsPaths = [f"{THISDIR}/data/issue_81.txt"]
skipDependencies = []
with contextlib.suppress(Exception):
deps = req_uv.get_reqs(skipDependencies, extras, requirementsPaths)
_deps = req_uv.get_reqs(skipDependencies, extras, requirementsPaths)
# RuntimeError: × No solution found when resolving dependencies:
# ╰─▶ Because nvidia-cudnn-cu12==8.9.2.26 has no wheels with a matching
# platform tag and you require nvidia-cudnn-cu12==8.9.2.26, we can
Expand Down

0 comments on commit 89240b9

Please sign in to comment.