Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit401e702

Browse files
committed
feat: allow an environment variable to specify config location
It can be useful (especially in scripts) to specify a configurationlocation via an environment variable. If the "PYTHON_GITLAB_CFG"environment variable is defined, treat its value as the path to aconfiguration file and include it in the set of default configurationlocations.
1 parentc7c431a commit401e702

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

‎docs/cli.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ Configuration
1414
Files
1515
-----
1616

17-
``gitlab`` looks up 2 configuration files by default:
17+
``gitlab`` looks up 3 configuration files by default:
18+
19+
``PYTHON_GITLAB_CFG`` environment variable
20+
An environment variable that contains the path to a configuration file
1821

1922
``/etc/python-gitlab.cfg``
2023
System-wide configuration file

‎gitlab/config.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,17 @@
1818
importos
1919
importconfigparser
2020

21-
_DEFAULT_FILES= ["/etc/python-gitlab.cfg",os.path.expanduser("~/.python-gitlab.cfg")]
21+
22+
def_env_config():
23+
if"PYTHON_GITLAB_CFG"inos.environ:
24+
return [os.environ["PYTHON_GITLAB_CFG"]]
25+
return []
26+
27+
28+
_DEFAULT_FILES=_env_config()+ [
29+
"/etc/python-gitlab.cfg",
30+
os.path.expanduser("~/.python-gitlab.cfg"),
31+
]
2232

2333

2434
classConfigError(Exception):

‎gitlab/tests/test_config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# You should have received a copy of the GNU Lesser General Public License
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

18+
importos
1819
importunittest
1920

2021
importmock
@@ -72,6 +73,16 @@
7273
"""
7374

7475

76+
classTestEnvConfig(unittest.TestCase):
77+
deftest_env_present(self):
78+
withmock.patch.dict(os.environ, {"PYTHON_GITLAB_CFG":"/some/path"}):
79+
self.assertEqual(["/some/path"],config._env_config())
80+
81+
deftest_env_missing(self):
82+
withmock.patch.dict(os.environ, {},clear=True):
83+
self.assertEqual([],config._env_config())
84+
85+
7586
classTestConfigParser(unittest.TestCase):
7687
@mock.patch("os.path.exists")
7788
deftest_missing_config(self,path_exists):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp