diff --git a/HISTORY.rst b/HISTORY.rst index b1e5b23..a8b3c19 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -30,6 +30,15 @@ and the release date, in year-month-day format (see examples below). Not Yet Released ---------------- +Fixed ++++++ +* If there was a bare token in the PVL-text (i.e. a parameter with no value assignment), + the returned error message was difficult to understand, should now be clear that + it was looking for an equals sign, and didn't find one (Issue 108). +* Just importing the pvl library would emit the PendingDeprecationWarning about the Units + class, even if a user did not import or instantiate the Units class. + The warn() was not properly issued from the __init__() function, it now is (Issue 109). + 1.3.2 (2022-02-05) ------------------ diff --git a/docs/quantities.rst b/docs/quantities.rst index edf24d7..da49349 100644 --- a/docs/quantities.rst +++ b/docs/quantities.rst @@ -17,7 +17,7 @@ In order to avoid optional dependencies, the ``pvl`` library provides the :class:`pvl.collections.Quantity` class, implemented as a :class:`collections.namedtuple` with a ``value`` and a ``unit`` parameter. However, the ``unit`` parameter is just a string and -so the ``pvl`` quantity objects doesn't have the super-powers that +so the ``pvl`` quantity object doesn't have the super-powers that the ``astropy`` and ``pint`` quntity objects do. By default, this means that when PVL text is parsed by :func:`pvl.load` @@ -191,7 +191,7 @@ would prefer to use those objects. Here is an example:: ('length', ) ]) >>> print(type(w_pint['length'])) - + Just as with :class:`astropy.units.Quantity`, :class:`pint.Quantity` doesn't recognize the upper case units, and will raise an error like this:: @@ -220,7 +220,7 @@ a registry on-the-fly, you must use the registry's Quantity to the ('INT_UNIT', ) ]) >>> print(type(label['FLOAT_UNIT'])) - .Quantity'> + Similarly, :class:`pint.Quantity` objects can be encoded to PVL text by :func:`pvl.dump` or :func:`pvl.dumps`:: diff --git a/environment.yml b/environment.yml index a27dd35..d18ce8e 100644 --- a/environment.yml +++ b/environment.yml @@ -5,15 +5,12 @@ dependencies: - bump2version - cookiecutter - flake8 - - pypy3.6 - - python=3.6 - pytest - pytest-cov - sphinx - sphinxcontrib - sphinxcontrib-apidoc - sphinxcontrib-autoprogram - - tox - twine # These are optional dependencies, and pvl should pass all its tests without them. - python-dateutil diff --git a/pvl/__init__.py b/pvl/__init__.py index 8b71efd..426431a 100755 --- a/pvl/__init__.py +++ b/pvl/__init__.py @@ -24,7 +24,7 @@ __author__ = "The pvl Developers" __email__ = "rbeyer@rossbeyer.net" -__version__ = "1.3.2" +__version__ = "1.3.3-dev" __all__ = [ "load", "loads", diff --git a/pvl/collections.py b/pvl/collections.py index 4687f2b..6571de5 100644 --- a/pvl/collections.py +++ b/pvl/collections.py @@ -697,8 +697,12 @@ def __float__(self): class Units(Quantity): - warnings.warn( - "The pvl.collections.Units object is deprecated, and may be removed at " - "the next major patch. Please use pvl.collections.Quantity instead.", - PendingDeprecationWarning, - ) + + def __init__(self, *args, **kwargs): + warnings.warn( + "The pvl.collections.Units object is deprecated, and may be " + "removed at the next major patch. Please use " + "pvl.collections.Quantity instead.", + PendingDeprecationWarning, + stacklevel=2 + ) diff --git a/pvl/parser.py b/pvl/parser.py index c7f312a..2ec04f7 100644 --- a/pvl/parser.py +++ b/pvl/parser.py @@ -319,12 +319,13 @@ def parse_aggregation_block(self, tokens: abc.Generator): # noqa: C901 present in the End-Aggregation-Statement. """ (begin, block_name) = self.parse_begin_aggregation_statement(tokens) + # print(f"parsed begin agg: {begin} {block_name}") agg = self.aggregation_cls(begin) while True: - self.parse_WSC_until(None, tokens) try: + # print("about to see if these tokens can be an agg block.") agg.append(*self.parse_aggregation_block(tokens)) except LexerError: raise @@ -337,16 +338,21 @@ def parse_aggregation_block(self, tokens: abc.Generator): # noqa: C901 # tokens.send(t) except LexerError: raise - except ValueError: + except ValueError as err: + # print(f"Had a ValueError: {err}") # t = next(tokens) # print(f'parsing agg block, next token is: {t}') # tokens.send(t) + if 'Expecting "="' in str(err): + tokens.throw(ValueError, str(err)) + try: self.parse_end_aggregation(begin, block_name, tokens) break except LexerError: raise except ValueError as ve: + # print(f"In ve: {ve}") try: (agg, keep_parsing) = self.parse_module_post_hook( agg, tokens @@ -390,7 +396,7 @@ def parse_begin_aggregation_statement( the name Block Name as a ``str``. ::= - * '=' * + * '=' * [] Where ::= @@ -399,15 +405,16 @@ def parse_begin_aggregation_statement( try: begin = next(tokens) if not begin.is_begin_aggregation(): + # print(f"{begin} is not a begin aggregation raise ValueError") tokens.send(begin) raise ValueError( - "Expecting a Begin-Aggegation-Statement, but " + "Expecting a Begin-Aggregation-Statement, but " f"found: {begin}" ) except StopIteration: raise ValueError( "Ran out of tokens before starting to parse " - "a Begin-Aggegation-Statement." + "a Begin-Aggregation-Statement." ) try: @@ -623,7 +630,7 @@ def _parse_set_seq(self, delimiters, tokens: abc.Generator) -> list: tokens.send(t) tokens.throw( ValueError, - "While parsing, expected a comma (,)" f'but found: "{t}"', + f'While parsing, expected a comma (,) but found: "{t}"', ) def parse_set(self, tokens: abc.Generator) -> frozenset: diff --git a/setup.cfg b/setup.cfg index 9302b19..02baa94 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.3.2 +current_version = 1.3.3-dev commit = False tag = False parse = (?P\d+)\.(?P\d+)\.(?P\d+)(\-(?P[a-z]+))? diff --git a/setup.py b/setup.py index a36a36d..29c3538 100755 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name='pvl', - version='1.3.2', + version='1.3.3-dev', description=( 'Python implementation for PVL (Parameter Value Language) ' 'parsing and encoding.'