Skip to content

Commit

Permalink
Update to add a simple CLI tool to show versions of common packages
Browse files Browse the repository at this point in the history
  • Loading branch information
MaddyGuthridge committed Jan 19, 2025
1 parent 6224160 commit ae8d01a
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 6 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Test and Lint

on: [push]

jobs:
Ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
- uses: Gr1N/setup-poetry@v8
- uses: actions/cache@v4
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
- run: poetry --version
- run: poetry install
- name: Lint with ruff
run: |
poetry run ruff check
Mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
- uses: Gr1N/setup-poetry@v8
- uses: actions/cache@v4
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
- run: poetry --version
- run: poetry install
- name: Lint with mypy
run: |
poetry run mypy
79 changes: 76 additions & 3 deletions comp1010/__main__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,86 @@
"""
# COMP1010 Metapackage
This library includes all required COMP1010 dependencies.
This library includes all required COMP1010 dependencies, as well as a simple
utility to display helpful debug information.
"""

import json
from os import uname
from sys import version_info as version

from colorama import Fore
from subtask import Subtask

__version__ = "1.1.0"

IMPORTANT_PACKAGES = ["pyhtml-enhanced", "pyhtml", "Flask"]
"""
Packages that tutors probably want to know the version of if debugging a setup
"""


BLUE = Fore.BLUE
GREEN = Fore.GREEN
RED = Fore.RED
YELLOW = Fore.YELLOW
RESET = Fore.RESET


RAINBOW = [
Fore.RED,
Fore.YELLOW,
Fore.GREEN,
Fore.CYAN,
Fore.BLUE,
Fore.MAGENTA,
]


def rainbow(text: str) -> str:
"""Rainbow text"""
return (
"".join(f"{RAINBOW[i % len(RAINBOW)]}{c}" for i, c in enumerate(text))
+ f"{RESET}"
)


def get_packages_info() -> dict[str, str]:
"""
Return package info as a mapping between packages and their versions.
"""
pip = Subtask(["pip", "list", "--format", "json"])
pip.wait()
packages = json.loads(pip.read_stdout())

return {package["name"]: package["version"] for package in packages}


def main():
print("COMP1010 Metapackage installed successfully!")
python_version = f"{version.major}.{version.minor}.{version.micro}"
print(rainbow("===================="))
print("COMP1010 Metapackage")
print(f"{BLUE}v{__version__}{RESET}")
print(rainbow("===================="))
print()
print(f"Python version: {BLUE}{python_version}{RESET}")
print(f"OS: {BLUE}{uname().sysname} {uname().release}{RESET}")
print()
print("Core package versions:")
print(f"{YELLOW} Don't stress if some are not installed. This is just")
print(" displayed in case your tutor needs to help you out!")
print(RESET)

installed = get_packages_info()

for package in IMPORTANT_PACKAGES:
if package in installed:
package_version = f"{GREEN} {installed[package]}"
else:
package_version = f"{RED} Not installed"

print(f"{package.ljust(20)}{package_version} {RESET}")


if __name__ == '__main__':
if __name__ == "__main__":
main()
103 changes: 101 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "comp1010"
version = "1.0.0"
version = "1.1.0"
description = "The COMP1010 metapackage, used to specify dependencies required for UNSW's COMP1010 course."
authors = [
{ name = "COMP1010 UNSW", email = "cs1010@cse.unsw.edu.au" },
Expand Down Expand Up @@ -29,6 +29,33 @@ comp1010 = "comp1010.__main__:main"
[tool.poetry]
packages = [{ include = "comp1010" }]

[tool.poetry.group.dev.dependencies]
mypy = "^1.14.1"
ruff = "^0.9.2"

[tool.mypy]
check_untyped_defs = true
files = ["comp1010"]

[tool.ruff]
line-length = 79

[tool.ruff.lint]
select = [
# pycodestyle
"E",
# Pyflakes
"F",
# pyupgrade
"UP",
# flake8-bugbear
"B",
# flake8-simplify
"SIM",
# isort
"I",
]

[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"

0 comments on commit ae8d01a

Please sign in to comment.