making-with-code-cli 5.0.1__tar.gz → 5.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/PKG-INFO +1 -1
  2. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/pyproject.toml +1 -1
  3. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/git_backend/mwc_backend.py +18 -14
  4. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/settings.py +1 -1
  5. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/setup/__init__.py +5 -3
  6. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/setup/tasks.py +44 -9
  7. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/update/__init__.py +17 -2
  8. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/README.md +0 -0
  9. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/__init__.py +0 -0
  10. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/cli.py +0 -0
  11. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/curriculum.py +0 -0
  12. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/decorators.py +0 -0
  13. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/errors.py +0 -0
  14. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/git_backend/__init__.py +0 -0
  15. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/git_backend/base_backend.py +0 -0
  16. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/git_wrapper.py +0 -0
  17. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/helpers.py +0 -0
  18. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/mwc_accounts_api.py +0 -0
  19. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/styles.py +0 -0
  20. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/submit.py +0 -0
  21. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/__init__.py +0 -0
  22. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/assess.py +0 -0
  23. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/check/__init__.py +0 -0
  24. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/check/check_module.py +0 -0
  25. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/gitea_api/api.py +0 -0
  26. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/gitea_api/exceptions.py +0 -0
  27. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/log.py +0 -0
  28. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/patch.py +0 -0
  29. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/section/__init__.py +0 -0
  30. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/section/create.py +0 -0
  31. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/section/edit.py +0 -0
  32. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/section/show.py +0 -0
  33. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/setup.py +0 -0
  34. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/status.py +0 -0
  35. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/student/__init__.py +0 -0
  36. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/student/create.py +0 -0
  37. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/student/update.py +0 -0
  38. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/student_repo_functions.py +0 -0
  39. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/student_repos.py +0 -0
  40. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/teach/update.py +0 -0
  41. {making_with_code_cli-5.0.1 → making_with_code_cli-5.0.3}/src/making_with_code_cli/version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: making-with-code-cli
3
- Version: 5.0.1
3
+ Version: 5.0.3
4
4
  Summary: Courseware for Making With Code
5
5
  Author: Chris Proctor
6
6
  Author-email: Chris Proctor <chris@chrisproctor.net>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "making-with-code-cli"
3
- version = "5.0.1"
3
+ version = "5.0.3"
4
4
  description = "Courseware for Making With Code"
5
5
  authors = [{ name = "Chris Proctor", email = "chris@chrisproctor.net" }]
6
6
  requires-python = ">=3.11,<4.0"
@@ -1,5 +1,6 @@
1
1
  from .base_backend import GitBackend
2
- from subprocess import run
2
+ from subprocess import run, CalledProcessError
3
+ import traceback
3
4
  from pathlib import Path
4
5
  from urllib.parse import urlparse
5
6
  import click
@@ -8,7 +9,11 @@ import os
8
9
  import requests
9
10
  from making_with_code_cli.helpers import cd
10
11
  from making_with_code_cli.styles import (
12
+ address,
11
13
  confirm,
14
+ debug,
15
+ error,
16
+ info,
12
17
  )
