Skip to content
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

Reorganize astropy.utils.misc a bit #2857

Merged
merged 9 commits into from Aug 18, 2014
Merged

Conversation

embray
Copy link
Member

@embray embray commented Aug 15, 2014

Following on from #2849, it became apparent to me that astropy.utils.misc was getting a bit cluttered, so this introduces a few new astropy.utils modules so that astropy.utils.misc could be broken up a bit.

Specifically it moves:

  • make_func_with_sig into the codegen submodule
  • deprecated, deprecated_attribute, lazyproperty, and wraps into the decorators submodule
  • find_current_module and find_mod_objs into the introspection submodule

Any other moves seem worthwhile? Note again, this has #2849 as a prerequisite.

<astropy#2835 (comment)>
this adds the make_func_with_sig function to astropy.utils.misc.
Taking advantage of this, a new astropy.utils.compat.misc.wraps
function is provided as a replacement for functools.wraps, which
provides the same functionality but while also preserving the original
wrapped function's signature (so that it displays properly in help())
… thought. And most of them are in utilties/backwards compatibility features that aren't terribly important. But I found this one case where the new wraps implementation is useful. And there could be others in the future.
…_sig, rather than only allowing the name of the wrapped function to be used
…eplacement, such that the new function gets the same *name* as the function being wrapped as well
… number into the module make_func_with_sig was called from, and a test to prove that it works.
…mplementation available on Python 3.4 as well. As such I moved it out of astropy.utils.compat since it's really providing a new function rather than some backward/forward compatibility.
….utils.misc was getting a bit cluttered, so this introduces a few new astropy.utils modules so that astropy.utils.misc could be broken up a bit.
@embray embray added the utils label Aug 15, 2014
@embray
Copy link
Member Author

embray commented Aug 15, 2014

Any opinions on this? Part of what motivated this, by the way, was a branch in which I've introduced yet another new decorator called sharedmethod.

@pllim
Copy link
Member

pllim commented Aug 15, 2014

👍 but I do have minor concern on how much this would impact affiliated packages.

@embray
Copy link
Member Author

embray commented Aug 15, 2014

Me too--really they should just use from astropy.utils import ... to get to most of these. Worse comes to worse I can provide backwards compat.

@embray
Copy link
Member Author

embray commented Aug 18, 2014

Went ahead and added a changelog entry clarifying which imports moved. I don't think this will have much impact but it can't hurt to have the change clearly documented.

@embray embray added this to the v1.0.0 milestone Aug 18, 2014
@embray
Copy link
Member Author

embray commented Aug 18, 2014

#2849 has been merged, so I'll go ahead and merge this too. If it ends up affecting any affiliated packages we'll find out quickly and I can take steps to make their lives easier.

embray added a commit that referenced this pull request Aug 18, 2014
Reorganize astropy.utils.misc a bit
@embray embray merged commit 2bf73db into astropy:master Aug 18, 2014
@embray embray deleted the utils/reorg branch August 18, 2014 22:12
@cdeil
Copy link
Member

cdeil commented Aug 19, 2014

In Gammapy we used from astropy.utils.misc import lazyproperty so this broke our test.
It's OK, I'll just add a try ... except to import it from the new or old location.

But could someone please wipe readthedocs so that this shows up at the right location (and hopefully with a docstring) in the development version of the docs?
http://astropy.readthedocs.org/en/latest/search.html?q=lazyproperty
http://astropy.readthedocs.org/en/latest/api/astropy.utils.misc.lazyproperty.html?highlight=lazyproperty

- Some members of ``astropy.utils.misc`` were moved into new submodules.
Specifically:

- ``deprecated`, ``deprecated_attribute``, and ``lazyproperty`` ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing double-backtick

``deprecated`

should be

``deprecated``

@astrofrog
Copy link
Member

@cdeil - I've wiped latest and started a new build.

@cdeil
Copy link
Member

cdeil commented Aug 19, 2014

@astrofrog Build log is here:
https://readthedocs.org/builds/astropy/1613002/

I"ve seen this error before, but never figured out the reason ... any idea?

Traceback (most recent call last):
  File "setup.py", line 112, in <module>
    **package_info
  File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/install.py", line 73, in run
    self.do_egg_install()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/install.py", line 88, in do_egg_install
    self.run_command('bdist_egg')
  File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/bdist_egg.py", line 177, in run
    self.run_command("egg_info")
  File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/egg_info.py", line 163, in run
    self.find_sources()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/egg_info.py", line 186, in find_sources
    mm.run()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/egg_info.py", line 246, in run
    self.add_defaults()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/egg_info.py", line 285, in add_defaults
    rcfiles = list(walk_revctrl())
  File "/usr/lib/python2.7/dist-packages/setuptools/command/sdist.py", line 18, in walk_revctrl
    for item in ep.load()(dirname):
  File "/usr/lib/python2.7/dist-packages/setuptools/command/sdist.py", line 65, in _default_revctrl
    for item in finder(dirname):
  File "/usr/lib/python2.7/dist-packages/setuptools/svn_utils.py", line 468, in svn_finder
    info = SvnInfo.load(dirname)
  File "/usr/lib/python2.7/dist-packages/setuptools/svn_utils.py", line 264, in load
    with TemporaryDirectory() as tempdir:
  File "/usr/lib/python2.7/dist-packages/setuptools/py31compat.py", line 27, in __init__
    self.name = tempfile.mkdtemp()
AttributeError: 'NoneType' object has no attribute 'mkdtemp'

@cdeil
Copy link
Member

cdeil commented Aug 19, 2014

Fixed in Gammapy at https://github.com/gammapy/gammapy/pull/168/files without try .. except by simply importing from the top-level astropy.utils after I saw @embray's comment in the change log ... thanks!

@embray
Copy link
Member Author

embray commented Aug 19, 2014

@cdeil Thanks, sorry for the trouble. And yes, import from astropy.utils is the way to go for most of those.

@kbarbary
Copy link
Member

I just ran into this change, with an sncosmo user working on astropy master. Glad to see the flatter astropy.utils namespace.

However, the docs look like they don't reflect this still. That is, http://astropy.readthedocs.org/en/latest/api/astropy.utils.decorators.lazyproperty.html

has the path as astropy.utils.decorators.lazyproperty rather than astropy.utils.lazyproperty.

@embray
Copy link
Member Author

embray commented Sep 24, 2014

@kbarbary I agree that's a problem. The docs aren't wrong because that is the correct fully-qualified name for that function. This was discussed a bit in #2873

@kbarbary
Copy link
Member

Thanks, I hadn't seen #2873. Looks like the docs issue will be resolved there.

astrofrog pushed a commit to astropy/sphinx-automodapi that referenced this pull request Jan 27, 2018
ntessore pushed a commit to glass-dev/cosmology that referenced this pull request Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants