Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jan 21, 2019
2 parents 32953e1 + 4310c97 commit 5d0ff09
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 106 deletions.
19 changes: 7 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@ jobs:
- stage: deploy
if: tag IS present
python: *latest_py3
install: skip
script: skip
deploy:
provider: pypi
on:
tags: true
all_branches: true
user: jaraco
password:
secure: ieliSqIQhbLtQFH9MQhh/kYY/Xjv2Bf3nyNjtjSfLjhgjKi/uzO9+UyTHV7BB4hL8NrrE+W/nAD1O+/h8CS1HUK/Lat0GoFTj8jvYyK3sDXvUxY5j3OMn0wyYq78r1ryaeB0yIC0h0DVVVUKVeBGOkGHY1uWre5XFalgZipMyz7ELwdEX37dMQJ7wLeEH2ZHV5S0Up/uDCMqP4TN3VjNhFNCoCnkDaH7O6uDY+pQ01LOJHpE95VdvgyApm7+vX5Xr9DOXkqsymArA4/97sDZVxis3jtt6stuazyHJtL9dh9Y73J4csjDbcu/4sQLnx7Yonh9i6MJgPTXZjQjF5lnCixFMMYYToWChhUJA8QsTEHQ+e3mFhmMkcCcBAodkp/INd5+sfJs/FF12mZlKiX7nQZNqwiEA8xjpM1JchHgf+7MOurQdWbCJVLd63qG1U87CgORbtXdv0xzcJ/KBMiKvXUcezBuPVU9XktJVkDQPUeV2V3Sj7RUh3MzAEwYEsyyubRcUTQzWwE2i8J1f4/6KdhSR6iBOQG8htOj2ER5/5T4OxHVZN40h1hDn9i0Zf+wULOxXIfH+FPhTm9TEgCJ9U0RSGIivR9QjFo23AGvHCXuXmLlaZK9SAeutMaCcit8yul3VoaQxoJyBXpaZoNmb27BloxcqJg6ruoQTT3lVJ4=
distributions: dists
skip_cleanup: true
before_script: skip
env:
- TWINE_USERNAME=jaraco
# TWINE_PASSWORD
- secure: hXvC5+Nh3IZ+P9a4/duh6tVXF0YVm/QfpgfWrtEu3Me1fRpnBOn6akx+IbjgSnSGQti2v8SNG2EyBx9W756TSfXdBQIP51cassFXR+5B5ZS4pQJM57NJd3L9/cP8YNyU75NcFVSz5jlQw9au40NtjIouxvsAaU2ptuBryJSYsp+E7wEpBU3cGrpeDgMDjqW836lUb3UU/N9npZ03jD+qEjrNdDeegrYe87MDJcOGGy2XRpOcsQjQ9UDDfo8AB+7zWFBmqB6mXnpm2Gvg6SKBajT+VrHp8ncWKd2gIm59m10WKjORUhTs60OZuHz0JfraRzDcTbKjkk4ddiUQxMM7vXkMMiN2UW7LDP+5oatfo+KFc3hZ4e3a+B8sKPNSd1xGica2ha6ac7DViq20I3CHpq+nGtPF1izEjtaENon8Qn3w0srYa5hmf2UwwFR9du2HrThHyXXXZO2/s9/hRJVj4ELbgP/3H701P+wCmKuBnT7skGX0boxnWF/9/S3+xL2vHRFu1jNLMTMl0uT2DNFM/D1grVzswSr437iRSyoNeIZyqMQFXxMUTsnYIZSv+EvKoLLD1czQ74UUDoQBIJk2yEFZyMNdB7jTSfVaTJGNYf45Qkw/lcrFoTbrFwm636ev/6y+/8qEppsp9KSI61qkLyt3aA+7Dg9GTbHoBcu5cd4=
- TOX_TESTENV_PASSENV="TWINE_USERNAME TWINE_PASSWORD"
script: tox -e release

cache: pip

Expand Down
44 changes: 19 additions & 25 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

extensions = [
'sphinx.ext.autodoc',
'jaraco.packaging.sphinx',
'rst.linker',
]
extensions = ["sphinx.ext.autodoc", "jaraco.packaging.sphinx", "rst.linker"]

master_doc = 'index'
master_doc = "index"

