git-uff 0.2.0__tar.gz → 0.4.0__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.
@@ -1,8 +1,7 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: git-uff
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Summary: Prints the forge url for a given file of a Git repository checkout
5
- Home-page: https://github.com/agateau/git-uff
6
5
  License: Apache 2.0
7
6
  Author: Aurélien Gâteau
8
7
  Author-email: mail@agateau.com
@@ -16,7 +15,13 @@ Classifier: Programming Language :: Python :: 3.6
16
15
  Classifier: Programming Language :: Python :: 3.7
17
16
  Classifier: Programming Language :: Python :: 3.8
18
17
  Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
19
22
  Requires-Dist: gitpython (>=3.1.12,<4.0.0)
23
+ Requires-Dist: pyperclip (>=1.8.2,<2.0.0)
24
+ Project-URL: Homepage, https://github.com/agateau/git-uff
20
25
  Project-URL: Repository, https://github.com/agateau/git-uff
21
26
  Description-Content-Type: text/markdown
22
27
 
@@ -52,7 +57,46 @@ $ git uff src/linux/nanonote.desktop -l 10
52
57
  https://github.com/agateau/nanonote/blob/master/src/linux/nanonote.desktop#L10
53
58
  ```
54
59
 
55
- ## But my code is not on GitHub...
60
+ `git-uff` has a few other available options. Here is its `--help` output:
61
+
62
+ <!-- [[[cog
63
+ import subprocess
64
+ result = subprocess.run(["git-uff", "--help"], capture_output=True, text=True)
65
+ cog.outl("```")
66
+ cog.out(result.stdout)
67
+ cog.outl("```")
68
+ ]]]-->
69
+ ```
70
+ usage: git-uff [-h] [-b BRANCH] [-p] [-c] [-l LINE] path
71
+
72
+ Prints the forge URL for a given file or path of a Git repository checkout.
73
+
74
+ positional arguments:
75
+ path File for which we want the URL
76
+
77
+ optional arguments:
78
+ -h, --help show this help message and exit
79
+ -b BRANCH, --branch BRANCH
80
+ Use branch BRANCH instead of the current one
81
+ -p, --permalink Replace the branch in the URL with the commit it
82
+ points to
83
+ -c, --copy Copy the result to the clipboard
84
+ -l LINE, --line LINE Line to point to
85
+
86
+ New forges can be declared in git configuration. You can do so using
87
+ `git config`, like this:
88
+
89
+ git config --global uff.<forge_base_url>.forge <forge>
90
+
91
+ Where <forge> must be one of: cgit, github, gitlab, sourcehut.
92
+
93
+ For example to declare that example.com uses GitLab:
94
+
95
+ git config --global uff.example.com.forge gitlab
96
+ ```
97
+ <!--[[[end]]] -->
98
+
99
+ ## What if my code is not on GitHub?
56
100
 
57
101
  `git-uff` is not tied to GitHub. It supports GitLab, SourceHut and CGit forges.
58
102
 
@@ -64,10 +108,11 @@ For example to declare that example.com uses GitLab:
64
108
 
65
109
  git config --global uff.example.com.forge gitlab
66
110
 
111
+ See the output of `git uff --help` for the valid `<forge>` values.
67
112
 
68
113
  ## Installation
69
114
 
70
- The recommended solution is to use [pipx][]:
115
+ The recommended method to install `git-uff` is to use [pipx][]:
71
116
 
72
117
  ```
73
118
  pipx install git-uff
@@ -30,7 +30,46 @@ $ git uff src/linux/nanonote.desktop -l 10
30
30
  https://github.com/agateau/nanonote/blob/master/src/linux/nanonote.desktop#L10
31
31
  ```
32
32
 
33
- ## But my code is not on GitHub...
33
+ `git-uff` has a few other available options. Here is its `--help` output:
34
+
35
+ <!-- [[[cog
36
+ import subprocess
37
+ result = subprocess.run(["git-uff", "--help"], capture_output=True, text=True)
38
+ cog.outl("```")
39
+ cog.out(result.stdout)
40
+ cog.outl("```")
41
+ ]]]-->
42
+ ```
43
+ usage: git-uff [-h] [-b BRANCH] [-p] [-c] [-l LINE] path
44
+
45
+ Prints the forge URL for a given file or path of a Git repository checkout.
46
+
47
+ positional arguments:
48
+ path File for which we want the URL
49
+
50
+ optional arguments:
51
+ -h, --help show this help message and exit
52
+ -b BRANCH, --branch BRANCH
53
+ Use branch BRANCH instead of the current one
54
+ -p, --permalink Replace the branch in the URL with the commit it
55
+ points to
56
+ -c, --copy Copy the result to the clipboard
57
+ -l LINE, --line LINE Line to point to
58
+
59
+ New forges can be declared in git configuration. You can do so using
60
+ `git config`, like this:
61
+
62
+ git config --global uff.<forge_base_url>.forge <forge>
63
+
64
+ Where <forge> must be one of: cgit, github, gitlab, sourcehut.
65
+
66
+ For example to declare that example.com uses GitLab:
67
+
68
+ git config --global uff.example.com.forge gitlab
69
+ ```
70
+ <!--[[[end]]] -->
71
+
72
+ ## What if my code is not on GitHub?
34
73
 
35
74
  `git-uff` is not tied to GitHub. It supports GitLab, SourceHut and CGit forges.
36
75
 
@@ -42,10 +81,11 @@ For example to declare that example.com uses GitLab:
42
81
 
43
82
  git config --global uff.example.com.forge gitlab
44
83
 
84
+ See the output of `git uff --help` for the valid `<forge>` values.
45
85
 
46
86
  ## Installation
47
87
 
48
- The recommended solution is to use [pipx][]:
88
+ The recommended method to install `git-uff` is to use [pipx][]:
49
89
 
