Debian Codegraph @

skeleton.md

raw
1 # Overview
2
3 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.
4
5 ## An SCM-Managed Approach
6
7 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.
8
9 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.
10
11 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.
12
13 Another advantage to using an SCM-managed approach is that tools like GitHub recognize that a change in the skeleton is the _same change_ across all projects that merge with that skeleton. Without the ancestry, with a traditional copy/paste approach, a [commit like this](https://github.com/jaraco/skeleton/commit/12eed1326e1bc26ce256e7b3f8cd8d3a5beab2d5) would produce notifications in the upstream project issue for each and every application, but because it's centralized, GitHub provides just the one notification when the change is added to the skeleton.
14
15 # Usage
16
17 ## new projects
18
19 To use skeleton for a new project, simply pull the skeleton into a new project:
20
21 ```
22 $ git init my-new-project
23 $ cd my-new-project
24 $ git pull gh://jaraco/skeleton
25 ```
26
27 Now customize the project to suit your individual project needs.
28
29 ## existing projects
30
31 If you have an existing project, you can still incorporate the skeleton by merging it into the codebase.
32
33 ```
34 $ git merge skeleton --allow-unrelated-histories
35 ```
36
37 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.
38
39 ## Updating
40
41 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.
42
43 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.
44
45 # Features
46
47 The features/techniques employed by the skeleton include:
48
49 - PEP 517/518-based build relying on Setuptools as the build tool
50 - Setuptools declarative configuration using setup.cfg
51 - tox for running tests
52 - A README.rst as reStructuredText with some popular badges, but with Read the Docs and AppVeyor badges commented out
53 - A CHANGES.rst file intended for publishing release notes about the project
54 - Use of [Black](https://black.readthedocs.io/en/stable/) for code formatting (disabled on unsupported Python 3.5 and earlier)
55
56 ## Packaging Conventions
57
58 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).
59
60 The setup.cfg file implements the following features:
61
62 - Assumes universal wheel for release
63 - Advertises the project's LICENSE file (MIT by default)
64 - Reads the README.rst file into the long description
65 - Some common Trove classifiers
66 - Includes all packages discovered in the repo
67 - Data files in the package are also included (not just Python files)
68 - Declares the required Python versions
69 - Declares install requirements (empty by default)
70 - Declares setup requirements for legacy environments
71 - Supplies two 'extras':
72 - testing: requirements for running tests
73 - docs: requirements for building docs
74 - 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
75 - Placeholder for defining entry points
76
77 Additionally, the setup.py file declares `use_scm_version` which relies on [setuptools_scm](https://pypi.org/project/setuptools_scm) to do two things:
78
79 - derive the project version from SCM tags
80 - ensure that all files committed to the repo are automatically included in releases
81
82 ## Running Tests
83
84 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).
85
86 Other environments (invoked with `tox -e {name}`) supplied include:
87
88 - a `docs` environment to build the documentation
89 - a `release` environment to publish the package to PyPI
90
91 A pytest.ini is included to define common options around running tests. In particular:
92
93 - rely on default test discovery in the current directory
94 - avoid recursing into common directories not containing tests
95 - run doctests on modules and invoke Flake8 tests
96 - 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.
97 - filters out known warnings caused by libraries/functionality included by the skeleton
98
99 Relies on a .flake8 file to correct some default behaviors:
100
101 - disable mutually incompatible rules W503 and W504
102 - support for Black format
103
104 ## Continuous Integration
105
106 The project is pre-configured to run tests through multiple CI providers.
107
108 ### Azure Pipelines
109
110 [Azure Pipelines](https://azure.microsoft.com/en-us/services/devops/pipelines/) are the preferred provider as they provide free, fast, multi-platform services. See azure-pipelines.yml for more details.
111
112 Features include:
113
114 - test against multiple Python versions
115 - run on Ubuntu Bionic
116
117 ### Travis CI
118
119 [Travis CI](https://travis-ci.org) is configured through .travis.yml. Any new project must be enabled either through their web site or with the `travis enable` command.
120
121 Features include:
122 - test against Python 3
123 - run on Ubuntu Bionic
124 - correct for broken IPv6
125
126 ### AppVeyor
127
128 A minimal template for running under AppVeyor (Windows) is provided.
129
130 ### Continuous Deployments
131
132 In addition to running tests, an additional deploy stage is configured to automatically release tagged commits to PyPI using [API tokens](https://pypi.org/help/#apitoken). The release process expects an authorized token to be configured with Azure as the `Azure secrets` variable group. This variable group needs to be created only once per organization. For example:
133
134 ```
135 # create a resource group if none exists
136 az group create --name main --location eastus2
137 # create the vault (try different names until something works)
138 az keyvault create --name secrets007 --resource-group main
139 # create the secret
140 az keyvault secret set --vault-name secrets007 --name PyPI-token --value $token
141 ```
142
143 Then, in the web UI for the project's Pipelines Library, create the `Azure secrets` variable group referencing the key vault name.
144
145 For more details, see [this blog entry](https://blog.jaraco.com/configuring-azure-pipelines-with-secets/).
146
147 ## Building Documentation
148
149 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 docs`. Both techniques rely on the dependencies declared in `setup.cfg/options.extras_require.docs`.
150
151 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.
152
153 ## Cutting releases
154
155 By default, tagged commits are released through the continuous integration deploy stage.
156
157 Releases may also be cut manually by invoking the tox environment `release` with the PyPI token set as the TWINE_PASSWORD:
158
159 ```
160 TWINE_PASSWORD={token} tox -e release
161 ```