From c69488718ba3ce2f9143fb93055d221b16197783 Mon Sep 17 00:00:00 2001 From: DavHau Date: Sun, 26 Mar 2023 17:53:02 +0800 Subject: [PATCH] refactor(utils): vendor semver.nix from poetry2nix --- src/modules/utils/implementation.nix | 2 +- src/modules/utils/poetry2nix/LICENSE | 1821 +++++++++++++++++++++++ src/modules/utils/poetry2nix/semver.nix | 87 ++ treefmt.toml | 1 + 4 files changed, 1910 insertions(+), 1 deletion(-) create mode 100644 src/modules/utils/poetry2nix/LICENSE create mode 100644 src/modules/utils/poetry2nix/semver.nix diff --git a/src/modules/utils/implementation.nix b/src/modules/utils/implementation.nix index ca2e3057..3213ad43 100644 --- a/src/modules/utils/implementation.nix +++ b/src/modules/utils/implementation.nix @@ -20,7 +20,7 @@ writeScriptBin ; - poetry2nixSemver = import "${config.externalSources.poetry2nix}/semver.nix" { + poetry2nixSemver = import ./poetry2nix/semver.nix { inherit (config) lib; # copied from poetry2nix ireplace = idx: value: list: ( diff --git a/src/modules/utils/poetry2nix/LICENSE b/src/modules/utils/poetry2nix/LICENSE new file mode 100644 index 00000000..b91e2ffd --- /dev/null +++ b/src/modules/utils/poetry2nix/LICENSE @@ -0,0 +1,1821 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + poetry2nix/LICENSE at master · nix-community/poetry2nix · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + +
+ +
+ + + + + + + +
+ + + + + + +
+ + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + +
+ + + + + + + +Permalink + +
+ +
+
+ + + master + + + + +
+
+
+ Switch branches/tags + +
+ + + +
+ +
+ +
+ + +
+ +
+ + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+ +
+ +
+ + +
+ +
+
+
+

Name already in use

+
+
+ +
+
+
+
+ +
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? +
+ +
+
+ + +
+
+ + + + Go to file + +
+ + + + +
+
+
+ + + +
+
+
+ +

+ nix-community/poetry2nix + is licensed under the +

+

MIT License

+

A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.

+
+ +
+
+

Permissions

+
    +
  • + + + Commercial use + +
  • +
  • + + + Modification + +
  • +
  • + + + Distribution + +
  • +
  • + + + Private use + +
  • +
+
+
+

Limitations

+
    +
  • + + + Liability + +
  • +
  • + + + Warranty + +
  • +
+
+
+

Conditions

+
    +
  • + + + License and copyright notice + +
  • +
+
+
+
+

+ This is not legal advice. + Learn more about repository licenses. +

+
+ + + + + + + +
+ +
+
+
 
+
+ +
+
 
+ Cannot retrieve contributors at this time +
+
+ + + + + + + + + +
+ +
+ + +
+ + 23 lines (19 sloc) + + 1.13 KB +
+ +
+ + + + +
+ +
+
+
+
+ +
+
+
+
+
+ + + Open in GitHub Desktop +
+
+
+
+
+ + + +
+
+ + + +
+
+ +
+ +
+
+ + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
MIT License
+
Copyright (c) 2019-2022 Adam Hose
Copyright (c) 2019-2022 The poetry2nix contributors
Copyright (c) 2019-2021 Tweag
+
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
+
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+
+ + + +
+ +
+ + + + +
+ + +
+ + +
+
+ + + +
+ +
+ + +
+ +
+ + +
+
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + diff --git a/src/modules/utils/poetry2nix/semver.nix b/src/modules/utils/poetry2nix/semver.nix new file mode 100644 index 00000000..0ef1d4c3 --- /dev/null +++ b/src/modules/utils/poetry2nix/semver.nix @@ -0,0 +1,87 @@ +{ lib, ireplace }: +let + inherit (builtins) elemAt match; + operators = + let + matchWildCard = s: match "([^*])(\\.[*])" s; + mkComparison = ret: version: v: builtins.compareVersions version v == ret; + mkIdxComparison = idx: version: v: + let + ver = builtins.splitVersion v; + minor = builtins.toString (lib.toInt (elemAt ver idx) + 1); + upper = builtins.concatStringsSep "." (ireplace idx minor ver); + in + operators.">=" version v && operators."<" version upper; + dropWildcardPrecision = f: version: constraint: + let + m = matchWildCard constraint; + hasWildcard = m != null; + c = if hasWildcard then (elemAt m 0) else constraint; + v = + if hasWildcard then (builtins.substring 0 (builtins.stringLength c) version) + else version; + in + f v c; + in + { + # Prefix operators + "==" = dropWildcardPrecision (mkComparison 0); + ">" = dropWildcardPrecision (mkComparison 1); + "<" = dropWildcardPrecision (mkComparison (-1)); + "!=" = v: c: ! operators."==" v c; + ">=" = v: c: operators."==" v c || operators.">" v c; + "<=" = v: c: operators."==" v c || operators."<" v c; + # Semver specific operators + "~" = mkIdxComparison 1; + "^" = mkIdxComparison 0; + "~=" = v: c: + let + # Prune constraint + parts = builtins.splitVersion c; + pruned = lib.take ((builtins.length parts) - 1) parts; + upper = builtins.toString ( + (lib.toInt (builtins.elemAt pruned (builtins.length pruned - 1))) + 1 + ); + upperConstraint = builtins.concatStringsSep "." (ireplace (builtins.length pruned - 1) upper pruned); + in + operators.">=" v c && operators."<" v upperConstraint; + # Infix operators + "-" = version: v: operators.">=" version v.vl && operators."<=" version v.vu; + # Arbitrary equality clause, just run simple comparison + "===" = v: c: v == c; + # + }; + re = { + operators = "([=>