Skip to content

Commit

Permalink
Merge pull request #23 from rarylson/develop
Browse files Browse the repository at this point in the history
Minor fix (config file not being closed) and multiple improvements and more automation in the build/publish process
  • Loading branch information
rarylson committed Oct 24, 2022
2 parents 8760c71 + 9bbc5c5 commit 5bb22a0
Show file tree
Hide file tree
Showing 15 changed files with 149 additions and 228 deletions.
7 changes: 0 additions & 7 deletions .coveragerc

This file was deleted.

24 changes: 24 additions & 0 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: build-and-publish

on:
push:
tags: ["v[0-9]+.[0-9]+"]

jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- run: python -m pip install -r requirements-dev.txt
- run: python setup.py sdist bdist_wheel
- run: make check-build
- uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
- uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
12 changes: 6 additions & 6 deletions .github/workflows/test.yml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

jobs:
tests:
Expand All @@ -13,16 +12,17 @@ jobs:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10"]
steps:
- uses: actions/checkout@master
- uses: actions/setup-python@master
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: pip install -r requirements-test.txt
- run: python -m pip install -r requirements-test.txt
# Install `update-conf.py` script to make it available to the
# 'test_script.py' test module.
- run: python setup.py develop
- run: make check && sudo PATH=$PATH make test-with-coverage
- uses: coverallsapp/github-action@master
- run: make check
- run: sudo PATH=$PATH make test-with-coverage
- uses: coverallsapp/github-action@1.1.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage.lcov
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/venv
/README.rst
/tests/tmp
/build
/dist
Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

1.0.2
-----

- **Fix:** Close config file as soon as possible
- Before, we were using `readfp` and keeping the config file opened forever
- Multiple improvements and more automation in the build/publish process
- Notadably, the release process now uses a CI/CD pipeline via Github Actions

1.0.1
-----

Expand All @@ -12,7 +20,7 @@ Changelog
- The global config file (`/etc/update-conf.py.conf`) is not auto-installed when running `python setup.py install` as root anymore;
- Support to Python 2 was removed;
- Code simplified to support only Python 3 (3.7 or newer);
- Switching CI from Travis to GitHub Workflows
- Switching CI from Travis to GitHub Actions

0.4.5
-----
Expand Down
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ When creating a pull request, please follow these guidelines:
```sh
make check
make test # or 'sudo make test' to run all tests
make test-coverage
```

- Push your changes:
Expand All @@ -95,7 +94,7 @@ When creating a pull request, please follow these guidelines:

