diff --git a/.github/workflows/black.yaml b/.github/workflows/black.yaml new file mode 100644 index 0000000..d65f7c6 --- /dev/null +++ b/.github/workflows/black.yaml @@ -0,0 +1,18 @@ +name: Code Formatting + +on: push + +jobs: + formatting: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: 3.11.1 + + - name: Code Formatting (App) + run: | + pip install black + pip install -r requirements.txt + black --check . diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 79fec85..c2b4095 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,114 +13,123 @@ jobs: runs-on: macos-latest env: PYTHONVERSION: "3.11.1" - MACOSX_DEPLOYMENT_TARGET: "10.9" + MACOSX_DEPLOYMENT_TARGET: "13.6" PYI_BUILD_MODE: "onedir" steps: - - uses: actions/checkout@v2 - - - name: Cache Python download - id: cache-python-download - uses: actions/cache@v3 - with: - path: ~/python.pkg - key: macOS-Python-${{ env.PYTHON_VERSION }} - - - name: Get Python - run: | - curl https://www.python.org/ftp/python/${PYTHONVERSION}/python-${PYTHONVERSION}-macos11.pkg -o ~/python.pkg - - - name: Install Python - run: sudo installer -pkg ~/python.pkg -target / - - - name: Install Python dependencies and build - run: | - python3 --version - pip3 install --upgrade pip wheel - pip3 install -r requirements.txt - pip3 install pyinstaller - pyinstaller weather.spec - - - name: Log files - run: | - ls dist - ls dist/Weather - mkdir Weather - mv ./dist/Weather.app ./Weather/Weather.app - ln -s /Applications ./Weather/Applications - hdiutil create -srcfolder ./Weather Weather.dmg - - - name: Upload binaries to release - uses: svenstaro/upload-release-action@v2 - with: - file: Weather.dmg - asset_name: Weather.dmg - tag: ${{ github.event.inputs.version }} - overwrite: true - + - uses: actions/checkout@v2 + + - name: Uninstall homebrew + run: | + curl -sLO https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh + chmod +x ./uninstall.sh + sudo ./uninstall.sh --force + sudo rm -rf /usr/local/Homebrew + sudo rm -rf /usr/local/Caskroom + sudo rm -rf /usr/local/bin/brew + + - name: Cache Python download + id: cache-python-download + uses: actions/cache@v3 + with: + path: ~/python.pkg + key: macOS-Python-${{ env.PYTHON_VERSION }} + + - name: Get Python + run: | + curl https://www.python.org/ftp/python/${PYTHONVERSION}/python-${PYTHONVERSION}-macos11.pkg -o ~/python.pkg + + - name: Install Python + run: sudo installer -pkg ~/python.pkg -target / + + - name: Install Python dependencies and build + run: | + python3 --version + pip3 install --upgrade pip wheel + pip3 install -r requirements.txt + pip3 install pyinstaller + pyinstaller weather.spec + + - name: Log files + run: | + ls dist + ls dist/Weather + mkdir Weather + mv ./dist/Weather.app ./Weather/Weather.app + ln -s /Applications ./Weather/Applications + hdiutil create -srcfolder ./Weather Weather.dmg + + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v2 + with: + file: Weather.dmg + asset_name: Weather.dmg + tag: ${{ github.event.inputs.version }} + overwrite: true + build-linux: runs-on: ubuntu-latest env: PYI_BUILD_MODE: "onefile" steps: - - uses: actions/checkout@v2 - - - name: Setup Python 3.11.1 - uses: actions/setup-python@v4 - with: - python-version: 3.11.1 - - - name: Install requirements - run: | - pip3 install pyinstaller - pip3 install -r requirements.txt - sudo apt install python3-tk python3-pil.imagetk - - - name: Build - run: pyinstaller weather.spec - - - name: Log files - run: | - ls dist - - - name: Upload binaries to release - uses: svenstaro/upload-release-action@v2 - with: - file: dist/Weather - asset_name: Weather - tag: ${{ github.event.inputs.version }} - overwrite: true - + - uses: actions/checkout@v2 + + - name: Setup Python 3.11.1 + uses: actions/setup-python@v4 + with: + python-version: 3.11.1 + + - name: Install requirements + run: | + pip3 install pyinstaller + pip3 install -r requirements.txt + sudo apt install python3-tk python3-pil.imagetk + + - name: Build + run: pyinstaller weather.spec + + - name: Log files + run: | + ls dist + + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v2 + with: + file: dist/Weather + asset_name: Weather + tag: ${{ github.event.inputs.version }} + overwrite: true + build-windows: runs-on: windows-latest env: PYI_BUILD_MODE: "onefile" - + steps: - - uses: actions/checkout@v2 - - - name: Setup Python 3.11.1 - uses: actions/setup-python@v4 - with: - python-version: 3.11.1 - - - name: Install Python dependencies and build - run: | - python3 --version - pip install --upgrade pip wheel - pip install -r requirements.txt - pip install pyinstaller - pyinstaller windows-weather.spec - - - name: Log files - run: | - ls dist - - - name: Upload binaries to release - uses: svenstaro/upload-release-action@v2 - with: - file: dist/Weather.exe - asset_name: Weather.exe - tag: ${{ github.event.inputs.version }} - overwrite: true \ No newline at end of file + - uses: actions/checkout@v2 + + - name: Setup Python 3.11.1 + uses: actions/setup-python@v4 + with: + python-version: 3.11.1 + + - name: Install Python dependencies and build + run: | + python3 --version + pip install --upgrade pip wheel + pip install -r requirements.txt + pip install pyinstaller + pyinstaller windows-weather.spec + + - name: Log files + run: | + ls dist + + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v2 + with: + file: dist/Weather.exe + asset_name: Weather.exe + tag: ${{ github.event.inputs.version }} + overwrite: true diff --git a/.github/workflows/debug-builds.yaml b/.github/workflows/debug-builds.yaml index b23e1a7..424a491 100644 --- a/.github/workflows/debug-builds.yaml +++ b/.github/workflows/debug-builds.yaml @@ -7,49 +7,57 @@ jobs: runs-on: macos-latest env: PYTHONVERSION: "3.11.1" - MACOSX_DEPLOYMENT_TARGET: "10.9" + MACOSX_DEPLOYMENT_TARGET: "13.6" PYI_BUILD_MODE: "onedir" steps: - - uses: actions/checkout@v2 - - - name: Cache Python download - id: cache-python-download - uses: actions/cache@v3 - with: - path: ~/python.pkg - key: macOS-Python-${{ env.PYTHON_VERSION }} - - - name: Get Python - run: | - curl https://www.python.org/ftp/python/${PYTHONVERSION}/python-${PYTHONVERSION}-macos11.pkg -o ~/python.pkg - - name: Install Python - run: sudo installer -pkg ~/python.pkg -target / - - - name: Install Python dependencies and build - run: | - python3 --version - pip3 install --upgrade pip wheel - pip3 install -r requirements.txt - pip3 install pyinstaller - pyinstaller weather.spec - - - name: Log files - run: | - ls dist - ls dist/Weather - mkdir Weather - mv ./dist/Weather.app ./Weather/Weather.app - ln -s /Applications ./Weather/Applications - hdiutil create -srcfolder ./Weather Weather.dmg - - - name: Upload a Build Artifact - uses: actions/upload-artifact@v3.1.2 - with: - # Artifact name - name: Weather-Mac - path: Weather.dmg + - uses: actions/checkout@v2 + - name: Uninstall homebrew + run: | + curl -sLO https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh + chmod +x ./uninstall.sh + sudo ./uninstall.sh --force + sudo rm -rf /usr/local/Homebrew + sudo rm -rf /usr/local/Caskroom + sudo rm -rf /usr/local/bin/brew + + - name: Cache Python download + id: cache-python-download + uses: actions/cache@v3 + with: + path: ~/python.pkg + key: macOS-Python-${{ env.PYTHON_VERSION }} + + - name: Get Python + run: | + curl https://www.python.org/ftp/python/${PYTHONVERSION}/python-${PYTHONVERSION}-macos11.pkg -o ~/python.pkg + - name: Install Python + run: sudo installer -pkg ~/python.pkg -target / + + - name: Install Python dependencies and build + run: | + python3 --version + pip3 install --upgrade pip wheel + pip3 install -r requirements.txt + pip3 install pyinstaller + pyinstaller weather.spec + + - name: Log files + run: | + ls dist + ls dist/Weather + mkdir Weather + mv ./dist/Weather.app ./Weather/Weather.app + ln -s /Applications ./Weather/Applications + hdiutil create -srcfolder ./Weather Weather.dmg + + - name: Upload a Build Artifact + uses: actions/upload-artifact@v3.1.2 + with: + # Artifact name + name: Weather-Mac + path: Weather.dmg build-linux: runs-on: ubuntu-20.04 @@ -57,30 +65,30 @@ jobs: PYI_BUILD_MODE: "onefile" steps: - - uses: actions/checkout@v2 - - - name: Setup Python 3.11.1 - uses: actions/setup-python@v4 - with: - python-version: 3.11.1 - - - name: Install requirements - run: | - pip3 install pyinstaller - pip3 install -r requirements.txt - sudo apt install python3-tk python3-pil.imagetk - - name: Build - run: pyinstaller weather.spec - - - name: Log files - run: | - ls dist - - name: Upload a Build Artifact - uses: actions/upload-artifact@v3.1.2 - with: - # Artifact name - name: Weather-Linux - path: dist/Weather + - uses: actions/checkout@v2 + + - name: Setup Python 3.11.1 + uses: actions/setup-python@v4 + with: + python-version: 3.11.1 + + - name: Install requirements + run: | + pip3 install pyinstaller + pip3 install -r requirements.txt + sudo apt install python3-tk python3-pil.imagetk + - name: Build + run: pyinstaller weather.spec + + - name: Log files + run: | + ls dist + - name: Upload a Build Artifact + uses: actions/upload-artifact@v3.1.2 + with: + # Artifact name + name: Weather-Linux + path: dist/Weather build-windows: runs-on: windows-latest @@ -88,28 +96,28 @@ jobs: PYI_BUILD_MODE: "onefile" steps: - - uses: actions/checkout@v2 - - - name: Setup Python 3.11.1 - uses: actions/setup-python@v4 - with: - python-version: 3.11.1 - - - name: Install Python dependencies and build - run: | - python3 --version - pip install --upgrade pip wheel - pip install -r requirements.txt - pip install pyinstaller - pyinstaller windows-weather.spec - - - name: Log files - run: | - ls dist - - - name: Upload a Build Artifact - uses: actions/upload-artifact@v3.1.2 - with: - # Artifact name - name: Weather-Windows - path: dist/Weather.exe + - uses: actions/checkout@v2 + + - name: Setup Python 3.11.1 + uses: actions/setup-python@v4 + with: + python-version: 3.11.1 + + - name: Install Python dependencies and build + run: | + python3 --version + pip install --upgrade pip wheel + pip install -r requirements.txt + pip install pyinstaller + pyinstaller windows-weather.spec + + - name: Log files + run: | + ls dist + + - name: Upload a Build Artifact + uses: actions/upload-artifact@v3.1.2 + with: + # Artifact name + name: Weather-Windows + path: dist/Weather.exe diff --git a/.github/workflows/formatting.yml b/.github/workflows/formatting.yml deleted file mode 100644 index b8b5e87..0000000 --- a/.github/workflows/formatting.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Code Formatting - -on: - schedule: - - cron: 30 05 15 * * - workflow_dispatch: - - -jobs: - formatting: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: 3.8 - - uses: extractions/setup-just@v1 - with: - just-version: 0.8 # optional semver specification, otherwise latest - - name: Code Formatting (App) - run: | - pip3 install ruff black isort autopep8 - just format - - uses: fregante/setup-git-user@v1 - - name: Commit - run: | - git add . - git commit -m "style(gh-actions): Code Formatting Workflow" -m "Either triggered by cron or workflow_dispatch" - git push --force diff --git a/.github/workflows/isort.yml b/.github/workflows/isort.yml new file mode 100644 index 0000000..7a2df47 --- /dev/null +++ b/.github/workflows/isort.yml @@ -0,0 +1,18 @@ +name: Code Formatting + +on: push + +jobs: + formatting: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: 3.11.1 + + - name: Code Formatting (App) + run: | + pip install isort + pip install -r requirements.txt + isort --check . diff --git a/.github/workflows/pyright.yaml b/.github/workflows/pyright.yaml new file mode 100644 index 0000000..b38460c --- /dev/null +++ b/.github/workflows/pyright.yaml @@ -0,0 +1,18 @@ +name: Code Formatting + +on: push + +jobs: + formatting: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: 3.11.1 + + - name: Code Formatting (App) + run: | + pip install pyright + pip install -r requirements.txt + pyright . diff --git a/.github/workflows/ruff.yaml b/.github/workflows/ruff.yaml new file mode 100644 index 0000000..7de34a9 --- /dev/null +++ b/.github/workflows/ruff.yaml @@ -0,0 +1,18 @@ +name: Code Formatting + +on: push + +jobs: + formatting: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: 3.11.1 + + - name: Code Formatting (App) + run: | + pip install ruff + pip install -r requirements.txt + ruff check . diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..230cf52 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,18 @@ +name: Code Formatting + +on: push + +jobs: + formatting: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: 3.11.1 + + - name: Code Formatting (App) + run: | + pip install pytest + pip install -r requirements.txt + pytest . diff --git a/.gitignore b/.gitignore index b4f5e80..b78c97d 100644 --- a/.gitignore +++ b/.gitignore @@ -131,4 +131,7 @@ dmypy.json .ruff-cache/ # Mac stuff -.DS_Store \ No newline at end of file +.DS_Store + +# VS Code +.vscode diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index f3a508e..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - - { - "name": "Python: Current File", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "externalTerminal", - "justMyCode": true - } - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index e9e6a80..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "python.testing.unittestArgs": [ - "-v", - "-s", - "./tests", - "-p", - "test_*.py" - ], - "python.testing.pytestEnabled": false, - "python.testing.unittestEnabled": true -} \ No newline at end of file diff --git a/Justfile b/Justfile deleted file mode 100644 index 520dd37..0000000 --- a/Justfile +++ /dev/null @@ -1,39 +0,0 @@ -ruff: - ruff . --fix - -isort: - python3 -m isort *.py - python3 -m isort tests/*.py - -black: - python3 -m black *.py - python3 -m black tests/*.py - -install: - python3 -m pip install -r requirements.txt - pip3 install autopep8 pyinstaller - ruff --version - -run: - python3 main.py - -run-tests: - ruff . - python3 -m unittest tests/test_*.py - -autopep8: - python3 -m autopep8 --in-place *.py - python3 -m autopep8 --in-place tests/test_*.py - - -format: - just black - just autopep8 - just isort - just ruff - -build: - pyinstaller weather.spec - -build-win: - pyinstaller weather-windows.spec diff --git a/dialogs.py b/dialogs.py index a1fb098..7587bc9 100644 --- a/dialogs.py +++ b/dialogs.py @@ -5,11 +5,11 @@ class Messagebox(Toplevel): - def __init__(self, parent, title, details, icon, *, buttons) -> bool: + def __init__(self, parent, title, details, icon, *, buttons) -> None: super().__init__() self.withdraw() - self.result = None + self.result: bool | None = None self.big_frame = Frame(self) self.big_frame.pack(fill="both", expand=True) @@ -79,8 +79,8 @@ def __init__(self, parent, title, details, icon, *, buttons) -> bool: text=button_value[0], width=18, command=partial(self.on_button, button_value[1]), - style=self.style, - state=self.state, + style=self.style, # type: ignore + state=self.state, # type: ignore ) if self.default: self.button.bind("", self.button["command"]) diff --git a/main.py b/main.py index 5da9b9a..9315168 100644 --- a/main.py +++ b/main.py @@ -30,7 +30,9 @@ if not data_dir.exists(): # Create the directory if it doesn't exist data_dir.mkdir(parents=True) - data_file.touch("dark\nmetric") + data_file.touch() + with open(data_file, "r+") as file: + file.write("dark\nmetric") # Ensure file exists and contains the correct data if data_file.exists(): @@ -112,7 +114,7 @@ def __init__(self): self.iconphoto(False, logo_img) except TclError: try: - self.iconphoto("./assets/icon.ico") + self.iconphoto("./assets/icon.ico") # type: ignore except TclError: pass @@ -297,6 +299,11 @@ def owm_search(self, _: Event | None = None) -> None: self.reset_app() return + # Removing redundancy + def failed_weather_request() -> None: + self.cityname.configure(text="City: Not Found") + self.reset_app() + # Check if city exists try: observation = mgr.weather_at_place(city) @@ -306,8 +313,12 @@ def owm_search(self, _: Event | None = None) -> None: or TimeoutError or InvalidSSLCertificateError ): - self.cityname.configure(text="City: Not Found") - self.reset_app() + failed_weather_request() + return + + # Check that observation is not None + if observation is None: + failed_weather_request() return # Get weather data