Skip to content

Commit 9a56b88

Browse files
committed
Follow modern python packaging and conf practices
* Add PEP 517/518 pyproject.toml file * Add setuptools_scm to handle versioning * Add setup.py content to setup.cfg * Update setup.py to act as a shim (so pip install -e works) Addresses: #2 Signed-off-by: Steven Esser <[email protected]>
1 parent 774dc7d commit 9a56b88

File tree

5 files changed

+80
-166
lines changed

5 files changed

+80
-166
lines changed

configure

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function setup {
3434

3535
setup
3636

37-
$CONFIGURE_ROOT_DIR/tmp/bin/pip install -r requirements-tests.txt -e .
37+
$CONFIGURE_ROOT_DIR/tmp/bin/pip install -e .[testing]
3838

3939
if [ -f "$CONFIGURE_ROOT_DIR/tmp/bin/activate" ]; then
4040
source "$CONFIGURE_ROOT_DIR/tmp/bin/activate"

pyproject.toml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[build-system]
2+
requires = ["setuptools >= 50", "wheel", "setuptools_scm[toml] >= 4"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.setuptools_scm]
6+
7+
[tool.pytest.ini_options]
8+
norecursedirs = [
9+
".git",
10+
"bin",
11+
"dist",
12+
"build",
13+
"_build",
14+
"dist",
15+
"etc",
16+
"local",
17+
"ci",
18+
"docs",
19+
"man",
20+
"share",
21+
"samples",
22+
".cache",
23+
".settings",
24+
"Include",
25+
"include",
26+
"Lib",
27+
"lib",
28+
"lib64",
29+
"Lib64",
30+
"Scripts",
31+
"thirdparty",
32+
"tmp",
33+
"tests/data",
34+
".eggs"
35+
]
36+
37+
python_files = "*.py"
38+
39+
python_classes="Test"
40+
python_functions="test"
41+
42+
addopts = [
43+
"-rfExXw",
44+
"--strict",
45+
"--doctest-modules"
46+
]

requirements-tests.txt

-1
This file was deleted.

setup.cfg

+30-43
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,36 @@
22
universal=1
33

44
[metadata]
5-
license_files =
6-
README.rst
7-
CHANGELOG.rst
8-
apache-2.0.LICENSE
9-
bsd-new.LICENSE
10-
mit.LICENSE
11-
NOTICE
5+
license_file = apache-2.0.LICENSE
6+
name = skeleton
7+
author = nexB. Inc. and others
8+
author_email = [email protected]
9+
description = skeleton
10+
long_description = file:README.rst
11+
url = https://github.com/nexB/skeleton
12+
classifiers =
13+
Development Status :: 5 - Production/Stable
14+
Intended Audience :: Developers
15+
Programming Language :: Python :: 3
16+
Programming Language :: Python :: 3 :: Only
17+
Topic :: Software Development
18+
Topic :: Utilities
19+
keywords =
1220

13-
[tool:pytest]
14-
norecursedirs =
15-
.git
16-
bin
17-
dist
18-
build
19-
_build
20-
dist
21-
etc
22-
local
23-
ci
24-
docs
25-
man
26-
share
27-
samples
28-
.cache
29-
.settings
30-
Include
31-
include
32-
Lib
33-
lib
34-
lib64
35-
Lib64
36-
Scripts
37-
thirdparty
38-
tmp
39-
tests/data
21+
[options]
22+
package_dir=
23+
=src
24+
packages=find:
25+
include_package_data = true
26+
zip_safe = false
27+
install_requires =
28+
setup_requires = setuptools_scm[toml] >= 4
4029

41-
python_files = *.py
30+
[options.packages.find]
31+
where=src
4232

43-
python_classes=Test
44-
python_functions=test
45-
46-
addopts =
47-
-rfExXw
48-
--strict
49-
--ignore setup.py
50-
--doctest-modules
33+
[options.extras_require]
34+
testing =
35+
# upstream
36+
pytest >= 6
37+
pytest-xdist >= 2

setup.py

+3-121
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,6 @@
11
#!/usr/bin/env python
2-
# -*- encoding: utf-8 -*-
32

4-
from __future__ import absolute_import
5-
from __future__ import print_function
3+
import setuptools
64

7-
import io
8-
from glob import glob
9-
from os.path import basename
10-
from os.path import dirname
11-
from os.path import join
12-
from os.path import splitext
13-
import re
14-
import sys
15-
16-
from setuptools import find_packages
17-
from setuptools import setup
18-
19-
version = '0.0.0'
20-
21-
#### Small hack to force using a plain version number if the option
22-
#### --plain-version is passed to setup.py
23-
24-
USE_DEFAULT_VERSION = False
25-
try:
26-
sys.argv.remove('--use-default-version')
27-
USE_DEFAULT_VERSION = True
28-
except ValueError:
29-
pass
30-
####
31-
32-
33-
def get_version(default=version, template='{tag}.{distance}.{commit}{dirty}',
34-
use_default=USE_DEFAULT_VERSION):
35-
"""
36-
Return a version collected from git if possible or fall back to an
37-
hard-coded default version otherwise. If `use_default` is True,
38-
always use the default version.
39-
"""
40-
if use_default:
41-
return default
42-
try:
43-
tag, distance, commit, dirty = get_git_version()
44-
if not distance and not dirty:
45-
# we are from a clean Git tag: use tag
46-
return tag
47-
48-
distance = 'post{}'.format(distance)
49-
if dirty:
50-
time_stamp = get_time_stamp()
51-
dirty = '.dirty.' + get_time_stamp()
52-
else:
53-
dirty = ''
54-
55-
return template.format(**locals())
56-
except:
57-
# no git data: use default version
58-
return default
59-
60-
61-
def get_time_stamp():
62-
"""
63-
Return a numeric UTC time stamp without microseconds.
64-
"""
65-
from datetime import datetime
66-
return (datetime.isoformat(datetime.utcnow()).split('.')[0]
67-
.replace('T', '').replace(':', '').replace('-', ''))
68-
69-
70-
def get_git_version():
71-
"""
72-
Return version parts from Git or raise an exception.
73-
"""
74-
from subprocess import check_output, STDOUT
75-
# this may fail with exceptions
76-
cmd = 'git', 'describe', '--tags', '--long', '--dirty',
77-
version = check_output(cmd, stderr=STDOUT).strip()
78-
dirty = version.endswith('-dirty')
79-
tag, distance, commit = version.split('-')[:3]
80-
# lower tag and strip V prefix in tags
81-
tag = tag.lower().lstrip('v ').strip()
82-
# strip leading g from git describe commit
83-
commit = commit.lstrip('g').strip()
84-
return tag, int(distance), commit, dirty
85-
86-
87-
def read(*names, **kwargs):
88-
return io.open(
89-
join(dirname(__file__), *names),
90-
encoding=kwargs.get('encoding', 'utf8')
91-
).read()
92-
93-
94-
setup(
95-
name='',
96-
version=get_version(),
97-
license='Apache-2.0',
98-
description='',
99-
long_description=read('README.rst'),
100-
author='nexB. Inc. and others',
101-
author_email='[email protected]',
102-
url='',
103-
packages=find_packages('src'),
104-
package_dir={'': 'src'},
105-
py_modules=[splitext(basename(path))[0] for path in glob('src/*.py')],
106-
include_package_data=True,
107-
zip_safe=False,
108-
classifiers=[
109-
# complete classifier list: http://pypi.python.org/pypi?%3Aaction=list_classifiers
110-
'Development Status :: 5 - Production/Stable',
111-
'Intended Audience :: Developers',
112-
'Programming Language :: Python',
113-
'Programming Language :: Python :: 3',
114-
'Programming Language :: Python :: 3.6',
115-
'Programming Language :: Python :: 3.7',
116-
'Programming Language :: Python :: 3.8',
117-
'Topic :: Software Development',
118-
'Topic :: Utilities',
119-
],
120-
keywords=[
121-
],
122-
install_requires=[
123-
]
124-
)
5+
if __name__ == "__main__":
6+
setuptools.setup()

0 commit comments

Comments
 (0)