Skip to content

Commit f15b98c

Browse files
authored
Drop python 2.7, add type hints (#271)
2 parents e6caccf + c2a1e12 commit f15b98c

27 files changed

+280
-1109
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
python-version: ["2.7", "3.x"]
10+
python-version: [ '3.6', '3.7', '3.8' ]
1111
steps:
1212
- uses: actions/checkout@v1
1313
- name: Configure git

CHANGES

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@
22

33
Here are the changes for libvcs.
44

5-
## current
5+
## libvcs 0.9-current
66

77
Generally speaking, refactor / magic is in the process of being stripped
88
out in the next few releases. The API is subject to change significantly
99
in pre-1.0 builds.
1010

11+
[#271]:
12+
- Big version bump (0.5 -> 0.9)
13+
- Remove Python 2.7 support
14+
- Add annotations
15+
- Change `libvcs.git.GitRepo.status()` to return `GitStatus` named tuple
16+
- Breaking change: Repo objects now require `repo_dir` to be passed
17+
- Update black to 21.6b0
18+
19+
[#271]: https://github.com/vcs-python/libvcs/pull/271
20+
1121
## libvcs 0.5 (2020-08-11)
1222

1323
- [refactor] [#267] overhaul docs

docs/Makefile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ checkbuild:
159159
rm -rf $(BUILDDIR)
160160
$(SPHINXBUILD) -n -q ./ $(BUILDDIR)
161161

162-
WATCH_FILES= find .. -type f -not -path '*/\.*' | grep -i '.*[.]rst\$\|.*[.].md\|.*[.]py\$\|CHANGES\|TODO\|.*conf\.py' 2> /dev/null
162+
WATCH_FILES= find .. -type f -not -path '*/\.*' | grep -i '.*[.]rst\$\|.*[.]md\$\|.*[.]py\$\|CHANGES\|TODO\|.*conf\.py' 2> /dev/null
163163

164164
watch:
165165
if command -v entr > /dev/null; then ${WATCH_FILES} | entr -c $(MAKE) html; else $(MAKE) html; fi
@@ -170,13 +170,7 @@ serve:
170170
@echo 'docs server running at http://localhost:${HTTP_PORT}/'
171171
@echo
172172
@echo '=============================================================='
173-
@if test ${PYVERSION} -eq 2; then $(MAKE) serve_py2; else make serve_py3; fi
174-
175-
serve_py2:
176-
pushd _build/html; python2 -m SimpleHTTPServer ${HTTP_PORT}; popd
177-
178-
serve_py3:
179-
python -m http.server ${HTTP_PORT} --directory _build/html
173+
poetry run python -m http.server ${HTTP_PORT} --directory _build/html
180174

181175
dev:
182176
$(MAKE) -j watch serve

docs/api.md

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,58 @@
11
# API Reference
22

3-
## Creating a repo object
3+
## Create from VCS url
44

55
Helper methods are available in ``libvcs.shortcuts`` which
66
can return a repo object from a single entry-point.
77

88
```eval_rst
9-
.. autofunction:: libvcs.shortcuts.create_repo
10-
11-
.. autofunction:: libvcs.shortcuts.create_repo_from_pip_url
9+
.. automodule:: libvcs.shortcuts
10+
:members:
1211
```
1312

14-
## Instantiating a repo by hand
15-
16-
Tools like :func:`libvcs.shortcuts.create_repo` and
17-
:func:`libvcs.shortcuts.create_repo_from_pip_url` are just wrappers
18-
around instantiated these classes.
19-
2013
See examples below of git, mercurial, and subversion.
2114

15+
## Instantiating a repo by hand
16+
2217
### Git
2318

2419
```eval_rst
25-
.. autoclass:: libvcs.git.GitRepo
20+
.. automodule:: libvcs.git
2621
:members:
2722
:show-inheritance:
28-
29-
.. autoclass:: libvcs.git.GitRemote
30-
:members:
31-
:show-inheritance:
32-
33-
.. autofunction:: libvcs.git.extract_status
23+
:inherited-members:
3424
```
3525

3626
### Mercurial
3727

3828
aka ``hg(1)``
3929

4030
```eval_rst
41-
.. autoclass:: libvcs.hg.MercurialRepo
31+
.. automodule:: libvcs.hg
4232
:members:
4333
:show-inheritance:
34+
:inherited-members:
4435
```
4536

4637
### Subversion
4738

4839
aka ``svn(1)``
4940

5041
```eval_rst
51-
.. autoclass:: libvcs.svn.SubversionRepo
42+
.. automodule:: libvcs.svn
5243
:members:
5344
:show-inheritance:
45+
:inherited-members:
5446
```
5547

56-
### Adding your own VCS
48+
### Under the hood
5749

58-
Extending libvcs can be done through subclassing ``BaseRepo``.
50+
Adding your own VCS / Extending libvcs can be done through subclassing ``BaseRepo``.
5951

6052
```eval_rst
61-
.. autoclass:: libvcs.base.BaseRepo
62-
:members:
63-
:show-inheritance:
53+
.. automodule:: libvcs.base
54+
:members:
55+
:show-inheritance:
6456
```
6557

6658
### Utility stuff

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import inspect
32
import os
43
import sys
@@ -20,6 +19,7 @@
2019

2120
extensions = [
2221
'sphinx.ext.autodoc',
22+
'sphinx_autodoc_typehints',
2323
'sphinx.ext.intersphinx',
2424
'sphinx.ext.todo',
2525
'sphinx.ext.napoleon',

docs/developing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Update `__version__` in `__about__.py` and `pyproject.toml`::
5151
git push
5252
git push --tags
5353
poetry build
54-
poetry deploy
54+
poetry publish
5555

5656
[poetry]: https://python-poetry.org/
5757
[entr(1)]: http://eradman.com/entrproject/

libvcs/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__title__ = 'libvcs'
22
__package_name__ = 'libvcs'
33
__description__ = 'vcs abstraction layer'
4-
__version__ = '0.5.0'
4+
__version__ = '0.9.0a2'
55
__author__ = 'Tony Narlock'
66
__github__ = 'https://github.com/vcs-python/libvcs'
77
__docs__ = 'https://libvcs.git-pull.com'

libvcs/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# -*- coding: utf-8 -*-
21
"""Repo package for libvcs."""
3-
from __future__ import absolute_import, print_function, unicode_literals
4-
52
import logging
63

74
from .base import BaseRepo, RepoLoggingAdapter

libvcs/_compat.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

libvcs/base.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
1-
# -*- coding: utf-8 -*-
21
"""Base class for Repository objects."""
3-
from __future__ import absolute_import, print_function, unicode_literals
4-
52
import logging
63
import os
4+
from typing import NamedTuple
5+
from urllib import parse as urlparse
76

8-
from ._compat import implements_to_string, urlparse
97
from .util import RepoLoggingAdapter, mkdir_p, run
108

119
logger = logging.getLogger(__name__)
1210

1311

14-
@implements_to_string
12+
class VCSLocation(NamedTuple):
13+
url: str
14+
rev: str
15+
16+
17+
def convert_pip_url(pip_url: str) -> VCSLocation:
18+
"""Return repo URL and revision by parsing `libvcs.base.BaseRepo.url`."""
19+
error_message = (
20+
"Sorry, '%s' is a malformed VCS url. "
21+
"The format is <vcs>+<protocol>://<url>, "
22+
"e.g. svn+http://myrepo/svn/MyApp#egg=MyApp"
23+
)
24+
assert '+' in pip_url, error_message % pip_url
25+
url = pip_url.split('+', 1)[1]
26+
scheme, netloc, path, query, frag = urlparse.urlsplit(url)
27+
rev = None
28+
if '@' in path:
29+
path, rev = path.rsplit('@', 1)
30+
url = urlparse.urlunsplit((scheme, netloc, path, query, ''))
31+
return VCSLocation(url=url, rev=rev)
32+
33+
1534
class BaseRepo(RepoLoggingAdapter, object):
1635

1736
"""Base class for repositories.
@@ -56,7 +75,7 @@ def __init__(self, url, repo_dir, progress_callback=None, *args, **kwargs):
5675

5776
@classmethod
5877
def from_pip_url(cls, pip_url, *args, **kwargs):
59-
url, rev = cls.get_url_and_revision_from_pip_url(pip_url)
78+
url, rev = convert_pip_url(pip_url)
6079
self = cls(url=url, rev=rev, *args, **kwargs)
6180

6281
return self
@@ -105,7 +124,7 @@ def run(
105124
cwd=cwd,
106125
)
107126

108-
def check_destination(self, *args, **kwargs):
127+
def ensure_dir(self, *args, **kwargs):
109128
"""Assure destination path exists. If not, create directories."""
110129
if os.path.exists(self.path):
111130
return True
@@ -122,22 +141,5 @@ def check_destination(self, *args, **kwargs):
122141

123142
return True
124143

125-
@classmethod
126-
def get_url_and_revision_from_pip_url(cls, pip_url):
127-
"""Return repo URL and revision by parsing `libvcs.base.BaseRepo.url`."""
128-
error_message = (
129-
"Sorry, '%s' is a malformed VCS url. "
130-
"The format is <vcs>+<protocol>://<url>, "
131-
"e.g. svn+http://myrepo/svn/MyApp#egg=MyApp"
132-
)
133-
assert '+' in pip_url, error_message % pip_url
134-
url = pip_url.split('+', 1)[1]
135-
scheme, netloc, path, query, frag = urlparse.urlsplit(url)
136-
rev = None
137-
if '@' in path:
138-
path, rev = path.rsplit('@', 1)
139-
url = urlparse.urlunsplit((scheme, netloc, path, query, ''))
140-
return url, rev
141-
142144
def __repr__(self):
143145
return "<{} {}>".format(self.__class__.__name__, self.repo_name)

0 commit comments

Comments
 (0)