|
2 | 2 |
|
3 | 3 | use anyhow::Result;
|
4 | 4 | use assert_cmd::prelude::*;
|
5 |
| -use assert_fs::prelude::*; |
| 5 | +use assert_fs::{fixture::ChildPath, prelude::*}; |
6 | 6 | use insta::assert_snapshot;
|
7 | 7 |
|
8 | 8 | use common::{uv_snapshot, TestContext};
|
| 9 | +use predicates::prelude::predicate; |
| 10 | +use tempfile::tempdir_in; |
9 | 11 |
|
10 | 12 | mod common;
|
11 | 13 |
|
@@ -1483,3 +1485,265 @@ fn convert_to_package() -> Result<()> {
|
1483 | 1485 |
|
1484 | 1486 | Ok(())
|
1485 | 1487 | }
|
| 1488 | + |
| 1489 | +#[test] |
| 1490 | +fn sync_custom_environment_path() -> Result<()> { |
| 1491 | + let mut context = TestContext::new("3.12"); |
| 1492 | + |
| 1493 | + let pyproject_toml = context.temp_dir.child("pyproject.toml"); |
| 1494 | + pyproject_toml.write_str( |
| 1495 | + r#" |
| 1496 | + [project] |
| 1497 | + name = "project" |
| 1498 | + version = "0.1.0" |
| 1499 | + requires-python = ">=3.12" |
| 1500 | + dependencies = ["iniconfig"] |
| 1501 | + "#, |
| 1502 | + )?; |
| 1503 | + |
| 1504 | + // Running `uv sync` should create `.venv` by default |
| 1505 | + uv_snapshot!(context.filters(), context.sync(), @r###" |
| 1506 | + success: true |
| 1507 | + exit_code: 0 |
| 1508 | + ----- stdout ----- |
| 1509 | +
|
| 1510 | + ----- stderr ----- |
| 1511 | + Resolved 2 packages in [TIME] |
| 1512 | + Prepared 1 package in [TIME] |
| 1513 | + Installed 1 package in [TIME] |
| 1514 | + + iniconfig==2.0.0 |
| 1515 | + "###); |
| 1516 | + |
| 1517 | + context |
| 1518 | + .temp_dir |
| 1519 | + .child(".venv") |
| 1520 | + .assert(predicate::path::is_dir()); |
| 1521 | + |
| 1522 | + // Running `uv sync` should create `foo` in the project directory when customized |
| 1523 | + uv_snapshot!(context.filters(), context.sync().env("UV_PROJECT_ENVIRONMENT", "foo"), @r###" |
| 1524 | + success: true |
| 1525 | + exit_code: 0 |
| 1526 | + ----- stdout ----- |
| 1527 | +
|
| 1528 | + ----- stderr ----- |
| 1529 | + Using Python 3.12.[X] interpreter at: [PYTHON-3.12] |
| 1530 | + Creating virtualenv at: foo |
| 1531 | + Resolved 2 packages in [TIME] |
| 1532 | + Prepared 1 package in [TIME] |
| 1533 | + Installed 1 package in [TIME] |
| 1534 | + + iniconfig==2.0.0 |
| 1535 | + "###); |
| 1536 | + |
| 1537 | + context |
| 1538 | + .temp_dir |
| 1539 | + .child("foo") |
| 1540 | + .assert(predicate::path::is_dir()); |
| 1541 | + |
| 1542 | + // We don't delete `.venv`, though we arguably could |
| 1543 | + context |
| 1544 | + .temp_dir |
| 1545 | + .child(".venv") |
| 1546 | + .assert(predicate::path::is_dir()); |
| 1547 | + |
| 1548 | + // An absolute path can be provided |
| 1549 | + uv_snapshot!(context.filters(), context.sync().env("UV_PROJECT_ENVIRONMENT", "foobar/.venv"), @r###" |
| 1550 | + success: true |
| 1551 | + exit_code: 0 |
| 1552 | + ----- stdout ----- |
| 1553 | +
|
| 1554 | + ----- stderr ----- |
| 1555 | + Using Python 3.12.[X] interpreter at: [PYTHON-3.12] |
| 1556 | + Creating virtualenv at: foobar/.venv |
| 1557 | + Resolved 2 packages in [TIME] |
| 1558 | + Prepared 1 package in [TIME] |
| 1559 | + Installed 1 package in [TIME] |
| 1560 | + + iniconfig==2.0.0 |
| 1561 | + "###); |
| 1562 | + |
| 1563 | + context |
| 1564 | + .temp_dir |
| 1565 | + .child("foobar") |
| 1566 | + .assert(predicate::path::is_dir()); |
| 1567 | + |
| 1568 | + context |
| 1569 | + .temp_dir |
| 1570 | + .child("foobar") |
| 1571 | + .child(".venv") |
| 1572 | + .assert(predicate::path::is_dir()); |
| 1573 | + |
| 1574 | + // An absolute path can be provided |
| 1575 | + uv_snapshot!(context.filters(), context.sync().env("UV_PROJECT_ENVIRONMENT", context.temp_dir.join("bar")), @r###" |
| 1576 | + success: true |
| 1577 | + exit_code: 0 |
| 1578 | + ----- stdout ----- |
| 1579 | +
|
| 1580 | + ----- stderr ----- |
| 1581 | + Using Python 3.12.[X] interpreter at: [PYTHON-3.12] |
| 1582 | + Creating virtualenv at: bar |
| 1583 | + Resolved 2 packages in [TIME] |
| 1584 | + Prepared 1 package in [TIME] |
| 1585 | + Installed 1 package in [TIME] |
| 1586 | + + iniconfig==2.0.0 |
| 1587 | + "###); |
| 1588 | + |
| 1589 | + context |
| 1590 | + .temp_dir |
| 1591 | + .child("bar") |
| 1592 | + .assert(predicate::path::is_dir()); |
| 1593 | + |
| 1594 | + // And, it can be outside the project |
| 1595 | + let tempdir = tempdir_in(TestContext::test_bucket_dir())?; |
| 1596 | + context = context.with_filtered_path(tempdir.path(), "OTHER_TEMPDIR"); |
| 1597 | + uv_snapshot!(context.filters(), context.sync().env("UV_PROJECT_ENVIRONMENT", tempdir.path().join(".venv")), @r###" |
| 1598 | + success: true |
| 1599 | + exit_code: 0 |
| 1600 | + ----- stdout ----- |
| 1601 | +
|
| 1602 | + ----- stderr ----- |
| 1603 | + Using Python 3.12.[X] interpreter at: [PYTHON-3.12] |
| 1604 | + Creating virtualenv at: [OTHER_TEMPDIR]/.venv |
| 1605 | + Resolved 2 packages in [TIME] |
| 1606 | + Prepared 1 package in [TIME] |
| 1607 | + Installed 1 package in [TIME] |
| 1608 | + + iniconfig==2.0.0 |
| 1609 | + "###); |
| 1610 | + |
| 1611 | + ChildPath::new(tempdir.path()) |
| 1612 | + .child(".venv") |
| 1613 | + .assert(predicate::path::is_dir()); |
| 1614 | + |
| 1615 | + Ok(()) |
| 1616 | +} |
| 1617 | + |
| 1618 | +#[test] |
| 1619 | +fn sync_workspace_custom_environment_path() -> Result<()> { |
| 1620 | + let context = TestContext::new("3.12"); |
| 1621 | + |
| 1622 | + let pyproject_toml = context.temp_dir.child("pyproject.toml"); |
| 1623 | + pyproject_toml.write_str( |
| 1624 | + r#" |
| 1625 | + [project] |
| 1626 | + name = "project" |
| 1627 | + version = "0.1.0" |
| 1628 | + requires-python = ">=3.12" |
| 1629 | + dependencies = ["iniconfig"] |
| 1630 | + "#, |
| 1631 | + )?; |
| 1632 | + |
| 1633 | + // Create a workspace member |
| 1634 | + context.init().arg("child").assert().success(); |
| 1635 | + |
| 1636 | + // Running `uv sync` should create `.venv` in the workspace root |
| 1637 | + uv_snapshot!(context.filters(), context.sync(), @r###" |
| 1638 | + success: true |
| 1639 | + exit_code: 0 |
| 1640 | + ----- stdout ----- |
| 1641 | +
|
| 1642 | + ----- stderr ----- |
| 1643 | + Resolved 3 packages in [TIME] |
| 1644 | + Prepared 1 package in [TIME] |
| 1645 | + Installed 1 package in [TIME] |
| 1646 | + + iniconfig==2.0.0 |
| 1647 | + "###); |
| 1648 | + |
| 1649 | + context |
| 1650 | + .temp_dir |
| 1651 | + .child(".venv") |
| 1652 | + .assert(predicate::path::is_dir()); |
| 1653 | + |
| 1654 | + // Similarly, `uv sync` from the child project uses `.venv` in the workspace root |
| 1655 | + uv_snapshot!(context.filters(), context.sync().current_dir(context.temp_dir.join("child")), @r###" |
| 1656 | + success: true |
| 1657 | + exit_code: 0 |
| 1658 | + ----- stdout ----- |
| 1659 | +
|
| 1660 | + ----- stderr ----- |
| 1661 | + Resolved 3 packages in [TIME] |
| 1662 | + Uninstalled 1 package in [TIME] |
| 1663 | + - iniconfig==2.0.0 |
| 1664 | + "###); |
| 1665 | + |
| 1666 | + context |
| 1667 | + .temp_dir |
| 1668 | + .child(".venv") |
| 1669 | + .assert(predicate::path::is_dir()); |
| 1670 | + |
| 1671 | + context |
| 1672 | + .temp_dir |
| 1673 | + .child("child") |
| 1674 | + .child(".venv") |
| 1675 | + .assert(predicate::path::missing()); |
| 1676 | + |
| 1677 | + // Running `uv sync` should create `foo` in the workspace root when customized |
| 1678 | + uv_snapshot!(context.filters(), context.sync().env("UV_PROJECT_ENVIRONMENT", "foo"), @r###" |
| 1679 | + success: true |
| 1680 | + exit_code: 0 |
| 1681 | + ----- stdout ----- |
| 1682 | +
|
| 1683 | + ----- stderr ----- |
| 1684 | + Using Python 3.12.[X] interpreter at: [PYTHON-3.12] |
| 1685 | + Creating virtualenv at: foo |
| 1686 | + Resolved 3 packages in [TIME] |
| 1687 | + Prepared 1 package in [TIME] |
| 1688 | + Installed 1 package in [TIME] |
| 1689 | + + iniconfig==2.0.0 |
| 1690 | + "###); |
| 1691 | + |
| 1692 | + context |
| 1693 | + .temp_dir |
| 1694 | + .child("foo") |
| 1695 | + .assert(predicate::path::is_dir()); |
| 1696 | + |
| 1697 | + // We don't delete `.venv`, though we arguably could |
| 1698 | + context |
| 1699 | + .temp_dir |
| 1700 | + .child(".venv") |
| 1701 | + .assert(predicate::path::is_dir()); |
| 1702 | + |
| 1703 | + // Similarly, `uv sync` from the child project uses `foo` relative to the workspace root |
| 1704 | + uv_snapshot!(context.filters(), context.sync().env("UV_PROJECT_ENVIRONMENT", "foo").current_dir(context.temp_dir.join("child")), @r###" |
| 1705 | + success: true |
| 1706 | + exit_code: 0 |
| 1707 | + ----- stdout ----- |
| 1708 | +
|
| 1709 | + ----- stderr ----- |
| 1710 | + Resolved 3 packages in [TIME] |
| 1711 | + Uninstalled 1 package in [TIME] |
| 1712 | + - iniconfig==2.0.0 |
| 1713 | + "###); |
| 1714 | + |
| 1715 | + context |
| 1716 | + .temp_dir |
| 1717 | + .child("foo") |
| 1718 | + .assert(predicate::path::is_dir()); |
| 1719 | + |
| 1720 | + context |
| 1721 | + .temp_dir |
| 1722 | + .child("child") |
| 1723 | + .child("foo") |
| 1724 | + .assert(predicate::path::missing()); |
| 1725 | + |
| 1726 | + // And, `uv sync --package child` uses `foo` relative to the workspace root |
| 1727 | + uv_snapshot!(context.filters(), context.sync().arg("--package").arg("child").env("UV_PROJECT_ENVIRONMENT", "foo"), @r###" |
| 1728 | + success: true |
| 1729 | + exit_code: 0 |
| 1730 | + ----- stdout ----- |
| 1731 | +
|
| 1732 | + ----- stderr ----- |
| 1733 | + Resolved 3 packages in [TIME] |
| 1734 | + Audited in [TIME] |
| 1735 | + "###); |
| 1736 | + |
| 1737 | + context |
| 1738 | + .temp_dir |
| 1739 | + .child("foo") |
| 1740 | + .assert(predicate::path::is_dir()); |
| 1741 | + |
| 1742 | + context |
| 1743 | + .temp_dir |
| 1744 | + .child("child") |
| 1745 | + .child("foo") |
| 1746 | + .assert(predicate::path::missing()); |
| 1747 | + |
| 1748 | + Ok(()) |
| 1749 | +} |
0 commit comments