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

pyproject(ruff): Add ICN, N, D, PT #420

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 2 additions & 3 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ def cwd_default(monkeypatch: pytest.MonkeyPatch, tmp_path: pathlib.Path) -> None


@pytest.fixture(autouse=True, scope="session")
@pytest.mark.usefixtures("set_home")
def xdg_config_path(user_path: pathlib.Path) -> pathlib.Path:
p = user_path / ".config"
p.mkdir()
return p


@pytest.fixture(scope="function")
@pytest.fixture()
def config_path(
xdg_config_path: pathlib.Path, request: pytest.FixtureRequest
) -> pathlib.Path:
Expand All @@ -61,7 +60,7 @@ def set_xdg_config_path(
monkeypatch.setenv("XDG_CONFIG_HOME", str(xdg_config_path))


@pytest.fixture(scope="function")
@pytest.fixture()
def repos_path(user_path: pathlib.Path, request: pytest.FixtureRequest) -> pathlib.Path:
"""Return temporary directory for repository checkout guaranteed unique."""
dir = user_path / "repos"
Expand Down
3 changes: 1 addition & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@


def linkcode_resolve(domain: str, info: dict[str, str]) -> t.Union[None, str]:
"""
Determine the URL corresponding to Python object
"""Determine the URL corresponding to Python object.

Notes
-----
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,16 @@ select = [
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"ICN", # flake8-import-conventions
"UP", # pyupgrade
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"Q", # flake8-quotes
"N", # pep8-naming
"D", # pydocstyle
"PTH", # flake8-use-pathlib
"SIM", # flake8-simplify
"PT", # flake8-pytest-style
"TRY", # Trycertatops
"PERF", # Perflint
"RUF", # Ruff-specific rules
Expand All @@ -186,6 +190,7 @@ combine-as-imports = true

[tool.ruff.per-file-ignores]
"*/__init__.py" = ["F401"]
"tests/*" = ["D"]

[build-system]
requires = ["poetry_core>=1.0.0", "setuptools>50"]
Expand Down
2 changes: 1 addition & 1 deletion src/vcspull/_internal/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _from_file(cls, path: pathlib.Path) -> dict[str, t.Any]:

@classmethod
def from_file(cls, path: pathlib.Path) -> "ConfigReader":
r"""Load data from file path
r"""Load data from file path.

**YAML file**

Expand Down
2 changes: 1 addition & 1 deletion src/vcspull/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Config utility functions for vcspull.
vcspull.config
~~~~~~~~~~~~~~
~~~~~~~~~~~~~~.

A lot of these items are todo.

Expand Down
1 change: 0 additions & 1 deletion src/vcspull/exc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class VCSPullException(Exception):

"""Standard exception raised by vcspull."""


Expand Down
1 change: 0 additions & 1 deletion src/vcspull/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def template(self, record: logging.LogRecord) -> str:
record : :class:`logging.LogRecord`
Passed from inside the :py:meth:`logging.Formatter.format` record.
"""

reset = [Style.RESET_ALL]
levelname = [
LEVEL_COLORS.get(record.levelname, ""),
Expand Down
4 changes: 1 addition & 3 deletions src/vcspull/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@


def get_config_dir() -> pathlib.Path:
"""
Return vcspull configuration directory.
"""Return vcspull configuration directory.

``VCSPULL_CONFIGDIR`` environmental variable has precedence if set. We also
evaluate XDG default directory from XDG_CONFIG_HOME environmental variable
Expand All @@ -26,7 +25,6 @@ def get_config_dir() -> pathlib.Path:
str :
absolute path to tmuxp config directory
"""

paths: list[pathlib.Path] = []
if "VCSPULL_CONFIGDIR" in os.environ:
paths.append(pathlib.Path(os.environ["VCSPULL_CONFIGDIR"]))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __call__(
...


@pytest.fixture
@pytest.fixture()
def load_yaml(tmp_path: pathlib.Path) -> LoadYAMLFn:
def fn(
content: str, dir: str = "randomdir", filename: str = "randomfilename.yaml"
Expand Down
12 changes: 6 additions & 6 deletions tests/test_config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
from .helpers import EnvironmentVarGuard, load_raw, write_config


@pytest.fixture(scope="function")
@pytest.fixture()
def yaml_config(config_path: pathlib.Path) -> pathlib.Path:
yaml_file = config_path / "repos1.yaml"
yaml_file.touch()
return yaml_file


@pytest.fixture(scope="function")
@pytest.fixture()
def json_config(config_path: pathlib.Path) -> pathlib.Path:
json_file = config_path / "repos2.json"
json_file.touch()
Expand Down Expand Up @@ -194,11 +194,11 @@ def test_multiple_config_files_raises_exception(tmp_path: pathlib.Path) -> None:
json_conf_file.touch()
yaml_conf_file = tmp_path / ".vcspull.yaml"
yaml_conf_file.touch()
with EnvironmentVarGuard() as env, pytest.raises(exc.MultipleConfigWarning):
env.set("HOME", str(tmp_path))
assert pathlib.Path.home() == tmp_path

config.find_home_config_files()
with EnvironmentVarGuard() as env:
env.set("HOME", str(tmp_path))
with pytest.raises(exc.MultipleConfigWarning):
config.find_home_config_files()


def test_in_dir(
Expand Down
92 changes: 60 additions & 32 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,39 +62,53 @@ def write_config_remote(
)


@pytest.mark.parametrize(
"config_tpl,remote_list",
[
[
"""
class ConfigVariationFixture(t.NamedTuple):
test_id: str
config_tpl: str
remote_list: list[str]


CONFIG_VARIATION_FIXTURES = [
ConfigVariationFixture(
test_id="1",
config_tpl="""
{tmp_path}/study/myrepo:
{CLONE_NAME}: git+file://{dir}
""",
["origin"],
],
[
"""
remote_list=["origin"],
),
ConfigVariationFixture(
test_id="2",
config_tpl="""
{tmp_path}/study/myrepo:
{CLONE_NAME}:
repo: git+file://{dir}
""",
["repo"],
],
[
"""
remote_list=["repo"],
),
ConfigVariationFixture(
test_id="3",
config_tpl="""
{tmp_path}/study/myrepo:
{CLONE_NAME}:
repo: git+file://{dir}
remotes:
secondremote: git+file://{dir}
""",
["secondremote"],
],
],
remote_list=["secondremote"],
),
]


@pytest.mark.parametrize(
list(ConfigVariationFixture._fields),
CONFIG_VARIATION_FIXTURES,
ids=[test.test_id for test in CONFIG_VARIATION_FIXTURES],
)
def test_config_variations(
tmp_path: pathlib.Path,
create_git_remote_repo: CreateProjectCallbackFixtureProtocol,
test_id: str,
config_tpl: str,
capsys: pytest.CaptureFixture[str],
remote_list: list[str],
Expand Down Expand Up @@ -131,39 +145,53 @@ def test_config_variations(
assert current_remote.fetch_url == repo_url


@pytest.mark.parametrize(
"config_tpl,has_extra_remotes",
[
[
"""
class UpdatingRemoteFixture(t.NamedTuple):
test_id: str
config_tpl: str
has_extra_remotes: bool


UPDATING_REMOTE_FIXTURES = [
UpdatingRemoteFixture(
test_id="basic",
config_tpl="""
{tmp_path}/study/myrepo:
{CLONE_NAME}: git+file://{dir}
""",
False,
],
[
"""
has_extra_remotes=False,
),
UpdatingRemoteFixture(
test_id="basic2",
config_tpl="""
{tmp_path}/study/myrepo:
{CLONE_NAME}:
repo: git+file://{dir}
""",
False,
],
[
"""
has_extra_remotes=False,
),
UpdatingRemoteFixture(
test_id="basic3",
config_tpl="""
{tmp_path}/study/myrepo:
{CLONE_NAME}:
repo: git+file://{dir}
remotes:
mirror_repo: git+file://{dir}
""",
True,
],
],
has_extra_remotes=True,
),
]


@pytest.mark.parametrize(
list(UpdatingRemoteFixture._fields),
UPDATING_REMOTE_FIXTURES,
ids=[test.test_id for test in UPDATING_REMOTE_FIXTURES],
)
def test_updating_remote(
tmp_path: pathlib.Path,
create_git_remote_repo: CreateProjectCallbackFixtureProtocol,
test_id: str,
config_tpl: str,
has_extra_remotes: bool,
) -> None:
Expand Down