pypas-cli 0.4.2__tar.gz → 0.4.4__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 (22) hide show
  1. {pypas_cli-0.4.2/src/pypas_cli.egg-info → pypas_cli-0.4.4}/PKG-INFO +1 -1
  2. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/pyproject.toml +1 -1
  3. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/src/pypas/lib/console.py +1 -1
  4. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/src/pypas/lib/exercise.py +18 -13
  5. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/src/pypas/lib/sysutils.py +32 -3
  6. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/src/pypas/main.py +2 -5
  7. {pypas_cli-0.4.2 → pypas_cli-0.4.4/src/pypas_cli.egg-info}/PKG-INFO +1 -1
  8. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/LICENSE +0 -0
  9. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/README.md +0 -0
  10. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/setup.cfg +0 -0
  11. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/src/pypas/__init__.py +0 -0
  12. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/src/pypas/lib/auth.py +0 -0
  13. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/src/pypas/lib/config.py +0 -0
  14. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/src/pypas/lib/decorators.py +0 -0
  15. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/src/pypas/lib/monads.py +0 -0
  16. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/src/pypas/lib/network.py +0 -0
  17. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/src/pypas/settings.py +0 -0
  18. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/src/pypas_cli.egg-info/SOURCES.txt +0 -0
  19. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/src/pypas_cli.egg-info/dependency_links.txt +0 -0
  20. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/src/pypas_cli.egg-info/entry_points.txt +0 -0
  21. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/src/pypas_cli.egg-info/requires.txt +0 -0
  22. {pypas_cli-0.4.2 → pypas_cli-0.4.4}/src/pypas_cli.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pypas-cli
3
- Version: 0.4.2
3
+ Version: 0.4.4
4
4
  Summary: Python Practical Assignments
5
5
  Author-email: Sergio Delgado Quintero <sdelquin@gmail.com>
6
6
  Maintainer-email: Sergio Delgado Quintero <sdelquin@gmail.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pypas-cli"
3
- version = "0.4.2"
3
+ version = "0.4.4"
4
4
  description = "Python Practical Assignments"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -51,7 +51,7 @@ class CustomConsole(Console):
51
51
  msg = f'{msg} '
52
52
  self.print(f'{msg}[error]✘')
53
53
 
54
- def resolve(self, msg: str = '', status: bool = None) -> None:
54
+ def resolve(self, msg: str = '', status=None) -> None:
55
55
  match status:
56
56
  case True:
57
57
  self.check(msg)
@@ -7,6 +7,7 @@ import subprocess
7
7
  import tempfile
8
8
  import zipfile
9
9
  from pathlib import Path
10
+ from typing import List
10
11
 
11
12
  import pathspec
12
13
  import pytest
@@ -101,18 +102,22 @@ class Exercise:
101
102
  )
102
103
  for dirpath, dirs, files in os.walk(src_dir):
103
104
  for filename in files:
104
- file = Path(dirpath) / filename
105
- rel_file = file.relative_to(src_dir)
106
- if (
107
- backup
108
- and backup_files.match_file(str(rel_file))
109
- and not filecmp.cmp(rel_file, file, shallow=False)
110
- ):
111
- backup_file = rel_file.with_suffix(rel_file.suffix + '.bak')
112
- console.debug(f'Backup {rel_file} → {backup_file}')
113
- shutil.copy(rel_file, backup_file)
114
- rel_file.parent.mkdir(parents=True, exist_ok=True)
115
- shutil.copy(file, rel_file)
105
+ incoming_file = Path(dirpath) / filename
106
+ current_file = incoming_file.relative_to(src_dir)
107
+ if current_file.exists():
108
+ if filecmp.cmp(current_file, incoming_file, shallow=False):
109
+ continue
110
+ console.info(f'[highlight][U][/highlight] {current_file}', cr=False)
111
+ if backup:
112
+ if backup_files.match_file(str(current_file)):
113
+ backup_file = current_file.with_suffix(current_file.suffix + '.bak')
114
+ console.debug(f' (Backup {current_file} → {backup_file})', cr=False)
115
+ shutil.copy(current_file, backup_file)
116
+ console.info('')
117
+ else:
118
+ console.info(f'[highlight][A][/highlight] {current_file}')
119
+ current_file.parent.mkdir(parents=True, exist_ok=True)
120
+ shutil.copy(incoming_file, current_file)
116
121
  shutil.rmtree(src_dir, ignore_errors=True)
117
122
  console.success('Exercise has been updated to the last version')
118
123
 
@@ -129,7 +134,7 @@ class Exercise:
129
134
  console.error(monad.payload)
130
135
  zipfile.unlink(missing_ok=True)
131
136
 
132
- def test(self, args: list[str]):
137
+ def test(self, args: List[str]):
133
138
  if test_cmd := self.config.get('test_cmd'):
134
139
  test_cmd = f'{test_cmd} {" ".join(args)}' if args else test_cmd
135
140
  console.info(f'Running tests with: [note]{test_cmd}[/note]')
@@ -73,10 +73,17 @@ def get_package_data(package: str = 'pypas-cli') -> dict[str, str]:
73
73
  return {}
74
74
 
75
75
 
76
- def get_package_info(package: str = 'pypas-cli') -> str:
76
+ def show_package_info(package: str = 'pypas-cli') -> None:
77
77
  if data := get_package_data(package):
78
- return f'Package: {data.get("name")}\nVersion: {data.get("version")}\nPath: {data.get("location")}'
79
- return "Package '{package}' is not already installed."
78
+ console.print(
79
+ dedent(f"""\
80
+ Package: {data.get('name')}
81
+ Version: [note]{data.get('version')}[/note]
82
+ Path: {data.get('location')}\
83
+ """)
84
+ )
85
+ else:
86
+ console.error(f"Package '{package}' is not yet installed")
80
87
 
81
88
 
82
89
  def get_latest_package_version(package: str = 'pypas-cli') -> str | None:
@@ -152,3 +159,25 @@ def unzip(zip_path: Path, extract_to: Path | None = None) -> Path:
152
159
  with zipfile.ZipFile(zip_path, 'r') as zip_ref:
153
160
  zip_ref.extractall(extract_to)
154
161
  return extract_to
162
+
163
+
164
+ def handle_upgrade_pypas():
165
+ latest_version = get_latest_package_version()
166
+ package_data = get_package_data()
167
+ current_version = package_data.get('version')
168
+ # current_version = '0.0.0' # Temporary hardcoded version for testing
169
+ if latest_version and current_version:
170
+ if latest_version != current_version:
171
+ if upgrade_pypas():
172
+ console.success(
173
+ f'Upgraded pypas-cli from [note]v{current_version}[/note] to [note]v{latest_version}[/note]'
174
+ )
175
+ else:
176
+ console.error('Error upgrading pypas')
177
+ else:
178
+ console.success(
179
+ f"You're on the latest version of pypas-cli: [note]v{current_version}[/note]",
180
+ emphasis=False,
181
+ )
182
+ else:
183
+ console.error('Could not determine pypas-cli version information')
@@ -27,7 +27,7 @@ def default(
27
27
  ):
28
28
  if version:
29
29
  sysutils.handle_package_version()
30
- print(sysutils.get_package_info())
30
+ sysutils.show_package_info()
31
31
  # https://typer.tiangolo.com/tutorial/commands/context/#exclusive-executable-callback
32
32
  elif ctx.invoked_subcommand is None:
33
33
  typer.echo(ctx.get_help())
@@ -94,10 +94,7 @@ def auth(token: str = typer.Argument(help='Access token')):
94
94
  @app.command()
95
95
  def upgrade():
96
96
  """Upgrade pypas-cli from PyPI."""
97
- if sysutils.upgrade_pypas():
98
- print(sysutils.get_package_info())
99
- else:
100
- console.error('Error upgrading pypas')
97
+ sysutils.handle_upgrade_pypas()
101
98
 
102
99
 
103
100
  @app.command()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pypas-cli
3
- Version: 0.4.2
3
+ Version: 0.4.4
4
4
  Summary: Python Practical Assignments
5
5
  Author-email: Sergio Delgado Quintero <sdelquin@gmail.com>
6
6
  Maintainer-email: Sergio Delgado Quintero <sdelquin@gmail.com>
File without changes
File without changes
File without changes