Skip to content

Commit a010380

Browse files
committed
First steps
1 parent 6dcf3a1 commit a010380

File tree

7 files changed

+93
-7
lines changed

7 files changed

+93
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.pydocstringformatter_primer_tests
12
pydocstringformatter.egg-info
23
dist/
34
docs/_build

pydocstringformatter/testutils/primer/__init__.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from pathlib import Path
2+
3+
PRIMER_DIRECTORY_PATH = (
4+
Path(__file__).parent.parent.parent.parent / ".pydocstringformatter_primer_tests"
5+
)
6+
"""Directory to store anything primer related in."""
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import logging
2+
from dataclasses import dataclass
3+
from pathlib import Path
4+
from typing import Dict, List, Union
5+
6+
import git
7+
8+
from pydocstringformatter.testutils.primer.const import PRIMER_DIRECTORY_PATH
9+
10+
11+
@dataclass
12+
class _PackageToCheck:
13+
"""Represents data about a package to be tested during primer tests."""
14+
15+
url: str
16+
"""URL of the repository to clone."""
17+
18+
branch: str
19+
"""Branch of the repository to clone."""
20+
21+
directories: List[str]
22+
"""Directories within the repository to run the program over."""
23+
24+
@property
25+
def clone_directory(self) -> Path:
26+
"""Directory to clone repository into."""
27+
clone_name = "/".join(self.url.split("/")[-2:]).replace(".git", "")
28+
return PRIMER_DIRECTORY_PATH / clone_name
29+
30+
@property
31+
def paths_to_lint(self) -> List[str]:
32+
"""The paths we need to run against."""
33+
return [str(self.clone_directory / path) for path in self.directories]
34+
35+
def lazy_clone(self) -> None:
36+
"""Clone the repo, if necessary."""
37+
logging.info("Lazy cloning %s", self.url)
38+
39+
# Clone if not yet cloned
40+
if not self.clone_directory.exists():
41+
options: Dict[str, Union[str, int]] = {
42+
"url": self.url,
43+
"to_path": str(self.clone_directory),
44+
"branch": self.branch,
45+
"depth": 1,
46+
}
47+
logging.info("Directory does not exists, cloning: %s", options)
48+
git.Repo.clone_from(**options)
49+
return
50+
51+
# Check if local clone is latest version
52+
remote_sha1_commit = (
53+
git.cmd.Git().ls_remote(self.url, self.branch).split("\t")[0]
54+
)
55+
local_sha1_commit = git.Repo(self.clone_directory).head.object.hexsha
56+
if remote_sha1_commit != local_sha1_commit:
57+
logging.info(
58+
"Remote sha is '%s' while local sha is '%s': pulling new commits",
59+
remote_sha1_commit,
60+
local_sha1_commit,
61+
)
62+
repo = git.Repo(self.clone_directory)
63+
origin = repo.remotes.origin
64+
origin.pull()
65+
else:
66+
logging.info("Repository already up to date.")
67+
68+
69+
PACKAGES = {
70+
"pylint": _PackageToCheck("https://github.com/PyCQA/pylint", "main", ["pylint"]),
71+
}

pydocstringformatter/utils/file_diference.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33

44
def _generate_diff(old: str, new: str, filename: str) -> str:
55
"""Generate a printable diff for two strings of sourcecode."""
6-
return "\n".join(
7-
difflib.unified_diff(
8-
old.split("\n"),
9-
new.split("\n"),
10-
fromfile=filename,
11-
tofile=filename,
12-
lineterm="",
6+
return (
7+
"\n".join(
8+
difflib.unified_diff(
9+
old.split("\n"),
10+
new.split("\n"),
11+
fromfile=filename,
12+
tofile=filename,
13+
lineterm="",
14+
)
1315
)
16+
+ "\n"
1417
)

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ exclude = "tests/data.*"
1414
strict = true
1515
show_error_codes = true
1616

17+
[[tool.mypy.overrides]]
18+
module = ["git.*"]
19+
ignore_missing_imports = true
20+
1721
[tool.pylint.MASTER]
1822
load-plugins=[
1923
"pylint.extensions.check_elif",

requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ coverage[toml]==6.2
44
coveralls==3.3.1
55
pytest==6.2.5
66
pytest-cov==3.0.0
7+
gitpython>=3
78

89
# Requirements for docs building
910
-r docs/requirements-doc.txt

0 commit comments

Comments
 (0)