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

fix: make topological sorting support fully cyclic dependencies #678

Merged
merged 4 commits into from
May 24, 2024

Conversation

schmelczer
Copy link
Contributor

In case the graph of dependencies only consisted of a directed cycle, sort_topologically returned an empty list. This was an issue when trying to sort the dependencies of an environment containing Python 3.12 and Pip on MacOS as both depend on each other. See the relevant section of the repodata from conda forge:

[{
    "build": "h1411813_0_cpython",
    "build_number": 0,
    "constrains": [
        "python_abi 3.12.* *_cp312"
    ],
    "depends": [
        "__osx >=10.9",
        "bzip2 >=1.0.8,<2.0a0",
        "libexpat >=2.6.2,<3.0a0",
        "libffi >=3.4,<4.0a0",
        "libsqlite >=3.45.2,<4.0a0",
        "libzlib >=1.2.13,<1.3.0a0",
        "ncurses >=6.4.20240210,<7.0a0",
        "openssl >=3.2.1,<4.0a0",
        "readline >=8.2,<9.0a0",
        "tk >=8.6.13,<8.7.0a0",
        "tzdata",
        "xz >=5.2.6,<6.0a0",
        "pip"
    ],
    "license": "Python-2.0",
    "md5": "df1448ec6cbf8eceb03d29003cf72ae6",
    "name": "python",
    "sha256": "3b327ffc152a245011011d1d730781577a8274fde1cf6243f073749ead8f1c2a",
    "size": 14557341,
    "subdir": "osx-64",
    "timestamp": 1713208068012,
    "version": "3.12.3",
    "fn": "python-3.12.3-h1411813_0_cpython.conda",
    "url": "https://conda.anaconda.org/conda-forge/osx-64/python-3.12.3-h1411813_0_cpython.conda",
    "channel": "https://conda.anaconda.org/conda-forge/"
},
{
    "build": "pyhd8ed1ab_0",
    "build_number": 0,
    "depends": [
        "python >=3.7",
        "setuptools",
        "wheel"
    ],
    "license": "MIT",
    "license_family": "MIT",
    "md5": "f586ac1e56c8638b64f9c8122a7b8a67",
    "name": "pip",
    "noarch": "python",
    "sha256": "b7c1c5d8f13e8cb491c4bd1d0d1896a4cf80fc47de01059ad77509112b664a4a",
    "size": 1398245,
    "subdir": "noarch",
    "timestamp": 1706960660581,
    "version": "24.0",
    "fn": "pip-24.0-pyhd8ed1ab_0.conda",
    "url": "https://conda.anaconda.org/conda-forge/noarch/pip-24.0-pyhd8ed1ab_0.conda",
    "channel": "https://conda.anaconda.org/conda-forge/"
},
...
]

Even though topological sorting theoretically requires a DAG as its input, the existing implementation of sort_topologically already handled directed cycles just not the case where all the nodes were part of such cycles.

The fix is that if we can't find any root nodes, we start cycle detection from a random (the first in the given list) node.

@schmelczer schmelczer changed the title Fix topological sorting for cyclic dependencies fix: make topological sorting support fully cyclic dependencies May 24, 2024
@baszalmstra
Copy link
Collaborator

Thanks!

@baszalmstra baszalmstra enabled auto-merge (squash) May 24, 2024 14:43
@baszalmstra baszalmstra disabled auto-merge May 24, 2024 14:58
@baszalmstra baszalmstra merged commit 75de1c9 into conda-incubator:main May 24, 2024
14 checks passed
This was referenced May 24, 2024
baszalmstra added a commit that referenced this pull request May 27, 2024
## 🤖 New release
* `rattler`: 0.25.0 -> 0.26.0
* `rattler_conda_types`: 0.23.1 -> 0.24.0
* `rattler_package_streaming`: 0.20.10 -> 0.21.0
* `rattler_networking`: 0.20.7 -> 0.20.8
* `rattler_lock`: 0.22.7 -> 0.22.8
* `rattler_repodata_gateway`: 0.20.1 -> 0.20.2
* `rattler_solve`: 0.22.0 -> 0.23.0
* `rattler_index`: 0.19.12 -> 0.19.13
* `rattler_shell`: 0.20.4 -> 0.20.5
* `rattler_virtual_packages`: 0.19.11 -> 0.19.12

<details><summary><i><b>Changelog</b></i></summary><p>

## `rattler`
<blockquote>

##
[0.26.0](rattler-v0.25.0...rattler-v0.26.0)
- 2024-05-27

### Fixed
- improve progress bar duration display
([#680](#680))

### Other
- introducing the installer
([#664](#664))
- create directories up front
([#533](#533))
</blockquote>

## `rattler_conda_types`
<blockquote>

##
[0.24.0](rattler_conda_types-v0.23.1...rattler_conda_types-v0.24.0)
- 2024-05-27

### Added
- removed Ord and more
([#673](#673))
- always store purls as a key in lock file
([#669](#669))
- add solve strategies
([#660](#660))

### Fixed
- make topological sorting support fully cyclic dependencies
([#678](#678))
</blockquote>

## `rattler_package_streaming`
<blockquote>

##
[0.21.0](rattler_package_streaming-v0.20.10...rattler_package_streaming-v0.21.0)
- 2024-05-27

### Other
- introducing the installer
([#664](#664))
</blockquote>

## `rattler_networking`
<blockquote>

##
[0.20.8](rattler_networking-v0.20.7...rattler_networking-v0.20.8)
- 2024-05-27

### Other
- introducing the installer
([#664](#664))
</blockquote>

## `rattler_lock`
<blockquote>

##
[0.22.8](rattler_lock-v0.22.7...rattler_lock-v0.22.8)
- 2024-05-27

### Added
- removed Ord and more
([#673](#673))
- always store purls as a key in lock file
([#669](#669))
</blockquote>

## `rattler_repodata_gateway`
<blockquote>

##
[0.20.2](rattler_repodata_gateway-v0.20.1...rattler_repodata_gateway-v0.20.2)
- 2024-05-27

### Fixed
- result grouped by subdir instead of channel
([#666](#666))

### Other
- introducing the installer
([#664](#664))
</blockquote>

## `rattler_solve`
<blockquote>

##
[0.23.0](rattler_solve-v0.22.0...rattler_solve-v0.23.0)
- 2024-05-27

### Added
- removed Ord and more
([#673](#673))
- always store purls as a key in lock file
([#669](#669))
- add solve strategies
([#660](#660))

### Fixed
- result grouped by subdir instead of channel
([#666](#666))

### Other
- introducing the installer
([#664](#664))
</blockquote>

## `rattler_index`
<blockquote>

##
[0.19.13](rattler_index-v0.19.12...rattler_index-v0.19.13)
- 2024-05-27

### Added
- always store purls as a key in lock file
([#669](#669))
</blockquote>

## `rattler_shell`
<blockquote>

##
[0.20.5](rattler_shell-v0.20.4...rattler_shell-v0.20.5)
- 2024-05-27

### Other
- updated the following local packages: rattler_conda_types
</blockquote>

## `rattler_virtual_packages`
<blockquote>

##
[0.19.12](rattler_virtual_packages-v0.19.11...rattler_virtual_packages-v0.19.12)
- 2024-05-27

### Other
- updated the following local packages: rattler_conda_types
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/MarcoIeni/release-plz/).
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.

None yet

2 participants