Skip to content

Commit

Permalink
Merge pull request #150 from eirrgang/149-pyproject-toml
Browse files Browse the repository at this point in the history
PEP 517 migration.
  • Loading branch information
Lnaden committed Aug 18, 2022
2 parents 51c8757 + e9b92a2 commit bf8f9d5
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 69 deletions.
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ remove deployment platforms, or test with a different suite.

## Features
* Python-centric skeletal structure with initial module files
* Pre-configured `setup.py` for installation and packaging
* Pre-configured `pyproject.toml` and `setup.cfg` for installation and packaging
* Pre-configured Windows, Linux, and OSX continuous integration on GitHub Actions.
* Choice of dependency locations through `conda-forge`, default `conda`, or `pip`
* Basic testing structure with [PyTest](https://docs.pytest.org/en/latest/)
Expand Down Expand Up @@ -179,21 +179,23 @@ Make a [LGTM](https://lgtm.com) account and add your project. If desired you can

Static code analysis dramatically enhances the quality of your code by finding a large number of common mistakes that both novice and advanced programmers make. There are many static analysis codes on the market, but we have seen that LGTM is a delicate balance between verbosity and catching true errors.

### Additional Python Settings in `setup.py`
### Additional Python Settings in `setup.cfg`

This Cookiecutter generates the package, but there are a several package-specific Python settings you can tune to your
package's installation needs. These are settings in the `setup.py` file which contains instructions for Python on
how to install your package. Each of the options in the file are commented with what it does and when it should be
package's installation needs.
These are settings in the `setup.cfg` file,
which contains instructions for Python on how to install your package.
Each of the options in the file are commented with what it does and when it should be
used.

### Versioneer
Versioneer automatically provides a version string based on the `git` tag and
commit hash which is exposed through a `project.__version__` attribute in your
`project/__init__.py`. For example, if you mint a tag (a release) for a project
through `git tag -a v0.1 -m "Release v0.1."` (push to GitHub through `git push
origin v0.1`), this tag will then relect in your project: `project.__version__
== v0.1`. Otherwise a per-commit version is available which looks like
`v0.3.0+81.g332bfc1`. This string shows the current git (the "g") hash `332bfc1`
through `git tag -a 0.1 -m "Release 0.1."` (push to GitHub through `git push
origin 0.1`), this tag will then reflect in your project: `project.__version__
== 0.1`. Otherwise a per-commit version is available which looks like
`0.3.0+81.g332bfc1`. This string shows the current git (the "g") hash `332bfc1`
is 81 commits beyond the version 0.3 tag.


Expand Down Expand Up @@ -316,6 +318,7 @@ upon setup.
│ ├── data <- Sample additional data (non-code) which can be packaged. Just an example, delete in production
│ │   ├── README.md
│ │   └── look_and_say.dat
│ ├── py.typed <- Marker file indicating PEP 561 type hinting.
│ └── tests <- Unit test directory with sample tests
│    ├── __init__.py
│     └── test_{{repo_name}}.py
Expand All @@ -340,6 +343,7 @@ upon setup.
│   ├── index.rst
│   ├── make.bat
│   └── requirements.yaml <- Documenation building specific requirements. Usually a smaller set than the main program
├── pyproject.toml <- Generic Python build system configuration (PEP-517).
├── readthedocs.yml
├── setup.cfg <- Near-master config file to make house INI-like settings for Coverage, Flake8, YAPF, etc.
├── setup.py <- Your package's setup file for installing with additional options that can be set
Expand Down
2 changes: 1 addition & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
],

"include_ReadTheDocs": ["y", "n"],
"_cms_cc_version": 1.6
"_cms_cc_version": 1.7
}
10 changes: 6 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ remove deployment platforms, or test with a different suite.
Features
--------
* Python-centric skeletal structure with initial module files
* Pre-configured ``setup.py`` for installation and packaging
* Pre-configured ``pyproject.toml`` and ``setup.cfg`` for installation and packaging
* Pre-configured Window, Linux, and OSX continuous integration on GitHub Actions
* Choice of dependency locations through ``conda-forge``, default ``conda``, or ``pip``
* Basic testing structure with `PyTest <https://docs.pytest.org/en/latest/>`_
Expand All @@ -34,6 +34,8 @@ Features
* Basic documentation structure powered by `Sphinx <http://www.sphinx-doc.org/en/master/>`_
* Automatic license file inclusion from several common Open Source licenses (optional)

.. versionchanged:: 1.7
Added support for :pep:`517` and :pep:`561`.

