-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to add a simple CLI tool to show versions of common packages
- Loading branch information
1 parent
6224160
commit ae8d01a
Showing
4 changed files
with
251 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters