Last active
August 2, 2023 05:53
-
-
Save goromal/e64b6bdc8a176c38092e9bde4c434d31 to your computer and use it in GitHub Desktop.
Generate a nix-shell file for Python development.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
def main(): | |
argparser = argparse.ArgumentParser( | |
description = "Generate a nix-shell file (shell.nix) for Python 3.9 development.", | |
formatter_class=argparse.ArgumentDefaultsHelpFormatter | |
) | |
argparser.add_argument("--nix-path", type=str, default="nixpkgs", help="Nix source path.") | |
argparser.add_argument("--modules", nargs="+", default=[], help="Python modules for development.") | |
args = argparser.parse_args() | |
with open("shell.nix", "w") as shellfile: | |
shellfile.write(""" | |
{{ pkgs ? import <{0}> {{}} }}: | |
let | |
py = pkgs.python39.withPackages (p: with p; [ | |
{1} | |
]); | |
in py.env | |
""".format(args.nix_path, "\n ".join(args.modules))) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment