Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
iulusoy authored May 28, 2024
0 parents commit 00415e6
Show file tree
Hide file tree
Showing 13 changed files with 467 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/Part1/example1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import glob


# find all png files in a folder
def find_files(path=None, pattern="*.png", recursive=True, limit=20) -> list:
"""Find image files on the file system.
:param path:
The base directory where we are looking for the images.
Defaults to None, which uses the XDG data directory if
set or the current working directory otherwise.
:param pattern:
The naming pattern that the filename should match. Defaults to
"*.png". Can be used to allow other patterns or to only include
specific prefixes or suffixes.
:param recursive:
Whether to recurse into subdirectories.
:param limit:
The maximum number of images to be found. Defaults to 20.
To return all images, set to None.
"""
if path is None:
path = os.environ.get("XDG_DATA_HOME", ".")

result = list(glob.glob(f"{path}/{pattern}", recursive=recursive))

if limit is not None:
result = result[:limit]

return result


if __name__ == "__main__":
list = find_files(path="./data/")
print("Found files {}".format(list))
22 changes: 22 additions & 0 deletions .github/workflows/Part1/example2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import numpy as np


def area_circ(r_in):
"""Calculate the area of a circle with given radius.
:Input: The radius of the circle (float, >=0).
:Returns: The area of the circle (float)."""
if r_in < 0:
raise ValueError("The radius must be >= 0.")
circle = np.pi * r_in**2
print(
"""The area of a circle with radius r = {:3.2f}cm is \
A = {:4.2f}cm2.""".format(
r_in, circle
)
)
return circle


if __name__ == "__main__":
_ = area_circ(5.0)
29 changes: 29 additions & 0 deletions .github/workflows/Part1/example3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
def validate_data_dict(data_dict):
if not data_dict:
raise ValueError("data_dict is empty")
for something, otherthing in data_dict.items():
if not otherthing:
raise ValueError(f"The dict content under {something} is empty.")
if not isinstance(otherthing, dict):
raise ValueError(
f"The content of {something} is \
not a dict but {type(otherthing)}."
)

list_ = ["data", "file_type", "sofa", "paragraph"]
missing_cats = []
for category in list_:
if category not in list(otherthing.keys()):
missing_cats.append(category)

if missing_cats:
raise ValueError(
f"Data dict is missing categories: \
{missing_cats}"
)


if __name__ == "__main__":
data_dict = {}
data_dict = {"test": {"testing": "just testing"}}
validate_data_dict(data_dict)
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: test
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
test-input:
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.12"]
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up environment
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests
run: |
python -m pytest -sxvv
27 changes: 27 additions & 0 deletions .github/workflows/classroom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Autograding Tests
'on':
- push
- repository_dispatch
permissions:
checks: write
actions: read
contents: read
jobs:
run-autograding-tests:
runs-on: ubuntu-latest
if: github.actor != 'github-classroom[bot]'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: check-for-stylistic-errors
id: check-for-stylistic-errors
uses: classroom-resources/autograding-python-grader@v1
with:
timeout: 10
setup-command: 'pip install flake8'
- name: Autograding Reporter
uses: classroom-resources/autograding-grading-reporter@v1
env:
CHECK-FOR-STYLISTIC-ERRORS_RESULTS: "${{steps.check-for-stylistic-errors.outputs.result}}"
with:
runners: check-for-stylistic-errors
160 changes: 160 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 ssciwr-courses

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# pbp-pep-fixmes
Correct the three example files in chapter 1 to adhere to PEP 8 recommendations.
34 changes: 34 additions & 0 deletions chapter1/example1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os
import glob



# find all png files in a folder
def find_files(path=None, pattern="*.png", recursive=True, limit = 20) -> list:
"""Find image files on the file system.
:param path:
The base directory where we are looking for the images. Defaults to None, which uses the XDG data directory if set or the current working directory otherwise.
:param pattern:
The naming pattern that the filename should match. Defaults to
"*.png". Can be used to allow other patterns or to only include
specific prefixes or suffixes.
:param recursive:
Whether to recurse into subdirectories.
:param limit:
The maximum number of images to be found. Defaults to 20.
To return all images, set to None.
"""
if path is None:
path = os.environ.get("XDG_DATA_HOME", ".")

result=list(glob.glob(f"{path}/{pattern}", recursive=recursive))

if limit is not None:
result = result[:limit]

return result

if __name__=="__main__":
list = find_files(path="./data/")
print("Found files {}".format(list))
19 changes: 19 additions & 0 deletions chapter1/example2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import numpy as np

def area_circ(r_in ):
"""Calculate the area of a circle with given radius.
:Input: The radius of the circle (float, >=0).
:Returns: The area of the circle (float)."""
if r_in<0:
raise ValueError("The radius must be >= 0.")
Kreis=np.pi*r_in**2
print(
"""The area of a circle with radius r = {:3.2f}cm is A = {:4.2f}cm2.""".format(
r_in,Kreis
)
)
return Kreis

if __name__ == "__main__":
_ = area_circ(5.0)
Loading

0 comments on commit 00415e6

Please sign in to comment.