""" File unrelated to the package, except for convenience in deploying """
import re
import sh
import os

commit_count = sh.git('rev-list', ['--all']).count('\n')

with open('setup.py') as f:
    setup = f.read()

setup = re.sub("MICRO_VERSION = '[0-9]+'", "MICRO_VERSION = '{}'".format(commit_count), setup)

major = re.search("MAJOR_VERSION = '([0-9]+)'", setup).groups()[0]
minor = re.search("MINOR_VERSION = '([0-9]+)'", setup).groups()[0]
micro = re.search("MICRO_VERSION = '([0-9]+)'", setup).groups()[0]
version = '{}.{}.{}'.format(major, minor, micro)

with open('setup.py', 'w') as f:
    f.write(setup)

with open('yagmail/__init__.py') as f:
    init = f.read()

with open('yagmail/__init__.py', 'w') as f:
    f.write(
        re.sub('__version__ = "[0-9.]+"',
               '__version__ = "{}"'.format(version), init))

py_version = "python3.7" if sh.which("python3.7") is not None else "python"
os.system('{} setup.py sdist bdist_wheel upload'.format(py_version))

@@ -125,17 +125,17 @@
 git(
-'
+%22
 rev-list
 ', %5B
@@ -134,19 +134,19 @@
 list
-', %5B'
+%22, %5B%22
 --all
-'
+%22
 %5D).c
@@ -154,12 +154,12 @@
 unt(
-'%5Cn'
+%22%5Cn%22
 )%0A%0Aw
@@ -167,25 +167,25 @@
 th open(
-'
+%22
 setup.py
 ') as f:
@@ -176,17 +176,17 @@
 setup.py
-'
+%22
 ) as f:%0A
@@ -518,17 +518,17 @@
 n = 
-'
+%22
 %7B%7D.%7B%7D.%7B%7D
 '.fo
@@ -523,17 +523,17 @@
 %7B%7D.%7B%7D.%7B%7D
-'
+%22
 .format(
@@ -568,17 +568,17 @@
 pen(
-'
+%22
 setup.py
 ', '
@@ -573,22 +573,22 @@
 setup.py
-', 'w'
+%22, %22w%22
 ) as f:%0A
@@ -609,33 +609,33 @@
 tup)%0A%0Awith open(
-'
+%22
 yagmail/__init__
@@ -637,17 +637,17 @@
 nit__.py
-'
+%22
 ) as f:%0A
@@ -677,17 +677,17 @@
 th open(
-'
+%22
 yagmail/
@@ -701,14 +701,14 @@
 _.py
-', 'w'
+%22, %22w%22
 ) as
@@ -723,25 +723,16 @@
 f.write(
-%0A        
 re.sub('
@@ -760,23 +760,8 @@
 +%22',
-%0A              
  '__
@@ -827,63 +827,35 @@
 thon
-3.7%22 if sh.which(%22python3.7%22) is not None else %22python%22
+%22%0Aos.system(%22rm -rf dist/%22)
 %0Aos.
@@ -861,17 +861,17 @@
 .system(
-'
+%22
 %7B%7D setup
@@ -895,16 +895,9 @@
 heel
- upload'
+%22
 .for
@@ -913,8 +913,41 @@
 rsion))%0A
+os.system(%22twine upload dist/*%22)%0A

update deploy script