Skip to content

Commit

Permalink
dev: upgrade flake.nix to self-contain without .venv
Browse files Browse the repository at this point in the history
  • Loading branch information
onjin committed Oct 4, 2024
1 parent 193bd67 commit 83f43fe
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 39 deletions.
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ local development.

7. Submit a pull request through the GitHub website.


# Nix
If you're using [nix](https://nix.dev/) package manager you can use included `flake.nix` by :

```console
$ nix develop
```

# Pull Request Guidelines

Before you submit a pull request, check that it meets these guidelines:
Expand Down
127 changes: 126 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 85 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,94 @@
{
description = "Python dev shell flake";
description = "Wrapper to run programs with different env";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
pyproject-nix.url = "github:nix-community/pyproject.nix";
pyproject-nix.inputs.nixpkgs.follows = "nixpkgs";
};

outputs = { nixpkgs, flake-utils, ... }:
outputs = { self, nixpkgs, flake-utils, pyproject-nix, }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in { devShells = { default = import ./shell.nix { inherit pkgs; }; }; });
let
pkgs = nixpkgs.legacyPackages.${system};
pypkgs = pkgs.python3Packages;
python = pkgs.python3.override {
packageOverrides = self: super: {
runenv = runenv;
hatch = pkgs.hatch;
ruff = pkgs.ruff;
mypy = pkgs.mypy;
black = pkgs.black;
};
};
project =
pyproject-nix.lib.project.loadPyproject { projectRoot = ./.; };

runenv = python.pkgs.buildPythonPackage rec {
pname = "runenv";
version = "1.2.2";

src = python.pkgs.fetchPypi {
inherit pname version;
sha256 = "";
};

doCheck = false;
checkInputs = [ ];
propagatedBuildInputs = [ pypkgs.feedparser ];

meta = with pkgs.lib; {
homepage = "https://github.com/onjin/runenv";
description = "Wrapper to run programs with different env";
license = licenses.mit;
};
};

in {
packages = {
runenv = let
# Returns an attribute set that can be passed to `buildPythonPackage`.
attrs = project.renderers.buildPythonPackage {
inherit python;
extras = [ ];
};
# Pass attributes to buildPythonPackage.
# Here is a good spot to add on any missing or custom attributes.
in python.pkgs.buildPythonPackage (attrs // {
# Because we're following main, use the git rev as version
version =
if (self ? rev) then self.shortRev else self.dirtyShortRev;
});
default = self.packages.${system}.runenv;
};
devShells = {
default = let
# Returns a function that can be passed to `python.withPackages`
arg = project.renderers.withPackages {
inherit python;
extras = [ "develop" ];
};

# Returns a wrapped environment (virtualenv like) with all our packages
pythonEnv = python.withPackages arg;

# Create a devShell like normal.
in pkgs.mkShell {
packages = [
self.packages.${system}.runenv
pythonEnv
pkgs.gnumake
pkgs.hatch
pkgs.ruff
pkgs.mypy
pkgs.black
pypkgs.keyrings-alt
];
shellHook = ''
export PYTHONPATH="$(pwd):$PYTHONPATH"
'';
};
};
});
}
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ Documentation = "https://github.com/onjin/runenv#readme"
Issues = "https://github.com/onjin/runenv/issues"
Source = "https://github.com/onjin/runenv"

[project.optional-dependencies]
develop = [
"hatch",
"black",
"ruff",
"mypy",
]

[tool.hatch.version]
path = "runenv/__about__.py"

Expand Down
34 changes: 0 additions & 34 deletions shell.nix

This file was deleted.

0 comments on commit 83f43fe

Please sign in to comment.