6
6
import shutil
7
7
import subprocess
8
8
import sys
9
+ import requests
9
10
from pathlib import Path
10
11
11
12
import click
12
13
13
-
14
+ PYPI_PACKAGE_NAME = 'O365'
15
+ PYPI_URL = 'https://pypi.org/pypi/{package}/json'
14
16
DIST_PATH = 'dist'
15
17
DIST_PATH_DELETE = 'dist_delete'
16
18
CONTEXT_SETTINGS = dict (help_option_names = ['-h' , '--help' ])
@@ -22,7 +24,7 @@ def cli():
22
24
23
25
24
26
@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' )
26
28
def build (force ):
27
29
""" Builds the distribution files: wheels and source. """
28
30
dist_path = Path (DIST_PATH )
@@ -41,8 +43,8 @@ def build(force):
41
43
42
44
43
45
@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)' )
46
48
@click .pass_context
47
49
def upload (ctx , release , rebuild ):
48
50
""" Uploads distribuition files to pypi or pypitest. """
@@ -76,30 +78,56 @@ def check():
76
78
77
79
subprocess .check_call (['twine' , 'check' , 'dist/*' ])
78
80
81
+
79
82
@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/' ]
87
90
if coverage :
88
- args .append (" --cov=O365" )
91
+ args .append (' --cov=O365' )
89
92
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' )
96
99
97
100
env = os .environ .copy ()
98
101
99
- p = subprocess .Popen (args ,env = env )
100
-
102
+ p = subprocess .Popen (args , env = env )
101
103
p .wait ()
102
104
103
105
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
+
104
132
if __name__ == "__main__" :
105
133
cli ()
0 commit comments