Created: 2021-05-29 Sat 06:49
Readme.{md,org}
LICENSE
.gitignore
$ git init # Inside project $ gibo macOS Windows Xcode Emacs \ Vim Python C++ \ CMake TeX > .gitignore $ touch readme.md $ license-generator MIT \ --author "Person" $ tree -L 2 . ├── LICENSE ├── docs │ └── pres └── readme.org 2 directories, 2 files
hypothesis
)pytest
)
$ tree -L 1 . ├── AUTHORS.rst ├── CODEOWNERS ├── CONTRIBUTING.rst ├── HISTORY.rst ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.rst ├── docs ├── poetry.lock ├── pyproject.toml ├── tests ├── wailord └── wailord_templates 5 directories, 15 files
.py
file is a modulefrom collections import namedtuple point_xy = namedtuple('point_xy', ('x', 'y'))
__init__.py
in it is a packagepip
"""Top-level package for Wailord.""" __author__ = """Rohit Goswami""" __email__ = "rog32@hi.is" __version__ = "0.0.2"
Standard
setuptools
with setup.py
.tar.gz
Binary
wheel
requirements.txt
(pip)pyproject.toml
poetry.lock
Pipfile
+ lockfilepip
but for applications)
docker
, flatpak
, snapcraft
Python
poetry
, pipenv
, pyenv
C++
conan
, vcpkg
, cpm
(Dolstra, Jonge, and Visser, n.d.; Dolstra, Löh, and Pierron, n.d.)
Protects against self harm
Exposes things taken for granted
Enforces consistency
sh <(curl https://nixos.org/nix/install) --daemon
sudo
but should not be run as rootnix-shell -p 'python38.withPackages(ps: with ps; [ numpy toolz ])'
python
is loaded-p
multiple times is allowed#! /usr/bin/env nix-shell #! nix-shell -i python3 -p "python3.withPackages(ps: [ps.numpy])" import numpy print(numpy.__version__)
chmod +x nixnp.sh
./nixnp.sh
#!/usr/bin/env nix-shell #!nix-shell -i python3 -p "python38.withPackages(ps: [ ps.sh ])" -p lieer from pathlib import Path import sh # For generic IMAP maildirs ISYNC_LABELS = ["rog32"] for isync in ISYNC_LABELS: sh.mbsync("-V",isync,_bg=True) # Gmaileer GMAIL_IDENTIFIERS = ["gmail", "ieee"] path = Path(r"/mail/") for dirs in path.iterdir(): if dirs.is_dir(): for gmi in GMAIL_IDENTIFIERS: if gmi in dirs.name: print(f"Syncing {dirs.name}") sh.gmi("sync", _cwd=dirs, _fg=True)
nix-shell -p python36 --pure
Figure 13: Stateless builds from https://slides.com/garbas/mozilla-all-hands-london-2016#/7/0/3
with import <nixpkgs> {}; let pythonEnv = python35.withPackages (ps: [ ps.numpy ps.toolz ]); in mkShell { buildInputs = [ pythonEnv which ];}
f90wrap = self.buildPythonPackage rec { pname = "f90wrap"; version = "0.2.3"; src = pkgs.fetchFromGitHub { owner = "jameskermode"; repo = "f90wrap"; rev = "master"; sha256 = "0d06nal4xzg8vv6sjdbmg2n88a8h8df5ajam72445mhzk08yin23"; }; buildInputs = with pkgs; [ gfortran stdenv ];
propagatedBuildInputs = with self; [ setuptools setuptools-git wheel numpy ]; preConfigure = '' export F90=${pkgs.gfortran}/bin/gfortran ''; doCheck = false; doInstallCheck = false; };
propagatedBuildInputs
are for the python packagesnix-env -i nox nox lieer
niv init
{ "nixpkgs": { "branch": "release-20.03", "description": "Nix Packages collection", "homepage": "", "owner": "NixOS", "repo": "nixpkgs", "rev": "1db42b7fe3878f3f5f7a4f2dc210772fd080e205", "sha256": "05k9y9ki6jhaqdhycnidnk5zrdzsdammbk5lsmsbz249hjhhgcgh", "type": "tarball", "url": "https://github.com/NixOS/nixpkgs/archive/.tar.gz", "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" } }
let sources = import ./nix/sources.nix; pkgs = import sources.nixpkgs { }; mach-nix = import (builtins.fetchGit { url = "https://github.com/DavHau/mach-nix/"; ref = "refs/tags/3.3.0"; }) { # optionally bring your own nixpkgs pkgs = pkgs; # optionally specify the python version python = "python38"; };
mach-nix
niv
pinned sourcescustomPython = mach-nix.mkPython { requirements = builtins.readFile ./requirements.txt; providers = { _default = "nixpkgs,wheel,sdist"; pytest = "nixpkgs"; }; pkgs = pkgs; }; in pkgs.mkShell { buildInputs = with pkgs; [ customPython ]; }
overrides_pre = [ (pythonSelf: pythonSuper: { pytest = pythonSuper.pytest.overrideAttrs (oldAttrs: { doCheck = false; }); f90wrap = pythonSelf.buildPythonPackage rec {...}; }) ];
Python
has great testing frameworks
pytest
, hypothesis
, etc.[tool.poetry.dev-dependencies] check-manifest = "*" pytest = "^4.6" pytest-datadir = "^1.3.1"
@pytest.fixture(scope="session") def mult_xyz(tmpdir_factory): """Copies folders and fixes input file paths""" dat = tmpdir_factory.mktemp("data") shutil.copytree(DATADIR, dat, dirs_exist_ok=True) with open(f"{dat}/orcaMultxyz.yml") as mxyz: t = yaml.full_load(mxyz) t["xyz"] = f"{dat}/{t['xyz']}" fn = Path(dat / "omult.yml") fn.write_text(yaml.dump(t)) return fn
. tree -L 2 . ├── basejob.sh ├── expmult.yml ├── orcaMultxyz.yml └── xyzdat ├── ch3.xyz ├── ch3oh_dimer.xyz ├── ch3oh_single.xyz └── h2inp.xyz 1 directory, 7 files
nixpkgs
can take over a day!docker
or nix
based systems
nix
name: Test theme on: push: branches: [src] pull_request: branches: [src] # every day https://crontab.guru/ schedule: - cron: "0 0 * * *" jobs: deploy: runs-on: ubuntu-latest
steps: - uses: actions/checkout@v2 - uses: cachix/install-nix-action@v12 with: nix_path: nixpkgs=channel:nixos-unstable - name: Get and initialize binary cache run: | nix-env -iA cachix -f \ https://cachix.org/api/v1/install cachix use hello-friend-ng-hz - name: Test Build run: nix-shell --run \ "hugo -s exampleSite --themesDir=../.." - name: Cache Nix Results env: authToken: ${{ secrets.CACHIX_AUTH_TOKEN }} cachixName: hello-friend-ng-hz run: | cachix authtoken $authToken nix-store -qR \ --include-outputs $(nix-instantiate shell.nix) \ | cachix push $cachixName
socat
madnessniv
nix
pretty often
nixpkgs
Dolstra, Eelco, Merijn de Jonge, and Eelco Visser. n.d. “Nix: A Safe and Policy-Free System for Software Deployment,” 15.
Dolstra, Eelco, Andres Löh, and Nicolas Pierron. n.d. “NixOS: A Purely Functional Linux Distribution” 20 (5-6):577–615.
Goswami, Rohit, Amrita Goswami, and Jayant K. Singh. n.d. “D-SEAMS: Deferred Structural Elucidation Analysis for Molecular Simulations” 60 (4):2169–77.