GeezerVison is showing github.com — feat(api,cli): make user agent configurable · python-gitlab/python-gitlab@4bb201b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: gitlab/__init__.py +11-8Lines changed: 11 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 24 | 24 | import requests.utils | 25 | 25 |
| 26 | 26 | import gitlab.config | | 27 | +from gitlab.__version__ import ( | | 28 | + __author__, | | 29 | + __copyright__, | | 30 | + __email__, | | 31 | + __license__, | | 32 | + __title__, | | 33 | + __version__, | | 34 | +) | 27 | 35 | from gitlab.const import * # noqa | 28 | 36 | from gitlab.exceptions import * # noqa | 29 | 37 | from gitlab import utils # noqa | 30 | 38 | from requests_toolbelt.multipart.encoder import MultipartEncoder | 31 | 39 |
| 32 | 40 |
| 33 | | -__title__ = "python-gitlab" | 34 | | -__version__ = "2.6.0" | 35 | | -__author__ = "Gauvain Pocentek" | 36 | | - | 37 | | -__license__ = "LGPL3" | 38 | | -__copyright__ = "Copyright 2013-2019 Gauvain Pocentek" | 39 | | - | 40 | 41 | warnings.filterwarnings("default", category=DeprecationWarning, module="^gitlab") | 41 | 42 |
| 42 | 43 | REDIRECT_MSG = ( | @@ -81,6 +82,7 @@ def __init__( | 81 | 82 | per_page=None, | 82 | 83 | pagination=None, | 83 | 84 | order_by=None, | | 85 | + user_agent=USER_AGENT, | 84 | 86 | ): | 85 | 87 |
| 86 | 88 | self._api_version = str(api_version) | @@ -90,7 +92,7 @@ def __init__( | 90 | 92 | #: Timeout to use for requests to gitlab server | 91 | 93 | self.timeout = timeout | 92 | 94 | #: Headers that will be used in request to GitLab | 93 | | - self.headers = {"User-Agent": "%s/%s" % (__title__, __version__)} | | 95 | + self.headers = {"User-Agent": user_agent} | 94 | 96 |
| 95 | 97 | #: Whether SSL certificates should be validated | 96 | 98 | self.ssl_verify = ssl_verify | @@ -204,6 +206,7 @@ def from_config(cls, gitlab_id=None, config_files=None): | 204 | 206 | per_page=config.per_page, | 205 | 207 | pagination=config.pagination, | 206 | 208 | order_by=config.order_by, | | 209 | + user_agent=config.user_agent, | 207 | 210 | ) | 208 | 211 |
| 209 | 212 | def auth(self): | |
Collapse file Copy file name to clipboard +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +__author__ = "Gauvain Pocentek, python-gitlab team" | | 2 | +__copyright__ = "Copyright 2013-2019 Gauvain Pocentek, 2019-2021 python-gitlab team" | | 3 | + | | 4 | +__license__ = "LGPL3" | | 5 | +__title__ = "python-gitlab" | | 6 | +__version__ = "2.6.0" |
Collapse file Copy file name to clipboardExpand all lines: gitlab/config.py +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 18 | 18 | import os | 19 | 19 | import configparser | 20 | 20 |
| | 21 | +from gitlab.const import USER_AGENT | | 22 | + | 21 | 23 |
| 22 | 24 | def _env_config(): | 23 | 25 | if "PYTHON_GITLAB_CFG" in os.environ: | @@ -177,3 +179,13 @@ def __init__(self, gitlab_id=None, config_files=None): | 177 | 179 | self.order_by = self._config.get(self.gitlab_id, "order_by") | 178 | 180 | except Exception: | 179 | 181 | pass | | 182 | + | | 183 | + self.user_agent = USER_AGENT | | 184 | + try: | | 185 | + self.user_agent = self._config.get("global", "user_agent") | | 186 | + except Exception: | | 187 | + pass | | 188 | + try: | | 189 | + self.user_agent = self._config.get(self.gitlab_id, "user_agent") | | 190 | + except Exception: | | 191 | + pass |
Collapse file Copy file name to clipboardExpand all lines: gitlab/const.py +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 15 | 15 | # You should have received a copy of the GNU Lesser General Public License | 16 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | 17 |
| | 18 | +from gitlab.__version__ import __title__, __version__ | | 19 | + | | 20 | + | 18 | 21 | NO_ACCESS = 0 | 19 | 22 | MINIMAL_ACCESS = 5 | 20 | 23 | GUEST_ACCESS = 10 | | 51 | 54 |
| 52 | 55 | # specific project scope | 53 | 56 | SEARCH_SCOPE_PROJECT_NOTES = "notes" | | 57 | + | | 58 | +USER_AGENT = "{}/{}".format(__title__, __version__) |
Collapse file Copy file name to clipboardExpand all lines: setup.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 |
| 7 | 7 |
| 8 | 8 | def get_version(): | 9 | | - with open("gitlab/__init__.py") as f: | | 9 | + with open("gitlab/__version__.py") as f: | 10 | 10 | for line in f: | 11 | 11 | if line.startswith("__version__"): | 12 | 12 | return eval(line.split("=")[-1]) | |
|