Skip to content

4.0 rc1: Possible circularity when creating ply files #9659

@olebole

Description

@olebole

On Debian, I generate the input files that are needed for the generation of the ply files for coordinates and units during the build with the following small script:

import astropy.coordinates
astropy.coordinates.angle_utilities.parse_angle("0°")
import astropy.units.format
astropy.units.format.CDS.parse("m/s")
astropy.units.format.Generic.parse("m")
astropy.units.format.OGIP.parse("m/s")

This worked nicely for 3.x. On 4.0 rc1 however, the imports fail with

import astropy.coordinates
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/usr/lib/python3/dist-packages/astropy/units/format/generic.py in _do_parse(cls, s, debug)
    565             # is just a single unit name
--> 566             return cls._parse_unit(s, detailed_exception=False)
    567         except ValueError as e:

/usr/lib/python3/dist-packages/astropy/units/format/generic.py in _parse_unit(cls, s, detailed_exception)
    486         else:
--> 487             raise ValueError()
    488 

ValueError: 

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
/usr/lib/python3/dist-packages/astropy/units/core.py in __call__(self, s, represents, format, namespace, doc, parse_strict)
   1853             try:
-> 1854                 return f.parse(s)
   1855             except Exception as e:

/usr/lib/python3/dist-packages/astropy/units/format/generic.py in parse(cls, s, debug)
    550 
--> 551         result = cls._do_parse(s, debug=debug)
    552         # Check for excess solidi, but exclude fractional exponents (accepted)

/usr/lib/python3/dist-packages/astropy/units/format/generic.py in _do_parse(cls, s, debug)
    568             try:
--> 569                 return cls._parser.parse(s, lexer=cls._lexer, debug=debug)
    570             except ValueError as e:

/usr/lib/python3/dist-packages/ply/yacc.py in parse(self, input, lexer, debug, tracking, tokenfunc)
    332         else:
--> 333             return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
    334 

/usr/lib/python3/dist-packages/ply/yacc.py in parseopt_notrack(self, input, lexer, debug, tracking, tokenfunc)
   1062                     if not lookaheadstack:
-> 1063                         lookahead = get_token()     # Get the next token
   1064                     else:

/usr/lib/python3/dist-packages/ply/lex.py in token(self)
    392                     self.lexpos = lexpos
--> 393                     newtok = self.lexerrorf(tok)
    394                     if lexpos == self.lexpos:

/usr/lib/python3/dist-packages/astropy/units/format/generic.py in t_error(t)
    172             raise ValueError(
--> 173                 f"Invalid character at col {t.lexpos}")
    174 

ValueError: Invalid character at col 0

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-1-45ece6429792> in <module>()
----> 1 import astropy.coordinates

/usr/lib/python3/dist-packages/astropy/coordinates/__init__.py in <module>()
      8 
      9 from .errors import *
---> 10 from .angles import *
     11 from .baseframe import *
     12 from .attributes import *

/usr/lib/python3/dist-packages/astropy/coordinates/angles.py in <module>()
     11 import numpy as np
     12 
---> 13 from . import angle_utilities as util
     14 from astropy import units as u
     15 from astropy.utils import isiterable

/usr/lib/python3/dist-packages/astropy/coordinates/angle_utilities.py in <module>()
     27                      IllegalSecondWarning, IllegalSecondError)
     28 from astropy.utils import format_exception
---> 29 from astropy import units as u
     30 
     31 

/usr/lib/python3/dist-packages/astropy/units/__init__.py in <module>()
     19 from . import si
     20 from . import cgs
---> 21 from . import astrophys
     22 from . import photometric
     23 from .function import units as function_units

/usr/lib/python3/dist-packages/astropy/units/astrophys.py in <module>()
     42          format={'latex': r'R_{\oplus}', 'unicode': 'R⊕'})
     43 
---> 44 def_unit(['lyr', 'lightyear'], (_si.c * si.yr).to(si.m),
     45          namespace=_ns, prefixes=True, doc="Light year")
     46 

/usr/lib/python3/dist-packages/astropy/constants/constant.py in wrapper(self, *args, **kwargs)
     39                     for inst in instances.values():
     40                         try:
---> 41                             self.unit.to(inst.unit)
     42                         except UnitsError:
     43                             self._has_incompatible_units.add(name_lower)

/usr/lib/python3/dist-packages/astropy/units/quantity.py in unit(self)
    757         """
    758 
--> 759         return self._unit
    760 
    761     @property

/usr/lib/python3/dist-packages/astropy/utils/decorators.py in __get__(self, obj, owner)
    742                 return val
    743             else:
--> 744                 val = self.fget(obj)
    745                 obj.__dict__[self._key] = val
    746                 return val

/usr/lib/python3/dist-packages/astropy/constants/constant.py in _unit(self)
    163         """The unit(s) in which this constant is defined."""
    164 
--> 165         return Unit(self._unit_string)
    166 
    167     @property

/usr/lib/python3/dist-packages/astropy/units/core.py in __call__(self, s, represents, format, namespace, doc, parse_strict)
   1872                            .format(s, format_clause, str(e)))
   1873                     if parse_strict == 'raise':
-> 1874                         raise ValueError(msg)
   1875                     elif parse_strict == 'warn':
   1876                         warnings.warn(msg, UnitsWarning)

ValueError: 'm / (s)' did not parse as unit: Invalid character at col 0 If this is meant to be a custom unit, define it with 'u.def_unit'. To have it recognized inside a file reader or other code, enable it with 'u.add_enabled_units'. For details, see http://docs.astropy.org/en/latest/units/combining_and_defining.html

The last error suggests that there is a circularity: to import units or coordinates, I need the ply files, which in are generated by the *tab.py files, whose generation needs a working units/coordinates import. However, I am not very knowledgable about ply, so maybe there is just a better solution than my hack.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions