-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcreate-python
executable file
·79 lines (69 loc) · 2.04 KB
/
create-python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
import argparse
import logging
from aush import (
cd,
direnv,
django_admin,
echo,
git,
python3,
t,
uv,
)
logging.basicConfig(level=logging.INFO)
# parse args
parser = argparse.ArgumentParser(description="Start a Python project")
parser.add_argument("name", help="The name of the project")
parser.add_argument("-d", "--django", action="store_true", help="Add Django to the project")
parser.add_argument("-n", "--no-dependencies", action='store_true', help="Don't install any dependencies when creating project")
args = parser.parse_args()
# initialize project
uv.init(args.name, author_from="auto")
cd(args.name)
# add default dev dependencies
if not args.no_dependencies:
uv.add('pytest', 'ipython', 'ptpython', 'mypy', 'pudb', dev=True)
# set up direnv
echo("""export PYTHONPATH="$PWD"
export VIRTUAL_ENV=.venv
layout python""") >> '.envrc'
direnv.allow()
# create repo and initial files
git.init()
echo(f"# {args.name}") >> 'README.md'
echo("""[pytest]
python_files = *.py
norecursedirs = bin
""") >> 'pytest.ini'
echo("test:\n\tpytest") > "justfile"
git.add(all=True)
git.commit(m="Initial Python commit")
# create project structure
if args.django:
# add django
uv.add("django")
uv.add("Werkzeug", "django-debug-toolbar", "django-extensions", dev=True)
django_admin.startproject(args.name)
cd(args.name)
django_manage = python3["manage.py"]
django_manage.startapp(f"{args.name}_app")
django_manage.migrate()
django_manage.createsuperuser(
noinput = True,
username = "admin",
email = git.config(get='user.email') or 'admin@localhost',
_env = dict(DJANGO_SUPERUSER_PASSWORD='admin'),
)
git.add(all=True)
git.commit(m="Add Django")
else:
# ├── bin
# ├── proj
# │ └── __init__.py
# └── tests
# └── __init__.py
files = [f'{args.name}/__init__.py', 'tests/__init__.py']
t(*files, 'bin/')
git.add(*files, force=True)
git.commit(m="Create Python project structure")