Skip to content
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
1 change: 1 addition & 0 deletions .tmuxp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ windows:
panes:
- focus: true
- pane
- make watch_mypy
- make watch_test
- window_name: docs
layout: main-horizontal
Expand Down
13 changes: 12 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ $ pipx install --suffix=@next 'vcspull' --pip-args '\--pre' --force

<!-- Maintainers, insert changes / features for the next release here -->


### Internal

- mypy: Add `--strict` typings (#386)

## vcspull v1.18.0 (2022-10-31)

### Python 3.11 support (#409)
Expand Down Expand Up @@ -218,7 +223,13 @@ $ pipx install --suffix=@next 'vcspull' --pip-args '\--pre' --force

- Move to `src/` directory structure (#382)
- libvcs: Update to 0.17.x (#373)
- Basic mypy annotations (#373)
- mypy:

- Basic mypy annotations (#373)
- [`mypy --strict`] compliant (#386)

[`mypy --strict`]: https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-strict

- Remove `.pre-commit-config.yaml`: Let's not automate what the contributor could /
should do themselves.
- Add [flake8-bugbear](https://github.com/PyCQA/flake8-bugbear) (#379)
Expand Down
16 changes: 10 additions & 6 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,40 @@ 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):
def xdg_config_path(user_path: pathlib.Path) -> pathlib.Path:
p = user_path / ".config"
p.mkdir()
return p


@pytest.fixture(scope="function")
def config_path(xdg_config_path: pathlib.Path, request: pytest.FixtureRequest):
def config_path(
xdg_config_path: pathlib.Path, request: pytest.FixtureRequest
) -> pathlib.Path:
conf_path = xdg_config_path / "vcspull"
conf_path.mkdir(exist_ok=True)

def clean():
def clean() -> None:
shutil.rmtree(conf_path)

request.addfinalizer(clean)
return conf_path


@pytest.fixture(autouse=True)
def set_xdg_config_path(monkeypatch: pytest.MonkeyPatch, xdg_config_path: pathlib.Path):
def set_xdg_config_path(
monkeypatch: pytest.MonkeyPatch, xdg_config_path: pathlib.Path
) -> None:
monkeypatch.setenv("XDG_CONFIG_HOME", str(xdg_config_path))


@pytest.fixture(scope="function")
def repos_path(user_path: pathlib.Path, request: pytest.FixtureRequest):
def repos_path(user_path: pathlib.Path, request: pytest.FixtureRequest) -> pathlib.Path:
"""Return temporary directory for repository checkout guaranteed unique."""
dir = user_path / "repos"
dir.mkdir(exist_ok=True)

def clean():
def clean() -> None:
shutil.rmtree(dir)

request.addfinalizer(clean)
Expand Down
20 changes: 11 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# flake8: noqa E501
import inspect
import os
import sys
import typing as t
from os.path import dirname, relpath
from pathlib import Path

import vcspull

# Get the project root dir, which is the parent dir of this
cwd = Path.cwd()
project_root = cwd.parent
Expand Down Expand Up @@ -60,7 +65,7 @@
html_css_files = ["css/custom.css"]
html_extra_path = ["manifest.json"]
html_theme = "furo"
html_theme_path: list = []
html_theme_path: list[str] = []
html_theme_options = {
"light_logo": "img/vcspull.svg",
"dark_logo": "img/vcspull-dark.svg",
Expand Down Expand Up @@ -171,13 +176,9 @@
}


def linkcode_resolve(domain, info): # NOQA: C901
import inspect
import sys
from os.path import dirname, relpath

import vcspull

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

Expand Down Expand Up @@ -210,7 +211,8 @@ def linkcode_resolve(domain, info): # NOQA: C901
except AttributeError:
pass
else:
obj = unwrap(obj)
if callable(obj):
obj = unwrap(obj)

try:
fn = inspect.getsourcefile(obj)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ files = [
"src",
"tests"
]
strict = true

[[tool.mypy.overrides]]
module = [
Expand Down
25 changes: 21 additions & 4 deletions scripts/generate_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import requests
import yaml

from libvcs.sync.git import GitRemote
from vcspull.cli.sync import guess_vcs
from vcspull.types import RawConfig

try:
gitlab_token = os.environ["GITLAB_TOKEN"]
except KeyError:
Expand Down Expand Up @@ -69,24 +73,37 @@
sys.exit(1)

path_prefix = os.getcwd()
config: dict = {}
config: RawConfig = {}

for group in response.json():
url_to_repo = group["ssh_url_to_repo"].replace(":", "/")
namespace_path = group["namespace"]["full_path"]
reponame = group["path"]

path = "%s/%s" % (path_prefix, namespace_path)
path = f"{path_prefix}/{namespace_path}"

if path not in config:
config[path] = {}

# simplified config not working - https://github.com/vcs-python/vcspull/issues/332
# config[path][reponame] = 'git+ssh://%s' % (url_to_repo)

vcs = guess_vcs(url_to_repo)
if vcs is None:
raise Exception(f"Could not guess VCS for URL: {url_to_repo}")

config[path][reponame] = {
"url": "git+ssh://%s" % (url_to_repo),
"remotes": {"origin": "ssh://%s" % (url_to_repo)},
"name": reponame,
"dir": path / reponame,
"url": f"git+ssh://{url_to_repo}",
"remotes": {
"origin": GitRemote(
name="origin",
fetch_url=f"ssh://{url_to_repo}",
push_url=f"ssh://{url_to_repo}",
)
},
"vcs": vcs,
}

config_yaml = yaml.dump(config)
Expand Down
36 changes: 21 additions & 15 deletions src/vcspull/_internal/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class ConfigReader:
'{\n "session_name": "my session"\n}'
"""

def __init__(self, content: "RawConfigData"):
def __init__(self, content: "RawConfigData") -> None:
self.content = content

@staticmethod
def _load(format: "FormatLiteral", content: str):
def _load(format: "FormatLiteral", content: str) -> t.Dict[str, t.Any]:
"""Load raw config data and directly return it.

>>> ConfigReader._load("json", '{ "session_name": "my session" }')
Expand All @@ -36,17 +36,20 @@ def _load(format: "FormatLiteral", content: str):
{'session_name': 'my session'}
"""
if format == "yaml":
return yaml.load(
content,
Loader=yaml.SafeLoader,
return t.cast(
t.Dict[str, t.Any],
yaml.load(
content,
Loader=yaml.SafeLoader,
),
)
elif format == "json":
return json.loads(content)
return t.cast(t.Dict[str, t.Any], json.loads(content))
else:
raise NotImplementedError(f"{format} not supported in configuration")

@classmethod
def load(cls, format: "FormatLiteral", content: str):
def load(cls, format: "FormatLiteral", content: str) -> "ConfigReader":
"""Load raw config data into a ConfigReader instance (to dump later).

>>> cfg = ConfigReader.load("json", '{ "session_name": "my session" }')
Expand All @@ -69,7 +72,7 @@ def load(cls, format: "FormatLiteral", content: str):
)

@classmethod
def _from_file(cls, path: pathlib.Path):
def _from_file(cls, path: pathlib.Path) -> t.Dict[str, t.Any]:
r"""Load data from file path directly to dictionary.

**YAML file**
Expand Down Expand Up @@ -102,7 +105,7 @@ def _from_file(cls, path: pathlib.Path):
content = open(path).read()

if path.suffix in [".yaml", ".yml"]:
format: FormatLiteral = "yaml"
format: "FormatLiteral" = "yaml"
elif path.suffix == ".json":
format = "json"
else:
Expand All @@ -114,7 +117,7 @@ def _from_file(cls, path: pathlib.Path):
)

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

**YAML file**
Expand Down Expand Up @@ -169,11 +172,14 @@ def _dump(
'{\n "session_name": "my session"\n}'
"""
if format == "yaml":
return yaml.dump(
content,
indent=2,
default_flow_style=False,
Dumper=yaml.SafeDumper,
return t.cast(
str,
yaml.dump(
content,
indent=2,
default_flow_style=False,
Dumper=yaml.SafeDumper,
),
)
elif format == "json":
return json.dumps(
Expand Down
22 changes: 19 additions & 3 deletions src/vcspull/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import argparse
import logging
import textwrap
import typing as t
from typing import overload

from libvcs.__about__ import __version__ as libvcs_version

Expand All @@ -30,7 +32,21 @@
).strip()


def create_parser(return_subparsers: bool = False):
@overload
def create_parser(
return_subparsers: t.Literal[True],
) -> t.Tuple[argparse.ArgumentParser, t.Any]:
...


@overload
def create_parser(return_subparsers: t.Literal[False]) -> argparse.ArgumentParser:
...


def create_parser(
return_subparsers: bool = False,
) -> t.Union[argparse.ArgumentParser, t.Tuple[argparse.ArgumentParser, t.Any]]:
parser = argparse.ArgumentParser(
prog="vcspull",
formatter_class=argparse.RawDescriptionHelpFormatter,
Expand Down Expand Up @@ -64,9 +80,9 @@ def create_parser(return_subparsers: bool = False):
return parser


def cli(args=None):
def cli(_args: t.Optional[t.List[str]] = None) -> None:
parser, sync_parser = create_parser(return_subparsers=True)
args = parser.parse_args(args)
args = parser.parse_args(_args)

setup_logger(log=log, level=args.log_level.upper())

Expand Down
Loading