Skip to content

Commit

Permalink
Revert "Verify that path is absolute"
Browse files Browse the repository at this point in the history
This reverts commit c617040.
  • Loading branch information
carmenbianca committed Jun 16, 2023
1 parent c617040 commit 03414ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
11 changes: 0 additions & 11 deletions src/reuse/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from dataclasses import dataclass, field
from gettext import gettext as _
from pathlib import Path
from typing import Any, Dict, Optional

import yaml
Expand Down Expand Up @@ -34,9 +33,6 @@ class Config:
default_factory=dict
)

def __post_init__(self) -> None:
self._validate_paths_are_absolute()

@classmethod
def from_dict(cls, value: Dict[str, Any]) -> "Config":
"""Factory method to create a Config from a dictionary."""
Expand Down Expand Up @@ -72,13 +68,6 @@ def from_yaml(cls, text: str) -> "Config":
"""
return cls.from_dict(yaml.load(text, Loader=yaml.Loader))

def _validate_paths_are_absolute(self) -> None:
for path in self.override_annotate_options:
if not Path(path).expanduser().is_absolute():
raise ValueError(
_("Path '{}' must be an absolute path.").format(path)
)


def _annotate_options_from_dict(value: Dict[str, str]) -> AnnotateOptions:
return AnnotateOptions(
Expand Down
20 changes: 6 additions & 14 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
"""Tests for some _config."""

from inspect import cleandoc
from pathlib import Path

import pytest

from reuse._config import AnnotateOptions, Config
from reuse._config import Config

# REUSE-IgnoreStart

Expand Down Expand Up @@ -49,26 +46,21 @@ def test_config_from_dict_override():
"default_name": "Jane Doe",
"overrides": [
{
"path": "/foo",
"path": "foo",
"default_name": "John Doe",
},
{
"path": "/bar",
"path": "bar",
"default_license": "MIT",
},
],
}
}
result = Config.from_dict(value)
assert result.global_annotate_options.name == "Jane Doe"
assert result.override_annotate_options["/foo"].name == "John Doe"
assert result.override_annotate_options["/bar"].name is None
assert result.override_annotate_options["/bar"].license == "MIT"


def test_config_only_absolute_path():
with pytest.raises(ValueError):
Config(override_annotate_options={Path("hello"): AnnotateOptions()})
assert result.override_annotate_options["foo"].name == "John Doe"
assert result.override_annotate_options["bar"].name is None
assert result.override_annotate_options["bar"].license == "MIT"


def test_config_from_yaml_simple():
Expand Down

0 comments on commit 03414ca

Please sign in to comment.