- Make a pull request comparing your new branch with the project develop branch;
- Verify if your code works for all supported Python versions;
- You can check [update-conf.py - GitHub - Actions](https://github.com/rarylson/update-conf.py/actions/workflows/test.yml) for troubleshooting if necessary.
- You can check [update-conf.py - GitHub Actions](https://github.com/rarylson/update-conf.py/actions/workflows/tests.yml) for troubleshooting if necessary.

If you follow all the previous guidelines, you're really an angel :angel: :+1:!

Expand Down
4 changes: 1 addition & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
# don't know if it is a bug. Anyway, we're adding it into our 'MANIFEST.in'.
# See: https://pythonhosted.org/setuptools/setuptools.html
# https://docs.python.org/2/distutils/sourcedist.html
include Makefile
include LICENSE
include .coveragerc
include *.md
include *.txt
recursive-include samples *
recursive-include tests *
global-exclude tests/tmp/*
global-exclude *.rst
global-exclude *.pyc
exclude Makefile
152 changes: 70 additions & 82 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ PREFIX=/usr/local
ETC=/etc
VENV=venv
TEST_PACKAGE=tests

VERSION=$(shell python setup.py --version)


Expand All @@ -15,30 +16,43 @@ all: help
help:
@echo "Usage:"
@echo
@echo " make install install project in system (global)"
@echo " make uninstall show tips for uninstalling"
@echo " make check check PEP8 compliance (and others)"
@echo " make test run tests (use 'sudo' to run all)"
@echo " make check-coverage run tests and check coverage (use 'sudo' to run all)"
@echo " make clean cleanup temporary files"
@echo " make install-develop install project in develop mode (virtual environment)"
@echo " make develop-deps-ubuntu install software dependencies (valid only in Ubuntu)"
@echo " make develop-deps-macos install software dependencies (valid only in MacOS if using Homebrew)"
@echo " make prepare prepare stuff (build, dist, etc) before publishing"
@echo " make publish-test test publishing a version (PyPI Test)"
@echo " make install-pypitest test install project (from PyPI Test)"
@echo " make publish publish a version (GitHub / PyPI)"


# Tests
@echo " make install install project in system (global)"
@echo " make install-develop install project in develop mode (virtual env with test and build tools)"
@echo " make check run checks (like PEP8 compliance)"
@echo " make test run tests (use 'sudo' to run all)"
@echo " make test-with-coverage run tests with coverage (use 'sudo' to run all)"
@echo " make coverage-report generate coverage report in html"
@echo " make build build (sdist and bdist_wheel)"
@echo " make check-and-test-publish run checks and test the process of publishing a version (using Test PyPI)"
@echo " make tag-for-publish push tag version on GitHub (which triggers the CI/CD pipeline to publish the version on PyPI"
@echo " make clean cleanup temporary files"


# Install

install:
python setup.py install


# Development

install-develop:
python3 -m venv $(VENV)
. $(VENV)/bin/activate && python -m pip install -r requirements-dev.txt
. $(VENV)/bin/activate && python setup.py develop
@echo
@echo "Environment setup done. Remember to activate your virtual env."
@echo
@tput setaf 2
@echo " . $(VENV)/bin/activate"
@tput sgr0


# Tests and checks

check:
CHECK_MANIFEST=True check-manifest
# Ignore 'N802' (function name should be lowercase) in tests because we need
# to inherit from the unittest class (that defines the setUp / tearDown
# functions). Ignore 'W503' (line break occurred before a binary operator)
# because it's now deprecated and PEP8 is recommending the opposite.
flake8 --ignore=N802,W503 $(TEST_PACKAGE)
check-manifest
flake8 $(PACKAGE) $(TEST_PACKAGE)

test:
python setup.py test
Expand All @@ -47,7 +61,7 @@ test-with-coverage:
coverage run setup.py test
coverage lcov

check-coverage: test-with-coverage
coverage-report:
coverage html
@echo
@echo "Check coverage results at"
Expand All @@ -58,89 +72,63 @@ check-coverage: test-with-coverage
@echo
cd htmlcov && python -m http.server

check-build:
check-wheel-contents dist/*.whl
python -m twine check dist/*

# Install

# setup.py does not have an uninstall command. We're only showing a tip.
# See: http://stackoverflow.com/a/1550235/2530295
uninstall:
@echo "'setup.py' does not have a uninstall command."
@echo "You can run the follow command to get a list of installed files and "
@echo "then removing them:"
@echo
@echo " python setup.py install --record files.txt"
@echo
@echo "It's also a good practice using 'pip' in a production env."

install:
python setup.py install


# Development
install-from-testpipy:
python3 -m venv $(VENV)
. $(VENV)/bin/activate && python -m pip install -i https://test.pypi.org/simple/ $(NAME)==$(VERSION)

develop-deps-ubuntu:
apt-get install -y pandoc

develop-deps-macos:
brew install pandoc
# Build

install-develop:
virtualenv $(VENV)
. $(VENV)/bin/activate && pip install --upgrade pip
. $(VENV)/bin/activate && pip install -r requirements-dev.txt
. $(VENV)/bin/activate && python setup.py develop
build: clean-build clean-dist
python setup.py sdist bdist_wheel

install-pypitest:
virtualenv $(VENV)
. $(VENV)/bin/activate && pip install \
--index-url https://test.pypi.org/simple/ $(NAME)==$(VERSION)

# Test publish

# Publish (release)
publish-testpypi:
twine upload -r testpypi dist/*

prepare:
python setup.py generate_rst
python setup.py sdist
python setup.py bdist_wheel
check-and-test-publish: build check-build publish-testpypi
@echo
@echo "Test of publishing on Test PyPI done. If necessary, remember to test install from Test PyPI."
@echo
@tput setaf 2
@echo " deactivate"
@echo " rm -Rf $(VENV)"
@echo " make install-from-testpypi"
@tput sgr0

# To use this command, you should have pypitest configured in your ~/.pypirc.
publish-pypitest: prepare
twine upload --repository testpypi dist/*

publish-pypi: prepare
twine upload dist/*
# Tag for publish

publish-github:
# It will trigger a CI/CD pipeline that will ending up on publishing on PyPI.
tag-for-publish:
git tag "v$(VERSION)"
git push origin "v$(VERSION)"

check-publish-test:
pip index versions --index https://testpypi.python.org/pypi/ $(NAME) | grep -o "Available versions: $(VERSION)"

check-publish:
pip index versions $(NAME) | grep -o "Available versions: $(VERSION)"

publish-test: publish-pypitest check-publish-test

publish: publish-github publish-pypi check-publish


# Clean

clean-rst:
rm -f README.rst

clean-build:
rm -Rf build/
rm -Rf dist/
python setup.py clean --all

clean-dist:
rm -Rf dist

clean-egg:
rm -Rf *.egg-info
rm -Rf .eggs

clean-coverage-report:
clean-coverage:
rm -f .coverage
rm -f coverage.lcov
rm -Rf htmlcov

clean-pyc:
find . -name "*.pyc" -type f -delete

clean: clean-rst clean-build clean-coverage-report clean-pyc
clean: clean-build clean-dist clean-egg clean-coverage clean-pyc

0 comments on commit 5bb22a0

Please sign in to comment.