forked from spacether/pycalculix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
A_MAKE_DIST.py
93 lines (77 loc) · 3.02 KB
/
A_MAKE_DIST.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""
This file makes distributable packages in the zip file format
It deletes folders before making them, then does cleanup after it's done
Results:
dist folder
Has the pyalculix zip file one installs with pip
examples folder
Has the example py files only
pycalculix
Source code for the distribution, and binaries of gmsh and calculix
"""
import shutil # needed for folder removel(cleanum) and making zip file
import subprocess # needed to call python setup.py to make distribution
import os #check if folder exists
distrib = 'pycalculix'
runstr = input('Make the distribution? (Y/y) ')
if runstr in ['Y','y']:
# remove folders before making them
folders_to_rem = ['dist', '%s.egg-info' % (distrib)]
for fold in folders_to_rem:
if os.path.isdir(fold):
print ('Deleting folder: '+fold)
shutil.rmtree(fold)
# call python
subprocess.call("python setup.py sdist --formats=zip", shell=True)
# delete egg-info folder
folders_to_rem = ['%s.egg-info' % (distrib)]
for fold in folders_to_rem:
if os.path.isdir(fold):
print ('Deleting folder: '+fold)
shutil.rmtree(fold)
# clean up the examples folder
folder_to_clean = 'examples'
print('Cleaning folder: '+folder_to_clean)
for f in os.listdir(folder_to_clean):
f = os.path.join(folder_to_clean, f)
ext = os.path.splitext(f)[1]
if ext not in ['.py', '.pdf', '.dxf']:
os.remove(f)
# zip the examples directory
fromdir = 'examples'
tofile = 'dist/examples'
shutil.make_archive(tofile, 'zip', fromdir)
# make documentation, zip it and move it into the dist folder
import A_MAKE_DOC as docmake
fromdir = '../pycalculix_docs'
tofile = 'dist/documentation'
shutil.make_archive(tofile, 'zip', fromdir)
# overwrite current installation?
over = input('Overwrite the current installation? (Y/y) ')
if over in ['Y','y']:
# check if the package is installed
import pip
installed_packs = pip.get_installed_distributions()
installed_packs = [ i.key for i in installed_packs ] #get names
if distrib in installed_packs:
print('Uninstalling...')
runstr = "pip uninstall -y %s" % (distrib)
subprocess.call(runstr, shell=True)
else:
print('The library has not been installed yet')
#install the library
print('Installing...')
zipfile = os.listdir('dist')
for fname in zipfile:
if distrib in fname:
zipfile = os.path.join('dist',fname)
subprocess.call("pip install %s" % (zipfile), shell=True)
# remove __pycache__ folder
folders_to_rem = ['__pycache__']
for fold in folders_to_rem:
if os.path.isdir(fold):
print ('Deleting folder: '+fold)
shutil.rmtree(fold)
else:
print ('User chose not to make distribution')
input('Press enter to exit 0_MAKE_DIST.py ')