-
Notifications
You must be signed in to change notification settings - Fork 3k
Create function to set user config #5943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
a1c435d
c5b09f2
7f97db2
a4bd675
491b018
98e398b
d68baf9
e3c7863
c9f7138
c538796
dab9c84
9b81078
9604a22
021a5dc
bf80f3f
9a973a6
4606836
fa4a210
b41a6f0
73cac9c
b561570
df16d94
94bad76
3c44909
c86d72d
912d60a
64cf239
46c0d20
5406a82
04a840a
6e3dbc7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -146,6 +146,39 @@ def read_config_file(self): | |||||
| self.settings['num_processes'] = num_processes | ||||||
|
|
||||||
|
|
||||||
| def set_config(key, value, section=None): | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also add an optional
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does setting
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking more if you want to create a new file separate the one currently loaded. path_backup = os.get_environ('QISKIT_SETTINGS')
os.environ['QISKIT_SETTINGS'] = '/new/path'
qiskit.user_config.set_config('circuit_drawer', 'latex')
os.environ['QISKIT_SETTINGS'] = path_backupwhich seems a bit clunky.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mtreinish Is the idea to create the function |
||||||
| """Adds or modifies a user configuration | ||||||
|
|
||||||
| It will add the configuration in either the default location | ||||||
| ~/.qiskit/settings.conf or if set the value of the `QISKIT_SETTINGS` env var. | ||||||
|
|
||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add a note here that any changes to the existing config file will not be reflected in the current session since the config file is parsed at import time. |
||||||
| Args: | ||||||
| key (str): name of the config | ||||||
| value (str): value of the config | ||||||
| section (str, optional): if not specified, adds it to the | ||||||
| `default` section of the config file. | ||||||
| """ | ||||||
| file_name = os.getenv('QISKIT_SETTINGS', DEFAULT_FILENAME) | ||||||
| sec_name = section if section is not None else 'default' | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| assert isinstance(key, str), 'Key must be string type' | ||||||
| assert isinstance(value, str), 'Value must be string type' | ||||||
|
1ucian0 marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| config = configparser.ConfigParser() | ||||||
| config.read(file_name) | ||||||
|
|
||||||
| if sec_name not in config.sections(): | ||||||
| config.add_section(sec_name) | ||||||
|
|
||||||
| config.set(sec_name, key, value) | ||||||
|
|
||||||
| with open(file_name, 'w') as cfgfile: | ||||||
| config.write(cfgfile) | ||||||
|
1ucian0 marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| user_config = UserConfig(file_name) | ||||||
| user_config.read_config_file() | ||||||
|
|
||||||
|
|
||||||
| def get_config(): | ||||||
| """Read the config file from the default location or env var | ||||||
|
|
||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.