Skip to content

Commit

Permalink
hello webapp
Browse files Browse the repository at this point in the history
  • Loading branch information
jab committed Feb 4, 2024
0 parents commit ff53c89
Show file tree
Hide file tree
Showing 10 changed files with 615 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if ! has nix_direnv_version || ! nix_direnv_version 2.4.0; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.4.0/direnvrc" "sha256-XQzUAvL6pysIJnRJyR7uVpmUSZfc7LSgWQwq/4mBr1U="
fi
use flake
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
*.pyc
*.so
__pycache__
.DS_Store
.benchmarks
.cache
.coverage*
.direnv
.eggs
.hypothesis
.idea
.mypy_cache
.tox
.venv
*.egg-info
build
_build
coverage.xml
dist
htmlcov
pip-wheel-metadata
image
376 changes: 376 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from datetime import datetime


def app(environ, start_response):
start_response("200 OK", [])
return [str(datetime.now().replace(microsecond=0)).encode()]


def main():
from wsgiref.simple_server import make_server

with make_server("0.0.0.0", 8000, app) as httpd:
print("Serving on port 8000...")
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("Bye")
127 changes: 127 additions & 0 deletions flake.lock

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

53 changes: 53 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
description = "hello";

# Flake inputs
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
mach-nix.url = "github:davhau/mach-nix";
};

# Flake outputs
outputs = { self, nixpkgs, mach-nix, flake-utils, ... }:
let
pythonVersion = "python39";
in
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
mach = mach-nix.lib.${system};

pythonApp = mach.buildPythonApplication ./.;
pythonAppEnv = mach.mkPython {
python = pythonVersion;
requirements = builtins.readFile ./requirements.txt;
};
pythonAppImage = pkgs.dockerTools.buildLayeredImage {
name = pythonApp.pname;
contents = [ pythonApp ];
config.Cmd = [ "${pythonApp}/bin/main" ];
};
in
rec
{
packages = {
image = pythonAppImage;
pythonPkg = pythonApp;
default = packages.pythonPkg;
};

apps.default = {
type = "app";
program = "${packages.pythonPkg}/bin/main";
};

devShells.default = pkgs.mkShellNoCC {
packages = [ pythonAppEnv ];
shellHook = ''
export PYTHONPATH="${pythonAppEnv}/bin/python"
'';
};
}
);
}
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

11 changes: 11 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[metadata]
name = hello-webapp
version = 0.1

[options]
packages = find:
install_requires =

[options.entry_points]
console_scripts =
main = app:main
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from setuptools import setup

setup()

0 comments on commit ff53c89

Please sign in to comment.