Skip to content

Commit

Permalink
Automate release workflow on Windows too.
Browse files Browse the repository at this point in the history
I initially hoped to have a single Makefile or script that
worked on Linux and Windows, but was unable to make it work
without massive over-complication.

So now we have makefile targets for Linux, and powershell
scripts for Windows. Documented in the README.
  • Loading branch information
tartley committed Oct 13, 2020
1 parent f14fc0b commit 6e5fef2
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 12 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
*.egg-info
.coverage
.tox/
MANIFEST
dist
tags
/MANIFEST
/build/
/dist/
/sandbox/
/tags
virtualenv
build

# PyCharm
.idea
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ clean: ## Remove build artifacts, .pyc files, virtualenv

$(virtualenv):
$(syspython) -m venv --clear $(virtualenv)
$(pip) install --upgrade pip

venv: $(virtualenv) ## Create or clear a virtualenv
.PHONY: venv
Expand Down Expand Up @@ -58,7 +59,7 @@ test-release: build
./test-release
.PHONY: test-release

upload: ## Upload our sdist and wheel
release: ## Upload our sdist and wheel
$(twine) upload dist/colorama-$(version)-*
.PHONY: release

34 changes: 31 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,43 @@ Help and fixes welcome!

Tested on CPython 2.7, 3.5, 3.6, 3.7 and 3.8.

No requirements. Development requirements are captured in requirements-dev.txt.
No requirements other than the standard library.
Development requirements are captured in requirements-dev.txt.

Tests are written using standard library ``unittest``. To run them, see
Makefile target 'test', along with a few other handy commands.
To create and populate a virtual environment::

./bootstrap.ps1 # Windows
make bootstrap # Linux

To run tests::

./test.ps1 # Windows
make test # Linux

If you use nose to run the tests, you must pass the ``-s`` flag; otherwise,
``nosetests`` applies its own proxy to ``stdout``, which confuses the unit
tests.

To build a local wheel file::

./build.ps1 # Windows
make build # Linux

To test the wheel, (upload to test PyPI, then 'pip install' & use it)::

./test-release.ps1 # Windows
make test-release # Linux

To upload the wheel to PyPI::

./release.ps1 # Windows
make release # Linux

To clean all generated files, builds, virtualenv::

./clean.ps1 # Windows
make clean # Linux


Professional support
--------------------
Expand Down
9 changes: 9 additions & 0 deletions bootstrap.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$syspython="python3.8.exe"
$ve="$HOME\.virtualenvs\colorama"
$bin="$ve\Scripts"

echo "Create $syspython virtualenv $ve"
& $syspython -m venv --clear "$ve"
& $bin\python.exe -m pip install --upgrade pip
& $bin\python.exe -m pip install -r requirements.txt -r requirements-dev.txt

6 changes: 6 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$ve="$HOME\.virtualenvs\colorama"
$bin="$ve\Scripts"

& $bin\python.exe -m pip install --upgrade setuptools wheel
& $bin\python.exe setup.py sdist bdist_wheel

6 changes: 6 additions & 0 deletions clean.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$syspython="python3.8.exe"
$ve="$HOME\.virtualenvs\colorama"

remove-item -r -fo * -I build,dist,MANIFEST,colorama.egg-info,$ve,sandbox
& $syspython -Bc "import pathlib, shutil; [shutil.rmtree(p) for p in pathlib.Path('.').rglob('__pycache__')]"

7 changes: 7 additions & 0 deletions release.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$ve="$HOME\.virtualenvs\colorama"
$bin="$ve\Scripts"
$version="$(& $bin\python.exe setup.py --version)"

# Upload to PyPI.
& $bin\twine.exe upload dist\colorama-$version-*

8 changes: 4 additions & 4 deletions test-release
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bin="$HOME/.virtualenvs/colorama/bin"
version=$($bin/python setup.py --version)
sandbox=test-release-playground

# Upload to the test pypi.
# Upload to the test PyPI.
$bin/twine upload --repository testpypi dist/colorama-$version-* \
|| echo " > Expect a 400 if package was already uploaded."

Expand All @@ -27,13 +27,13 @@ mkdir -p $sandbox
(
cd $sandbox

# Create a new virtualenv
# Create a temporary disposable virtualenv.
$syspython -m venv --clear venv

# Install the package we just uploaded
# Install the package we just uploaded.
venv/bin/python -m pip --quiet install --index-url https://test.pypi.org/simple colorama==$version

# Test the package can be imported
# Import and use Colorama from the temp virtualenv.
venv/bin/python -c "import colorama; colorama.init(); print(colorama.Fore.GREEN + \"OK: Colorama\", colorama.__version__, \"from test pypi install.\")"
)

Expand Down
29 changes: 29 additions & 0 deletions test-release.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
$syspython="python3.8.exe"
$ve="$HOME\.virtualenvs\colorama"
$bin="$ve\Scripts"
$version="$(& $bin\python.exe setup.py --version)"

# Upload to the test PyPI.
& $bin\twine.exe upload --repository testpypi dist\colorama-$version-*
if(!$?) {
write-host " > Expect a 400 if package was already uploaded"
}

# cd elsewhere so we cannot import from local source.
mkdir -force sandbox | out-null
cd sandbox

# Create a temporary disposable virtualenv.
& $syspython -m venv --clear venv

# Install the package we just uploaded.
venv\Scripts\python -m pip --quiet install --index-url https://test.pypi.org/simple colorama==$version
# Import and use colorama from the temp virtualenv.
venv\Scripts\python.exe -c @"
import colorama;
colorama.init();
print(colorama.Fore.GREEN + ""OK Colorama "" + colorama.__version__ + "" from test pypi install."")
"@

cd ..

5 changes: 5 additions & 0 deletions test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$ve="$HOME\.virtualenvs\colorama"
$bin="$ve\Scripts"

& $bin\python.exe -m unittest discover -p *_test.py

0 comments on commit 6e5fef2

Please sign in to comment.