Skip to content

Instantly share code, notes, and snippets.

@kalbasit
Last active July 21, 2019 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kalbasit/fcba95f1fe574e2633fd03507c461dd7 to your computer and use it in GitHub Desktop.
Save kalbasit/fcba95f1fe574e2633fd03507c461dd7 to your computer and use it in GitHub Desktop.
{ lib, pythonPackages }:
with lib;
let
pkgs = {
area = { version = "1.1.1"; };
dask = { version = "1.2.2"; };
geojson = { version = "2.4.1"; };
geopy = { version = "1.19.0"; };
h3 = { version = "3.4.2"; };
pandas = { version = "0.24.2"; };
psycopg2 = { version = "2.7.6.1"; };
pyarrow = { version = "0.12.0"; };
pytz = { version = "2018.9"; };
pyyaml = { version = "5.1"; };
s3fs = { version = "0.2.2"; };
scikitlearn = { version = "0.20.3"; };
simple-salesforce = { version = "0.74.2"; };
snowflake-sqlalchemy = { version = "1.1.4"; };
sqlalchemy = { version = "1.3.3"; };
timezonefinder = { version = "4.0.2"; };
};
/* Get the version of a package
Example:
getPackageVersion python37Packages area
=> "1.1.1"
*/
getPackageVersion = pythonPackages: pythonPackage: (builtins.parseDrvName pythonPackages."${pythonPackage}".name).version;
/* Validate package versions
Example:
validatePackageVersion python37Packages "area" { version = "1.1.1"; }
=> true
*/
validatePackageVersion = pythonPackages: pythonPackage: pkgDef: (getPackageVersion pythonPackages pythonPackage) == pkgDef.version;
/* Filter the valid packages out of the set
Example:
filterValidPackages python37Packages { area = { version = "1.1.1"; }; geopy = { version = "1.19.0"; }; }
=> { geopy = { version = "1.19.0"; }; }
*/
filterValidPackages = pythonPackages: pkgs: filterAttrs (pythonPackage: pkgDef: !validatePackageVersion pythonPackages pythonPackage pkgDef) pkgs;
/* Generate error messages for every package in a set, and include the want/got versions
Example:
getErrorPackageVersions { geopy = { version = "1.19.0"; }; }
=> [ "Expected geopy at 1.19.0 got 1.20.0" ]
*/
getErrorPackageVersions = invalidPackages: mapAttrsToList (pythonPackage: pkgDef: "Expected ${pythonPackage} at ${pkgDef.version} got ${getPackageVersion pythonPackages pythonPackage}") invalidPackages;
invalidPackages = filterValidPackages pythonPackages pkgs;
in
if invalidPackages == {} then (builtins.attrNames pkgs)
else throw (builtins.concatStringsSep "\n" (["Some packages did not match the expect version:"] ++ (getErrorPackageVersions invalidPackages)))
@kalbasit
Copy link
Author

kalbasit commented Jul 21, 2019

 λ  nix-shell -E '(with import ./lib/nix/nixpkgs.nix {}; (python3.withPackages(ps: import ./src/requirements.nix { inherit lib; pythonPackages = python37Packages; })))'
error: Some packages did not match the expect version:
Expected geopy at 1.19.0 got 1.20.0
Expected h3 at 3.4.2 got 3.4.3
Expected psycopg2 at 2.7.6.1 got 2.7.7
Expected pyarrow at 0.12.0 got 0.13.0
Expected pytz at 2018.9 got 2019.1
Expected scikitlearn at 0.20.3 got 0.21.2
Expected simple-salesforce at 0.74.2 got 0.74.3
Expected snowflake-sqlalchemy at 1.1.4 got 1.1.13
Expected sqlalchemy at 1.3.3 got 1.3.5
Expected timezonefinder at 4.0.2 got 4.1.0
(use '--show-trace' to show detailed location information)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment