pypas-cli 0.0.2__tar.gz → 0.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.
@@ -2,3 +2,6 @@ dist
2
2
  *.egg-info
3
3
  *.pyc
4
4
  .python-version
5
+ .DS_Store
6
+ .env
7
+ .sandbox
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pypas-cli
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: Python Practical Assignments
5
5
  Project-URL: homepage, https://pypas.es
6
6
  Project-URL: repository, https://github.com/sdelquin/pypas-cli
@@ -33,7 +33,12 @@ Classifier: License :: OSI Approved :: MIT License
33
33
  Classifier: Operating System :: OS Independent
34
34
  Classifier: Programming Language :: Python :: 3
35
35
  Requires-Python: >=3.10
36
+ Requires-Dist: prettyconf
37
+ Requires-Dist: pytest
38
+ Requires-Dist: requests
39
+ Requires-Dist: rich
36
40
  Requires-Dist: setuptools
41
+ Requires-Dist: tqdm
37
42
  Requires-Dist: typer
38
43
  Description-Content-Type: text/markdown
39
44
 
@@ -4,9 +4,17 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "pypas-cli"
7
- version = "0.0.2"
7
+ version = "0.0.3"
8
8
  license = { file = "LICENSE" }
9
- dependencies = ['setuptools', 'typer']
9
+ dependencies = [
10
+ 'setuptools',
11
+ 'typer',
12
+ 'prettyconf',
13
+ 'requests',
14
+ 'rich',
15
+ 'tqdm',
16
+ 'pytest',
17
+ ]
10
18
  authors = [
11
19
  { email = "sdelquin@gmail.com" },
12
20
  { name = "Sergio Delgado Quintero" },
@@ -0,0 +1,13 @@
1
+ from rich.console import Console
2
+ from rich.theme import Theme
3
+
4
+ custom_theme = Theme(
5
+ {
6
+ 'info': 'cyan',
7
+ 'warning': 'yellow',
8
+ 'danger': 'bold red',
9
+ 'success': 'bold green',
10
+ }
11
+ )
12
+
13
+ console = Console(theme=custom_theme)
@@ -0,0 +1,23 @@
1
+ import tempfile
2
+ from pathlib import Path
3
+
4
+ import requests
5
+ from tqdm import tqdm
6
+
7
+
8
+ def download(url: str, fname: str, save_temp=False, chunk_size=1024) -> Path:
9
+ # https://gist.github.com/yanqd0/c13ed29e29432e3cf3e7c38467f42f51
10
+ if save_temp:
11
+ tmp_file = tempfile.NamedTemporaryFile(delete=False)
12
+ target_file = tmp_file.name
13
+ else:
14
+ target_file = fname
15
+ resp = requests.get(url, stream=True)
16
+ total = int(resp.headers.get('content-length', 0))
17
+ with open(target_file, 'wb') as file, tqdm(
18
+ desc=fname, total=total, unit='iB', unit_scale=True, unit_divisor=1024
19
+ ) as bar:
20
+ for data in resp.iter_content(chunk_size=chunk_size):
21
+ size = file.write(data)
22
+ bar.update(size)
23
+ return Path(target_file)
@@ -0,0 +1,40 @@
1
+ import os
2
+ import zipfile
3
+ from urllib.parse import urljoin
4
+
5
+ import typer
6
+ from rich import print
7
+
8
+ from pypas import settings
9
+ from pypas.lib import utils
10
+ from pypas.lib.console import console
11
+
12
+ app = typer.Typer(
13
+ add_completion=False,
14
+ help='✨ pypas',
15
+ no_args_is_help=True,
16
+ )
17
+
18
+
19
+ @app.command()
20
+ def run():
21
+ print('Hi there!')
22
+
23
+
24
+ @app.command()
25
+ def get(exercise_slug: str):
26
+ exercise_url = urljoin(settings.PYPAS_EXERCISES_URLPATH, exercise_slug + '/')
27
+ console.print(f'Getting exercise from: {exercise_url}')
28
+ fname = utils.download(exercise_url, f'{exercise_slug}.zip', save_temp=True)
29
+ console.print('Inflating exercise bundle', end=' ')
30
+ with zipfile.ZipFile(fname) as zip_ref:
31
+ zip_ref.extractall()
32
+ console.print('✔', style='success')
33
+ os.remove(fname)
34
+ console.print(
35
+ f'Exercise is available at folder [info]./{exercise_slug}[/info] [success]✔[/success]'
36
+ )
37
+
38
+
39
+ if __name__ == '__main__':
40
+ app()
@@ -0,0 +1,6 @@
1
+ from urllib.parse import urljoin
2
+
3
+ from prettyconf import config
4
+
5
+ PYPAS_BASE_URL = config('PYPAS_BASE_URL', default='https://pypas.es/')
6
+ PYPAS_EXERCISES_URLPATH = urljoin(PYPAS_BASE_URL, '/exercises/')
@@ -1,16 +0,0 @@
1
- import typer
2
-
3
- app = typer.Typer(
4
- add_completion=False,
5
- help='✨ pypas',
6
- no_args_is_help=True,
7
- )
8
-
9
-
10
- @app.command()
11
- def run():
12
- print('Hi there!')
13
-
14
-
15
- if __name__ == '__main__':
16
- app()
File without changes
File without changes
File without changes
File without changes