diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..51e8321 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/greet.yml b/.github/workflows/greet.yml new file mode 100644 index 0000000..be7f542 --- /dev/null +++ b/.github/workflows/greet.yml @@ -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} diff --git a/.github/workflows/run_unit_tests.yml b/.github/workflows/run_unit_tests.yml new file mode 100644 index 0000000..313c899 --- /dev/null +++ b/.github/workflows/run_unit_tests.yml @@ -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 . diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..04e9f7d --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.pyc + diff --git a/cm_pkg/__init__.py b/cm_pkg/__init__.py index 377d808..ffffe1e 100644 --- a/cm_pkg/__init__.py +++ b/cm_pkg/__init__.py @@ -1 +1 @@ -__all__ = ["module1"] \ No newline at end of file +__all__ = ["module1"] diff --git a/cm_pkg/module1.py b/cm_pkg/module1.py index 9cebc23..054ce56 100755 --- a/cm_pkg/module1.py +++ b/cm_pkg/module1.py @@ -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") diff --git a/cm_pkg/ui/__init__.py b/cm_pkg/ui/__init__.py index 98c6741..54df6ca 100644 --- a/cm_pkg/ui/__init__.py +++ b/cm_pkg/ui/__init__.py @@ -1 +1 @@ -__all__ = ["main_ui"] \ No newline at end of file +__all__ = ["main_ui"] diff --git a/cm_pkg/ui/main_ui.py b/cm_pkg/ui/main_ui.py index bbb45f6..19a1638 100644 --- a/cm_pkg/ui/main_ui.py +++ b/cm_pkg/ui/main_ui.py @@ -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() diff --git a/setup.py b/setup.py index 7b91526..aedd97a 100644 --- a/setup.py +++ b/setup.py @@ -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"]}, +) diff --git a/tests/test_add_numbers.py b/tests/test_add_numbers.py index 4869592..9bb6694 100644 --- a/tests/test_add_numbers.py +++ b/tests/test_add_numbers.py @@ -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)