Skip to content

Commit 02b9ec9

Browse files
INITIAL COMMIT
0 parents  commit 02b9ec9

File tree

13 files changed

+345
-0
lines changed

13 files changed

+345
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "pip"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"

.gitignore

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
105+
__pypackages__/
106+
107+
# Celery stuff
108+
celerybeat-schedule
109+
celerybeat.pid
110+
111+
# SageMath parsed files
112+
*.sage.py
113+
114+
# Environments
115+
.env
116+
.venv
117+
env/
118+
venv/
119+
ENV/
120+
env.bak/
121+
venv.bak/
122+
123+
# Spyder project settings
124+
.spyderproject
125+
.spyproject
126+
127+
# Rope project settings
128+
.ropeproject
129+
130+
# mkdocs documentation
131+
/site
132+
133+
# mypy
134+
.mypy_cache/
135+
.dmypy.json
136+
dmypy.json
137+
138+
# Pyre type checker
139+
.pyre/
140+
141+
# pytype static type analyzer
142+
.pytype/
143+
144+
# Cython debug symbols
145+
cython_debug/
146+
147+
# PyCharm
148+
# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
149+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
150+
# and can be added to the global gitignore or merged into this file. For a more nuclear
151+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
152+
#.idea/

LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2+
Version 2, December 2004
3+
4+
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
5+
6+
Everyone is permitted to copy and distribute verbatim or modified
7+
copies of this license document, and changing it is allowed as long
8+
as the name is changed.
9+
10+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12+
13+
0. You just DO WHAT THE FUCK YOU WANT TO.

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# wsl2-python-webdev
2+
3+
This is a template for a Python web development environment in WSL2. It includes:
4+
5+
* pip - Python package manager
6+
* virtualenv - Python virtual environment manager
7+
* pipx - Python package manager for command line tools
8+
* poetry - Python package manager and virtual environment manager
9+
* mypy - Python static type checker
10+
* micro - A modern and intuitive terminal-based text editor
11+
* gh-cli (GitHub CLI) - https://cli.github.com/
12+
13+
No other tools or modules are installed. You can add them as you need them.
14+
15+
## Usage
16+
17+
Just run `./bootstrap.sh`, preferably in a clean Ubuntu container, and you're good to go. It will install the tools listed above and add them to your path. `gh` will require you to authenticate with GitHub. To do that, run `gh auth login` and follow the instructions.
18+
19+
For the sake of convenience, the script will also setup `gh` completion for `bash`. If you use another shell, you'll have to do that yourself.
20+
21+
## Why?
22+
23+
I wanted to have a Python web development environment in WSL2 that was as close to a "clean" environment as possible. I didn't want to install a bunch of tools and modules that I might not need. I also wanted to be able to use the same environment on my Windows machine and my Linux machine. This template is the result of that.
24+
25+
### Why not just use a Docker container?
26+
27+
Because I don't want to have to run a Docker container every time I want to run a Python script. I want to be able to run Python scripts directly from the command line.
28+
29+
### Why not just use a virtual environment?
30+
31+
Because I don't want to have to activate a virtual environment every time I want to run a Python script. I want to be able to run Python scripts directly from the command line. I've told you that just above.
32+
33+
### Why pyinfra and not Ansible?
34+
35+
Because I wanted to try pyinfra. I've used Ansible before and I like it, but I wanted to try something new. pyinfra is a lot simpler than Ansible and it's written in Python, so it's easier to understand than the mess that Ansible's YAML files are.

SECURITY.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Security Policy
2+
3+
## Supported Tags
4+
5+
| Tag |
6+
| ------- |
7+
| latest |
8+
9+
## Reporting a Vulnerability
10+
11+
To report a vulnerability, please open an Issue in our issue tracker here on GitHub.

bootstrap.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
printf "Installing python-venv and making python3 the default major version on this system:\n"
4+
5+
sudo apt update
6+
sudo apt upgrade -y
7+
sudo apt autoremove -y
8+
sudo apt install python3-venv python-is-python3 -y
9+
10+
printf "Installing pip module for the current user...\n"
11+
12+
wget https://bootstrap.pypa.io/get-pip.py -O get-pip.py
13+
python ./get-pip.py
14+
15+
printf "Installing pipx for the current user...\n"
16+
17+
python3 -m pip install --user pipx
18+
python3 -m pipx ensurepath
19+
echo 'eval "$(register-python-argcomplete pipx)"' >> ~/.profile
20+
source ~/.profile
21+
22+
printf "Installing pyinfra for the current user...\n"
23+
24+
python3 -m pipx install pyinfra
25+
26+
printf "Starting deployment..."
27+
28+
pyinfra inventory.py deploy.py --use-sudo-password

deploy.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from pyinfra import local
2+
3+
# Install system packages
4+
5+
local.include('tasks/system_packages.py')
6+
7+
# Install python modules
8+
9+
local.include('tasks/python_modules.py')
10+
11+
# Setup oh-my-posh
12+
13+
local.include('tasks/shell_configuration.py')
14+
15+
# Setup gh cli
16+
17+
local.include('tasks/github_cli.py')

inventory.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
Defines a list of hosts on which we should deploy.
3+
"""
4+
5+
targets = ["@local"] # This configuration should only be applied to the current host

tasks/github_cli.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from typing import List
2+
from pyinfra.operations import server, apt
3+
4+
github_cli_repo_config: List[str] = [
5+
"curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg",
6+
"sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg",
7+
'echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null'
8+
]
9+
10+
server.shell(
11+
name="Setup gh cli repositories",
12+
commands=github_cli_repo_config,
13+
_sudo=True,
14+
)
15+
16+
apt.packages(
17+
name="Ensure that gh cli is installed",
18+
packages=["gh"],
19+
_sudo=True,
20+
)
21+
22+
server.shell(
23+
name="Setup gh completion",
24+
commands=["gh completion -s bash | sudo tee /etc/bash_completion.d/gh > /dev/null"],
25+
_sudo=True
26+
)

0 commit comments

Comments
 (0)