Requirements
------------
Expand Down Expand Up @@ -123,11 +125,11 @@ documentation yourself through `Sphinx <http://www.sphinx-doc.org/en/master/usag
publish the documentation for you. The initial skeleton of the documentation can be found in the ``docs`` folder
of your output.

Additional Python Settings in ``setup.py``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Additional Python Settings in ``setup.cfg``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This Cookiecutter generates the package, but there are a several package-specific Python settings you can tune to your
package's installation needs. These are settings in the ``setup.py`` file which contains instructions for Python on
package's installation needs. These are settings in the ``setup.cfg`` file which contains instructions for Python on
how to install your package. Each of the options in the file are commented with what it does and when it should be
used.

Expand Down
5 changes: 1 addition & 4 deletions {{cookiecutter.repo_name}}/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
include LICENSE
include MANIFEST.in
include CODE_OF_CONDUCT.md
include versioneer.py

graft {{cookiecutter.repo_name}}
global-exclude *.py[cod] __pycache__ *.so
global-exclude *.py[cod] __pycache__ *.so
3 changes: 3 additions & 0 deletions {{cookiecutter.repo_name}}/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools>=42.0", "wheel"]
build-backend = "setuptools.build_meta"
59 changes: 59 additions & 0 deletions {{cookiecutter.repo_name}}/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,64 @@
# Helper file to handle all configs

# setuptools configuration.
# see https://setuptools.pypa.io/en/latest/userguide/declarative_config.html
[metadata]
# Self-descriptive entries which should always be present
name = {{cookiecutter.repo_name}}
author = {{cookiecutter.author_name}}
author_email = {{cookiecutter.author_email}}
description = {{cookiecutter.description}}
long_description = file: README.md
long_description_content_type = "text/markdown"
version = attr: {{cookiecutter.repo_name}}.__version__
license = {{cookiecutter.open_source_license}}
python_requires = ">=3.7"
# See https://pypi.org/classifiers/
classifiers ={% if cookiecutter.open_source_license == 'MIT' %}
License :: OSI Approved :: MIT License{% elif cookiecutter.open_source_license == 'BSD-3-Clause' %}
License :: OSI Approved :: BSD License{% elif cookiecutter.open_source_license == 'LGPLv3' %}
License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+){% endif %}
Programming Language :: Python :: 3
# Update the urls and uncomment, once the hosting is set up.
#project_urls =
# Source = https://github.com/<username>/{{cookiecutter.repo_name}}/
# Documentation = https://{{cookiecutter.repo_name}}.readthedocs.io/
# Other possible metadata.
# Ref https://packaging.python.org/en/latest/specifications/declaring-project-metadata/
#keywords = one, two
#platforms = ["Linux",
# "Mac OS-X",
# "Unix",
# "Windows"]

[options]
# As of version 0.971, mypy does not support type checking of installed zipped
# packages (because it does not actually import the Python packages).
# We declare the package not-zip-safe so that our type hints are also available
# when checking client code that uses our (installed) package.
# Ref:
# https://mypy.readthedocs.io/en/stable/installed_packages.html?highlight=zip#using-installed-packages-with-mypy-pep-561
zip_safe = False
install_requires =
importlib-resources; python_version<"3.10"
tests_require =
pytest>=6.1.2
pytest-runner
# Which Python importable modules should be included when your package is installed
# Handled automatically by setuptools. Use 'exclude' to prevent some specific
# subpackage(s) from being added, if needed
packages = find:
# Alternatively, see ; https://setuptools.pypa.io/en/latest/userguide/declarative_config.html#using-a-src-layout
#package_dir =
# =src
[options.packages.find]
where = .

# Optionally, include package data to ship with your package
# Customize MANIFEST.in if the general case does not suit your needs
[options.package_data]
{{cookiecutter.repo_name}} = py.typed

[coverage:run]
# .coveragerc to control coverage.py and pytest-cov
omit =
Expand Down
56 changes: 7 additions & 49 deletions {{cookiecutter.repo_name}}/setup.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,17 @@
"""
{{cookiecutter.project_name}}
"""{{cookiecutter.project_name}}
{{cookiecutter.description}}
"""
import os.path
import sys
from setuptools import setup, find_packages
import versioneer

short_description = "{{cookiecutter.description}}".split("\n")[0]
from setuptools import setup

# from https://github.com/pytest-dev/pytest-runner#conditional-requirement
needs_pytest = {'pytest', 'test', 'ptr'}.intersection(sys.argv)
pytest_runner = ['pytest-runner'] if needs_pytest else []

try:
with open("README.md", "r") as handle:
long_description = handle.read()
except:
long_description = None
sys.path.append(os.path.dirname(__file__))
import versioneer


setup(
# Self-descriptive entries which should always be present
name='{{cookiecutter.repo_name}}',
author='{{cookiecutter.author_name}}',
author_email='{{cookiecutter.author_email}}',
description=short_description,
long_description=long_description,
long_description_content_type="text/markdown",
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
license='{{cookiecutter.open_source_license}}',

# Which Python importable modules should be included when your package is installed
# Handled automatically by setuptools. Use 'exclude' to prevent some specific
# subpackage(s) from being added, if needed
packages=find_packages(),

# Optional include package data to ship with your package
# Customize MANIFEST.in if the general case does not suit your needs
# Comment out this line to prevent the files from being packaged with your software
include_package_data=True,

# Allows `setup.py test` to work correctly with pytest
setup_requires=[] + pytest_runner,

# Additional entries you may want simply uncomment the lines you want and fill in the data
# url='http://www.my_package.com', # Website
# install_requires=[], # Required packages, pulls from pip if needed; do not use for Conda deployment
# platforms=['Linux',
# 'Mac OS-X',
# 'Unix',
# 'Windows'], # Valid platforms your code works on, adjust to your flavor
# python_requires=">=3.5", # Python version restrictions

# Manual control if final package is compressible or not, set False to prevent the .egg from being made
# zip_safe=False,

cmdclass=versioneer.get_cmdclass()
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ cap.

## Including package data

Modify your package's `setup.py` file and the `setup()` command. Include the
[`package_data`](http://setuptools.readthedocs.io/en/latest/setuptools.html#basic-use) keyword and point it at the
correct files.
Modify your package's `setup.cfg` file.
Update the [options.package_data](https://setuptools.pypa.io/en/latest/userguide/declarative_config.html#options)
and point it at the correct files.
Paths are relative to `package_dir`.

## Manifest

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# PEP 561 marker file. See https://peps.python.org/pep-0561/

0 comments on commit bf8f9d5

Please sign in to comment.