Commit graph

2258 commits

Author SHA1 Message Date
Charlie Marsh
41f051db3b
Remove exclude newer methods on test context (#4535)
## Summary

Closes https://github.com/astral-sh/uv/issues/4531.
2024-06-25 23:45:35 +00:00
konsti
c28a2c7583
Small lock.rs improvements (#4239)
Small improvements i made reading through `lock.rs`.
2024-06-25 22:19:00 +00:00
konsti
ff2f927579
Replace PubGrubDependencies by PubGrubDependency (#4481)
In the last PR (#4430), we flatten the requirements. In the next PR
(#4435), we want to pass `Url` around next to `PubGrubPackage` and
`Range<Version>` to keep track of which `Requirement`s added a url
across forking. This PR is a refactoring split out from #4435 that rolls
the dependency conversion into a single iterator and introduces a new
`PubGrubDependency` struct as abstraction over `(PubGrubPackage,
Range<Version>)` (or `(PubGrubPackage, Range<Version>,
VerbatimParsedUrl)` in the next PR), and it removes the now unnecessary
`PubGrubDependencies` abstraction.
2024-06-25 22:11:52 +00:00
konsti
e6103dcab1
Deduplicate test command creation (#4512)
This PR refactors the command creation in the test suite to remove the
duplication.

**1)** We add the same set of test stubbing args to almost any uv
invocation in the tests:

```rust
command
    .arg("--cache-dir")
    .arg(self.cache_dir.path())
    .env("VIRTUAL_ENV", self.venv.as_os_str())
    .env("UV_NO_WRAP", "1")
    .env("HOME", self.home_dir.as_os_str())
    .env("UV_TOOLCHAIN_DIR", "")
    .env("UV_TEST_PYTHON_PATH", &self.python_path())
    .current_dir(self.temp_dir.path());

if cfg!(all(windows, debug_assertions)) {
    // TODO(konstin): Reduce stack usage in debug mode enough that the tests pass with the
    // default windows stack of 1MB
    command.env("UV_STACK_SIZE", (8 * 1024 * 1024).to_string());
}
```

Centralizing these into a `TestContext::add_shared_args` method removes
them from everywhere.

**2)** Prefix all `TextContext` methods of the pip interface with
`pip_`. This is now necessary due to `uv sync` vs. `uv pip sync`.

**3)** Move command creation in the various test files into dedicated
functions or methods to avoid repeating the arguments. Except for error
message tests, there should be at most one `Command::new(get_bin())`
call per test file. `EXCLUDE_NEWER` is exclusively used in
`TestContext`.

---

I'm considering adding a `TestCommand` on top of these changes (in
another PR) that holds a reference to the `TextContext`, has
`add_shared_args` as a method and uses `Fn(Self) -> Self` instead of
`Fn(&mut Self) -> Self` for methods to improved chaining.
2024-06-25 22:06:54 +00:00
Charlie Marsh
e1708689a9
Add a universal resolution mode to pip compile (#4505)
## Summary

This needs more tests and a few more changes, but checkpointing it for
now.
2024-06-25 21:28:50 +00:00
konsti
f2f48d339e
Flatten requirements eagerly in get_dependencies (#4430)
Downstack PR: #4515 Upstack PR: #4481

Consider these two cases:

A:
```
werkzeug==2.0.0
werkzeug @ 960bb4017c/Werkzeug-2.0.0-py3-none-any.whl
```

B:
```toml
dependencies = [
  "iniconfig == 1.1.1 ; python_version < '3.12'",
  "iniconfig @ git+https://github.com/pytest-dev/iniconfig@93f5930e668c0d1ddf4597e38dd0dea4e2665e7a ; python_version >= '3.12'",
]
```

In the first case, `werkzeug==2.0.0` should be overridden by the url. In
the second case `iniconfig == 1.1.1` is in a different fork and must
remain a registry distribution.

That means the conversion from `Requirement` to `PubGrubPackage` is
dependent on the other requirements of the package. We can either look
into the other packages immediately, or we can move the forking before
the conversion to `PubGrubDependencies` instead of after. Either version
requires a flat list of `Requirement`s to use. This refactoring gives us
this list.

I'll add support for both of the above cases in the forking urls branch
before merging this PR. I also have to move constraints over to this.
2024-06-25 21:13:47 +00:00
Zanie Blue
e242cdf713
Update project::update_environment to respect reinstall options (#4502)
While working on https://github.com/astral-sh/uv/pull/4492 I noticed
that `--reinstall-package` was not actually respected by
`update_environment`, it exited early due to satisfied requirements.

Before

```

❯ cargo run -q -- tool install black -v --reinstall-package tomli
...
DEBUG All requirements satisfied: black | click>=8.0.0 | mypy-extensions>=0.4.3 | packaging>=22.0 | pathspec>=0.9.0 | platformdirs>=2 | tomli>=1.1.0 ; python_version < '3.11' | typing-extensions>=4.0.1 ; python_version < '3.11'
```

After

```
❯ cargo run -q -- tool install black -v --reinstall-package tomli
...
Uninstalled 1 package in 0.99ms
Installed 1 package in 4ms
 - tomli==2.0.1
 + tomli==2.0.1
```
2024-06-25 17:12:51 -04:00
Charlie Marsh
08bf6fb87c
Deduplicate source edges in annotations (#4530)
## Summary

Not relevant today, but it will be once we support universal resolution,
in which a package can be repeated.
2024-06-25 21:10:09 +00:00
konsti
ad42206e50
Unify dependency iteration in ResolverState::get_dependencies (#4515)
Upstack PR: #4430

Split out from #4430 according to
https://github.com/astral-sh/uv/pull/4430#discussion_r1650192338.
2024-06-25 23:04:49 +02:00
Charlie Marsh
5732209be3
Add support for --no-strip-markers in pip compile output (#4503)
## Summary

This is an intermediary change in enabling universal resolution for
`requirements.txt` files. To start, we need to be able to preserve
markers in the `requirements.txt` output _and_ propagate those markers,
such that if you have a dependency that's only included with a given
marker, the transitive dependencies respect that marker too.

Closes #1429.
2024-06-25 20:55:58 +00:00
konsti
af1f1369e5
Remove useless #[allow(clippy::too_many_arguments)] (#4529)
I went through all `#[allow(clippy::too_many_arguments)]` and removed
the useless ones.
2024-06-25 19:09:59 +00:00
Charlie Marsh
a81742c06b
Read persistent configuration from non-workspace pyproject.toml (#4526)
## Summary

If the user puts their configuration in a `pyproject.toml` that _isn't_
a valid workspace root (e.g., it's a Poetry file), we won't discover it,
because we only look in `uv.toml` files in that case. I think this is
somewhat debatable... We could choose to _require_ `uv.toml` there, but
as a user I'd probably expect it to work?

Closes https://github.com/astral-sh/uv/issues/4521.
2024-06-25 18:53:14 +00:00
Zanie Blue
5641f3a5d9
Add guard to replace_symlink on Windows (#4519)
`junction::create` apparently will happily succeed but not create a link
to files? Since our symlink function does not indicate that it cannot
handle files, this was quite surprising.


Tested over in #4509 which previously failed on an assertion that
`black.exe` existed.
```
error: Failed to install entrypoint
    Caused by: Cannot create a junction for [TEMP_DIR]/tools/black/Scripts/black.exe: is not a directory
```

We should file an issue upstream too, I think?
2024-06-25 13:47:40 -05:00
Charlie Marsh
a07e70d93a
Avoid panic for invalid, non-base index URLs (#4527)
## Summary

See: https://github.com/astral-sh/uv/issues/4510
2024-06-25 18:32:58 +00:00
Charlie Marsh
904957bf80
Allow local index references in requirements.txt files (#4525)
## Summary

We currently accept `--index-url /path/to/index` on the command line,
but confusingly, not in `requirements.txt`. This PR just brings the two
in sync.

## Test Plan

New snapshot tests.
2024-06-25 18:06:37 +00:00
Charlie Marsh
e39f5f72fe
Allow non-file:// paths to serve as --index-url values (#4524)
## Summary

pip allows these with the following logic:

```python
if os.path.exists(location):  # Is a local path.
    url = path_to_url(location)
    path = location
elif location.startswith("file:"):  # A file: URL.
    url = location
    path = url_to_path(location)
elif is_url(location):
    url = location
```

Closes https://github.com/astral-sh/uv/issues/4510.

## Test Plan

`cargo run pip install --index-url ../packse/index/simple-html/
example-a-961b4c22 --reinstall --no-cache --no-deps`
2024-06-25 17:57:12 +00:00
Andrew Gallant
3379e4c8c2
uv/tests: tweak toolchain_find test (#4523)
I was getting this test failure locally on my Archlinux system:

```
-old snapshot
+new results
    0     0 │ success: true
    1     1 │ exit_code: 0
    2     2 │ ----- stdout -----
    3       │-[PYTHON-3.12]
          3 │+/usr/bin/python3
    4     4 │
    5     5 │ ----- stderr -----
```

Where I have `/usr/bin/python3` and `/usr/bin/python3.12`.

Thanks @zanieb for the help with figuring out the fix here!
2024-06-25 13:23:36 -04:00
Zanie Blue
7fe7d8b34e
Fix symlink doc (#4514)
This bit me.
2024-06-25 08:27:03 -05:00
Zanie Blue
e25cbee4d2
Isolate the tests from the real home directory (#4508)
Nice to have for #4492 and seems like a good idea in general to avoid
mutating a developer's machine.
2024-06-25 07:47:55 -05:00
Eric Mark Martin
967f136564
More precise locking with --prefix option (#4506)
## Summary

In #4085, support was implemented for the `--prefix` option. When using
this option, however, a lock is either acquired on the virtualenv or
globally, preventing multiple installs to different `--prefix`s from the
same interpreter.

In this change, acquire the lock on just the prefix in question.

## Test Plan

Ran a `uv pip install` with `--prefix` and `RUST_LOG=trace` and observed
that the lock was acquired in the prefix.
2024-06-25 06:47:52 -04:00
Charlie Marsh
ddacede7db
Move requirements.txt distribution into separate file (#4500)
## Summary

No functional changes, but this has outgrown being in the module root.
2024-06-25 00:32:44 +00:00
Charlie Marsh
7946509931
Change Operations API to always accept PythonRequirement (#4498)
## Summary

I think this is more intuitive than taking an `Option` and computing the
requirement if it's `None`.
2024-06-24 23:37:08 +00:00
Zanie Blue
25cde888ae
Rename SitePackages::from_environment for clarity (#4497) 2024-06-24 23:32:45 +00:00
Charlie Marsh
604be9ed71
Use Preferences struct in Manifest API (#4496)
## Summary

This is just a bit more consistent with `Overrides` and `Constraints`.
2024-06-24 23:28:55 +00:00
Charlie Marsh
10ec9c9d0b
Use operations API in pip compile (#4493)
## Summary

Closes https://github.com/astral-sh/uv/issues/4235.
2024-06-24 22:20:03 +00:00
Charlie Marsh
9905521957
Use shared client in Git fetch implementation (#4487)
## Summary

It turns out that the Git fetch implementation is initializing its own
client, which can be really expensive on macOS (due to loading native
certificates) _and_ bypasses any of our middleware. This PR modifies the
Git implementation to accept a shared client.
2024-06-24 17:09:29 -04:00
Charlie Marsh
7221514136
Make overrides a workspace method (#4491)
## Summary

No functional changes; just encapsulating the logic within the workspace
module.
2024-06-24 17:09:23 -04:00
Charlie Marsh
7d3fb4330f
Skip submodule update for fresh clones (#4482)
## Summary

We unconditionally update the submodules in our Git code, but AFAICT it
shouldn't be necessary if we already have a complete, up-to-date fetch
available.
2024-06-24 17:09:14 -04:00
Charlie Marsh
849478fa91
Add unowned settings variants (#4490)
## Summary

This PR adds unowned settings variants so that we can convert from
`ResolverInstallerSettings` to `ResolverSettings` without allocating.
2024-06-24 20:18:16 +00:00
Charlie Marsh
8afad69b03
Implement settings conversion traits (#4489)
## Summary

This does require cloning the settings, but I think it's fine. A better
solution would be to have owned and unowned settings structs, so that we
could convert `ResolverInstallerSettingsRef` to `InstallerSettingsRef`
without cloning, but that requires maintaining owned and unowned
variants.

Closes https://github.com/astral-sh/uv/issues/4455.
2024-06-24 16:08:11 -04:00
Charlie Marsh
ff72bb9bcc
Read content length from response rather than request (#4488)
## Summary

I might be mistaken, but I think we need to read the header from the
response, not the request. The request would only contain headers that
we set.

I verified (with extra logging) that the request header is `None` while
PyPI returns a valid length in the response header.
2024-06-24 15:58:21 -04:00
Charlie Marsh
f6aec0a96c
Remove non-existent extras from lockfile (#4479)
## Summary

Ultimately decided to view this as part of `LockWire` normalization:
removing references to extras that don't exist. I think it would be nice
if the resolver avoided omitting these, but I don't know if it's fully
possible.

Closes https://github.com/astral-sh/uv/issues/4405.
2024-06-24 14:56:56 -04:00
konsti
1984ada57c
Break PubGrubReportFormatter::hints into methods (#4478)
I have to add yet another indentation level to the prerelease-available
check in `PubGrubReportFormatter::hints` for #4435, so i've broken the
code into methods and decreased indentation in this split out
refactoring-only change.
2024-06-24 19:14:09 +02:00
Chan Kang
c127632419
implement --no-dedupe for uv pip tree (#4449)
<!--
Thank you for contributing to uv! To help us out with reviewing, please
consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary
Resolves https://github.com/astral-sh/uv/issues/4439 partially.

Implements for `uv pip tree`:
- `--no-dedupe` flag, similar to `cargo tree --no-dedupe` .
- denote dependency cycles with `(#)` and add a footnote if there's a
cycle (using `(*)` would require keeping track of the cycle state, so
opted to do this instead).
<!-- What's the purpose of the change? What does it do, and why? -->

## Test Plan
The existing tests pass + added a couple of tests to validate
`--no-dedupe` behavior.
<!-- How was it tested? -->
2024-06-24 11:54:55 -05:00
Sandu
03cfdc2275
uv lock to use overrides from tool.uv (#4108) (#4369)
## Summary

This will make `uv lock` read `override-dependencies` from the
`[tool.uv]` section of `pyproject.toml`.
Resolves #4108

This [other](https://github.com/astral-sh/uv/pull/4446) implementation
touches more code but seems more consistent.

## Test Plan

Unit test
2024-06-24 12:44:54 -04:00
Zanie Blue
bfc342da94
Bump version to 0.2.15 (#4475)
Releasing 0.2.15 with a few additions over 0.2.14. Motivated by the
incorrect tagging of 0.2.14 (#4474).

Generated the changelog with a small patch to Rooster allowing me to
force the previous commit to be correct.

```diff
diff --git a/src/rooster/_cli.py b/src/rooster/_cli.py
index 2a4f61b..4ec1299 100644
--- a/src/rooster/_cli.py
+++ b/src/rooster/_cli.py
@@ -38,6 +38,7 @@ def release(
     without_sections: list[str] = typer.Option(
         [], help="Sections to exclude from the changelog"
     ),
+    previous_commit: str = None,
 ):
     """
     Create a new release.
@@ -58,7 +59,11 @@ def release(
         typer.echo("It looks like there are no version tags for this project.")
 
     # Get the commits since the last release
-    changes = list(get_commits_between(config, repo, last_version))
+    changes = list(
+        get_commits_between(
+            config, repo, last_version, force_first_commit=previous_commit
+        )
+    )
     since = "since last release" if last_version else "in the project"
     typer.echo(f"Found {len(changes)} commits {since}.")
 
diff --git a/src/rooster/_git.py b/src/rooster/_git.py
index 597bb88..66bc54e 100644
--- a/src/rooster/_git.py
+++ b/src/rooster/_git.py
@@ -29,12 +29,13 @@ def get_commits_between(
     target: Path,
     first_version: Version | None = None,
     second_version: Version | None = None,
+    force_first_commit: str | None = None,
 ) -> Generator[git.Commit, None, None]:
     """
     Yield all commits between two tags
     """
     repo = git.repository.Repository(target.absolute())
-    first_commit = (
+    first_commit = force_first_commit or (
         repo.lookup_reference(
             TAG_PREFIX + config.version_tag_prefix + str(first_version)
         )
```
2024-06-24 10:04:09 -05:00
konsti
40f852687b
Add context to unregistered task name to error context (#4471)
I caused this error during development and having the name of the task
on it is helpful for debugging.

Split out from #4435
2024-06-24 14:42:55 +00:00
Zanie Blue
64e07b68a8
Reapply "Bump version to 0.2.14" (#4472)
Restores #4431

This reverts commit 9ff6a5ed74 (#4436)
2024-06-24 09:14:16 -05:00
Charlie Marsh
f07308823e
Add --emit-build-options flag to uv pip compile interface (#4463)
## Summary

Closes https://github.com/astral-sh/uv/issues/4420.
2024-06-24 12:25:01 +00:00
Charlie Marsh
cba270f750
Respect index strategy in source distribution builds (#4468)
## Summary

The `--index-strategy` is linked to the index locations, which we
propagate to source distribution builds; so it makes sense to pass the
`--index-strategy` too.

While I was here, I made `exclude_newer` a required argument so that we
don't forget to set it via the `with_options` builder.

Closes https://github.com/astral-sh/uv/issues/4465.
2024-06-24 12:03:38 +00:00
Charlie Marsh
1eee427c94
Add standalone CLI crate (#4456)
## Summary

This PR moves all the CLI code into its own crate, separate from the
`uv` crate. The `uv` crate is iterated on frequently, and the CLI code
comprises a significant portion of it but rarely changes. Removing the
CLI code reduces the `uv` crate size from 1.4MiB to 1.0MiB.
2024-06-24 06:16:22 -04:00
renovate[bot]
3251690327
Update Rust crate rustc-hash to v2 (#4461) 2024-06-24 01:13:05 +00:00
Charlie Marsh
757ea61bea
Fix casing of --no-compile alias (#4453)
## Summary

Closes https://github.com/astral-sh/uv/issues/4452.
2024-06-23 17:25:50 +00:00
Zanie Blue
d4f2a8a52f
Adjust the docs for the pip CLI commands (#4445) 2024-06-23 12:03:49 -04:00
Zanie Blue
03e2e6b99a
Fix construction of Python path in test context (#4443)
When executables were not named `python3` e.g. `python3.11` we would
construct a Python path that would only work for _some_ requests in
tests since we don't search for those names unless a specific version is
requested. To solve, we construct a test context with constant Python
executable names. For example, if a test context was created with `3.11`
and `3.12` we could end up with the search path
`/usr/local/python-3.11/bin:/usr/local/python-3.12/bin` where the
executables are named `python3.11` and `python3` respectively. A test
invocation of uv requesting any Python toolchain version would then
locate the `3.12` executable since the `3.11` executable doesn't have
the generic name, but we want `3.11` to come first.

On Windows, we just leave things as-is because executables are always
called `python.exe`.

Closes https://github.com/astral-sh/uv/issues/4376
2024-06-23 10:05:48 -05:00
samypr100
2288ff7bf4
feat: pythonw support on gui scripts (#4409)
## Summary

Closes https://github.com/astral-sh/uv/issues/2956

This changes the bootstrap launcher script to use `pythonw.exe` instead
of `python.exe` on `gui_scripts` via a helper fn both in the shebang and
the python exe path encoded before `UVUV` magic, that way
uv-trampoline's `find_python_exe` can use the right pythonw executable.

## Test Plan

New unit tests for the helper was added.
Tested on example from #2956 on Windows to make sure it works as
expected.

## Questions

I noticed the docs in `fn windows_script_launcher` says ```The launcher
will look for `python[w].exe` adjacent to it in the same directory to
start the embedded script.``` but I didn't find such functionality when
I looked in uv-trampoline.
I only saw `clear_app_starting_state` getting called when `is_gui` is
set.

Was the intention to do this in uv-trampoline at some point instead?

---------

Co-authored-by: konstin <konstin@mailbox.org>
2024-06-23 09:48:47 +00:00
Zanie Blue
3a63e1410d
Adjust deduplicated message in pip tree (#4448) 2024-06-22 14:53:01 +00:00
Zanie Blue
c7149e96ca
Collapse duplicate toolchain search in test setup (#4442) 2024-06-22 09:43:03 -05:00
Zanie Blue
8f2d8b3f4f
Fix ordering of prefer-system toolchain preference (#4441)
Whoopsies!
2024-06-22 09:42:51 -05:00
Chan Kang
dd45fce2d4
implement uv pip tree (#3859)
## Summary

resolves https://github.com/astral-sh/uv/issues/3272

added it as a new subcommand rather than a flag on an existing
command since that seems more consistent with `cargo tree` + cleaner
code organization, but can make changes if it's preferred the other way.
2024-06-21 15:48:30 -04:00