diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 7239390..9b0f533 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -10,7 +10,7 @@ jobs: steps: - uses: actions/setup-python@v2 with: - python-version: 3.8 + python-version: 3.12 - uses: actions/checkout@master with: fetch-depth: 0 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9ac5ced..da192a0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.8, 3.9] + python-version: [3.9, '3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v2 diff --git a/nachos/core/making.py b/nachos/core/making.py index a657fa3..c5e8b0d 100644 --- a/nachos/core/making.py +++ b/nachos/core/making.py @@ -1,32 +1,30 @@ import os from prompt_toolkit import document as pt_document, prompt as prompt_pt -from prompt_toolkit.completion import Completer, Completion -from prompt_toolkit.contrib.completers import WordCompleter, PathCompleter +from prompt_toolkit.completion import WordCompleter, PathCompleter, Completer, Completion from prompt_toolkit.validation import Validator, ValidationError -from prompt_toolkit.contrib.validators.base import SentenceValidator from qcip_tools.chemistry_files import helpers, PropertyNotPresent, PropertyNotDefined, gaussian from nachos.core import files, CONFIG -class SentenceValidatorWithDefault(SentenceValidator): +class ChoicesValidator(Validator): - def __init__(self, default=None, **kwargs): + def __init__(self, choices=None, default=None, **kwargs): super().__init__(**kwargs) - self.default_sentence = default - - if default is not None and default not in self.sentences: + if default is not None and default not in choices: raise ValueError('default value {} not in list'.format(default)) - def validate(self, document): + self.choices = [] if choices is None else choices + self.default = default - if document.text == '' and self.default_sentence is not None: - document.text = self.default_sentence - else: - super().validate(document) + def validate(self, document): + if document.text == '' and self.default is not None: + document.text = self.default + elif document.text not in self.choices: + raise ValidationError(message='Invalid choice: {}'.format(document.text)) class ChemistryFileValidator(Validator): @@ -403,7 +401,7 @@ def make(self, args): 'What flavor for you, today?', SetRecipeAction(recipe), completer=WordCompleter(words=CONFIG.keys()), - validator=SentenceValidatorWithDefault(sentences=CONFIG.keys()) + validator=ChoicesValidator(choices=CONFIG.keys()) ) config = CONFIG[recipe['flavor']] @@ -413,7 +411,7 @@ def make(self, args): 'What type of differentiation?', SetRecipeAction(recipe), completer=WordCompleter(words=config['types']), - validator=SentenceValidatorWithDefault(sentences=config['types'])) + validator=ChoicesValidator(choices=config['types'])) methods = [a[0] for a in config['methods']] self._make_var( @@ -422,7 +420,7 @@ def make(self, args): 'With which method?', SetRecipeAction(recipe), completer=WordCompleter(words=methods), - validator=SentenceValidatorWithDefault(sentences=methods)) + validator=ChoicesValidator(choices=methods)) if recipe['method'] == 'DFT': self._make_var( @@ -495,13 +493,20 @@ def make(self, args): SetRecipeAction(recipe), default=files.DEFAULT_RECIPE['name']) + # change default for type='G' + min_field = files.DEFAULT_RECIPE['min_field'] + k_max = files.DEFAULT_RECIPE['k_max'] + if recipe['type'] == 'G': + min_field = 0.01 + k_max = 3 + self._make_var( args, 'min_field', 'Minimum field (F0)?', SetRecipeWithConversionAction(recipe), - validator=TypeFloatValidator(default=files.DEFAULT_RECIPE['min_field']), - default=files.DEFAULT_RECIPE['min_field']) + validator=TypeFloatValidator(default=min_field), + default=min_field) self._make_var( args, @@ -516,8 +521,8 @@ def make(self, args): 'k_max', 'Maximum k?', SetRecipeWithConversionAction(recipe), - validator=TypeIntValidator(default=files.DEFAULT_RECIPE['k_max']), - default=files.DEFAULT_RECIPE['k_max']) + validator=TypeIntValidator(default=k_max), + default=k_max) self._make_var( args, @@ -599,7 +604,8 @@ def _prompt_toolkit(message, validator, completer, default=None): v = prompt_pt( message='{}{} '.format(message, ' [{}]'.format(default) if default is not None else ''), validator=validator, - completer=completer + completer=completer, + validate_while_typing=False ) if default is not None and validator is None and v == '': diff --git a/pyproject.toml b/pyproject.toml index 3c75a54..9da5b79 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,23 +6,23 @@ authors = [ ] description = "NACHOS: numerical differentiation code" readme = "README.md" -requires-python = ">=3.7" +requires-python = ">=3.9" classifiers = [ "Development Status :: 3 - Alpha", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", ] dependencies = [ 'pyyaml>=5.0', 'h5py', - 'qcip-tools @ git+https://github.com/pierre-24/qcip_tools.git@v0.7.1', - 'prompt_toolkit==1.0.15', + 'qcip-tools @ git+https://github.com/pierre-24/qcip_tools.git@v0.7.2', + 'prompt_toolkit', 'pandas>=1.2', 'scipy>=1.7', 'numpy>=1.20' diff --git a/requirements.in b/requirements.in index fa71b65..ba4d273 100644 --- a/requirements.in +++ b/requirements.in @@ -1,5 +1,5 @@ -e file:. #egg=nachos -flake8<6.0 +flake8 flake8-quotes autopep8 sphinxcontrib-autoprogram diff --git a/requirements.txt b/requirements.txt index fcfb251..432a4e9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,56 +1,56 @@ # -# This file is autogenerated by pip-compile with Python 3.11 +# This file is autogenerated by pip-compile with Python 3.12 # by the following command: # # pip-compile requirements.in # -e file:. # via -r requirements.in -alabaster==0.7.12 +alabaster==0.7.16 # via sphinx -autopep8==2.0.0 +autopep8==2.0.4 # via -r requirements.in -babel==2.11.0 +babel==2.14.0 # via sphinx -beautifulsoup4==4.11.1 +beautifulsoup4==4.12.2 # via qcip-tools bump2version==1.0.1 # via -r requirements.in -certifi==2022.12.7 +certifi==2023.11.17 # via requests -charset-normalizer==2.1.1 +charset-normalizer==3.3.2 # via requests colorama==0.4.6 # via mendeleev -docutils==0.17.1 +docutils==0.20.1 # via # sphinx # sphinx-rtd-theme -flake8==5.0.4 +flake8==7.0.0 # via # -r requirements.in # flake8-quotes -flake8-quotes==3.3.1 +flake8-quotes==3.3.2 # via -r requirements.in -greenlet==2.0.1 +greenlet==3.0.3 # via sqlalchemy -h5py==3.7.0 +h5py==3.10.0 # via # nachos # qcip-tools -idna==3.4 +idna==3.6 # via requests imagesize==1.4.1 # via sphinx jinja2==3.1.2 # via sphinx -markupsafe==2.1.1 +markupsafe==2.1.3 # via jinja2 mccabe==0.7.0 # via flake8 -mendeleev==0.12.1 +mendeleev==0.15.0 # via qcip-tools -numpy==1.23.5 +numpy==1.26.3 # via # h5py # mendeleev @@ -58,85 +58,93 @@ numpy==1.23.5 # pandas # qcip-tools # scipy -packaging==22.0 +packaging==23.2 # via sphinx -pandas==1.5.2 +pandas==2.1.4 # via # mendeleev # nachos # qcip-tools -pint==0.20.1 +pint==0.23 # via qcip-tools -prompt-toolkit==1.0.15 +prompt-toolkit==3.0.43 # via nachos -pycodestyle==2.9.1 +pycodestyle==2.11.1 # via # autopep8 # flake8 pyfiglet==0.8.post1 # via mendeleev -pyflakes==2.5.0 +pyflakes==3.2.0 # via flake8 -pygments==2.13.0 +pygments==2.17.2 # via # mendeleev # sphinx python-dateutil==2.8.2 # via pandas -pytz==2022.6 - # via - # babel - # pandas -pyyaml==6.0 +pytz==2023.3.post1 + # via pandas +pyyaml==6.0.1 # via nachos -qcip-tools @ git+https://github.com/pierre-24/qcip_tools.git@v0.7.1 +qcip-tools @ git+https://github.com/pierre-24/qcip_tools.git@v0.7.2 # via nachos -requests==2.28.1 +requests==2.31.0 # via # qcip-tools # sphinx -scipy==1.9.3 +scipy==1.11.4 # via # nachos # qcip-tools six==1.16.0 # via - # mendeleev - # prompt-toolkit # python-dateutil # sphinxcontrib-autoprogram snowballstemmer==2.2.0 # via sphinx -soupsieve==2.3.2.post1 +soupsieve==2.5 # via beautifulsoup4 -sphinx==5.3.0 +sphinx==7.2.6 # via # -r requirements.in # sphinx-rtd-theme + # sphinxcontrib-applehelp # sphinxcontrib-autoprogram -sphinx-rtd-theme==1.1.1 + # sphinxcontrib-devhelp + # sphinxcontrib-htmlhelp + # sphinxcontrib-jquery + # sphinxcontrib-qthelp + # sphinxcontrib-serializinghtml +sphinx-rtd-theme==2.0.0 # via -r requirements.in -sphinxcontrib-applehelp==1.0.2 +sphinxcontrib-applehelp==1.0.7 # via sphinx -sphinxcontrib-autoprogram==0.1.7 +sphinxcontrib-autoprogram==0.1.8 # via -r requirements.in -sphinxcontrib-devhelp==1.0.2 +sphinxcontrib-devhelp==1.0.5 # via sphinx -sphinxcontrib-htmlhelp==2.0.0 +sphinxcontrib-htmlhelp==2.0.4 # via sphinx +sphinxcontrib-jquery==4.1 + # via sphinx-rtd-theme sphinxcontrib-jsmath==1.0.1 # via sphinx -sphinxcontrib-qthelp==1.0.3 +sphinxcontrib-qthelp==1.0.6 # via sphinx -sphinxcontrib-serializinghtml==1.1.5 +sphinxcontrib-serializinghtml==1.1.9 # via sphinx -sqlalchemy==1.4.45 +sqlalchemy==2.0.25 # via mendeleev -tomli==2.0.1 - # via autopep8 transforms3d==0.4.1 # via qcip-tools -urllib3==1.26.13 +typing-extensions==4.9.0 + # via + # pint + # sqlalchemy +tzdata==2023.4 + # via pandas +urllib3==2.1.0 # via requests -wcwidth==0.2.5 +wcwidth==0.2.13 # via prompt-toolkit