Skip to content

Commit

Permalink
Allow pre-release versions for Python native packages in case of == a…
Browse files Browse the repository at this point in the history
…nd === specifiers (#133)
  • Loading branch information
pilosus authored Feb 25, 2023
1 parent 7636764 commit 5f0dc7e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ This change log follows the conventions of [keepachangelog.com](http://keepachan

## [Unreleased]

## [0.44.0] - 2023-02-25

### Fixed
- Allow pre-release versions for Python native packages in case of
exact equal (`==`) or arbitrary string equal (`===`) specifiers
([#132](https://github.com/pilosus/pip-license-checker/issues/132))

## [0.43.0] - 2023-02-10

### Fixed
Expand Down Expand Up @@ -406,7 +413,8 @@ weak copyleft types.
### Added
- Structure for Leiningen app project

[Unreleased]: https://github.com/pilosus/pip-license-checker/compare/0.43.0...HEAD
[Unreleased]: https://github.com/pilosus/pip-license-checker/compare/0.44.0...HEAD
[0.44.0]: https://github.com/pilosus/pip-license-checker/compare/0.43.0...0.44.0
[0.43.0]: https://github.com/pilosus/pip-license-checker/compare/0.42.1...0.43.0
[0.42.1]: https://github.com/pilosus/pip-license-checker/compare/0.42.0...0.42.1
[0.42.0]: https://github.com/pilosus/pip-license-checker/compare/0.42.0-SNAPSHOT...0.42.0
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject org.pilosus/pip-license-checker "0.43.1-SNAPSHOT"
(defproject org.pilosus/pip-license-checker "0.44.0"
:description "License compliance tool to identify dependencies license names and types: permissive, copyleft, proprietory, etc."
:url "https://github.com/pilosus/pip-license-checker"
:license {:name "Eclipse Public License 2.0 OR GNU GPL v2+ with Classpath exception"
Expand Down
13 changes: 10 additions & 3 deletions src/pip_license_checker/version.clj
Original file line number Diff line number Diff line change
Expand Up @@ -501,22 +501,29 @@
result (and version-not-pre? version-not-dev?)]
result))

(defn- contains-eq-specifier?
"Return true if the specifiers vector contains `==` or `===`"
[specifiers]
(some #(contains? #{eq arbitrary-eq} (first %)) specifiers))

(defn remove-yanked-versions
"Remove yanked versions for non-exact specifiers"
[specifiers versions]
(if (some #(contains? #{eq arbitrary-eq} (first %)) specifiers)
(if (contains-eq-specifier? specifiers)
versions
(remove #(= (get-in % [:meta :yanked]) true) versions)))

(defn filter-versions
"Return lazy seq of parsed versions that satisfy specifiers"
[specifiers versions & {:keys [pre] :or {pre true}}]
(let [versions'
(let [pre-release-included?
(or pre (contains-eq-specifier? specifiers))
versions'
(->>
versions
(filter #(version-ok? specifiers %))
(remove-yanked-versions specifiers))]
(if pre
(if pre-release-included?
versions'
(filter version-stable? versions'))))

Expand Down
16 changes: 15 additions & 1 deletion test/pip_license_checker/version_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,21 @@
["1.48.2" {:yanked false}]]
false
["1.48.0"]
"use yanked version for arbitrary-string equal specifier"]])
"use yanked version for arbitrary-string equal specifier"]
[[["==" "0.0.2a32"]]
[["0.0.1" {:yanked false}]
["0.0.2a32" {:yanked false}]
["0.0.3" {:yanked false}]]
false
["0.0.2a32"]
"use pre-release version for exact equal specifier with --no-pre option"]
[[["===" "0.0.2a32"]]
[["0.0.1" {:yanked false}]
["0.0.2a32" {:yanked false}]
["0.0.3" {:yanked false}]]
false
["0.0.2a32"]
"use pre-release version for arbitrary-string equal specifier with --no-pre option"]])

(deftest test-filter-versions
(testing "Check versions filtering"
Expand Down

0 comments on commit 5f0dc7e

Please sign in to comment.