Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Computers don't actually think. You just think they think. (We think.)


devel / comp.lang.python / configargparse - reading option from config only

SubjectAuthor
* configargparse - reading option from config onlyLoris Bennett
+* Re: configargparse - reading option from config onlytuxifreund
|`- Re: configargparse - reading option from config onlyLoris Bennett
`* Re: configargparse - reading option from config onlyRichard Damon
 `* Re: configargparse - reading option from config onlyLoris Bennett
  `* Re: configargparse - reading option from config onlyRichard Damon
   `- Re: configargparse - reading option from config onlyLoris Bennett

1
configargparse - reading option from config only

<87lf4o7ce2.fsf@hornfels.zedat.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14754&group=comp.lang.python#14754

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.be...@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: configargparse - reading option from config only
Date: Thu, 26 Aug 2021 12:01:41 +0200
Organization: Freie Universitaet Berlin
Lines: 20
Message-ID: <87lf4o7ce2.fsf@hornfels.zedat.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: news.uni-berlin.de 1ybsqZugJBWD91ionoWBlQT5xFGddOdqprUOsvwEEeuhtX
Cancel-Lock: sha1:ovzdVF91IwO8iaKFISa6WWQzYoY=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
 by: Loris Bennett - Thu, 26 Aug 2021 10:01 UTC

Hi,

When using configargparse, it seems that if a value is to be read from a
config file, it also has to be defined as a command-line argument in
order to turn up as an attribute in the parser namespace.

I can sort of see why this is the case, but there are also some options
I would like to read just from the config file and not have them
available as command-line options. This would be, say, to prevent the
number of options on the command-line from becoming bloated by
little-used settings.

Is there an elegant way to do this?

Cheers,

Loris

--
This signature is currently under construction.

Re: configargparse - reading option from config only

<sg8tek$d28$1@solani.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14757&group=comp.lang.python#14757

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: kaiser.b...@yandex.com (tuxifreund)
Newsgroups: comp.lang.python
Subject: Re: configargparse - reading option from config only
Date: Thu, 26 Aug 2021 20:27:00 -0000 (UTC)
Message-ID: <sg8tek$d28$1@solani.org>
References: <87lf4o7ce2.fsf@hornfels.zedat.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 26 Aug 2021 20:27:00 -0000 (UTC)
Injection-Info: solani.org;
logging-data="13384"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Pan/0.146 (Hic habitat felicitas; 8107378
git@gitlab.gnome.org:GNOME/pan.git)
Cancel-Lock: sha1:Zu364i58Rd4sS7QMuQREsOp1fIk=
X-User-ID: eJwFwYEBwCAIA7CXlEJx56CU/09YEuDmS2fQY2LKqMZmz0jh6+y0kzjZVtK1j+vJGLcBoy8V+KaKCYx4f1gzFcI=
 by: tuxifreund - Thu, 26 Aug 2021 20:27 UTC

Hello,

you could use the argparse module[1] to parse command line arguments and
configparser[2] to parse configuration files following the ini file
structure. Is that what you are expecting?

Cheers

[1]: https://docs.python.org/3/library/argparse.html
[2]: https://docs.python.org/3/library/configparser.html

Re: configargparse - reading option from config only

<mailman.474.1630027132.4164.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14759&group=comp.lang.python#14759

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: Rich...@Damon-Family.org (Richard Damon)
Newsgroups: comp.lang.python
Subject: Re: configargparse - reading option from config only
Date: Thu, 26 Aug 2021 21:18:47 -0400
Lines: 26
Message-ID: <mailman.474.1630027132.4164.python-list@python.org>
References: <87lf4o7ce2.fsf@hornfels.zedat.fu-berlin.de>
<fed6d9c0-8934-4925-d6ac-7d6bc0132f86@Damon-Family.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de XrTdgbOnni2HKPXPyMSvHwjwcZkyOqAnJW6IMeW0NhxQ==
Return-Path: <Richard@Damon-Family.org>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.006
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'argument': 0.04;
'settings.': 0.05; 'command-line': 0.07; 'damon': 0.09; 'cheers,':
0.10; 'received:173': 0.11; 'be,': 0.16; 'bennett': 0.16;
'from:addr:damon-family.org': 0.16; 'from:addr:richard': 0.16;
'from:name:richard damon': 0.16; 'message-id:@Damon-Family.org':
0.16; 'subject:option': 0.16; 'subject:reading': 0.16; 'wrote:':
0.16; 'object': 0.23; 'to:addr:python-list': 0.23; 'section':
0.26; 'seems': 0.26; 'function': 0.28; 'this?': 0.28; 'header
:User-Agent:1': 0.31; 'there': 0.31; 'member': 0.31; 'but': 0.31;
'am,': 0.31; 'options.': 0.32; 'using': 0.33; 'header:In-Reply-
To:1': 0.33; 'subject:from': 0.35; 'way': 0.37; 'file': 0.38;
'read': 0.38; 'hi,': 0.39; 'look': 0.66; 'prevent': 0.68; 'order':
0.68; 'supply': 0.69; 'attribute': 0.84; 'say,': 0.84;
'subject:only': 0.84
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0)
Gecko/20100101 Thunderbird/78.13.0
In-Reply-To: <87lf4o7ce2.fsf@hornfels.zedat.fu-berlin.de>
Content-Language: en-US
X-Provags-ID: V03:K1:a5Thl0aFU3aD83VJGZh30j9pMMwHBOXisaKQ3SLRbFNLRPP5jTR
XzBwanmsBemEQQAP9wAzOW7XuyPClbIGfz8p3j1QIFM3+vVF0+TYeTXe4S2as389LMx9GwG
Zdff3pBU5dLLxeZWbllYcHBRxMh3lJrF6amS1pUIYa6iVXHZXZ+1/L+XOqHuQ4T9UqdkzCX
2VFvOO895q1P1tEljnVvQ==
X-Spam-Flag: NO
X-UI-Out-Filterresults: notjunk:1;V03:K0:5XGqFG3ci58=:OJsQz+BWbQDHmqgUxwdMMu
JvqGWB+uF8gWL1Zow7W1Mn4V9oZYlwkbC4akfT/G5CXuDqYJUAgtwdmr0ckO8UkMzAyLE2FxK
zu0ibx5IAFcRBKvNVDgkqifN3o0FMm0PQesZmSsQTPTPhd0q9t9xdmc1ZM0sPQuagHsqHrw9Q
3RZMHaRiO22jB4f4BWtwBT9I8dUwuPZkgQ/+Ot3ORRT+RHl6Eo+UIw6uZ/CSNGYaz3a/5RHCy
ccXnAAUiLs8hIGaN1aWl/5QMb/xr1yPO5U8Z6CBZYVdn99ZdjsuLBOZGh978cestMf6sSSnUt
nGoyoraGUR7jvVwe4xz0viWUF4VC7rCXkLcgRkfoYZ+u75KUfSXtbJhK6nQX4EbikFpZyCdF3
UGTPDWtO7ilkZLFvdEIEyNtm7KTxTqYs/NTyIcdfR4rszVs9D61jtfIMuhDKAllQfjmkXe3Bq
TZ1eCWLuILzcNTAN+qMwvw2vJvgluebv6o3jjgFaRA3j1yqiq7o1jiZSn5y0c7KJBT27f2MmB
UUqR2rjCaAEBqBj14oQGZ/bekrqF28jL1vm+lbjSW2USq9lc2y4LCkjFv6uuD+yaWAoshY6ze
N+ayqo1JETsAVuB5mvE2He4IK2dwS/GUjvS2mCWPxoXHbOOHbWrLnzppbd12eN/KgTwZbWbRG
x9hXpOC9L2+pNHdzd4WnHy+7uL/sc9bwGQtR7TrNwAVfUZCu5dMDnwW454EjI5Am8sCZATi7m
lyd+BGXR4384PrP7iUNPWIrzokFnJTAPW3v7jBVRk9zGhL5gcvaKtdoWqw4=
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <fed6d9c0-8934-4925-d6ac-7d6bc0132f86@Damon-Family.org>
X-Mailman-Original-References: <87lf4o7ce2.fsf@hornfels.zedat.fu-berlin.de>
 by: Richard Damon - Fri, 27 Aug 2021 01:18 UTC

On 8/26/21 6:01 AM, Loris Bennett wrote:
> Hi,
>
> When using configargparse, it seems that if a value is to be read from a
> config file, it also has to be defined as a command-line argument in
> order to turn up as an attribute in the parser namespace.
>
> I can sort of see why this is the case, but there are also some options
> I would like to read just from the config file and not have them
> available as command-line options. This would be, say, to prevent the
> number of options on the command-line from becoming bloated by
> little-used settings.
>
> Is there an elegant way to do this?
>
> Cheers,
>
> Loris
>
Look at the read() member function to supply the file name to read. Then
in the config object there will be sections for each section in the
config file. No need for any of these to be 'options'

--
Richard Damon

Re: configargparse - reading option from config only

<87mtp3jq2h.fsf@hornfels.zedat.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14760&group=comp.lang.python#14760

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.be...@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Re: configargparse - reading option from config only
Date: Fri, 27 Aug 2021 09:37:42 +0200
Organization: Freie Universitaet Berlin
Lines: 46
Message-ID: <87mtp3jq2h.fsf@hornfels.zedat.fu-berlin.de>
References: <87lf4o7ce2.fsf@hornfels.zedat.fu-berlin.de>
<fed6d9c0-8934-4925-d6ac-7d6bc0132f86@Damon-Family.org>
<mailman.474.1630027132.4164.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: news.uni-berlin.de c3HR/oIlUMukGSIE/Zqh1QiHq1Y4EzVEik4x7zffVTAzvJ
Cancel-Lock: sha1:KCM4y7Zz3u3ZG3z2GsLnVDre2dU=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
 by: Loris Bennett - Fri, 27 Aug 2021 07:37 UTC

Richard Damon <Richard@Damon-Family.org> writes:

> On 8/26/21 6:01 AM, Loris Bennett wrote:
>> Hi,
>>
>> When using configargparse, it seems that if a value is to be read from a
>> config file, it also has to be defined as a command-line argument in
>> order to turn up as an attribute in the parser namespace.
>>
>> I can sort of see why this is the case, but there are also some options
>> I would like to read just from the config file and not have them
>> available as command-line options. This would be, say, to prevent the
>> number of options on the command-line from becoming bloated by
>> little-used settings.
>>
>> Is there an elegant way to do this?
>>
>> Cheers,
>>
>> Loris
>>
> Look at the read() member function to supply the file name to read. Then
> in the config object there will be sections for each section in the
> config file. No need for any of these to be 'options'

Do you have a link for this? As far as I can see, the config files are
given in the following manner:

p = configargparse.ArgParser(default_config_files=['/etc/app/conf.d/*.conf', '~/.my_settings'])

I can obviously just read the config file with configparser, but the
idea of configargparse is that an option can be specified as an option,
in a config file, or as an environment variable,

As far as I can tell, configargparse only loads entries from the config
file into the appropriate namespace if they have also been defined as
long options (i.e. with '--'). I was hoping to access *all* the config
file entries, regardless of whether they are also options, since the
config is obviously being read.

Cheers,

Loris

--
This signature is currently under construction.

Re: configargparse - reading option from config only

<87ilzrjpxe.fsf@hornfels.zedat.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14761&group=comp.lang.python#14761

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.be...@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Re: configargparse - reading option from config only
Date: Fri, 27 Aug 2021 09:40:45 +0200
Organization: ZEDAT, Freie Universität Berlin
Lines: 25
Message-ID: <87ilzrjpxe.fsf@hornfels.zedat.fu-berlin.de>
References: <87lf4o7ce2.fsf@hornfels.zedat.fu-berlin.de>
<sg8tek$d28$1@solani.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de nu8PHxSs5XxnSy0tK1PnAgippni5wD8ES3v+17twoCh4aX
Cancel-Lock: sha1:shelEZSlws+BKabzv/eczmGoonw=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
 by: Loris Bennett - Fri, 27 Aug 2021 07:40 UTC

tuxifreund <kaiser.barbarossa@yandex.com> writes:

> Hello,
>
> you could use the argparse module[1] to parse command line arguments and
> configparser[2] to parse configuration files following the ini file
> structure. Is that what you are expecting?

I have used the combination of argparse and configparser before.
However, I was hoping to just use configargparse instead.

Cheers,

Loris

>
> Cheers
>
>
> [1]: https://docs.python.org/3/library/argparse.html
> [2]: https://docs.python.org/3/library/configparser.html
--
Dr. Loris Bennett (Hr./Mr.)
ZEDAT, Freie Universität Berlin Email loris.bennett@fu-berlin.de

Re: configargparse - reading option from config only

<mailman.478.1630109188.4164.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14765&group=comp.lang.python#14765

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: Rich...@Damon-Family.org (Richard Damon)
Newsgroups: comp.lang.python
Subject: Re: configargparse - reading option from config only
Date: Fri, 27 Aug 2021 20:06:24 -0400
Lines: 57
Message-ID: <mailman.478.1630109188.4164.python-list@python.org>
References: <87lf4o7ce2.fsf@hornfels.zedat.fu-berlin.de>
<fed6d9c0-8934-4925-d6ac-7d6bc0132f86@Damon-Family.org>
<mailman.474.1630027132.4164.python-list@python.org>
<87mtp3jq2h.fsf@hornfels.zedat.fu-berlin.de>
<9976b879-98cd-5a2b-5394-e42923334948@Damon-Family.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de uaUlcn64bxXoy+w81mW8CQQauTFfm5yzTJZhqeJ/CeUA==
Return-Path: <Richard@Damon-Family.org>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'argument': 0.04;
'settings.': 0.05; 'command-line': 0.07; 'have,': 0.07; 'damon':
0.09; 'namespace': 0.09; 'obviously': 0.09; 'options,': 0.09;
'tool.': 0.09; 'writes:': 0.09; 'cheers,': 0.10; 'looks': 0.11;
'received:173': 0.11; '*all*': 0.16; 'be,': 0.16; 'bennett': 0.16;
'from:addr:damon-family.org': 0.16; 'from:addr:richard': 0.16;
'from:name:richard damon': 0.16; 'message-id:@Damon-Family.org':
0.16; 'option,': 0.16; 'parsing': 0.16; 'subject:option': 0.16;
'subject:reading': 0.16; 'variable,': 0.16; 'want,': 0.16;
'wrote:': 0.16; 'option': 0.21; 'object': 0.23; 'to:addr:python-
list': 0.23; 'command': 0.24; 'idea': 0.25; '>>>': 0.26;
'section': 0.26; 'seems': 0.26; 'wrong': 0.27; 'environment':
0.28; 'function': 0.28; 'this?': 0.28; "isn't": 0.29; 'header
:User-Agent:1': 0.31; 'there': 0.31; 'member': 0.31; 'but': 0.31;
'am,': 0.31; "doesn't": 0.32; 'question': 0.32; 'options.': 0.32;
'specified': 0.32; 'structure': 0.32; 'using': 0.33; 'present':
0.33; 'header:In-Reply-To:1': 0.33; 'files': 0.33; 'subject:from':
0.35; 'following': 0.35; 'way': 0.37; 'file': 0.38; 'read': 0.38;
'use': 0.38; 'hi,': 0.39; 'whether': 0.40; "skip:' 10": 0.40;
'your': 0.64; 'talking': 0.65; 'look': 0.66; 'right': 0.66;
'prevent': 0.68; 'order': 0.68; 'supply': 0.69; 'see,': 0.77;
'skip:c 70': 0.84; 'attribute': 0.84; 'say,': 0.84;
'subject:only': 0.84
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0)
Gecko/20100101 Thunderbird/78.13.0
In-Reply-To: <87mtp3jq2h.fsf@hornfels.zedat.fu-berlin.de>
Content-Language: en-US
X-Provags-ID: V03:K1:204pUcNYp5MojJpvpqnZg8KGjCzMHsZg/IxuRcegrQmrv3YdXD9
NT23aE1QCN6IbBipuJ2pyM7VSkGQbZx5TcoDmVxq19/7Jp3+5hs0ZxXioYhaCmBtMf/ESPl
c/NZUTr8JLcQ9/2ul56U9snCblazBAsNcXW2vFjugZSDPKRsdHdCwDuqPpdW/kHgXgkUfKs
jf2CvDWCN4tWUQNnLrh9A==
X-Spam-Flag: NO
X-UI-Out-Filterresults: notjunk:1;V03:K0:V9RS10KsTUw=:SrVu/E1LjwM15vvGKgodW9
MRVFL7e2r42VsKAstU0FZz+sUxBm3Y7/V1LT5hNhcjaEmjTICXnIMEXFu1qR9eNECTmYq1bjN
4wpMIWotiZRRbvxr27SjTabKMH7JzqOvnAnKRHyQkuPNihqfMwGe1HfJuv6XkR+l6+LfVK1ld
ezKM+Ujbefw86vf+7BEJb7z65q3z1suI0FkUmp8sUODTeA/nL889MtE4reEuySAxZuqOTiSC/
N8flF7To0eL60sToRataIpyTLT2Qb5YW6Auw0SGPyQcgVWModfauetD32C4svet2+VRrIHmdm
ys6CDpzzz6XL5jfIkpWiY6sNyR39vRfh9t11Rms+Z0kdStbGEG7MQAHs+VQItusi2ED+oYqJk
oPzq2NYhlB1idoAGMzrjLvXBGN73cUxnd79CVMKNpC1CgQnTjUNZPD6g6QsDsXDn9032fP51x
NKyDwoWwhvQUjbSFPk5uyHCYml6zXA8nITjltvB87vEsOliY/9FGxfYcMWgXZBoffyE9FUhG2
hNlvoxOtreeBAOt89Jby8tU6YrqkQ4e5Eq7cEfl7EsRLRl+5VcmufNZ4xB4Zv3Ry2jxoazFOq
P3pf52XTRnGxFDPyQUQ1471FK0Rj9Yqm4ig6e3wPQezoQ2zY8Bq55oAquTTuc1JzZBr+VVZrs
pYVFTtVWeNC0OwTTaQk/5xQVwGLPK4O6gn41c3bhI0OfxQ56wW3Od6wQGz5tNw2epKfrp0RhP
O2qY+JoXWDl+qfauEEan509JWLAT4CHIy5RNcLCevuQHD5P7rqi85ZYGo3c=
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <9976b879-98cd-5a2b-5394-e42923334948@Damon-Family.org>
X-Mailman-Original-References: <87lf4o7ce2.fsf@hornfels.zedat.fu-berlin.de>
<fed6d9c0-8934-4925-d6ac-7d6bc0132f86@Damon-Family.org>
<mailman.474.1630027132.4164.python-list@python.org>
<87mtp3jq2h.fsf@hornfels.zedat.fu-berlin.de>
 by: Richard Damon - Sat, 28 Aug 2021 00:06 UTC

On 8/27/21 3:37 AM, Loris Bennett wrote:
> Richard Damon <Richard@Damon-Family.org> writes:
>
>> On 8/26/21 6:01 AM, Loris Bennett wrote:
>>> Hi,
>>>
>>> When using configargparse, it seems that if a value is to be read from a
>>> config file, it also has to be defined as a command-line argument in
>>> order to turn up as an attribute in the parser namespace.
>>>
>>> I can sort of see why this is the case, but there are also some options
>>> I would like to read just from the config file and not have them
>>> available as command-line options. This would be, say, to prevent the
>>> number of options on the command-line from becoming bloated by
>>> little-used settings.
>>>
>>> Is there an elegant way to do this?
>>>
>>> Cheers,
>>>
>>> Loris
>>>
>> Look at the read() member function to supply the file name to read. Then
>> in the config object there will be sections for each section in the
>> config file. No need for any of these to be 'options'
> Do you have a link for this? As far as I can see, the config files are
> given in the following manner:
>
> p = configargparse.ArgParser(default_config_files=['/etc/app/conf.d/*.conf', '~/.my_settings'])
>
> I can obviously just read the config file with configparser, but the
> idea of configargparse is that an option can be specified as an option,
> in a config file, or as an environment variable,
>
> As far as I can tell, configargparse only loads entries from the config
> file into the appropriate namespace if they have also been defined as
> long options (i.e. with '--'). I was hoping to access *all* the config
> file entries, regardless of whether they are also options, since the
> config is obviously being read.
>
> Cheers,
>
> Loris
>
I misread your question, I thought you were talking about configparse.

Question is, if configargparse doesn't do what you want, then it isn't
the right tool.

It looks like configargparse is SPECIFICALLY designed to allow the use
to use a file as a shorthand to present command line arguements. The
whole parsing structure is based on an enumerated set of options, if
that isn't what you have, it is the wrong tool.

--
Richard Damon

Re: configargparse - reading option from config only

<87y28j8nnp.fsf@hornfels.zedat.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14806&group=comp.lang.python#14806

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.be...@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Re: configargparse - reading option from config only
Date: Mon, 30 Aug 2021 08:14:18 +0200
Organization: Freie Universitaet Berlin
Lines: 76
Message-ID: <87y28j8nnp.fsf@hornfels.zedat.fu-berlin.de>
References: <87lf4o7ce2.fsf@hornfels.zedat.fu-berlin.de>
<fed6d9c0-8934-4925-d6ac-7d6bc0132f86@Damon-Family.org>
<mailman.474.1630027132.4164.python-list@python.org>
<87mtp3jq2h.fsf@hornfels.zedat.fu-berlin.de>
<9976b879-98cd-5a2b-5394-e42923334948@Damon-Family.org>
<mailman.478.1630109188.4164.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: news.uni-berlin.de 8wiD37fnEDGMNEyvRUZxgwrgVAMXAN4+GNAv/KHm+q+qFF
Cancel-Lock: sha1:C9iy3QQlnh7HwhS4cokpMl3oYCk=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
 by: Loris Bennett - Mon, 30 Aug 2021 06:14 UTC

Richard Damon <Richard@Damon-Family.org> writes:

> On 8/27/21 3:37 AM, Loris Bennett wrote:
>> Richard Damon <Richard@Damon-Family.org> writes:
>>
>>> On 8/26/21 6:01 AM, Loris Bennett wrote:
>>>> Hi,
>>>>
>>>> When using configargparse, it seems that if a value is to be read from a
>>>> config file, it also has to be defined as a command-line argument in
>>>> order to turn up as an attribute in the parser namespace.
>>>>
>>>> I can sort of see why this is the case, but there are also some options
>>>> I would like to read just from the config file and not have them
>>>> available as command-line options. This would be, say, to prevent the
>>>> number of options on the command-line from becoming bloated by
>>>> little-used settings.
>>>>
>>>> Is there an elegant way to do this?
>>>>
>>>> Cheers,
>>>>
>>>> Loris
>>>>
>>> Look at the read() member function to supply the file name to read. Then
>>> in the config object there will be sections for each section in the
>>> config file. No need for any of these to be 'options'
>> Do you have a link for this? As far as I can see, the config files are
>> given in the following manner:
>>
>> p = configargparse.ArgParser(default_config_files=['/etc/app/conf.d/*.conf', '~/.my_settings'])
>>
>> I can obviously just read the config file with configparser, but the
>> idea of configargparse is that an option can be specified as an option,
>> in a config file, or as an environment variable,
>>
>> As far as I can tell, configargparse only loads entries from the config
>> file into the appropriate namespace if they have also been defined as
>> long options (i.e. with '--'). I was hoping to access *all* the config
>> file entries, regardless of whether they are also options, since the
>> config is obviously being read.
>>
>> Cheers,
>>
>> Loris
>>
> I misread your question, I thought you were talking about configparse.
>
> Question is, if configargparse doesn't do what you want, then it isn't
> the right tool.
>
> It looks like configargparse is SPECIFICALLY designed to allow the use
> to use a file as a shorthand to present command line arguements. The
> whole parsing structure is based on an enumerated set of options, if
> that isn't what you have, it is the wrong tool.

I am not sure what you mean by using

a file as a shorthand to present command line arguements

since the command-line arguments are defined by caling the 'add_argument'
method of the configargparse object. However, I agree with your
analysis that configargparse is the wrong tool for what I want to do.

I like the idea that a variable can be defined as a command-line option,
an entry in a config file, or as an environment variable. However, when
I think about it, it seems that command-line options are essentially
different from parameters in a configuration file, not least because the
former need some sort of description for the output of '--help', whereas
the latter do not.

Cheers,

Loris
--
This signature is currently under construction.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor