Skip to content

Commit 8cf2417

Browse files
author
Jandro
committed
Added help messages to release.py
Added new command "list" to release.py that lists all pypi releases
1 parent 3615076 commit 8cf2417

File tree

1 file changed

+48
-20
lines changed

1 file changed

+48
-20
lines changed

release.py

+48-20
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
import shutil
77
import subprocess
88
import sys
9+
import requests
910
from pathlib import Path
1011

1112
import click
1213

13-
14+
PYPI_PACKAGE_NAME = 'O365'
15+
PYPI_URL = 'https://pypi.org/pypi/{package}/json'
1416
DIST_PATH = 'dist'
1517
DIST_PATH_DELETE = 'dist_delete'
1618
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
@@ -22,7 +24,7 @@ def cli():
2224

2325

2426
@cli.command()
25-
@click.option('--force/--no-force', default=False)
27+
@click.option('--force/--no-force', default=False, help='Will force a new build removing the previous ones')
2628
def build(force):
2729
""" Builds the distribution files: wheels and source. """
2830
dist_path = Path(DIST_PATH)
@@ -41,8 +43,8 @@ def build(force):
4143

4244

4345
@cli.command()
44-
@click.option('--release/--no-release', default=False)
45-
@click.option('--rebuild/--no-rebuild', default=True)
46+
@click.option('--release/--no-release', default=False, help='--release to upload to pypi otherwise upload to test.pypi')
47+
@click.option('--rebuild/--no-rebuild', default=True, help='Will force a rebuild of the build files (src and wheels)')
4648
@click.pass_context
4749
def upload(ctx, release, rebuild):
4850
""" Uploads distribuition files to pypi or pypitest. """
@@ -76,30 +78,56 @@ def check():
7678

7779
subprocess.check_call(['twine', 'check', 'dist/*'])
7880

81+
7982
@cli.command()
80-
@click.option('--annotate/--no-annotate',default=False)
81-
@click.option('--coverage/--no-coverage',default=False)
82-
@click.option('-v/-nv',default=False)
83-
@click.option('-vv/-nvv',default=False)
84-
def test(annotate,coverage,v,vv):
85-
""" runs tests and optionally creates annotated files of coverage. """
86-
args = ["python3","-m","pytest","tests/"]
83+
@click.option('--annotate/--no-annotate', default=False, help='Annotate coverage on files')
84+
@click.option('--coverage/--no-coverage', default=False, help='Run coverage')
85+
@click.option('-v/-nv', default=False, help='Verbose')
86+
@click.option('-vv/-nvv', default=False, help='Very verbose')
87+
def test(annotate, coverage, v, vv):
88+
""" Runs tests and optionally creates annotated files of coverage. """
89+
args = ['python3', '-m', 'pytest', 'tests/']
8790
if coverage:
88-
args.append("--cov=O365")
91+
args.append('--cov=O365')
8992
if annotate:
90-
args.append("--cov-report")
91-
args.append("annotate")
92-
if v:#Verbose
93-
args.append("-v")
94-
if vv and not v:#Very verbose
95-
args.append("-vv")
93+
args.append('--cov-report')
94+
args.append('annotate')
95+
if v: # Verbose
96+
args.append('-v')
97+
if vv and not v: # Very verbose
98+
args.append('-vv')
9699

97100
env = os.environ.copy()
98101

99-
p = subprocess.Popen(args,env=env)
100-
102+
p = subprocess.Popen(args, env=env)
101103
p.wait()
102104

103105

106+
# noinspection PyShadowingBuiltins
107+
@cli.command(name='list')
108+
def list_releases():
109+
""" Lists all releases published on pypi. """
110+
response = requests.get(PYPI_URL.format(package=PYPI_PACKAGE_NAME))
111+
if response:
112+
data = response.json()
113+
114+
releases_dict = data.get('releases', {})
115+
116+
if releases_dict:
117+
for version, release in releases_dict.items():
118+
release_formats = []
119+
published_on_date = None
120+
for fmt in release:
121+
release_formats.append(fmt.get('packagetype'))
122+
published_on_date = fmt.get('upload_time')
123+
124+
release_formats = ' | '.join(release_formats)
125+
print('{:<10}{:>15}{:>25}'.format(version, published_on_date, release_formats))
126+
else:
127+
print('No releases found for {}'.format(PYPI_PACKAGE_NAME))
128+
else:
129+
print('Package "{}" not found on Pypi.org'.format(PYPI_PACKAGE_NAME))
130+
131+
104132
if __name__ == "__main__":
105133
cli()

0 commit comments

Comments
 (0)