Skip to content

Move astropy to src directory #13678

Open

Description

@nstarman

Activity

  1. nstarman commented on Sep 16, 2022

    @nstarman
    MemberAuthor

    Maybe the release manager can do this in the v5.2 release? It doesn't take too much work, just a few files like setup.cfg need to be updated.

  2. pllim commented on Sep 16, 2022

    @pllim
    Member

    Oh, dear... Won't this create some backport nightmare? I think @Cadair brought this up several times in the past but I don't think we have the energy to deal with the amount of work this will generate.

    Nothing is broken (yet), why is this needed now?

  3. dhomeier commented on Sep 16, 2022

    @dhomeier
    Contributor

    I don't see real context in the link, other than the given example using a src subdirectory – is there some reference why that should be safer (other than possibly allowing to run python in the top dir without import astropy importing directly from the repo, which numpy for example expressly forbids)?

  4. nstarman commented on Sep 16, 2022

    @nstarman
    MemberAuthor

    The section on flat layouts outlines why src layouts are preferred.

  5. nstarman commented on Sep 16, 2022

    @nstarman
    MemberAuthor

    Oh, dear... Won't this create some backport nightmare?

    Instead of v5.2, could we instead do this when the new LTS is out. That should solve back ports.
    Also, I'm not 100% sure of this, but if a commit just moves a file and then another commit is rebased on that 1st commit, I think it still works. Meaning, I don't think this breaks backports.

  6. dhomeier commented on Sep 16, 2022

    @dhomeier
    Contributor

    I don't see a clear recommendation of either layout over the other there, so we'll need to weigh the pros and cons of both ourselves.

  7. nstarman commented on Sep 16, 2022

    @nstarman
    MemberAuthor

    Some highlighted issues with flat-layout:

    in some situations it can be more error-prone (e.g. during tests or if you have a bunch of folders or Python files hanging around your project root).

    If you are using auto-discovery with flat-layout, setuptools will refuse to create distribution archives with multiple top-level packages or modules.

    These aren't insurmountable, but src-layout has no issues. If we could transition in a non-painful way, it could be nice.

  8. 33 remaining items

  9. namurphy commented on Mar 27, 2024

    @namurphy
    Contributor

    I've been working on PlasmaPy/PlasmaPy#2598 to switch PlasmaPy to an src layout with a separate top-level directory for tests. I'm putting a summary of my thoughts this comment, in case Astropy eventually switches to an src layout.

    Overall:

    • it wasn't as bad as I thought 🤔
    • until I remembered I needed to update tox.ini 🥲
  10. namurphy commented on May 7, 2024

    @namurphy
    Contributor

    To follow up on my previous post, switching to an src layout in PlasmaPy ended up causing very few disruptions, either to myself or others. Overall it's been a pretty smooth transition! 🎉🎂💖🎆🪩🌌🥦

    Because we used git mv when changing the layout, we were able to apply the layout changes to the PR branches with a git pull upstream main. I had no merge conflicts associated with the change for all of the ∼10 PRs I had open at the time.

    The impacts we've noticed have been:

    • Editable installations needed to be redone (see this comment).
    • git does not remove directories, so it'll be necessary to manually remove the empty plasmapy/ directory alongside the src/plasmapy/ directory, and empty tests/ subdirectories.
    • Having to change habits and get used to the new directory structure.

    The caveat is that because Astropy has a much larger contributor base, the chance of at least some noteworthy disruptions happening is higher. But, at least for PlasmaPy, it's been a quite smooth process.

    Update: we did run into one trickier situation recently where an older PR created new files under the old directory structure, so we had to resolve a merge conflict there. If Astropy does eventually switch to an src layout, it may be worthwhile for a core maintainer to do a git pull upstream main and git push to all active PRs just after the src pull request is merged.

  11. astrofrog commented on Sep 26, 2026

    @astrofrog
    Member

    @adrn might also want to comment on this as he advocated for it at the coordination meeting this year (this was not discussed in a breakout or plenary session though)

    My personal opinion is that I can see arguments both ways, and I think having things in the src/ layout may be a bit cleaner, but if we did move I would advocate for keeping the tests in the source tree rather than moving them out - it's very useful to have the tests be part of the installed version.

  12. nstarman commented on Sep 27, 2026

    @nstarman
    MemberAuthor

    +1 on moving to src layout.
    IMO there are good reasons to move the test directory, but I think we can have the test directory discussion independently of this one.

  13. mhvk commented on Sep 27, 2026

    @mhvk
    Contributor

    Continued 👎 to refactoring for very minor benefits.

  14. taldcroft commented on Sep 27, 2026

    @taldcroft
    Member
  15. nstarman commented on Sep 27, 2026

    @nstarman
    MemberAuthor

    @taldcroft I'd like to hear more about that, because I must be missing something critical. From my understanding the whole point of worktrees is to isolate changes, e.g. allowing development on multiple branches simultaneously because each is in a different worktree — a particularly nice pattern I use everyday with AI since it can crunch on those separate trees in the background. A common editable install sounds like its breaking that isolation, which seems to defeat the whole point of the worktree, and sounds equivalent to developing on multiple branches on the same code. How does this not crash together? Is this to try to save env space? If you use conda then it's an issue, but with uv its global cache means you’re not actually reinstalling dependencies, so you get the isolation point of worktrees at minimal (some symlinks) extra disk space. (all my codes, some with 100+ worktrees (I know, I need to prune 😆), use src-layout + uv and it all works great.)

    @mhvk, I'm sure this is on your radar, but https://git-scm.com/docs/directory-rename-detection describes the git mv mechanism, and more importantly how if we did git mv astropy src/astropy very few branches — active, in-development, or moldering on an old laptop — should need to be rebased. Migrating to a src directory seems like a largely infrastructural choice with little impact on subpackages ... except that it's verifiably safer, esp for testing: https://hynek.me/articles/testing-packaging.

  16. taldcroft commented on Sep 27, 2026

    @taldcroft
    Member

    @nstarman - I use conda for several reasons, so yes, making lots of new full installs gets expensive. Claude was able to figure out a clever way to use worktrees with a single editable install and they are indeed isolated. I can give you Claude's explanation if you care, but probably not. 😄

    The more important point is that the astropy developer community is large and they have evolved many ways of doing things based on the current flat layout. Breaking those current workflows would require strongly compelling reasons. The ones presented seem marginal at best. If there are compelling issues then why have so few other major packages changed their layout?

    in some situations it can be more error-prone (e.g. during tests or if you have a bunch of folders or Python files hanging around your project root).

    In theory yes, but in practice I'm not aware of it being a real issue.

    If you are using auto-discovery with flat-layout, setuptools will refuse to create distribution archives with multiple top-level packages or modules.

    Astropy doesn't use auto-discovery and there is only one top-level package.

  17. mhvk commented on Sep 27, 2026

    @mhvk
    Contributor

    @nstarman - my problem is finger memory. Yes, it will slowly adapt to every single time I open a file in an editor or run pytest ... having to type s<TAB>/a<TAB> instead of a direct a<TAB>, but it is a negative.

    I suggest we do not revisit layout until there is a general move in the scientific python ecosystem towards a different one.

  18. nstarman commented on Sep 27, 2026

    @nstarman
    MemberAuthor

    Breaking those current workflows would require strongly compelling reasons.

    I think one of the few workflows that would break is this Claude workaround you're describing, which is also a new development, giving that AI post November 2024 is what popularized git worktrees. Most other workflows are building an editable install, modifying files, and pushing, which a src-layout doesn't break, just protects.

    If there are compelling issues then why have so few other major packages changed their layout?

    Presumably because it can be a bit of a hassle to check the infrastructure / CI change. Which to me begs the different question, how much of a hassle is it for us? IMO if we're planning to do a migration to Meson et al then this is a comparatively minor change.
    But it also depends on which "major" packages, you mean, e.g. https://github.com/psf/requests is about as big as it gets and switched many years ago to src-layout. I've never been convinced that a scientific-python bubble that sometimes doesn't closely track the rest of python is a good idea; if we want to be small and not tap into Python everywhere, we'd be Julia. src-layouts are minor in those set of things, e.g. I think Pydantic and other things are proverbially larger potatoes, but still.

    I also think we have a different onus of responsibility than numpy and pandas. We used to have a package template because Astropy is also trying to help the astronomy community to develop open source packages. We don't maintain that package template anymore and defer to resources like https://packaging.python.org/en/latest/ or https://www.pyopensci.org/python-package-guide/. IMO it's b bad that we don't practice what we recommend — e.g. see https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/ and https://www.pyopensci.org/python-package-guide/tutorials/get-to-know-hatch.html#step-3 — where those resources pretty clearly favour src layouts. We basically tell people: "do as we aught, not as we do".

  19. mhvk commented on Sep 27, 2026

    @mhvk
    Contributor

    Well, in terms of recommendations, there is still https://packaging-guide.openastronomy.org/en/latest/ -- which does not use a src layout.

    Anyway, I don't think we'll convince each other here. I do not really want to spend more time on this, but my vote is for no change unless scientific python as a whole decides to change.

  20. nstarman commented on Sep 27, 2026

    @nstarman
    MemberAuthor

    Well, in terms of recommendations, there is still https://packaging-guide.openastronomy.org/en/latest/ -- which does not use a src layout.

    That's the latest iteration of our outdated template. It still recommends distutils.

    no change unless scientific python as a whole decides to change.

    https://giphy.com/gifs/foxtv-the-simpsons-fox-hSulTsYX8yatJMVtiQ

  21. adrn commented on Sep 27, 2026

    @adrn
    Member

    FWIW I do support changing to the src layout, but appreciate your reasons for not wanting to. Perhaps this is something that will require a vote at some point.

    I was reminded of this during the coordination meeting (and hence discussed with @astrofrog) because I was trying to check if a failing test was also failing in the latest stable version - I installed v8.0.1 but running the test in my environment grabbed the dev version (from the cloned repo). I've gotten used to being protected from issues like this in other packages I develop that use src.

    Well, in terms of recommendations, there is still https://packaging-guide.openastronomy.org/en/latest/

    The Open Astronomy packaging guide seems to be a bit out of date relative to the vast majority of recommendations that recommend the src layout (@nstarman linked to some already):

    Anyway, I don't think we'll convince each other here

    I agree with that part at least 😅.

  22. namurphy commented on Sep 28, 2026

    @namurphy
    Contributor

    Let's say we're in the top-level directory of the astropy repository, and run pip install .. We open python and then do import astropy. Is the astropy that gets imported going to be the installed version, or the version contained in the astropy/ directory? When we run pytest, are we running tests on the installed version, or the files contained in astropy/? If we add a new .py file but neglect to include it in MANIFEST.in, will it be included when running pytest?

    The reason why flat-layouts make me cringe is because flat-layouts introduce subtle ambiguities that can confuse contributors, and cause subtle packaging errors that are detected in CI but that don't get reproduced locally when running pytest.

    But given the reticence, I'm wondering if an effective way to encourage the scientific pythoniverse to adopt src-layouts would be to write a SPEC. 🤔

  23. mhvk commented on Sep 28, 2026

    @mhvk
    Contributor

    Just for the record -- if we started astropy now, it would indeed have made sense to do a src layout. The discussion is whether it makes sense to change, where I'm with @taldcroft, who wrote

    The more important point is that the astropy developer community is large and they have evolved many ways of doing things based on the current flat layout. Breaking those current workflows would require strongly compelling reasons. The ones presented seem marginal at best.

    Anyway, I agree that if there is a SPEC, which presumably means that most of the scientific stack is happy to change, astropy should definitely follow that. In the meantime, though, I'll use the little spare time I have to do reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions