Skip to content

Commit

Permalink
lint: Add black and isort formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
itsamirhn committed Jun 7, 2024
1 parent 589c18d commit 0b0e766
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 51 deletions.
133 changes: 131 additions & 2 deletions pdm.lock

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

16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,19 @@ build-backend = "pdm.backend"

[tool.pdm]
distribution = true

[tool.pdm.dev-dependencies]
dev = [
"black>=24.4.2",
"isort>=5.13.2",
"ruff>=0.4.8",
]

[tool.black]
line-length = 120

[tool.isort]
profile = "black"

[tool.ruff]
line-length = 120
4 changes: 3 additions & 1 deletion src/autolms/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from autolms.main import run, go
from autolms.main import go, run

__all__ = ["go", "run"]
54 changes: 30 additions & 24 deletions src/autolms/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from InquirerPy.utils import color_print
from InquirerPy.validator import PathValidator

yml_path = Path.home() / Path('config.yml')
yml_path = Path.home() / Path("config.yml")


def find(name, path, tl=None):
Expand All @@ -26,7 +26,7 @@ def find(name, path, tl=None):

def find_chromedriver(tl):
chromedriver = "chromedriver"
if os.name == 'nt':
if os.name == "nt":
chromedriver = "chromedriver.exe"
paths = [Path.home() / "Downloads", Path.home() / "Desktop", Path("/")]
start = time.time()
Expand All @@ -37,7 +37,7 @@ def find_chromedriver(tl):
color_print([("#00E676", "Found!")])
return f
color_print([("#B00020", "Not Found!")])
return ''
return ""


def find_id(url_or_id):
Expand Down Expand Up @@ -70,7 +70,7 @@ def find_id(url_or_id):
"name": "password",
"message": "Enter your LMS Password:",
"validate": lambda x: len(x) > 0,
}
},
]

options_questions = [
Expand Down Expand Up @@ -99,7 +99,7 @@ def find_id(url_or_id):
"filter": lambda x: find_id(x),
"transformer": lambda x: find_id(x),
"long_instruction": "URL Something like `lms.com/course/view.php?id=1194` or just ID like `1194`",
}
},
]

session_questions = [
Expand All @@ -122,7 +122,7 @@ def find_id(url_or_id):
"name": "time",
"message": "Enter the Session Time:",
"instruction": "(HH:MM Format)",
"validate": lambda x: re.match(r"^([0-2]\d:)?[0-5]\d:[0-5]\d$", x)
"validate": lambda x: re.match(r"^([0-2]\d:)?[0-5]\d:[0-5]\d$", x),
},
]

Expand All @@ -133,9 +133,9 @@ def find_id(url_or_id):
"name": "chromedriver",
"validate": PathValidator(is_file=True, message="Input is not a file"),
"long_instruction": "If you don't know what is this, checkout:\n"
"https://github.com/itsamirhn/AutoLMS#how-to-download-chromedriver",
"https://github.com/itsamirhn/AutoLMS#how-to-download-chromedriver",
"filter": lambda file: str(Path(file).absolute()),
"default": lambda _: find_chromedriver(10)
"default": lambda _: find_chromedriver(10),
},
]

Expand All @@ -151,8 +151,9 @@ def prompt_course():
finished = False
while not finished:
course["sessions"].append(prompt_session())
finished = inquirer.confirm("Are you finished adding Sessions for %s course ?" % course["name"],
default=True).execute()
finished = inquirer.confirm(
"Are you finished adding Sessions for %s course ?" % course["name"], default=True
).execute()
return course


Expand All @@ -161,7 +162,7 @@ def prompt_config():
"credentials": prompt(credentials_questions),
"paths": prompt(paths_questions),
"options": prompt(options_questions),
"courses": []
"courses": [],
}
finished = False
while not finished:
Expand All @@ -174,7 +175,7 @@ def save_config(config):
if not config:
return
color_print([("#00E676", "New Config saved successfully!")])
with open(yml_path, 'w+') as f:
with open(yml_path, "w+") as f:
yaml.safe_dump(config, f)


Expand All @@ -189,20 +190,22 @@ def setup():

def get_config():
if Path(yml_path).exists():
with open(yml_path, 'r') as f:
with open(yml_path, "r") as f:
config = yaml.safe_load(f)
return config
else:
return None


def edit_session(session):
action = inquirer.select(message="What to you want to do with the Session:",
instruction="%s on %s" % (session["time"], session["day"].title()),
choices=[
Choice("edit", "Edit this Session"),
Choice("delete", "Delete this Session"),
]).execute()
action = inquirer.select(
message="What to you want to do with the Session:",
instruction="%s on %s" % (session["time"], session["day"].title()),
choices=[
Choice("edit", "Edit this Session"),
Choice("delete", "Delete this Session"),
],
).execute()
if action == "delete":
return None
if action == "edit":
Expand Down Expand Up @@ -234,11 +237,14 @@ def edit_course(course):


def edit_config(config):
sections = inquirer.select(message="Which section do you want to change:", choices=[
Choice("credentials", name="Credentials"),
Choice("options", name="Options"),
Choice("courses", name="Courses"),
]).execute()
sections = inquirer.select(
message="Which section do you want to change:",
choices=[
Choice("credentials", name="Credentials"),
Choice("options", name="Options"),
Choice("courses", name="Courses"),
],
).execute()
if sections == "credentials":
config["credentials"] = prompt(credentials_questions)
if sections == "options":
Expand Down
Loading

0 comments on commit 0b0e766

Please sign in to comment.