Skip to content

Commit 0bd4b5f

Browse files
committed
Initial commit
0 parents  commit 0bd4b5f

File tree

224 files changed

+48636
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

224 files changed

+48636
-0
lines changed

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
extend-ignore = E203
3+
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist
4+
max-complexity = 10

.githooks/pre-commit

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
#current_branch=$(git symbolic-ref --short head)
4+
current_branch=$(git rev-parse --abbrev-ref HEAD)
5+
echo "Running pre-commit hook on branch: $current_branch"
6+
if [[ "$current_branch" == "main" ]]; then
7+
echo "Commit on main is not allowed. Please use a feature branch."
8+
exit 1
9+
fi
10+
11+
valid_branch_regex="^(lab|project|assignment|homework|issue|dev|feature|bugfix|improvement|library|prerelease|release|hotfix)\/.+$"
12+
13+
message="ERROR on Commit. Branch name must adhere to this contract: $valid_branch_regex. Rename your branch to a valid name and try again."
14+
15+
if [[ ! $current_branch =~ $valid_branch_regex ]]
16+
then
17+
echo "$message"
18+
echo "git branch -m <branch/sub-branch>"
19+
exit 1
20+
fi
21+
22+
exit 0

.githooks/pre-push

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
#current_branch=$(git symbolic-ref --short head)
4+
current_branch=$(git rev-parse --abbrev-ref HEAD)
5+
if [[ $current_branch != "main" ]]; then
6+
exit 0
7+
fi
8+
echo "Running pre-push hook on $current_branch branch"
9+
make all
10+
# $? stores exit value of the last command
11+
if [[ $? != 0 ]]; then
12+
echo "Tests must pass before push to main!"
13+
exit 1
14+
fi
15+
16+
exit 0

.github/workflows/ci-test.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: GitHub Actions CI/CD
5+
6+
on:
7+
push:
8+
branches: ["main"]
9+
pull_request:
10+
branches: ["main"]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Set up Python 3.10
21+
uses: actions/setup-python@v3
22+
with:
23+
python-version: "3.10"
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install flake8
28+
# can install packages from a requirements file
29+
if [ -f ci-cd-requirements.txt ]; then pip install -r ci-cd-requirements.txt; fi
30+
- name: Lint with flake8
31+
run: |
32+
# stop the build if there are Python syntax errors or undefined names
33+
flake8 --count --show-source --statistics demo-assignments/A0/hello
34+
flake8 --count --show-source --statistics demo-assignments/A0-OOP/hello
35+
flake8 --count --show-source --statistics demo-assignments/A1/cold
36+
flake8 --count --show-source --statistics demo-assignments/A1-OOP/cold
37+
flake8 --count --show-source --statistics demo-assignments/A2-ABC/egypt
38+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
39+
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
40+
- name: Check types with mypy
41+
run: |
42+
mypy --strict --allow-untyped-decorators --ignore-missing-imports demo-assignments/A0/hello
43+
mypy --strict --allow-untyped-decorators --ignore-missing-imports demo-assignments/A0-OOP/hello
44+
mypy --strict --allow-untyped-decorators --ignore-missing-imports demo-assignments/A1/cold
45+
mypy --strict --allow-untyped-decorators --ignore-missing-imports demo-assignments/A1-OOP/cold
46+
mypy --strict --allow-untyped-decorators --ignore-missing-imports demo-assignments/A2-ABC/egypt
47+
- name: Test with pytest
48+
run: |
49+
pytest --verbose demo-assignments/A0/hello/tests
50+
pytest --verbose demo-assignments/A0-OOP/hello/tests
51+
pytest --verbose demo-assignments/A1/cold/tests
52+
pytest --verbose demo-assignments/A1-OOP/cold/tests
53+
pytest --verbose demo-assignments/A2-ABC/egypt/tests

.gitignore

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
local_settings.py
60+
db.sqlite3
61+
db.sqlite3-journal
62+
63+
# Flask stuff:
64+
instance/
65+
.webassets-cache
66+
67+
# Scrapy stuff:
68+
.scrapy
69+
70+
# Sphinx documentation
71+
docs/_build/
72+
73+
# PyBuilder
74+
target/
75+
76+
# Jupyter Notebook
77+
.ipynb_checkpoints
78+
79+
# IPython
80+
profile_default/
81+
ipython_config.py
82+
83+
# pyenv
84+
.python-version
85+
86+
# pipenv
87+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
88+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
89+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
90+
# install all needed dependencies.
91+
#Pipfile.lock
92+
93+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
94+
__pypackages__/
95+
96+
# Celery stuff
97+
celerybeat-schedule
98+
celerybeat.pid
99+
100+
# SageMath parsed files
101+
*.sage.py
102+
103+
# Environments
104+
.env
105+
.venv
106+
env/
107+
venv/
108+
ENV/
109+
env.bak/
110+
venv.bak/
111+
112+
# Spyder project settings
113+
.spyderproject
114+
.spyproject
115+
116+
# Rope project settings
117+
.ropeproject
118+
119+
# mkdocs documentation
120+
/site
121+
122+
# mypy
123+
.mypy_cache/
124+
.dmypy.json
125+
dmypy.json
126+
127+
# Pyre type checker
128+
.pyre/
129+
.DS_Store
130+
htmlcov/

.mypy.ini

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[mypy]
2+
exclude = (?x)(
3+
kattis-cli # file/folder that starts with kattis-cli
4+
| \.github # file/folder that starts with .github
5+
| \.githooks # file/folder that starts with .githooks
6+
| tests # file/folder that starts with tests
7+
)
8+
disallow_any_generics = false
9+
disallow_incomplete_defs = true
10+
disallow_untyped_calls = true
11+
disallow_untyped_decorators = false
12+
disallow_untyped_defs = true
13+
follow_imports = normal
14+
ignore_missing_imports = true
15+
no_implicit_reexport = true
16+
show_error_codes = true
17+
show_error_context = true
18+
strict_equality = true
19+
strict_optional = true
20+
warn_redundant_casts = true
21+
warn_return_any = true
22+
warn_unused_ignores = true

Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
FROM python:3.10
2+
3+
RUN apt update \
4+
&& apt install -y \
5+
g++ gcc make sqlite3 time curl git nano dos2unix \
6+
net-tools iputils-ping iproute2 sudo gdb less \
7+
&& apt clean;
8+
9+
# Install Java and Graphviz for plantuml
10+
RUN apt install default-jre graphviz -y
11+
12+
ARG USER=user
13+
ARG UID=1000
14+
ARG GID=1000
15+
16+
# Set environment variables
17+
ENV USER ${USER}
18+
ENV HOME /home/${USER}
19+
20+
# Create user and setup permissions on /etc/sudoers
21+
RUN useradd -m -s /bin/bash -N -u $UID $USER && \
22+
echo "${USER} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers && \
23+
chmod 0440 /etc/sudoers && \
24+
chmod g+w /etc/passwd
25+
26+
WORKDIR ${HOME}
27+
28+
RUN pip install --upgrade pip
29+
30+
COPY requirements.txt ./
31+
RUN pip install --no-cache-dir -r requirements.txt
32+
33+
# Install zsh - use "Bira" theme with some customization.
34+
RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.5/zsh-in-docker.sh)" -- \
35+
-t bira \
36+
-p git \
37+
-p ssh-agent \
38+
-p https://github.com/zsh-users/zsh-autosuggestions \
39+
-p https://github.com/zsh-users/zsh-completions
40+
41+
USER user
42+
43+
CMD zsh

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Ram Basnet
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
TEST = pytest
2+
TEST_ARGS = -s --verbose --color=yes
3+
TYPE_CHECK = mypy --strict --allow-untyped-decorators --ignore-missing-imports
4+
STYLE_CHECK = flake8
5+
COVERAGE = python -m pytest
6+
DEMO = './demo-assignments'
7+
8+
.PHONY: all
9+
all: check-style check-type run-test-coverage clean
10+
@echo "All checks passed!"
11+
12+
.PHONY: check-type
13+
check-type:
14+
$(TYPE_CHECK) $(DEMO)/A0/hello
15+
$(TYPE_CHECK) $(DEMO)/A0-OOP/hello
16+
$(TYPE_CHECK) $(DEMO)/A1/cold
17+
$(TYPE_CHECK) $(DEMO)/A1-OOP/cold
18+
$(TYPE_CHECK) $(DEMO)/A2-ABC/egypt
19+
20+
.PHONY: check-style
21+
check-style:
22+
$(STYLE_CHECK) $(DEMO)/A0/hello
23+
$(STYLE_CHECK) $(DEMO)/A0-OOP/hello
24+
$(STYLE_CHECK) $(DEMO)/A1/cold
25+
$(STYLE_CHECK) $(DEMO)/A1-OOP/cold
26+
$(STYLE_CHECK) $(DEMO)/A2-ABC/egypt
27+
28+
# discover and run all tests
29+
.PHONY: run-test
30+
run-test:
31+
$(TEST) $(TEST_ARGS) $(DEMO)/A0/hello/tests
32+
$(TEST) $(TEST_ARGS) $(DEMO)/A0-OOP/hello/tests
33+
$(TEST) $(TEST_ARGS) $(DEMO)/A1/cold/tests
34+
$(TEST) $(TEST_ARGS) $(DEMO)/A1-OOP/cold/tests
35+
$(TEST) $(TEST_ARGS) $(DEMO)/A2-ABC/egypt/tests
36+
37+
.PHONY: run-test-coverage
38+
run-test-coverage:
39+
$(COVERAGE) -v --cov-report=html:$(DEMO)/A0/hello/htmlcov --cov-report=term --cov=$(DEMO)/A0/hello $(DEMO)/A0/hello/tests
40+
$(COVERAGE) -v --cov-report=html:$(DEMO)/A0-OOP/hello/htmlcov --cov-report=term --cov=$(DEMO)/A0-OOP/hello $(DEMO)/A0-OOP/hello/tests
41+
$(COVERAGE) -v --cov-report=html:$(DEMO)/A1/cold/htmlcov --cov-report=term --cov=$(DEMO)/A1/cold $(DEMO)/A1/cold/tests
42+
$(COVERAGE) -v --cov-report=html:$(DEMO)/A1-OOP/cold/htmlcov --cov-report=term --cov=$(DEMO)/A1-OOP/cold $(DEMO)/A1-OOP/cold/tests
43+
$(COVERAGE) -v --cov-report=html:$(DEMO)/A2-ABC/egypt/htmlcov --cov-report=term --cov=$(DEMO)/A2-ABC/egypt $(DEMO)/A2-ABC/egypt/tests
44+
45+
.PHONY: clean
46+
clean:
47+
# remove all caches recursively
48+
rm -rf `find . -type d -name __pycache__` # remove all pycache
49+
rm -rf `find . -type d -name .pytest_cache` # remove all pytest cache
50+
rm -rf `find . -type d -name .mypy_cache` # remove all mypy cache
51+
rm -rf `find . -type d -name .hypothesis` # remove all hypothesis cache
52+
rm -rf `find . -name .coverage` # remove all coverage cache

0 commit comments

Comments
 (0)