From e02319ff244e51a17c92df65b7dc7f05c6f90e91 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Tue, 7 Feb 2023 13:46:57 -0500 Subject: [PATCH] Implement in Python --- .gitignore | 3 +++ flake.nix | 4 ++-- python/.envrc | 3 +++ python/bin/soe | 4 ++++ python/default.nix | 11 +++++++++++ python/setup.py | 7 +++++++ python/shell.nix | 2 ++ python/soe/__init__.py | 1 + python/soe/main.py | 26 ++++++++++++++++++++++++++ 9 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 python/.envrc create mode 100644 python/bin/soe create mode 100644 python/default.nix create mode 100644 python/setup.py create mode 100644 python/shell.nix create mode 100644 python/soe/__init__.py create mode 100644 python/soe/main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d4575f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ + +result* +.direnv diff --git a/flake.nix b/flake.nix index 1d96fbe..cf65e5a 100644 --- a/flake.nix +++ b/flake.nix @@ -15,6 +15,6 @@ dirs = pkgs.lib.filterAttrs (_: v: v == "directory") currentDir; in { packages = builtins.mapAttrs (dir: _: pkgs.callPackage ./${dir} {}) dirs; - } - ); + devShells = builtins.mapAttrs (dir: _: pkgs.callPackage ./${dir}/shell.nix {}) dirs; + }); } diff --git a/python/.envrc b/python/.envrc new file mode 100644 index 0000000..e4c941b --- /dev/null +++ b/python/.envrc @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +use flake ..#python diff --git a/python/bin/soe b/python/bin/soe new file mode 100644 index 0000000..9ef8dcc --- /dev/null +++ b/python/bin/soe @@ -0,0 +1,4 @@ +#!/usr/bin/env python + +import soe +soe.main() diff --git a/python/default.nix b/python/default.nix new file mode 100644 index 0000000..daa861d --- /dev/null +++ b/python/default.nix @@ -0,0 +1,11 @@ +{ python3, ... }: + +python3.pkgs.buildPythonApplication { + pname = "soe-python"; + version = "1.0"; + src = ./.; + + doCheck = false; + + meta.mainProgram = "soe"; +} diff --git a/python/setup.py b/python/setup.py new file mode 100644 index 0000000..158092b --- /dev/null +++ b/python/setup.py @@ -0,0 +1,7 @@ +from setuptools import setup + +setup( + name="soe", + version="1.0.0", + scripts=["bin/soe"] +) diff --git a/python/shell.nix b/python/shell.nix new file mode 100644 index 0000000..5feafb5 --- /dev/null +++ b/python/shell.nix @@ -0,0 +1,2 @@ +{ python3, ... }: +python3.buildEnv.env diff --git a/python/soe/__init__.py b/python/soe/__init__.py new file mode 100644 index 0000000..15b6a64 --- /dev/null +++ b/python/soe/__init__.py @@ -0,0 +1 @@ +from .main import * diff --git a/python/soe/main.py b/python/soe/main.py new file mode 100644 index 0000000..23f1cf2 --- /dev/null +++ b/python/soe/main.py @@ -0,0 +1,26 @@ + + +def sieve_of_eratosthenes(n): + nums = list(range(2, n)) + while nums: + prime = nums[0] + nums = [i for i in nums if i % prime] + yield prime + +def main(): + num = 0 + another = True + while another: + try: + num = int(input()) + another = False + except ValueError: + pass + + print() + for i in sieve_of_eratosthenes(num): + print(i) + + +if __name__ == "__main__": + main()