Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add flakes support and convert to poetry #24

Merged
merged 1 commit into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
use nix
use flake
30 changes: 25 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,29 @@ on:
pull_request:
push:
jobs:
tests:
runs-on: ubuntu-latest

simple-build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v13
- run: nix-build -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixpkgs-unstable.tar.gz
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v16
with:
nix_path: nixpkgs=channel:nixos-unstable
- run: nix-build

flakes:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v16
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- run: nix build
- run: nix flake check
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
__pycache__/
__pycache__
secrets.py
runs
.ipynb_*
*.csv
.direnv
*.pyc
/.mypy_cache/
/*.egg-info/
/.direnv/
result
/**/result*
35 changes: 11 additions & 24 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
{ pkgs ? import <nixpkgs> {} }:

with pkgs.python3.pkgs;
buildPythonPackage {
name = "hydra-check";
src = ./.;
propagatedBuildInputs = [
docopt
requests
beautifulsoup4
];
postUnpack = ''
echo -e "\x1b[32m## build on ${pkgs.lib.version} \x1b[0m"
'';
checkInputs = [ black mypy jq flake8 ];
checkPhase = ''
echo -e "\x1b[32m## run black\x1b[0m"
LC_ALL=en_US.utf-8 black --check .
echo -e "\x1b[32m## run flake8\x1b[0m"
flake8 hydracheck
echo -e "\x1b[32m## run mypy\x1b[0m"
mypy hydracheck
'';
}
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url =
"https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }).defaultNix
84 changes: 84 additions & 0 deletions flake.lock

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

74 changes: 74 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
description = "Python application managed with poetry2nix";

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

outputs = { self, nixpkgs, flake-utils, poetry2nix, flake-compat }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ poetry2nix.overlay ];
};
python = pkgs.python310;
packageName = "hydra-check";
packageVersion = "1.2.0";
in
{
packages = rec {
hydra-check = python.pkgs.buildPythonApplication rec {
pname = packageName;
version = packageVersion;
format = "pyproject";
nativeBuildInputs = with python.pkgs; [ poetry-core ];
propagatedBuildInputs = with python.pkgs; [ requests beautifulsoup4 docopt ];
src = ./.;
checkInputs = with pkgs; [ mypy ];
checkPhase = ''
export MYPYPATH=$PWD/src
mypy src/hydra_check
'';
};
default = hydra-check;
};

devShells = {
default = pkgs.mkShell {
buildInputs = with pkgs; [
pyright
mypy
(pkgs.poetry.override { python = python; })
(pkgs.poetry2nix.mkPoetryEnv {
inherit python;
projectDir = ./.;
overrides = pkgs.poetry2nix.overrides.withDefaults (self: super: { });
editablePackageSources = {
hydra-check = ./src;
};
extraPackages = (ps: with ps; [
]);
})
] ++ (with python.pkgs; [
black
pylint
]);
shellHook = ''
export MYPYPATH=$PWD/src
'';
};
};

});
}
Loading