link_files = {
'../CHANGES.rst': dict(
using=dict(
GH='https://github.com',
),
replace=[
dict(
pattern=r'(Issue #|\B#)(?P<issue>\d+)',
url='{package_url}/issues/{issue}',
),
dict(
pattern=r'^(?m)((?P<scm_version>v?\d+(\.\d+){1,2}))\n[-=]+\n',
with_scm='{text}\n{rev[timestamp]:%d %b %Y}\n',
),
dict(
pattern=r'PEP[- ](?P<pep_number>\d+)',
url='https://www.python.org/dev/peps/pep-{pep_number:0>4}/',
),
],
),
"../CHANGES.rst": dict(
using=dict(GH="https://github.com"),
replace=[
dict(
pattern=r"(Issue #|\B#)(?P<issue>\d+)",
url="{package_url}/issues/{issue}",
),
dict(
pattern=r"^(?m)((?P<scm_version>v?\d+(\.\d+){1,2}))\n[-=]+\n",
with_scm="{text}\n{rev[timestamp]:%d %b %Y}\n",
),
dict(
pattern=r"PEP[- ](?P<pep_number>\d+)",
url="https://www.python.org/dev/peps/pep-{pep_number:0>4}/",
),
],
)
}
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[build-system]
requires = ["setuptools>=30.3", "wheel", "setuptools_scm>=1.15"]
requires = ["setuptools>=34.4", "wheel", "setuptools_scm>=1.15"]
build-backend = "setuptools.build_meta"
7 changes: 7 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@
norecursedirs=dist build .tox .eggs
addopts=--doctest-modules --flake8
doctest_optionflags=ALLOW_UNICODE ELLIPSIS
filterwarnings=
ignore:Possible nested set::pycodestyle:113
ignore:Using or importing the ABCs::flake8:410
# workaround for https://sourceforge.net/p/docutils/bugs/348/
ignore:'U' mode is deprecated::docutils.io
# workaround for https://gitlab.com/pycqa/flake8/issues/275
ignore:You passed a bytestring as `filenames`.::flake8
44 changes: 41 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,9 +1,47 @@
[aliases]
dists = clean --all sdist bdist_wheel

[bdist_wheel]
universal = 1

[metadata]
license_file = LICENSE
name = rst.linker
author = Jason R. Coombs
author_email = jaraco@jaraco.com
description = Tools for adding metadata and hyperlinks to reStructuredText
long_description = file:README.rst
url = https://github.com/jaraco/rst.linker
classifiers =
Development Status :: 5 - Production/Stable
Intended Audience :: Developers
License :: OSI Approved :: MIT License
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Framework :: Sphinx :: Extension

[options]
packages = find:
include_package_data = true
python_requires = >=2.7
install_requires =
six
python-dateutil
setup_requires = setuptools_scm >= 1.15.0

[options.extras_require]
testing =
# upstream
pytest >= 3.5, !=3.7.3
pytest-checkdocs
pytest-flake8

# local
path.py

docs =
# upstream
sphinx
jaraco.packaging >= 3.2
rst.linker >= 1.9

# local

[options.entry_points]
66 changes: 2 additions & 64 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,6 @@
#!/usr/bin/env python

# Project skeleton maintained at https://github.com/jaraco/skeleton

import setuptools

name = 'rst.linker'
description = ''
nspkg_technique = 'native'
"""
Does this package use "native" namespace packages or
pkg_resources "managed" namespace packages?
"""

params = dict(
name=name,
use_scm_version=True,
author="Jason R. Coombs",
author_email="jaraco@jaraco.com",
description=description or name,
url="https://github.com/jaraco/" + name,
packages=setuptools.find_packages(),
include_package_data=True,
namespace_packages=(
name.split('.')[:-1] if nspkg_technique == 'managed'
else []
),
python_requires='>=2.7',
install_requires=[
'six',
'python-dateutil',
],
extras_require={
'testing': [
# upstream
'pytest>=3.5,!=3.7.3',
'pytest-sugar>=0.9.1',
'collective.checkdocs',
'pytest-flake8',

# local
'path.py',
],
'docs': [
# upstream
'sphinx',
'jaraco.packaging>=3.2',
'rst.linker>=1.9',

# local
],
},
setup_requires=[
'setuptools_scm>=1.15.0',
],
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Framework :: Sphinx :: Extension",
],
entry_points={
},
)
if __name__ == '__main__':
setuptools.setup(**params)
if __name__ == "__main__":
setuptools.setup(use_scm_version=True)
126 changes: 126 additions & 0 deletions skeleton.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Overview

