Skip to content

Commit

Permalink
Refactor how version is set
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokokada committed Nov 1, 2023
1 parent 054d639 commit 468f583
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
let
inherit (pkgs) lib;
dirty = lib.optionalString (!(self ? rev)) "_dirty";
rev = "0.1.0+git${self.lastModifiedDate}${dirty}";
version = "0.1.0+git${self.lastModifiedDate}${dirty}";
in
{
nix-alien = pkgs.callPackage ./nix-alien.nix {
inherit rev;
inherit version;
inherit (self.inputs) nix-filter;
python3 = pkgs.python310;
nix-index = self.inputs.nix-index-database.packages.${pkgs.system}.nix-index-with-db;
Expand Down
12 changes: 4 additions & 8 deletions nix-alien.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@
narHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
}
, python3
, rev ? null
, dev ? false
, version
}:

let
version = if (rev != null) then rev else "dev";
deps = (lib.importTOML ./pyproject.toml).project.dependencies;
in
python3.pkgs.buildPythonApplication {
inherit version;
pname = "nix-alien";
format = "pyproject";
inherit version;

src = nix-filter.lib {
root = ./.;
Expand All @@ -39,16 +37,14 @@ python3.pkgs.buildPythonApplication {
setuptools
] ++ (lib.attrVals deps python3.pkgs);

preBuild = lib.optionalString (rev != null) ''
echo "__version__ = \"${rev}\"" > nix_alien/_version.py
preBuild = ''
echo "__version__ = \"${version}\"" > nix_alien/_version.py
substituteInPlace {nix_alien,tests}/*.{py,nix} \
--subst-var-by nixpkgsLastModifiedDate ${nixpkgs-src.lastModifiedDate} \
--subst-var-by nixpkgsRev ${nixpkgs-src.rev} \
--subst-var-by nixpkgsHash ${nixpkgs-src.narHash}
'';

doCheck = !dev;

nativeCheckInputs = with python3.pkgs; [
pytestCheckHook
];
Expand Down
4 changes: 3 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
}:

let
nix-alien = self.outputs.packages.${pkgs.system}.nix-alien.override { dev = true; };
nix-alien = self.outputs.packages.${pkgs.system}.nix-alien.overrideAttrs (
oldAttrs: { doCheck = false; }
);
python-with-packages = pkgs.python3.withPackages (ps: with ps; [
black
mypy
Expand Down

0 comments on commit 468f583

Please sign in to comment.