Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CI

on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master

env: # configure environment variables for git commits
actor: "41898282+github-actions[bot]"

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code for push
if: github.event_name == 'push'
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.ref_name }}
- name: Checkout code for pull request
if: github.event_name == 'pull_request'
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: Set up Python 3.11
uses: actions/setup-python@v3
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest black flake8 # also install black & flake8
if [ -f requirements.txt ]; then
pip install -r requirements.txt
fi
- name: Configure git # use the environment variable we set above
run: |
git config --local user.email "${actor}@users.noreply.github.com"
git config --local user.name "$actor"
- name: Test
run: |
pytest .
- name: Format & lint
run: |
black . # first run black, then run flake8
flake8 --extend-ignore E203 --max-line-length 88 .
- name: Commit and push changes
run: |
git add .
git commit -m "🎨 Style code" || echo "No changes to commit"
git push
34 changes: 34 additions & 0 deletions .github/workflows/greet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# name of the workflow
name: greet

# when the workflow should run
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master

# independent jobs in the workflow
jobs:
# this workflow just has one job called "greet"
greet:
# the operating system to use for this workflow
runs-on: ubuntu-latest
# list of steps in the workflow
steps:
# use an action provided by github to checkout the repo
- uses: actions/checkout@v3
# a custom step that runs a couple shell commands
- name: List
run: |
echo "listing files in the bioinitio directory"
ls cm_pkg
# a custom step that runs R code
- name: Greet
run: print("Hello, world!")
# Replace `shell: Rscript {0}` with `shell: python {0}` to run Python code instead!
shell: python {0}
31 changes: 31 additions & 0 deletions .github/workflows/run_unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI

on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v3
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
if [ -f requirements.txt ]; then
pip install -r requirements.txt
fi
- name: Test with pytest
run: |
pytest .
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.pyc

2 changes: 1 addition & 1 deletion cm_pkg/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__all__ = ["module1"]
__all__ = ["module1"]
32 changes: 18 additions & 14 deletions cm_pkg/module1.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
def add_numbers(x,y):
return(x+y)

def add_numbers(x, y):
return x + y


def say_hello():
print("Hello there!")
print("Hello there!")


def hello_world():
print("Hello world!")
print("Hello world!")


def multiply_numbers(x, y):
"""
Funtion to multiply two numbers
Args:
x (numerical: int or float): number to be multiplied
y (numerical: int or float): number to be multiplied
Returns numerical value (int or float) the result of multiplying x and y
"""
return(x*y)
"""
Funtion to multiply two numbers
Args:
x (numerical: int or float): number to be multiplied
y (numerical: int or float): number to be multiplied
Returns numerical value (int or float) the result of multiplying x and y
"""
return x * y


def new_function():
print("new function code working")
print("new function code working")
2 changes: 1 addition & 1 deletion cm_pkg/ui/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__all__ = ["main_ui"]
__all__ = ["main_ui"]
46 changes: 19 additions & 27 deletions cm_pkg/ui/main_ui.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
import tkinter as tk


def main():
window = tk.Tk()
window.title("Python UI example")
window.geometry("500x200")

label = tk.Label(text = "Python rocks!",
font = ('Arial 16'))
label.place(relx = 0.15,
rely = 0.1,
anchor = 'nw')
entry = tk.Entry()
entry.place(relx = 0.15,
rely = 0.25,
anchor = 'nw')

def change_label():
label.config(text = entry.get(),
font = ('Helvetica 30'))

button = tk.Button(text = "Change label",
command = change_label)
button.place(relx = 0.15,
rely = 0.50,
anchor = 'nw')

window.mainloop()
window = tk.Tk()
window.title("Python UI example")
window.geometry("500x200")

if __name__ == "__main__":
main()
label = tk.Label(text="Python rocks!", font=("Arial 16"))
label.place(relx=0.15, rely=0.1, anchor="nw")
entry = tk.Entry()
entry.place(relx=0.15, rely=0.25, anchor="nw")

def change_label():
label.config(text=entry.get(), font=("Helvetica 30"))

button = tk.Button(text="Change label", command=change_label)
button.place(relx=0.15, rely=0.50, anchor="nw")

window.mainloop()


if __name__ == "__main__":
main()
16 changes: 6 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from setuptools import setup

setup(name='python_prj',
version='0.1.0',
packages=['cm_pkg', "cm_pkg.ui"],
entry_points={
'console_scripts': [
'greeting = cm_pkg.module1:say_hello'
]
}
)

setup(
name="python_prj",
version="0.1.0",
packages=["cm_pkg", "cm_pkg.ui"],
entry_points={"console_scripts": ["greeting = cm_pkg.module1:say_hello"]},
)
14 changes: 8 additions & 6 deletions tests/test_add_numbers.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import sys
import sys
import os
from cm_pkg import module1


def test_addn_pos():
assert module1.add_numbers(2,5) == 7, "Adding 2 and 5 should result in 7"
assert module1.add_numbers(2, 5) == 7, "Adding 2 and 5 should result in 7"

def test_multiplication:
assert module1.multiply_numbers(2,5) == 10, "Multiplying 2 and 5 should result in 10"

def test_multiplication():
assert (
module1.multiply_numbers(2, 5) == 10
), "Multiplying 2 and 5 should result in 10"


cd = os.path.dirname(os.getcwd())
ccd = os.path.join(cd, "cm_pkg")
print(ccd)
sys.path.insert(0, ccd)

sys.path.insert(0, ccd)