Skip to content

Commit 8709f5e

Browse files
authored
ci: mypy: basic annotations + libvcs update (#373)
Updates libvcs to 0.17.0a0 and adds basic mypy annotation
2 parents 728c432 + 4d0e874 commit 8709f5e

File tree

17 files changed

+421
-174
lines changed

17 files changed

+421
-174
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ jobs:
3333
- name: Lint with flake8
3434
run: poetry run flake8
3535

36+
- name: Lint with mypy
37+
run: poetry run mypy .
38+
3639
- name: Test with pytest
3740
run: poetry run py.test --cov=./ --cov-append --cov-report=xml
3841
env:

CHANGES

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ $ pipx install --suffix=@next 'vcspull' --pip-args '\--pre' --force
2626
### Development
2727

2828
- Move to `src/` directory structure (#382)
29-
- libvcs: Update to 0.13.x
29+
- libvcs: Update to 0.17.x (#373)
30+
- Basic mypy annotations (#373)
3031
- Remove `.pre-commit-config.yaml`: Let's not automate what the contributor could /
3132
should do themselves.
3233
- Add [flake8-bugbear](https://github.com/PyCQA/flake8-bugbear) (#379)

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,9 @@ watch_mypy:
4949

5050
format_markdown:
5151
prettier --parser=markdown -w *.md docs/*.md docs/**/*.md CHANGES
52+
53+
monkeytype_create:
54+
poetry run monkeytype run `poetry run which py.test`
55+
56+
monkeytype_apply:
57+
poetry run monkeytype list-modules | xargs -n1 -I{} sh -c 'poetry run monkeytype apply {}'

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
sys.path.insert(0, str(cwd / "_ext"))
1313

1414
# package data
15-
about = {}
15+
about: dict[str, str] = {}
1616
with open(src_root / "vcspull" / "__about__.py") as fp:
1717
exec(fp.read(), about)
1818

@@ -60,7 +60,7 @@
6060
html_css_files = ["css/custom.css"]
6161
html_extra_path = ["manifest.json"]
6262
html_theme = "furo"
63-
html_theme_path = []
63+
html_theme_path: list = []
6464
html_theme_options = {
6565
"light_logo": "img/vcspull.svg",
6666
"dark_logo": "img/vcspull-dark.svg",

docs/developing.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ $ make serve
163163

164164
## Linting
165165

166-
[flake8] run via CI in our GitHub Actions. See the configuration in `pyproject.toml` and
166+
[flake8] and [mypy] run via CI in our GitHub Actions. See the configuration in `pyproject.toml` and
167167
`setup.cfg`.
168168

169169
### flake8
@@ -217,6 +217,55 @@ See `[flake8]` in setup.cfg.
217217
218218
````
219219

220+
### mypy
221+
222+
[mypy] is used for static type checking.
223+
224+
````{tab} Command
225+
226+
poetry:
227+
228+
```console
229+
$ poetry run mypy .
230+
```
231+
232+
If you setup manually:
233+
234+
```console
235+
$ mypy .
236+
```
237+
238+
````
239+
240+
````{tab} make
241+
242+
```console
243+
$ make mypy
244+
```
245+
246+
````
247+
248+
````{tab} Watch
249+
250+
```console
251+
$ make watch_mypy
252+
```
253+
254+
requires [`entr(1)`].
255+
````
256+
257+
````{tab} Configuration
258+
259+
See `[flake8]` in setup.cfg.
260+
261+
```{literalinclude} ../setup.cfg
262+
:language: ini
263+
:start-at: "[mypy]"
264+
265+
```
266+
267+
````
268+
220269
## Publishing to PyPI
221270

222271
As of 0.10, [poetry] handles virtualenv creation, package requirements, versioning,
@@ -237,3 +286,4 @@ Update `__version__` in `__about__.py` and `pyproject.toml`::
237286
[black]: https://github.com/psf/black
238287
[isort]: https://pypi.org/project/isort/
239288
[flake8]: https://flake8.pycqa.org/
289+
[mypy]: http://mypy-lang.org/

poetry.lock

Lines changed: 56 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ vcspull = 'vcspull:cli.cli'
5757
python = "^3.9"
5858
click = "~8"
5959
kaptan = "*"
60-
libvcs = "~0.13.7"
60+
libvcs = "~0.17.0a0"
6161
colorama = ">=0.3.9"
6262

6363
[tool.poetry.dev-dependencies]
@@ -94,6 +94,11 @@ flake8-bugbear = "^22.8.23"
9494
flake8-comprehensions = "*"
9595
mypy = "*"
9696

97+
### Lint : Annotations ###
98+
types-requests = "^2.28.11"
99+
types-PyYAML = "^6.0.11"
100+
types-colorama = "^0.4.15"
101+
97102
[tool.poetry.extras]
98103
docs = [
99104
"sphinx",
@@ -111,7 +116,25 @@ docs = [
111116
test = ["pytest", "pytest-rerunfailures", "pytest-watcher"]
112117
coverage = ["codecov", "coverage", "pytest-cov"]
113118
format = ["black", "isort"]
114-
lint = ["flake8", "flake8-bugbear", "flake8-comprehensions", "mypy"]
119+
lint = [
120+
"flake8",
121+
"flake8-bugbear",
122+
"flake8-comprehensions",
123+
"mypy",
124+
"types-requests",
125+
"types-PyYAML",
126+
"types-colorama",
127+
]
128+
129+
[tool.mypy]
130+
python_version = 3.9
131+
warn_unused_configs = true
132+
133+
[[tool.mypy.overrides]]
134+
module = [
135+
"kaptan.*",
136+
]
137+
ignore_missing_imports = true
115138

116139
[tool.coverage.run]
117140
branch = true

scripts/generate_gitlab.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,20 @@
5858
print("File %s not accesible" % (config_filename))
5959
sys.exit(1)
6060

61-
result = requests.get(
61+
response = requests.get(
6262
"%s/api/v4/groups/%s/projects" % (gitlab_host, gitlab_namespace),
6363
params={"include_subgroups": "true", "per_page": "100"},
6464
headers={"Authorization": "Bearer %s" % (gitlab_token)},
6565
)
6666

67-
if 200 != result.status_code:
68-
print("Error: ", result)
67+
if 200 != response.status_code:
68+
print("Error: ", response)
6969
sys.exit(1)
7070

7171
path_prefix = os.getcwd()
72-
config = {}
72+
config: dict = {}
7373

74-
for group in result.json():
74+
for group in response.json():
7575
url_to_repo = group["ssh_url_to_repo"].replace(":", "/")
7676
namespace_path = group["namespace"]["full_path"]
7777
reponame = group["path"]

src/vcspull/cli/sync.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import click.shell_completion
77
from click.shell_completion import CompletionItem
88

9-
from libvcs.shortcuts import create_project_from_pip_url
9+
from libvcs._internal.shortcuts import create_project
10+
from libvcs.url import registry as url_tools
11+
from vcspull.types import ConfigDict
1012

1113
from ..config import filter_repos, find_config_files, load_configs
1214

@@ -21,13 +23,13 @@ def get_repo_completions(
2123
if ctx.params["config"] is None
2224
else load_configs(files=[ctx.params["config"]])
2325
)
24-
found_repos = []
26+
found_repos: list[ConfigDict] = []
2527
repo_terms = [incomplete]
2628

2729
for repo_term in repo_terms:
2830
dir, vcs_url, name = None, None, None
2931
if any(repo_term.startswith(n) for n in ["./", "/", "~", "$HOME"]):
30-
dir = repo_term
32+
dir = dir
3133
elif any(repo_term.startswith(n) for n in ["http", "git", "svn", "hg"]):
3234
vcs_url = repo_term
3335
else:
@@ -105,9 +107,21 @@ def update_repo(repo_dict):
105107
repo_dict = deepcopy(repo_dict)
106108
if "pip_url" not in repo_dict:
107109
repo_dict["pip_url"] = repo_dict.pop("url")
110+
if "url" not in repo_dict:
111+
repo_dict["url"] = repo_dict.pop("pip_url")
108112
repo_dict["progress_callback"] = progress_cb
109113

110-
r = create_project_from_pip_url(**repo_dict) # Creates the repo object
114+
if repo_dict.get("vcs") is None:
115+
vcs_matches = url_tools.registry.match(url=repo_dict["url"], is_explicit=True)
116+
117+
if len(vcs_matches) == 0:
118+
raise Exception(f"No vcs found for {repo_dict}")
119+
if len(vcs_matches) > 1:
120+
raise Exception(f"No exact matches for {repo_dict}")
121+
122+
repo_dict["vcs"] = vcs_matches[0].vcs
123+
124+
r = create_project(**repo_dict) # Creates the repo object
111125
r.update_repo(set_remotes=True) # Creates repo if not exists and fetches
112126

113127
return r

0 commit comments

Comments
 (0)