This project is merged with [skeleton](https://github.com/jaraco/skeleton). What is skeleton? It's the scaffolding of a Python project jaraco [introduced in his blog](https://blog.jaraco.com/a-project-skeleton-for-python-projects/). It seeks to provide a means to re-use techniques and inherit advances when managing projects for distribution.

## An SCM Managed Approach

While maintaining dozens of projects in PyPI, jaraco derives best practices for project distribution and publishes them in the [skeleton repo](https://github.com/jaraco/skeleton), a git repo capturing the evolution and culmination of these best practices.

It's intended to be used by a new or existing project to adopt these practices and honed and proven techniques. Adopters are encouraged to use the project directly and maintain a small deviation from the technique, make their own fork for more substantial changes unique to their environment or preferences, or simply adopt the skeleton once and abandon it thereafter.

The primary advantage to using an SCM for maintaining these techniques is that those tools help facilitate the merge between the template and its adopting projects.

# Usage

## new projects

To use skeleton for a new project, simply pull the skeleton into a new project:

```
$ git init my-new-project
$ cd my-new-project
$ git pull gh://jaraco/skeleton
```

Now customize the project to suit your individual project needs.

## existing projects

If you have an existing project, you can still incorporate the skeleton by merging it into the codebase.

```
$ git merge skeleton --allow-unrelated-histories
```

The `--allow-unrelated-histories` is necessary because the history from the skeleton was previously unrelated to the existing codebase. Resolve any merge conflicts and commit to the master, and now the project is based on the shared skeleton.

## Updating

Whenever a change is needed or desired for the general technique for packaging, it can be made in the skeleton project and then merged into each of the derived projects as needed, recommended before each release. As a result, features and best practices for packaging are centrally maintained and readily trickle into a whole suite of packages. This technique lowers the amount of tedious work necessary to create or maintain a project, and coupled with other techniques like continuous integration and deployment, lowers the cost of creating and maintaining refined Python projects to just a few, familiar git operations.

Thereafter, the target project can make whatever customizations it deems relevant to the scaffolding. The project may even at some point decide that the divergence is too great to merit renewed merging with the original skeleton. This approach applies maximal guidance while creating minimal constraints.

# Features

The features/techniques employed by the skeleton include:

- PEP 517/518 based build relying on setuptools as the build tool
- setuptools declarative configuration using setup.cfg
- tox for running tests
- A README.rst as reStructuredText with some popular badges, but with readthedocs and appveyor badges commented out
- A CHANGES.rst file intended for publishing release notes about the project.

## Packaging Conventions

A pyproject.toml is included to enable PEP 517 and PEP 518 compatibility and declares the requirements necessary to build the project on setuptools (a minimum version compatible with setup.cfg declarative config).

The setup.cfg file implements the following features:

- Assumes universal wheel for release
- Advertises the project's LICENSE file (MIT by default)
- Reads the README.rst file into the long description
- Some common Trove classifiers
- Includes all packages discovered in the repo
- Data files in the package are also included (not just Python files)
- Declares the required Python versions
- Declares install requirements (empty by default)
- Declares setup requirements for legacy environments
- Supplies two 'extras':
- testing: requirements for running tests
- docs: requirements for building docs
- these extras split the declaration into "upstream" (requirements as declared by the skeleton) and "local" (those specific to the local project); these markers help avoid merge conflicts
- Placeholder for defining entry points

Additionally, the setup.py file declares `use_scm_version` which relies on [setuptools_scm](https://pypi.org/project/setuptools_scm) to do two things:

- derive the project version from SCM tags
- ensure that all files committed to the repo are automatically included in releases

## Running Tests

The skeleton assumes the developer has [tox](https://pypi.org/project/tox) installed. The developer is expected to run `tox` to run tests on the current Python version using [pytest](https://pypi.org/project/pytest).

Other environments (invoked with `tox -e {name}`) supplied include:

- a `build-docs` environment to build the documentation
- a `release` environment to publish the package to PyPI

A pytest.ini is included to define common options around running tests. In particular:

- rely on default test discovery in the current directory
- avoid recursing into common directories not containing tests
- run doctests on modules and invoke flake8 tests
- in doctests, allow unicode literals and regular literals to match, allowing for doctests to run on Python 2 and 3. Also enable ELLIPSES, a default that would be undone by supplying the prior option.
- filters out known warnings caused by libraries/functionality included by the skeleton

Relies a .flake8 file to correct some default behaviors:

- allow tabs for indentation (legacy for jaraco projects)
- disable mutually incompatible rules W503 and W504.

## Continuous Integration

The project is pre-configured to run tests in [Travis-CI](https://travis-ci.org) (.travis.yml). Any new project must be enabled either through their web site or with the `travis enable` command. In addition to running tests, an additional deploy stage is configured to automatically release tagged commits. The username and password for PyPI must be configured for each project using the `travis` command and only after the travis project is created. As releases are cut with [twine](https://pypi.org/project/twine), the two values are supplied through the `TWINE_USERNAME` and `TWINE_PASSWORD`. To configure the latter as a secret, run the following command:

```
echo "TWINE_PASSWORD={password}" | travis encrypt
```

Or disable it in the CI definition and configure it through the web UI.

Features include:
- test against Python 2 and 3
- run on Ubuntu Xenial
- correct for broken IPv6

Also provided is a minimal template for running under Appveyor (Windows).

## Building Documentation

Documentation is automatically built by [Read the Docs](https://readthedocs.org) when the project is registered with it, by way of the .readthedocs.yml file. To test the docs build manually, a tox env may be invoked as `tox -e build-docs`. Both techniques rely on the dependencies declared in `setup.cfg/options.extras_require.docs`.

In addition to building the sphinx docs scaffolded in `docs/`, the docs build a `history.html` file that first injects release dates and hyperlinks into the CHANGES.rst before incorporating it as history in the docs.

## Cutting releases

By default, tagged commits are released through the continuous integration deploy stage.
13 changes: 12 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ deps =
setuptools>=31.0.1
commands =
pytest {posargs}
python setup.py checkdocs
usedevelop = True
extras = testing

Expand All @@ -18,3 +17,15 @@ extras =
changedir = docs
commands =
python -m sphinx . {toxinidir}/build/html

[testenv:release]
skip_install = True
deps =
pep517>=0.5
# workaround for https://github.com/pypa/twine/issues/423
git+https://github.com/pypa/twine
path.py
commands =
python -c "import path; path.Path('dist').rmtree_p()"
python -m pep517.build .
python -m twine upload dist/*

0 comments on commit 5d0ff09

Please sign in to comment.