skilleter-modules 0.0.8__tar.gz → 0.0.9__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.
Files changed (36) hide show
  1. {skilleter_modules-0.0.8/src/skilleter_modules.egg-info → skilleter_modules-0.0.9}/PKG-INFO +1 -5
  2. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/README.md +0 -4
  3. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/pyproject.toml +1 -1
  4. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/src/skilleter_modules/git.py +16 -27
  5. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9/src/skilleter_modules.egg-info}/PKG-INFO +1 -5
  6. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/src/skilleter_modules.egg-info/SOURCES.txt +0 -2
  7. skilleter_modules-0.0.8/src/skilleter_modules/gitlab.py +0 -193
  8. skilleter_modules-0.0.8/tests/test_gitlab.py +0 -4
  9. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/LICENSE +0 -0
  10. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/setup.cfg +0 -0
  11. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/src/skilleter_modules/__init__.py +0 -0
  12. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/src/skilleter_modules/colour.py +0 -0
  13. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/src/skilleter_modules/dc_curses.py +0 -0
  14. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/src/skilleter_modules/dc_defaults.py +0 -0
  15. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/src/skilleter_modules/dc_util.py +0 -0
  16. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/src/skilleter_modules/dircolors.py +0 -0
  17. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/src/skilleter_modules/docker.py +0 -0
  18. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/src/skilleter_modules/files.py +0 -0
  19. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/src/skilleter_modules/path.py +0 -0
  20. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/src/skilleter_modules/popup.py +0 -0
  21. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/src/skilleter_modules/run.py +0 -0
  22. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/src/skilleter_modules/tidy.py +0 -0
  23. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/src/skilleter_modules/venv_template.py +0 -0
  24. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/src/skilleter_modules.egg-info/dependency_links.txt +0 -0
  25. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/src/skilleter_modules.egg-info/requires.txt +0 -0
  26. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/src/skilleter_modules.egg-info/top_level.txt +0 -0
  27. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/tests/test_colour.py +0 -0
  28. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/tests/test_dircolors.py +0 -0
  29. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/tests/test_docker.py +0 -0
  30. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/tests/test_files.py +0 -0
  31. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/tests/test_git.py +0 -0
  32. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/tests/test_path.py +0 -0
  33. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/tests/test_popup.py +0 -0
  34. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/tests/test_run.py +0 -0
  35. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/tests/test_tfm_pane.py +0 -0
  36. {skilleter_modules-0.0.8 → skilleter_modules-0.0.9}/tests/test_tidy.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: skilleter_modules
3
- Version: 0.0.8
3
+ Version: 0.0.9
4
4
  Summary: Modules used by my various Python projects (and hopefully useful to other people)
5
5
  Author-email: John Skilleter <john@skilleter.org.uk>
6
6
  Project-URL: Home, https://skilleter.org.uk
@@ -38,10 +38,6 @@ Miscellaneous file-related functions - backup creation, file-type detection, etc
38
38
 
39
39
  A git library
40
40
 
41
- ## gitlab.py
42
-
43
- GitLab access module - due to be deprecated as I no longer support GitLab
44
-
45
41
  ## path.py
46
42
 
47
43
  Filesystem path-related functions
@@ -20,10 +20,6 @@ Miscellaneous file-related functions - backup creation, file-type detection, etc
20
20
 
21
21
  A git library
22
22
 
23
- ## gitlab.py
24
-
25
- GitLab access module - due to be deprecated as I no longer support GitLab
26
-
27
23
  ## path.py
28
24
 
29
25
  Filesystem path-related functions
@@ -7,7 +7,7 @@ name = "skilleter_modules"
7
7
 
8
8
  # Version must be incremented to install updated skilleter-extras
9
9
 
10
- version = "0.0.8"
10
+ version = "0.0.9"
11
11
 
