git-get 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- git_get-0.1.3/.gitignore +2 -0
- git_get-0.1.3/.pre-commit-config.yaml +26 -0
- git_get-0.1.3/PKG-INFO +9 -0
- git_get-0.1.3/git_get.py +101 -0
- git_get-0.1.3/pyproject.toml +50 -0
- git_get-0.1.3/requirements.txt +18 -0
git_get-0.1.3/.gitignore
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# To install hooks, run:
|
|
2
|
+
# pre-commit install --hook-type pre-commit
|
|
3
|
+
# pre-commit install --hook-type commit-msg
|
|
4
|
+
|
|
5
|
+
repos:
|
|
6
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
7
|
+
rev: v4.6.0
|
|
8
|
+
hooks:
|
|
9
|
+
- id: trailing-whitespace
|
|
10
|
+
- id: end-of-file-fixer
|
|
11
|
+
- id: check-yaml
|
|
12
|
+
- id: check-added-large-files
|
|
13
|
+
|
|
14
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
15
|
+
rev: v0.4.2
|
|
16
|
+
hooks:
|
|
17
|
+
- id: ruff-format
|
|
18
|
+
- id: ruff
|
|
19
|
+
args:
|
|
20
|
+
- --fix
|
|
21
|
+
- --exit-non-zero-on-fix
|
|
22
|
+
|
|
23
|
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
|
24
|
+
rev: v1.10.0
|
|
25
|
+
hooks:
|
|
26
|
+
- id: mypy
|
git_get-0.1.3/PKG-INFO
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: git-get
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: Automatically clone Git repos.
|
|
5
|
+
Author-email: Daniel Rocha <daniel@rocha.io>
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Requires-Dist: typer >= 0.6.1
|
|
8
|
+
Requires-Dist: rich >= 12.6.0
|
|
9
|
+
Project-URL: homepage, https://github.com/danroc/git-get
|
git_get-0.1.3/git_get.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""Automatically clone Git repos."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import enum
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
import subprocess # noqa: S404
|
|
9
|
+
import sys
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
|
|
12
|
+
import typer
|
|
13
|
+
|
|
14
|
+
__version__ = "0.1.3"
|
|
15
|
+
|
|
16
|
+
app = typer.Typer()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Options(str, enum.Enum):
|
|
20
|
+
REPOS_DIR = "GIT_GET_REPOS_DIR"
|
|
21
|
+
SSH_USERS = "GIT_GET_SSH_USERS"
|
|
22
|
+
DEFAULT_PREFIX = "GIT_GET_DEFAULT_PREFIX"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# Default configuration, which can be overridden by environment variables.
|
|
26
|
+
config = {
|
|
27
|
+
Options.REPOS_DIR: "~/repos",
|
|
28
|
+
Options.SSH_USERS: "danroc,metamask",
|
|
29
|
+
Options.DEFAULT_PREFIX: "https://github.com/",
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
config = {k: os.getenv(k, config[k]) for k in config}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class InvalidURL(Exception):
|
|
36
|
+
pass
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class Schema(enum.Enum):
|
|
40
|
+
SSH = enum.auto()
|
|
41
|
+
HTTP = enum.auto()
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
FORMATS = {
|
|
45
|
+
Schema.SSH: re.compile(
|
|
46
|
+
r"^(.*?)@(?P<host>.*?):(?P<user>.*?)/(?P<repo>.*?)\.git$",
|
|
47
|
+
),
|
|
48
|
+
Schema.HTTP: re.compile(
|
|
49
|
+
r"^https?://(?P<host>.*?)(?P<port>:\d+)?/(?P<user>.*?)/(?P<repo>.*?)\.git$",
|
|
50
|
+
),
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@dataclass(frozen=True)
|
|
55
|
+
class Repo:
|
|
56
|
+
host: str
|
|
57
|
+
user: str
|
|
58
|
+
name: str
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def parse(url: str) -> Repo:
|
|
62
|
+
for format in FORMATS.values():
|
|
63
|
+
m = format.match(url)
|
|
64
|
+
if m:
|
|
65
|
+
return Repo(
|
|
66
|
+
host=m.group("host"),
|
|
67
|
+
user=m.group("user"),
|
|
68
|
+
name=m.group("repo"),
|
|
69
|
+
)
|
|
70
|
+
raise InvalidURL
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@app.command()
|
|
74
|
+
def main(repo_url: str) -> None:
|
|
75
|
+
clone_url = repo_url.strip()
|
|
76
|
+
if not clone_url.endswith(".git"):
|
|
77
|
+
clone_url += ".git"
|
|
78
|
+
|
|
79
|
+
try:
|
|
80
|
+
# Try to parse the URL
|
|
81
|
+
repo = parse(clone_url)
|
|
82
|
+
except InvalidURL:
|
|
83
|
+
# Retry with the prefix
|
|
84
|
+
clone_url = config[Options.DEFAULT_PREFIX] + clone_url
|
|
85
|
+
repo = parse(clone_url)
|
|
86
|
+
|
|
87
|
+
# Check if should force SSH
|
|
88
|
+
use_ssh_on = config[Options.SSH_USERS].lower().split(",")
|
|
89
|
+
if repo.user.lower() in use_ssh_on:
|
|
90
|
+
clone_url = f"git@{repo.host}:{repo.user}/{repo.name}.git"
|
|
91
|
+
|
|
92
|
+
path = os.path.join(config[Options.REPOS_DIR], repo.host, repo.user, repo.name)
|
|
93
|
+
path = os.path.expanduser(path)
|
|
94
|
+
|
|
95
|
+
print(f"Cloning repo '{clone_url}'...")
|
|
96
|
+
out = subprocess.run(["git", "clone", clone_url, path]) # noqa: S603,S607
|
|
97
|
+
sys.exit(out.returncode)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
if __name__ == "__main__":
|
|
101
|
+
app()
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["flit_core >=3.2,<4"]
|
|
3
|
+
build-backend = "flit_core.buildapi"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "git-get"
|
|
7
|
+
authors = [{ name = "Daniel Rocha", email = "daniel@rocha.io" }]
|
|
8
|
+
dynamic = ["version", "description"]
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
dependencies = ["typer >= 0.6.1", "rich >= 12.6.0"]
|
|
11
|
+
|
|
12
|
+
[project.urls]
|
|
13
|
+
homepage = "https://github.com/danroc/git-get"
|
|
14
|
+
|
|
15
|
+
[project.scripts]
|
|
16
|
+
git-get = "gitget:app"
|
|
17
|
+
|
|
18
|
+
[tool.ruff]
|
|
19
|
+
preview = true
|
|
20
|
+
|
|
21
|
+
[tool.ruff.lint]
|
|
22
|
+
extend-select = [
|
|
23
|
+
# "D", # pydocstyle
|
|
24
|
+
"I", # isort
|
|
25
|
+
"UP", # pyupgrade
|
|
26
|
+
"S", # flake8-bandit
|
|
27
|
+
"B", # flake8-bugbear
|
|
28
|
+
"COM", # flake8-commas
|
|
29
|
+
"C4", # flake8-comprehensions
|
|
30
|
+
"ISC", # flake8-implicit-str-concat
|
|
31
|
+
"FIX", # flake8-fixme
|
|
32
|
+
"FA", # flake8-future-annotations
|
|
33
|
+
"SIM", # flake8-simplify
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[tool.ruff.lint.pydocstyle]
|
|
37
|
+
convention = "google"
|
|
38
|
+
|
|
39
|
+
[tool.mypy]
|
|
40
|
+
check_untyped_defs = true
|
|
41
|
+
disallow_any_generics = true
|
|
42
|
+
disallow_any_unimported = true
|
|
43
|
+
disallow_untyped_defs = true
|
|
44
|
+
no_implicit_optional = true
|
|
45
|
+
show_column_numbers = true
|
|
46
|
+
show_error_codes = true
|
|
47
|
+
show_error_context = true
|
|
48
|
+
warn_redundant_casts = true
|
|
49
|
+
warn_return_any = true
|
|
50
|
+
warn_unused_ignores = true
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#
|
|
2
|
+
# This file is autogenerated by pip-compile with Python 3.12
|
|
3
|
+
# by the following command:
|
|
4
|
+
#
|
|
5
|
+
# pip-compile pyproject.toml
|
|
6
|
+
#
|
|
7
|
+
click==8.1.3
|
|
8
|
+
# via typer
|
|
9
|
+
markdown-it-py==2.2.0
|
|
10
|
+
# via rich
|
|
11
|
+
mdurl==0.1.2
|
|
12
|
+
# via markdown-it-py
|
|
13
|
+
pygments==2.14.0
|
|
14
|
+
# via rich
|
|
15
|
+
rich==13.3.2
|
|
16
|
+
# via gitget (pyproject.toml)
|
|
17
|
+
typer==0.7.0
|
|
18
|
+
# via gitget (pyproject.toml)
|