Skip to content

Commit

Permalink
Add Nix Dev Environment Support
Browse files Browse the repository at this point in the history
Resolves #20
  • Loading branch information
jteppinette authored Jan 23, 2025
1 parent 52ec578 commit 2671307
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 32 deletions.
7 changes: 6 additions & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
layout pyenv $(cat runtimes.txt)
if command -v pyenv >/dev/null 2>&1; then
layout pyenv $(cat runtimes.txt)
elif command -v nix >/dev/null 2>&1; then
use flake
layout python python3.12
fi
8 changes: 6 additions & 2 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/action@v2.0.0
- uses: DeterminateSystems/nix-installer-action@v3
- uses: DeterminateSystems/magic-nix-cache-action@main
- uses: HatsuneMiku3939/direnv-action@v1
- run: |
pip install -r requirements/pre-commit.txt
pre-commit run -a
13 changes: 4 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@ on:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
name: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- uses: DeterminateSystems/nix-installer-action@v3
- uses: DeterminateSystems/magic-nix-cache-action@main
- uses: HatsuneMiku3939/direnv-action@v1
- run: |
pip install -r requirements/test.txt
pip install -e .
pytest
tox
28 changes: 17 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,28 @@ repos:
- id: sort-simple-yaml # Sorts simple YAML files which consist only of top-level keys, preserving comments and blocks.
- id: trailing-whitespace # This hook trims trailing whitespace.

- repo: https://github.com/psf/black
rev: 22.10.0
- repo: local
hooks:
- id: black
name: black
language: system
entry: black --check
types: [python]

- repo: https://github.com/timothycrosley/isort
rev: 5.12.0
hooks:
- id: isort
name: isort
language: system
entry: isort --check
types: [python]

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
name: flake8
language: system
entry: flake8
types: [python]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
hooks:
- id: mypy
name: mypy
language: system
entry: mypy --ignore-missing-imports
types: [python]
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ This will cause all logs to have the `trace_id=123` pair regardless of including

### Required Software

Refer to the links provided below to install these development dependencies:
If you are using [nix](https://zero-to-nix.com/start/install/) & [direnv](https://direnv.net/docs/installation.html), then your dev environment will be managed automatically. Otherwise, you will need to manually install the following software:

- [direnv](https://direnv.net)
- [git](https://git-scm.com/)
Expand All @@ -244,8 +244,9 @@ Refer to the links provided below to install these development dependencies:

**Setup**

> If you are using pyenv, you will need to install the correct versions of python using `<runtimes.txt xargs -n 1 pyenv install -s`.
```sh
$ <runtimes.txt xargs -n 1 pyenv install -s
$ direnv allow
$ pip install -r requirements/dev.txt
$ pre-commit install
Expand Down
61 changes: 61 additions & 0 deletions flake.lock

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

26 changes: 26 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
flake-utils.url = "github:numtide/flake-utils";
};

outputs =
{ nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShells.default = pkgs.mkShell {
packages = [
pkgs.python39
pkgs.python310
pkgs.python311
pkgs.python312
];
shellHook = "unset PYTHONPATH";
};
}
);
}
8 changes: 2 additions & 6 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
-r ./pre-commit.txt
-r ./publish.txt
-r ./setuptools.txt
-r ./test.txt
black==22.10.0
flake8==5.0.4
isort==5.10.1
mypy==0.991
pre-commit==2.20.0
pytest-watch==4.2.0
tox==3.27.1
5 changes: 5 additions & 0 deletions requirements/pre-commit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
black==22.10.0
flake8==5.0.4
isort==5.10.1
mypy==0.991
pre-commit==2.20.0
1 change: 1 addition & 0 deletions requirements/publish.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
-r ./setuptools.txt
build==0.7.0
twine==3.8.0
1 change: 1 addition & 0 deletions requirements/setuptools.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
setuptools==75.8.0
2 changes: 2 additions & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
-r ./setuptools.txt
pytest==7.2.0
tox==3.27.1
2 changes: 1 addition & 1 deletion runtimes.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9.10 3.10.1 3.11.9 3.12.3
3.9 3.10 3.11 3.12

0 comments on commit 2671307

Please sign in to comment.