Skip to content

feat: add --no-deps to mirror only the listed requirements - #125

Merged
grische merged 4 commits into
mainfrom
feature/no-dependencies
Nov 26, 2026
Merged

grische merged 4 commits into
mainfrom
feature/no-dependencies

Conversation

@grische

@grische grische commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

This is an improved version of #116, that doesn't need a configuration change.

@shamilbi what do you think about this approach? Would be great if you can do a review.

Closes #116
Fixes #112

grische and others added 4 commits November 23, 2026 14:22
A requirement can list its specifiers on continuation lines:

    [requirements]
    foo =
      ==2.0
      ==2.1

configparser returns the value of this key as "\n==2.0\n==2.1", and
splitlines() turns it into ["", "==2.0", "==2.1"]. mirror() called
Mirrorer.mirror() once for each entry, so the empty first entry
mirrored "foo" without a specifier. morgan therefore downloaded the
latest release of foo in addition to 2.0 and 2.1.

Drop empty lines before mirroring. A key without any value, such as
"morgan =", still mirrors the latest version.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
morgan mirrors the dependencies of every requirement, and for each
dependency it downloads the latest version that matches the
dependency's specifier. This is unwanted when the [requirements]
section already is a complete set of pinned versions, for example one
generated from a lock file. With "bar = ==1.0" and "foo = ==2.0" in
the config, and bar depending on "foo>=2.0", morgan downloads foo 2.0
and also the latest release of foo.

Add the --no-deps flag to "morgan mirror". With the flag,
Mirrorer._process_file returns no dependencies, so only the packages
listed in [requirements] are mirrored. This also leaves out extras
and the build requirements of source distributions.

The .metadata file next to each downloaded file is still written, so
that clients can resolve dependencies without downloading the archive
(PEP 658). With --use-pypi-metadata, the request to PyPI's JSON API
is skipped, because morgan uses its response only to find
dependencies.

Mirrorer reads the option with getattr(), because library callers
build the argparse.Namespace by hand, and reading a missing attribute
directly would raise an AttributeError for them.

Suggested-by: shamilbi <shamilbi@gmail.com>
Link: #112
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The README describes the mirroring of dependencies as unconditional
and does not mention the --no-deps flag.

Add the section "Mirroring Only the Listed Requirements". It says
when to use the flag. It also says that morgan then does not mirror
the build requirements of source distributions, because a lock file
usually does not list them and clients that build a package from
source fail without them.

Mention the flag in the feature list as well.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@grische
grische force-pushed the feature/no-dependencies branch from caeb825 to 408c6bb Compare November 23, 2026 13:24
@james-smith-za

Copy link
Copy Markdown

Thanks for taking this up!

I must admit I totally missed the thumbs-up on my original issue so this fell off my radar.

@grische

grische commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@james-smith-za if you can review the code change and test it, it would be appreciated

@james-smith-za james-smith-za left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested and it's working great.

Thanks again!

@grische
grische merged commit ca54e8e into main Nov 26, 2026
16 checks passed
@grische
grische deleted the feature/no-dependencies branch November 26, 2026 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to disable dependency resolver?

4 participants