amuse icon indicating copy to clipboard operation
amuse copied to clipboard

changing default printing strategy in source breaks imports

Open ipelupessy opened this issue 3 years ago • 9 comments

changing the default printing strategy in console.py can break import of units

e.g. changing:

class _Defaults(options.OptionalAttributes):

    @options.option(sections=['output',])
    def printing_strategy(self):
        return 'simple'

to

class _Defaults(options.OptionalAttributes):

    @options.option(sections=['output',])
    def printing_strategy(self):
        return 'astro'

break things. This is not a problem, but it is strange..

ipelupessy avatar Sep 18 '22 15:09 ipelupessy

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 28 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 17 '22 19:11 stale[bot]

It seems to be a circular import...

from amuse.units import constants -> from amuse.units.derivedsi import * -> one = 1 | none -> (requires new_quantity) from amuse.units import quantities -> from amuse.support import console -> set_printing_strategy(_Defaults().printing_strategy) -> from amuse.units import units -> kms = named('kilometer per seconds', 'kms', km / s) -> fail (km not yet imported from derivedsi)

rieder avatar Nov 17 '22 19:11 rieder

explicitly adding the 'km' input to units.py gives:

File ~/Code/amuse/src/amuse/units/units.py:4, in <module>
      2 from . import quantities
      3 from amuse.units.si import *
----> 4 from amuse.units.derivedsi import km
      5 from amuse.units.derivedsi import *
      6 from amuse.units import constants

ImportError: cannot import name 'km' from partially initialized module 'amuse.units.derivedsi' (most likely due to a circular import) (/Users/rieder/Code/amuse/src/amuse/units/derivedsi.py)

rieder avatar Nov 17 '22 19:11 rieder

i.e. console cannot be used by ~units~quantities if this is to work... But it has to be of course.

rieder avatar Nov 17 '22 19:11 rieder

'simple' is a fine strategy to use as default, but anything with preferred units cannot work as it is.

rieder avatar Nov 17 '22 19:11 rieder

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 28 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 16 '23 23:01 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 28 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Mar 18 '23 06:03 stale[bot]