From a51e9a8f6e832c7effcdf65b3d93c4733619906e Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 3 Apr 2022 17:58:58 -0500 Subject: [PATCH 1/3] refactor!: Move git, hg, svn to libvcs.states --- docs/api/git.md | 17 ----------------- docs/index.md | 2 +- docs/redirects.txt | 6 +++++- docs/{api => states}/base.md | 8 +++++--- docs/states/git.md | 24 ++++++++++++++++++++++++ docs/{api => states}/hg.md | 8 ++++---- docs/{api => states}/index.md | 11 ++++++++--- docs/{api => states}/svn.md | 8 ++++---- libvcs/__init__.py | 9 +++++---- libvcs/{ => states}/base.py | 2 +- libvcs/{ => states}/constants.py | 0 libvcs/{ => states}/git.py | 4 ++-- libvcs/{ => states}/hg.py | 0 libvcs/{ => states}/svn.py | 0 tests/test_base.py | 2 +- tests/test_git.py | 4 ++-- 16 files changed, 62 insertions(+), 43 deletions(-) delete mode 100644 docs/api/git.md rename docs/{api => states}/base.md (60%) create mode 100644 docs/states/git.md rename docs/{api => states}/hg.md (56%) rename docs/{api => states}/index.md (59%) rename docs/{api => states}/svn.md (55%) rename libvcs/{ => states}/base.py (98%) rename libvcs/{ => states}/constants.py (100%) rename libvcs/{ => states}/git.py (99%) rename libvcs/{ => states}/hg.py (100%) rename libvcs/{ => states}/svn.py (100%) diff --git a/docs/api/git.md b/docs/api/git.md deleted file mode 100644 index 123a4e420..000000000 --- a/docs/api/git.md +++ /dev/null @@ -1,17 +0,0 @@ -# Git - -```{eval-rst} -.. autosummary:: - :recursive: - - libvcs.git.GitRemote - libvcs.git.GitRepo -``` - -```{eval-rst} -.. automodule:: libvcs.git - :members: - :show-inheritance: - :undoc-members: - :inherited-members: -``` diff --git a/docs/index.md b/docs/index.md index 838b0296b..f51a5a3b0 100644 --- a/docs/index.md +++ b/docs/index.md @@ -9,7 +9,7 @@ :hidden: quickstart -api/index +states/index ``` ```{toctree} diff --git a/docs/redirects.txt b/docs/redirects.txt index af9e29659..4aeeae9cf 100644 --- a/docs/redirects.txt +++ b/docs/redirects.txt @@ -1 +1,5 @@ -"api.md" "api/index.md" +"api.md" "states/index.md" +"api/base.md" "states/base.md" +"api/git.md" "states/git.md" +"api/hg.md" "states/hg.md" +"api/svn.md" "states/svn.md" diff --git a/docs/api/base.md b/docs/states/base.md similarity index 60% rename from docs/api/base.md rename to docs/states/base.md index edb2b9aa6..1ca2410b8 100644 --- a/docs/api/base.md +++ b/docs/states/base.md @@ -1,4 +1,6 @@ -# Base objects +# `libvcs.states.base` + +Base objects / classes for states. Adding your own VCS / Extending libvcs can be done through subclassing `BaseRepo`. @@ -6,11 +8,11 @@ Adding your own VCS / Extending libvcs can be done through subclassing `BaseRepo .. autosummary:: :recursive: - libvcs.base.BaseRepo + libvcs.states.base.BaseRepo ``` ```{eval-rst} -.. automodule:: libvcs.base +.. automodule:: libvcs.states.base :members: :show-inheritance: ``` diff --git a/docs/states/git.md b/docs/states/git.md new file mode 100644 index 000000000..a8714be8b --- /dev/null +++ b/docs/states/git.md @@ -0,0 +1,24 @@ +# `libvcs.states.git` + +For `git(1)`. + +Compare to: +[`fabtools.require.git`](https://fabtools.readthedocs.io/en/0.19.0/api/require/git.html), +[`salt.states.git`](https://docs.saltproject.io/en/latest/ref/states/all/salt.states.git.html), +[`ansible.builtin.git`](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/git_module.html) + +```{eval-rst} +.. autosummary:: + :recursive: + + libvcs.states.git.GitRemote + libvcs.states.git.GitRepo +``` + +```{eval-rst} +.. automodule:: libvcs.states.git + :members: + :show-inheritance: + :undoc-members: + :inherited-members: +``` diff --git a/docs/api/hg.md b/docs/states/hg.md similarity index 56% rename from docs/api/hg.md rename to docs/states/hg.md index 355685046..93c1ab2d3 100644 --- a/docs/api/hg.md +++ b/docs/states/hg.md @@ -1,16 +1,16 @@ -# Mercurial (hg) +# `libvcs.states.hg` -aka `hg(1)` +For mercurial, aka `hg(1)`. ```{eval-rst} .. autosummary:: :recursive: - libvcs.hg.MercurialRepo + libvcs.states.hg.MercurialRepo ``` ```{eval-rst} -.. automodule:: libvcs.hg +.. automodule:: libvcs.states.hg :members: :show-inheritance: :undoc-members: diff --git a/docs/api/index.md b/docs/states/index.md similarity index 59% rename from docs/api/index.md rename to docs/states/index.md index b48391426..09f567106 100644 --- a/docs/api/index.md +++ b/docs/states/index.md @@ -1,6 +1,11 @@ -(api)= +(states)= -# API Reference +# `libvcs.states` + +Compare to: +[`fabtools.require.git`](https://fabtools.readthedocs.io/en/0.19.0/api/require/git.html), +[`salt.states.git`](https://docs.saltproject.io/en/latest/ref/states/all/salt.states.git.html), +[`ansible.builtin.git`](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/git_module.html) :::{warning} @@ -33,7 +38,7 @@ See examples below of git, mercurial, and subversion. ## Constants ```{eval-rst} -.. automodule:: libvcs.constants +.. automodule:: libvcs.states.constants :members: ``` diff --git a/docs/api/svn.md b/docs/states/svn.md similarity index 55% rename from docs/api/svn.md rename to docs/states/svn.md index 7b1f938a8..1061de893 100644 --- a/docs/api/svn.md +++ b/docs/states/svn.md @@ -1,16 +1,16 @@ -# Subversion (svn) +# `libvcs.states.svn` -aka `svn(1)` +For subversion, aka `svn(1)` ```{eval-rst} .. autosummary:: :recursive: - libvcs.svn.SubversionRepo + libvcs.states.svn.SubversionRepo ``` ```{eval-rst} -.. automodule:: libvcs.svn +.. automodule:: libvcs.states.svn :members: :show-inheritance: :undoc-members: diff --git a/libvcs/__init__.py b/libvcs/__init__.py index 52e543d6e..bc978fc2c 100644 --- a/libvcs/__init__.py +++ b/libvcs/__init__.py @@ -1,10 +1,11 @@ """Repo package for libvcs.""" import logging -from .base import BaseRepo, RepoLoggingAdapter -from .git import GitRepo -from .hg import MercurialRepo -from .svn import SubversionRepo +from .states.base import BaseRepo +from .states.git import GitRepo +from .states.hg import MercurialRepo +from .states.svn import SubversionRepo +from .util import RepoLoggingAdapter __all__ = [ "GitRepo", diff --git a/libvcs/base.py b/libvcs/states/base.py similarity index 98% rename from libvcs/base.py rename to libvcs/states/base.py index aad3e64bd..7be30ffe5 100644 --- a/libvcs/base.py +++ b/libvcs/states/base.py @@ -4,7 +4,7 @@ from typing import NamedTuple from urllib import parse as urlparse -from .util import RepoLoggingAdapter, mkdir_p, run +from ..util import RepoLoggingAdapter, mkdir_p, run logger = logging.getLogger(__name__) diff --git a/libvcs/constants.py b/libvcs/states/constants.py similarity index 100% rename from libvcs/constants.py rename to libvcs/states/constants.py diff --git a/libvcs/git.py b/libvcs/states/git.py similarity index 99% rename from libvcs/git.py rename to libvcs/states/git.py index ec35dfa07..f5aaa462b 100644 --- a/libvcs/git.py +++ b/libvcs/states/git.py @@ -20,8 +20,8 @@ from typing import Dict, NamedTuple, Optional, TypedDict, Union from urllib import parse as urlparse -from . import exc -from .base import BaseRepo, VCSLocation, convert_pip_url as base_convert_pip_url +from .. import exc +from ..states.base import BaseRepo, VCSLocation, convert_pip_url as base_convert_pip_url logger = logging.getLogger(__name__) diff --git a/libvcs/hg.py b/libvcs/states/hg.py similarity index 100% rename from libvcs/hg.py rename to libvcs/states/hg.py diff --git a/libvcs/svn.py b/libvcs/states/svn.py similarity index 100% rename from libvcs/svn.py rename to libvcs/states/svn.py diff --git a/tests/test_base.py b/tests/test_base.py index 504454bb9..0bdea0b2d 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -1,8 +1,8 @@ """tests for libvcs repo abstract base class.""" import pathlib -from libvcs.base import BaseRepo, convert_pip_url from libvcs.shortcuts import create_repo +from libvcs.states.base import BaseRepo, convert_pip_url def test_repr(): diff --git a/tests/test_git.py b/tests/test_git.py index b80d0cea8..521ed1860 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -11,14 +11,14 @@ from pytest_mock import MockerFixture from libvcs import exc -from libvcs.git import ( +from libvcs.shortcuts import create_repo_from_pip_url +from libvcs.states.git import ( FullRemoteDict, GitRemote, GitRepo, convert_pip_url as git_convert_pip_url, extract_status, ) -from libvcs.shortcuts import create_repo_from_pip_url from libvcs.util import run, which if not which("git"): From ac58a8d00c06674644127e81be0b9992cf36ea7f Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 3 Apr 2022 20:05:02 -0500 Subject: [PATCH 2/3] test: Move to test/states --- tests/{ => states}/test_base.py | 0 tests/{ => states}/test_git.py | 0 tests/{ => states}/test_hg.py | 0 tests/{ => states}/test_svn.py | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename tests/{ => states}/test_base.py (100%) rename tests/{ => states}/test_git.py (100%) rename tests/{ => states}/test_hg.py (100%) rename tests/{ => states}/test_svn.py (100%) diff --git a/tests/test_base.py b/tests/states/test_base.py similarity index 100% rename from tests/test_base.py rename to tests/states/test_base.py diff --git a/tests/test_git.py b/tests/states/test_git.py similarity index 100% rename from tests/test_git.py rename to tests/states/test_git.py diff --git a/tests/test_hg.py b/tests/states/test_hg.py similarity index 100% rename from tests/test_hg.py rename to tests/states/test_hg.py diff --git a/tests/test_svn.py b/tests/states/test_svn.py similarity index 100% rename from tests/test_svn.py rename to tests/states/test_svn.py From 006cc020a7eb05667d9f861768e4f06b18583d44 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 3 Apr 2022 18:11:35 -0500 Subject: [PATCH 3/3] docs(CHANGES): Note breaking change / move --- CHANGES | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 89677b519..6653a9803 100644 --- a/CHANGES +++ b/CHANGES @@ -11,9 +11,14 @@ $ pip install --user --upgrade --pre libvcs ## libvcs 0.12.0 (unreleased, beta 0) +### Breaking + +- `GitRepo`, `SVNRepo`, `MercurialRepo`, `BaseRepo` have been moved to + `libvcs.states.{module}.{Module}Repo` + ### What's new -- {class}`libvcs.git.GitRepo` now accepts remotes in `__init__` +- {class}`libvcs.states.git.GitRepo` now accepts remotes in `__init__` ```python repo = GitRepo( @@ -38,7 +43,7 @@ $ pip install --user --upgrade --pre libvcs ) ``` -- {meth}`libvcs.git.GitRepo.update_repo` now accepts `set_remotes=True` +- {meth}`libvcs.states.git.GitRepo.update_repo` now accepts `set_remotes=True` ### Compatibility @@ -55,9 +60,9 @@ $ pip install --user --upgrade --pre libvcs [@actions/setup v3.1](https://github.com/actions/setup-python/releases/tag/v3.1.0), (:issue:`316`) - New constants for `str` -> class mappings - - {data}`libvcs.constants.DEFAULT_VCS_CLASS_MAP` - - {data}`libvcs.constants.DEFAULT_VCS_CLASS_UNION` - - {data}`libvcs.constants.DEFAULT_VCS_LITERAL` + - {data}`libvcs.states.constants.DEFAULT_VCS_CLASS_MAP` + - {data}`libvcs.states.constants.DEFAULT_VCS_CLASS_UNION` + - {data}`libvcs.states.constants.DEFAULT_VCS_LITERAL` - Remove tox and tox-poetry-installer. It turns out installing poetry inside a poetry project doesn't work well. (`poetry update`, `poetry publish`, etc. commands would fail)