Skip to content

mypy annotations (basic) + libvcs update #373

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

Merged
merged 10 commits into from
Sep 25, 2022
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
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
- name: Lint with flake8
run: poetry run flake8

- name: Lint with mypy
run: poetry run mypy .

- name: Test with pytest
run: poetry run py.test --cov=./ --cov-append --cov-report=xml
env:
Expand Down
3 changes: 2 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ $ pipx install --suffix=@next 'vcspull' --pip-args '\--pre' --force
### Development

- Move to `src/` directory structure (#382)
- libvcs: Update to 0.13.x
- libvcs: Update to 0.17.x (#373)
- Basic mypy annotations (#373)
- 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
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ watch_mypy:

format_markdown:
prettier --parser=markdown -w *.md docs/*.md docs/**/*.md CHANGES

monkeytype_create:
poetry run monkeytype run `poetry run which py.test`

monkeytype_apply:
poetry run monkeytype list-modules | xargs -n1 -I{} sh -c 'poetry run monkeytype apply {}'
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
sys.path.insert(0, str(cwd / "_ext"))

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

Expand Down Expand Up @@ -60,7 +60,7 @@
html_css_files = ["css/custom.css"]
html_extra_path = ["manifest.json"]
html_theme = "furo"
html_theme_path = []
html_theme_path: list = []
html_theme_options = {
"light_logo": "img/vcspull.svg",
"dark_logo": "img/vcspull-dark.svg",
Expand Down
52 changes: 51 additions & 1 deletion docs/developing.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ $ make serve

## Linting

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

### flake8
Expand Down Expand Up @@ -217,6 +217,55 @@ See `[flake8]` in setup.cfg.

````

### mypy

[mypy] is used for static type checking.

````{tab} Command

poetry:

```console
$ poetry run mypy .
```

If you setup manually:

```console
$ mypy .
```

````

````{tab} make

```console
$ make mypy
```

````

````{tab} Watch

```console
$ make watch_mypy
```

requires [`entr(1)`].
````

````{tab} Configuration

See `[flake8]` in setup.cfg.

```{literalinclude} ../setup.cfg
:language: ini
:start-at: "[mypy]"

```

````

## Publishing to PyPI

As of 0.10, [poetry] handles virtualenv creation, package requirements, versioning,
Expand All @@ -237,3 +286,4 @@ Update `__version__` in `__about__.py` and `pyproject.toml`::
[black]: https://github.com/psf/black
[isort]: https://pypi.org/project/isort/
[flake8]: https://flake8.pycqa.org/
[mypy]: http://mypy-lang.org/
61 changes: 56 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 25 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ vcspull = 'vcspull:cli.cli'
python = "^3.9"
click = "~8"
kaptan = "*"
libvcs = "~0.13.7"
libvcs = "~0.17.0a0"
colorama = ">=0.3.9"

[tool.poetry.dev-dependencies]
Expand Down Expand Up @@ -94,6 +94,11 @@ flake8-bugbear = "^22.8.23"
flake8-comprehensions = "*"
mypy = "*"

### Lint : Annotations ###
types-requests = "^2.28.11"
types-PyYAML = "^6.0.11"
types-colorama = "^0.4.15"

[tool.poetry.extras]
docs = [
"sphinx",
Expand All @@ -111,7 +116,25 @@ docs = [
test = ["pytest", "pytest-rerunfailures", "pytest-watcher"]
coverage = ["codecov", "coverage", "pytest-cov"]
format = ["black", "isort"]
lint = ["flake8", "flake8-bugbear", "flake8-comprehensions", "mypy"]
lint = [
"flake8",
"flake8-bugbear",
"flake8-comprehensions",
"mypy",
"types-requests",
"types-PyYAML",
"types-colorama",
]

[tool.mypy]
python_version = 3.9
warn_unused_configs = true

[[tool.mypy.overrides]]
module = [
"kaptan.*",
]
ignore_missing_imports = true

[tool.coverage.run]
branch = true
Expand Down
10 changes: 5 additions & 5 deletions scripts/generate_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@
print("File %s not accesible" % (config_filename))
sys.exit(1)

result = requests.get(
response = requests.get(
"%s/api/v4/groups/%s/projects" % (gitlab_host, gitlab_namespace),
params={"include_subgroups": "true", "per_page": "100"},
headers={"Authorization": "Bearer %s" % (gitlab_token)},
)

if 200 != result.status_code:
print("Error: ", result)
if 200 != response.status_code:
print("Error: ", response)
sys.exit(1)

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

for group in result.json():
for group in response.json():
url_to_repo = group["ssh_url_to_repo"].replace(":", "/")
namespace_path = group["namespace"]["full_path"]
reponame = group["path"]
Expand Down
22 changes: 18 additions & 4 deletions src/vcspull/cli/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import click.shell_completion
from click.shell_completion import CompletionItem

from libvcs.shortcuts import create_project_from_pip_url
from libvcs._internal.shortcuts import create_project
from libvcs.url import registry as url_tools
from vcspull.types import ConfigDict

from ..config import filter_repos, find_config_files, load_configs

Expand All @@ -21,13 +23,13 @@ def get_repo_completions(
if ctx.params["config"] is None
else load_configs(files=[ctx.params["config"]])
)
found_repos = []
found_repos: list[ConfigDict] = []
repo_terms = [incomplete]

for repo_term in repo_terms:
dir, vcs_url, name = None, None, None
if any(repo_term.startswith(n) for n in ["./", "/", "~", "$HOME"]):
dir = repo_term
dir = dir
elif any(repo_term.startswith(n) for n in ["http", "git", "svn", "hg"]):
vcs_url = repo_term
else:
Expand Down Expand Up @@ -105,9 +107,21 @@ def update_repo(repo_dict):
repo_dict = deepcopy(repo_dict)
if "pip_url" not in repo_dict:
repo_dict["pip_url"] = repo_dict.pop("url")
if "url" not in repo_dict:
repo_dict["url"] = repo_dict.pop("pip_url")
repo_dict["progress_callback"] = progress_cb

r = create_project_from_pip_url(**repo_dict) # Creates the repo object
if repo_dict.get("vcs") is None:
vcs_matches = url_tools.registry.match(url=repo_dict["url"], is_explicit=True)

if len(vcs_matches) == 0:
raise Exception(f"No vcs found for {repo_dict}")
if len(vcs_matches) > 1:
raise Exception(f"No exact matches for {repo_dict}")

repo_dict["vcs"] = vcs_matches[0].vcs

r = create_project(**repo_dict) # Creates the repo object
r.update_repo(set_remotes=True) # Creates repo if not exists and fetches

return r
Loading