50
90
  ```
51
91
  pipx install git-uff
@@ -1,13 +1,28 @@
1
1
  # Copyright 2021 Aurélien Gâteau <mail@agateau.com>
2
2
  # SPDX-License-Identifier: Apache-2.0
3
3
  import re
4
+ import sys
4
5
 
5
6
  from typing import Dict, Type, Optional
6
7
 
8
+ from urllib.error import HTTPError
7
9
  from urllib.parse import quote_plus
10
+ from urllib.request import Request, urlopen
8
11
  from pathlib import Path
9
12
 
10
13
 
14
+ BUG_URL = "https://github.com/agateau/git-uff/issues/new"
15
+
16
+
17
+ def check_existence(url: str) -> bool:
18
+ req = Request(url, method='HEAD')
19
+ try:
20
+ with urlopen(req) as f:
21
+ return True
22
+ except HTTPError:
23
+ return False
24
+
25
+
11
26
  class Converter:
12
27
  """A Converter turns a local path into its matching forge URL.
13
28
 
@@ -41,6 +56,13 @@ class Converter:
41
56
  url = self.URL_TEMPLATE.format(**dct)
42
57
  if line is not None:
43
58
  url += self.LINE_SUFFIX.format(line=line)
59
+
60
+ if not check_existence(url):
61
+ print(
62
+ f"URL {url} does not exist, maybe you have not pushed your changes yet?\n"
63
+ f"If you think this is a bug in git-uff, please report it on {BUG_URL}.",
64
+ file=sys.stderr)
65
+ sys.exit(1)
44
66
  return url
45
67
 
46
68
  def get_project(self, remote_url: str) -> str:
@@ -10,6 +10,7 @@ import sys
10
10
  from pathlib import Path
11
11
  from typing import Tuple, List
12
12
 
13
+ import pyperclip
13
14
  from git import Repo
14
15
 
15
16
  from git_uff.config import load_config
@@ -69,6 +70,14 @@ def main() -> None:
69
70
  )
70
71
 
71
72
  parser.add_argument("path", help="File for which we want the URL")
73
+ parser.add_argument("-b", "--branch",
74
+ help="Use branch BRANCH instead of the current one",
75
+ metavar="BRANCH")
76
+ parser.add_argument("-p", "--permalink", action="store_true",
77
+ help="Replace the branch in the URL with the commit"
78
+ " it points to")
79
+ parser.add_argument("-c", "--copy", action="store_true",
80
+ help="Copy the result to the clipboard")
72
81
  parser.add_argument("-l", "--line", type=int, help="Line to point to")
73
82
 
74
83
  args = parser.parse_args()
@@ -84,10 +93,17 @@ def main() -> None:
84
93
  repo = Repo(repo_root)
85
94
  converters = load_config(repo)
86
95
  converter, remote_url = find_converter(converters, repo)
87
- url = converter.run(remote_url, repo.active_branch.name,
96
+ if args.branch:
97
+ branch = args.branch
98
+ else:
99
+ branch = repo.active_branch.name
100
+ if args.permalink:
101
+ branch = repo.rev_parse(branch).hexsha
102
+ url = converter.run(remote_url, branch,
88
103
  path.relative_to(repo_root), args.line)
89
-
90
104
  print(url)
105
+ if args.copy:
106
+ pyperclip.copy(url)
91
107
  except ToolError as e:
92
108
  print(e)
93
109
  sys.exit(1)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "git-uff"
3
- version = "0.2.0"
3
+ version = "0.4.0"
4
4
  description = "Prints the forge url for a given file of a Git repository checkout"
5
5
  readme = "README.md"
6
6
  authors = ["Aurélien Gâteau <mail@agateau.com>"]
@@ -16,6 +16,7 @@ classifiers = [
16
16
  [tool.poetry.dependencies]
17
17
  python = "^3.6"
18
18
  gitpython = "^3.1.12"
19
+ pyperclip = "^1.8.2"
19
20
 
20
21
  [tool.poetry.dev-dependencies]
21
22
 
git-uff-0.2.0/setup.py DELETED
@@ -1,34 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- from setuptools import setup
3
-
4
- packages = \
5
- ['git_uff']
6
-
7
- package_data = \
8
- {'': ['*']}
9
-
10
- install_requires = \
11
- ['gitpython>=3.1.12,<4.0.0']
12
-
13
- entry_points = \
14
- {'console_scripts': ['git-uff = git_uff.main:main']}
15
-
16
- setup_kwargs = {
17
- 'name': 'git-uff',
18
- 'version': '0.2.0',
19
- 'description': 'Prints the forge url for a given file of a Git repository checkout',
20
- 'long_description': '# git-uff\n\nPrints the forge URL for a given file of a Git repository checkout.\n\n## Intro\n\nHave you ever been discussing with colleagues over IRC/Slack/Matrix/whatever about source code and found yourself needing to point them to a particular file in a git repository?\n\nThis is tedious to do.\n\nOne solution is to tell them the path in their checkout, hoping they are on the same branch as you.\n\nAnother solution is to point your browser to the forge hosting your git repository, select the right branch, navigate the file hierarchy, find your file and copy the file URL.\n\nA better (in my opinion 😉) solution is to use `git-uff`. This tool adds an `uff` (short for "URL for file") git sub-command, which takes the path to a file in your repository checkout and prints the matching forge URL.\n\nFor example to print the URL of the `src/linux/nanonote.desktop` file from my [Nanonote][] project:\n\n```\n$ git uff src/linux/nanonote.desktop\nhttps://github.com/agateau/nanonote/blob/master/src/linux/nanonote.desktop\n```\n\n[Nanonote]: https://github.com/agateau/nanonote\n\nYou can also point them to a specific line with the `-l` argument:\n\n```\n$ git uff src/linux/nanonote.desktop -l 10\nhttps://github.com/agateau/nanonote/blob/master/src/linux/nanonote.desktop#L10\n```\n\n## But my code is not on GitHub...\n\n`git-uff` is not tied to GitHub. It supports GitLab, SourceHut and CGit forges.\n\nTo declare a new forge, add it to your git configuration with:\n\n git config --global uff.<forge_base_url>.forge <forge>\n\nFor example to declare that example.com uses GitLab:\n\n git config --global uff.example.com.forge gitlab\n\n\n## Installation\n\nThe recommended solution is to use [pipx][]:\n\n```\npipx install git-uff\n```\n\n[pipx]: https://github.com/pipxproject/pipx\n\nBut you can also install it with `pip`:\n\n```\npip install --user git-uff\n```\n\n## License\n\nApache 2.0\n',
21
- 'author': 'Aurélien Gâteau',
22
- 'author_email': 'mail@agateau.com',
23
- 'maintainer': None,
24
- 'maintainer_email': None,
25
- 'url': 'https://github.com/agateau/git-uff',
26
- 'packages': packages,
27
- 'package_data': package_data,
28
- 'install_requires': install_requires,
29
- 'entry_points': entry_points,
30
- 'python_requires': '>=3.6,<4.0',
31
- }
32
-
33
-
34
- setup(**setup_kwargs)
File without changes
File without changes