13
18
  from making_with_code_cli.errors import (
14
19
  MissingSetting,
@@ -40,26 +45,25 @@ class MWCBackend(GitBackend):
40
45
  if (modpath / self.COMMIT_TEMPLATE).exists():
41
46
  run(f"git config commit.template {self.COMMIT_TEMPLATE}", shell=True,
42
47
  check=True, cwd=modpath)
43
- run("uv venv", shell=True, check=True, cwd=modpath)
48
+ run("uv venv", shell=True, check=True, cwd=modpath, capture_output=True)
44
49
  self.init_direnv(modpath)
45
50
 
46
51
  def update(self, module, modpath, install=True):
47
52
  if (modpath / ".git").is_dir():
48
53
  with cd(modpath):
49
54
  relpath = self.relative_path(modpath)
50
- try:
51
- click.echo(address(f"Checking {relpath} for updates.", preformatted=True))
52
- gitresult = run("git pull", shell=True, check=True, capture_output=True,
53
- text=True)
54
- click.echo(info(gitresult.stdout))
55
- if install and Path("pyproject.toml").exists():
56
- result = run("uv sync", shell=True, check=True,
57
- capture_output=True, text=True)
55
+ click.echo(address(f"Checking {relpath} for updates.", preformatted=True))
56
+ gitresult = run("git pull", shell=True, check=True, capture_output=True,
57
+ text=True)
58
+ click.echo(info(gitresult.stdout))
59
+ if install and Path("pyproject.toml").exists():
60
+ result = run("uv sync", shell=True, capture_output=True, text=True, cwd=modpath)
61
+ if result.returncode != 0:
62
+ click.echo(debug("Error running uv sync:"))
63
+ click.echo(debug(result.stderr, preformatted=True))
64
+ click.echo(error(f"There was a problem updating {relpath}. Ask a teacher."))
65
+ else:
58
66
  self.init_direnv(modpath)
59
- click.echo(info(result.stdout, preformatted=True))
60
- except CalledProcessError as e:
61
- click.echo(error(f"There was a problem updating {relpath}. Ask a teacher."))
62
- raise e
63
67
 
64
68
  def init_direnv(self, modpath):
65
69
  if not (modpath / ".envrc").exists():
@@ -15,7 +15,7 @@ def get_settings_path(settings_path=None):
15
15
  return Path(os.environ["MWC_CONFIG"])
16
16
  else:
17
17
  xdg_config_home = Path(os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config"))
18
- return xdg_config_home / "settings.toml"
18
+ return xdg_config_home / "mwc" / "settings.toml"
19
19
 
20
20
  def read_settings(settings_path=None):
21
21
  """Reads the settings file and returns a dict.
@@ -31,6 +31,7 @@ from making_with_code_cli.setup.tasks import (
31
31
  choose_editor,
32
32
  WriteMWCShellConfig,
33
33
  SourceMWCShellConfig,
34
+ SuppressDirenvDiffs,
34
35
  InstallXCode,
35
36
  InstallDirenv,
36
37
  InstallGit,
@@ -95,15 +96,16 @@ def setup(ctx, config, debug, git_name, git_email, mwc_accounts_url):
95
96
  if settings.get('mwc_accounts_url'):
96
97
  click.echo(debug_fmt(f"Using custom MWC accounts server: {settings['mwc_accounts_url']}"))
97
98
  click.echo(debug_fmt("MWC Accounts Server status:"))
98
- click.echo(debug_fmt(str(status)))
99
- click.echo(info("MWC settings:"))
100
- click.echo(info(settings, preformatted=True))
99
+ click.echo(debug_fmt(str(status), preformatted=True))
100
+ click.echo(debug_fmt("MWC settings:"))
101
+ click.echo(debug_fmt(settings, preformatted=True))
101
102
  write_settings(settings, config)
102
103
 
103
104
  task_classes = [
104
105
  WriteMWCShellConfig,
105
106
  SourceMWCShellConfig,
106
107
  InstallXCode,
108
+ SuppressDirenvDiffs,
107
109
  InstallDirenv,
108
110
  InstallGit,
109
111
  InstallTree,
@@ -5,12 +5,13 @@ import sys
5
5
  import os
6
6
  import re
7
7
  import platform
8
+ import tomlkit
8
9
  from importlib.util import find_spec
9
10
  from making_with_code_cli.mwc_accounts_api import MWCAccountsAPI
10
11
  from making_with_code_cli.styles import (
11
12
  address,
12
13
  question,
13
- debug,
14
+ debug as debug_fmt,
14
15
  confirm,
15
16
  info,
16
17
  success,
@@ -177,7 +178,7 @@ def get_mwc_rc_path():
177
178
  xdg_config_home = Path(os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config"))
178
179
  return xdg_config_home / "mwc" / "shell_config.sh"
179
180
 
180
- def platform_rc_file():
181
+ def platform_rc_file(debug=False):
181
182
  shell = get_shell_name()
182
183
  if shell == "zsh":
183
184
  dothome = Path(os.environ.get("ZDOTDIR", Path.home()))
@@ -195,7 +196,7 @@ def platform_rc_file():
195
196
  ]
196
197
  for sh, rc in candidates:
197
198
  if shell == sh and rc.exists():
198
- click.echo(debug(f"Shell identified as {sh}. Using {rc} as rc file."))
199
+ click.echo(debug_fmt(f"Shell identified as {sh}. Using {rc} as rc file."))
199
200
  return rc
200
201
  raise IOError("Can't find an rc file.")
201
202
 
@@ -230,13 +231,14 @@ class SetupTask:
230
231
 
231
232
  def debug_log(self, message):
232
233
  if self.debug:
233
- click.echo(debug(message))
234
+ click.echo(debug_fmt(message))
234
235
 
235
236
  def executable_on_path(self, name):
236
237
  return bool(run(f"which {name}", shell=True, capture_output=True).stdout)
237
238
 
238
239
  class WriteMWCShellConfig(SetupTask):
239
240
  description = "Write the MWC shell config file to ~/.config/mwc/shell_config.sh or XDG_CONFIG_HOME"
241
+ docs_url = "https://docs.makingwithcode.org/making-with-code-cli/students.html#configuration"
240
242
 
241
243
  def is_complete(self):
242
244
  p = get_mwc_rc_path()
@@ -253,7 +255,8 @@ class WriteMWCShellConfig(SetupTask):
253
255
  "Generates the shell configuration file contents"
254
256
  f = ""
255
257
  shell = get_shell_name()
256
- f += "# Making With Code RC File\n\n"
258
+ f += "# Making With Code RC File\n"
259
+ f += f"# See {self.docs_url}\n\n"
257
260
  f += "## Hook direnv into shell\n"
258
261
  f += f'eval "$(direnv hook {shell})"\n\n'
259
262
 
@@ -278,16 +281,48 @@ class SourceMWCShellConfig(SetupTask):
278
281
  return f"source {get_mwc_rc_path()}" in platform_rc_file().read_text()
279
282
 
280
283
  def run_task(self):
281
- rc_file = platform_rc_file()
284
+ rc_file = platform_rc_file(self.debug)
282
285
  self.debug_log(f"Adding `mwc` path to {rc_file}")
283
286
  with rc_file.open('a') as fh:
284
- result = run("which mwc", shell=True, check=True, text=True, capture_output=True)
285
- mwcpath = Path(result.stdout).parent
286
287
  fh.write(f"\n# MAKING WITH CODE\n")
287
- fh.write(f'export PATH="$PATH:{mwcpath}"\n')
288
288
  fh.write(f"source {get_mwc_rc_path()}\n")
289
289
  click.echo(info(f"Updated your shell login file ({rc_file}). You may need to close and reopen Terminal."))
290
290
 
291
+ class SuppressDirenvDiffs(SetupTask):
292
+ "Tell direnv not to pring out diffs when changing dirs"
293
+ description = "Write direnv config file"
294
+
295
+ def is_complete(self):
296
+ if self.settings.get("skip_direnv_config") == True:
297
+ return True
298
+ f = self.get_direnv_config_file()
299
+ if not f.exists():
300
+ return False
301
+ with open(f, 'rb') as fh:
302
+ direnv_conf = tomlkit.load(fh)
303
+ g = direnv_conf.get("global", {})
304
+ return g.get("hide_env_diff") == True and g.get("log_filter") == "^$"
305
+
306
+ def run_task(self):
307
+ f = self.get_direnv_config_file()
308
+ if f.exists():
309
+ with open(f, 'rb') as fh:
310
+ direnv_conf = tomlkit.load(fh)
311
+ else:
312
+ f.parent.mkdir(parents=True)
313
+ direnv_conf = {}
314
+ if 'global' not in direnv_conf:
315
+ direnv_conf['global'] = {}
316
+ direnv_conf["global"]["hide_env_diff"] = True
317
+ direnv_conf["global"]["log_filter"] = "^$"
318
+ with open(f, 'w') as fh:
319
+ tomlkit.dump(direnv_conf, fh)
320
+
321
+ def get_direnv_config_file(self):
322
+ config_home = os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config")
323
+ return Path(config_home) / "direnv" / "direnv.toml"
324
+
325
+
291
326
  class InstallXCode(SetupTask):
292
327
  description = "Install XCode"
293
328
  platform = Platform.MAC
@@ -2,7 +2,7 @@ import click
2
2
  import traceback
3
3
  from pathlib import Path
4
4
  from subprocess import run
5
- from making_with_code_cli.settings import read_settings
5
+ from making_with_code_cli.settings import read_settings, get_settings_path
6
6
  from making_with_code_cli.curriculum import get_curriculum
7
7
  from making_with_code_cli.git_backend import get_backend
8
8
  from making_with_code_cli.mwc_accounts_api import MWCAccountsAPI
@@ -18,13 +18,19 @@ from making_with_code_cli.styles import (
18
18
 
19
19
  @click.command()
20
20
  @click.option("--config", help="Path to config file (default: ~/.mwc)")
21
- def update(config):
21
+ @click.option("--debug", is_flag=True, help="Show debug-level output")
22
+ def update(config, debug):
22
23
  """Update the MWC work directory"""
23
24
  settings = read_settings(config)
25
+ sp = get_settings_path(config)
26
+ if debug:
27
+ click.echo(debug_fmt(f"Reading settings from {sp}"))
24
28
  if not settings:
25
29
  click.echo(error(f"Please run mwc setup first."))
26
30
  return
27
31
  mwc_home = Path(settings["work_dir"])
32
+ if debug:
33
+ click.echo(debug_fmt(f"mwc home is {mwc_home}."))
28
34
  if not mwc_home.exists():
29
35
  mwc_home.mkdir(mode=WORK_DIR_PERMISSIONS, parents=True)
30
36
  api = MWCAccountsAPI(settings.get('mwc_accounts_url'))
@@ -33,6 +39,15 @@ def update(config):
33
39
  except api.RequestFailed as bad_token:
34
40
  click.echo(error(f"Error logging into MWC accounts server. Please run mwc setup."))
35
41
  return
42
+ if debug:
43
+ if settings.get('mwc_accounts_url'):
44
+ click.echo(debug_fmt(f"Using custom MWC accounts server: {settings['mwc_accounts_url']}"))
45
+ click.echo(debug_fmt("MWC Accounts Server status:"))
46
+ click.echo(debug_fmt(str(status), preformatted=True))
47
+ click.echo(debug_fmt("MWC settings:"))
48
+ click.echo(debug_fmt(settings, preformatted=True))
49
+ if len(status['student_section_memberships']) == 0:
50
+ click.echo(info("There are no updates to run because you are not a student in any courses."))
36
51
  for course in status['student_section_memberships']:
37
52
  curr = get_curriculum(course['curriculum_site_url'], course['course_name'])
38
53
  git_backend = get_backend(curr['git_backend'])(settings)