12
12
  authors = [
13
13
  {name="John Skilleter", email="john@skilleter.org.uk"},
@@ -32,7 +32,6 @@ from functools import cache
32
32
  import pygit2
33
33
 
34
34
  from . import run
35
- from . import gitlab
36
35
 
37
36
  ################################################################################
38
37
  # Configuration files to access
@@ -1216,47 +1215,37 @@ def isbranch(branchname, path=None):
1216
1215
 
1217
1216
  ################################################################################
1218
1217
 
1219
- def is_default_branch(branchname=None):
1218
+ def is_default_branch(path, branchname=None):
1220
1219
  """ Return True if the specified branch is a default branch """
1221
1220
 
1222
- if not branchname:
1223
- branchname = branch()
1221
+ # Use the current branch if not specified
1224
1222
 
1225
- default_branches = config_get('skilleter-thingy', 'defaultBranches', defaultvalue=DEFAULT_DEFAULT_BRANCHES, path=path).split(',')
1223
+ if not branchname:
1224
+ branchname = branch(path=path)
1226
1225
 
1227
- return branchname in default_branches
1226
+ # Get the list of default branch wildcards
1228
1227
 
1229
- ################################################################################
1228
+ default_branches = config_get('skilleter-thingy', 'defaultBranches', defaultvalue=DEFAULT_DEFAULT_BRANCHES, path=path).split(',')
1230
1229
 
1231
- def default_branch(path=None):
1232
- """ Return the name of the default branch, attempting to interrogate GitLab
1233
- if the repo appears to have been cloned from there and falling back to
1234
- returning whichever one of 'develop', 'main' or 'master' exists. """
1230
+ # If the branch matches any of the wildcards, return True
1235
1231
 
1236
- remote_list = remotes(path=path)
1237
- if remote_list:
1238
- for name in remote_list:
1239
- if 'gitlab' in remote_list[name]:
1240
- url = remote_list[name].split('@')[1].split(':')[0]
1241
- repo = remote_list[name].split(':')[1]
1232
+ for defbranch in default_branches:
1233
+ if fnmatch.fnmatch(branchname, defbranch):
1234
+ return True
1242
1235
 
1243
- if not url.startswith('http://') and not url.startswith('https://'):
1244
- url = f'https://{url}'
1236
+ # No match, so not a default branch
1245
1237
 
1246
- if repo.endswith('.git'):
1247
- repo = repo[:-4]
1238
+ return False
1248
1239
 
1249
- try:
1250
- gl = gitlab.GitLab(url)
1251
- return gl.default_branch(repo)
1240
+ ################################################################################
1252
1241
 
1253
- except gitlab.GitLabError:
1254
- return None
1242
+ def default_branch(path=None):
1243
+ """ Return the name of the default branch """
1255
1244
 
1256
1245
  git_branches = branches(path=path)
1257
1246
 
1258
1247
  for branchname in git_branches:
1259
- if is_default_branch(branchname):
1248
+ if is_default_branch(path, branchname):
1260
1249
  return branchname
1261
1250
 
1262
1251
  raise GitError('Unable to determine default branch in the repo')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: skilleter_modules
3
- Version: 0.0.8
3
+ Version: 0.0.9
4
4
  Summary: Modules used by my various Python projects (and hopefully useful to other people)
5
5
  Author-email: John Skilleter <john@skilleter.org.uk>
6
6
  Project-URL: Home, https://skilleter.org.uk
@@ -38,10 +38,6 @@ Miscellaneous file-related functions - backup creation, file-type detection, etc
38
38
 
39
39
  A git library
40
40
 
41
- ## gitlab.py
42
-
43
- GitLab access module - due to be deprecated as I no longer support GitLab
44
-
45
41
  ## path.py
46
42
 
47
43
  Filesystem path-related functions
@@ -10,7 +10,6 @@ src/skilleter_modules/dircolors.py
10
10
  src/skilleter_modules/docker.py
11
11
  src/skilleter_modules/files.py
12
12
  src/skilleter_modules/git.py
13
- src/skilleter_modules/gitlab.py
14
13
  src/skilleter_modules/path.py
15
14
  src/skilleter_modules/popup.py
16
15
  src/skilleter_modules/run.py
@@ -26,7 +25,6 @@ tests/test_dircolors.py
26
25
  tests/test_docker.py
27
26
  tests/test_files.py
28
27
  tests/test_git.py
29
- tests/test_gitlab.py
30
28
  tests/test_path.py
31
29
  tests/test_popup.py
32
30
  tests/test_run.py
@@ -1,193 +0,0 @@
1
- #! /usr/bin/env python3
2
-
3
- ################################################################################
4
- """ GitLab module - implemented using the REST API as some features are not
5
- available (or don't work) in the official Python module
6
-
7
- Copyright (C) 2017-20 John Skilleter
8
-
9
- Licence: GPL v3 or later
10
-
11
- Note: There are two types of function for returning data from GitLab;
12
- the paged functions and the non-paged ones - the paged ones return a page
13
- (normally 20 items) of data and need to be called repeated until no data is
14
- left whereas the non-paged ones query all the data and concatenate it
15
- together.
16
-
17
- The paged functions expect a full request string with the URL, as returned
18
- by the request_string() member. The non-paged ones call request_string()
19
- to add the URL & API prefix.
20
- """
21
- ################################################################################
22
-
23
- import sys
24
- import os
25
-
26
- try:
27
- import requests
28
- except ModuleNotFoundError:
29
- sys.stderr.write('This code requires the Python "requests" module which should be installed via your package manager\n')
30
- sys.exit(1)
31
-
32
- ################################################################################
33
-
34
- class GitLabError(Exception):
35
- """ Gitlab exceptions """
36
-
37
- def __init__(self, response):
38
- """ Save the error code and text """
39
-
40
- self.status = response.status_code
41
- self.message = response.reason
42
-
43
- def __str__(self):
44
- """ Return a string version of the exception """
45
-
46
- return '%s: %s' % (self.status, self.message)
47
-
48
- ################################################################################
49
-
50
- class GitLab:
51
- """ Class for GitLab access """
52
-
53
- def __init__(self, gitlab, token=None):
54
- """ Initialisation """
55
-
56
- # Save the GitLab URL
57
-
58
- self.gitlab = gitlab
59
-
60
- # If we have a private token use it, otherwise try and get it from
61
- # the environmnet
62
-
63
- self.token = token if token else os.getenv('GITLAB_TOKEN', None)
64
-
65
- # Create the default header for requests
66
-
67
- self.header = {'Private-Token': self.token}
68
-
69
- ################################################################################
70
-
71
- @staticmethod
72
- def encode_project(name):
73
- """ Encode a project name in the form request by GitLab requests """
74
-
75
- return name.replace('/', '%2F')
76
-
77
- ################################################################################
78
-
79
- def request_string(self, request):
80
- """ Add the URL/API header onto a request string """
81
-
82
- return '%s/api/v4/%s' % (self.gitlab, request)
83
-
84
- ################################################################################
85
-
86
- def request(self, request, parameters=None):
87
- """ Send a request to GitLab - handles pagination and returns all the
88
- results concatenated together """
89
-
90
- if parameters:
91
- request = '%s?%s' % (request, '&'.join(parameters))
92
-
93
- gl_request = self.request_string(request)
94
-
95
- # Keep requesting data until there's no 'next' link in the response
96
-
97
- while True:
98
- response = requests.get(gl_request, headers=self.header)
99
-
100
- if not response:
101
- raise GitLabError(response)
102
-
103
- yield response.json()
104
-
105
- if 'next' not in response.links:
106
- break
107
-
108
- gl_request = response.links['next']['url']
109
-
110
- ################################################################################
111
-
112
- def paged_request(self, request):
113
- """ Send a request to GitLab - returns all the results concatenated together
114
- and returns a page of results along with the request for the next page of
115
- results (if any).
116
-
117
- Note that the request parameter is the full request string as returned by
118
- request_string(). """
119
-
120
- response = requests.get(request, headers=self.header)
121
-
122
- result = response.json()
123
-
124
- if not response:
125
- raise GitLabError(response)
126
-
127
- request = response.links['next']['url'] if 'next' in response.links else None
128
-
129
- return result, request
130
-
131
- ################################################################################
132
-
133
- def projects(self):
134
- """ Return a list of projects """
135
-
136
- return self.request('projects')
137
-
138
- ################################################################################
139
-
140
- def branches(self, repo):
141
- """ Return the list of branches in a repo """
142
-
143
- for batch in self.request('projects/%s/repository/branches' % self.encode_project(repo)):
144
- for branch in batch:
145
- yield branch
146
-
147
- ################################################################################
148
-
149
- def merge_requests(self, **kwargs):
150
- """ Return a list of merge requests filtered according to the parameters """
151
-
152
- request = 'merge_requests'
153
-
154
- parameters = []
155
-
156
- for data in kwargs:
157
- parameters.append('%s=%s' % (data, kwargs[data]))
158
-
159
- for result in self.request(request, parameters):
160
- for r in result:
161
- yield r
162
-
163
- ################################################################################
164
-
165
- def default_branch(self, repo):
166
- """ Query gitlab to retreive the default branch for the repo """
167
-
168
- # Look for the default branch
169
-
170
- for branch in self.branches(repo):
171
- if branch['default']:
172
- return branch['name']
173
-
174
- return None
175
-
176
- ################################################################################
177
-
178
- def isbranch(self, repo, branchname):
179
- """ Return True if the branch exists in the repo """
180
-
181
- request = self.request_string('projects/%s/repository/branches' % self.encode_project(repo))
182
-
183
- while True:
184
- branches, request = self.paged_request(request)
185
-
186
- for branch in branches:
187
- if branch['name'] == branchname:
188
- return True
189
-
190
- if not request:
191
- break
192
-
193
- return False
@@ -1,4 +0,0 @@
1
- import skilleter_modules.gitlab as gitlab
2
-
3
- def test_gitlab():
4
- pass