-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from jamadden/updates
Add check to prevent .dev dependencies from being released
- Loading branch information
Showing
9 changed files
with
321 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
See `prereleaser_before`. | ||
""" | ||
|
||
import re | ||
import sys | ||
|
||
from pathlib import Path | ||
|
||
class DevelopmentDependency(Exception): | ||
""" | ||
Raised when a development dependency is detected. | ||
""" | ||
|
||
# An expression that matches dependency specification lines that have | ||
# ".dev" versions. | ||
# | ||
# TODO: The ``packaging`` library | ||
# (https://packaging.pypa.io/en/stable/index.html) has support to | ||
# actually parse all of these complicated specifiers; the problem is | ||
# extracting which lines need to be parsed like that. We're just | ||
# matching the entire file | ||
_SETUP_PY_DEV_REQUIREMENT_MATCHER = re.compile( | ||
# open single or double quote | ||
br"['\"]" | ||
# one or more alphanumeric characters, underscores, periods | ||
# commas, spaces or square brackets (for extras) | ||
# and zero or more spaces | ||
br"[\w.,\[\] ]+\s*" | ||
# followed by an operator. | ||
# (recall that 'foo < 3, >2, !=2.1' is valid syntax; the clauses can come in | ||
# any order). See https://peps.python.org/pep-0508/ | ||
br"[>=<!~]" | ||
# followed by any number of characters of any sort, but with at least one number. | ||
br".*\d+.*" | ||
# followed by the ".dev" sequence | ||
br"\.dev" | ||
# followed by any number of characters | ||
br".*" | ||
# ended with the closing string quote | ||
# (if we wanted to be super smart, we would use a capture group to match | ||
# the actual opening quote) | ||
br"['\"]" | ||
) | ||
|
||
def prereleaser_before(data): | ||
""" | ||
Checks for development dependencies and raise an error | ||
if found. | ||
A non-released dependency is something in setup.py that has a version number | ||
containing ".dev". An exception is raised if this is found. | ||
This is a "prereleaser before" hook so that it runs before anything | ||
tries to commit to the project (e.g., to update the version number). | ||
.. todo:: | ||
This only supports traditional setuptools-style | ||
projects and only supports setup.py. Ideally, it would | ||
support pyproject.toml, setup.cfg and generic build backends. | ||
We'd need to be able to get the project metadata (``.egg-info`` in setuptools, | ||
or part of the records recorded in the wheel file) to make that | ||
work reliably, though, and I'm not sure how to do that. | ||
""" | ||
report = data.get('icrs.releaser:report', print) | ||
report('Checking for the existence of development dependencies.') | ||
root_dir = Path(data['reporoot']) | ||
|
||
for p in ( | ||
root_dir / 'setup.py', | ||
): | ||
if not p.is_file(): | ||
report('Project file', p, "does not exist; not checking for development deps.", | ||
file=sys.stderr) | ||
continue | ||
|
||
contents = p.read_bytes() | ||
if (match := _SETUP_PY_DEV_REQUIREMENT_MATCHER.search(contents)): | ||
raise DevelopmentDependency( | ||
"Project file %s had development dependency: %s" % ( | ||
p, match.group().decode('utf-8', errors='ignore') | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# pragma: no cover | ||
# Copyright 2020 NextThought | ||
# Released under the terms of the LICENSE file. | ||
import codecs | ||
from setuptools import setup | ||
from setuptools import find_namespace_packages | ||
|
||
|
||
version = '1.1.1.dev0' | ||
|
||
entry_points = { | ||
'zest.releaser.prereleaser.before': [ | ||
# XXX: This only works doing fullrelease | ||
'rm_cflags = icrs.releaser.removecflags:prereleaser_before', | ||
], | ||
'zest.releaser.prereleaser.middle': [ | ||
'version_next = icrs.releaser.versionreplacer:prereleaser_middle', | ||
# XXX: This only works doing fullrelease | ||
'scm_middle = icrs.releaser.setuptools_scm_versionfixer:prereleaser_middle', | ||
'dev_middle = icrs.releaser.devremover:prereleaser_middle', | ||
], | ||
'console_scripts': [ | ||
'icrs_release = icrs.releaser.fullrelease:main', | ||
] | ||
} | ||
|
||
TESTS_REQUIRE = [ | ||
'coverage', | ||
'zope.testrunner', | ||
] | ||
|
||
def _read(fname): | ||
with codecs.open(fname, encoding='utf-8') as f: | ||
return f.read() | ||
|
||
setup( | ||
name='icrs.releaser', | ||
version=version, | ||
author='Jason Madden', | ||
author_email='jason@seecoresoftware.com', | ||
description="zest.releaser/setuptools_scm plugin.", | ||
long_description=_read('README.rst') + '\n\n' + _read('CHANGES.rst'), | ||
license='Apache', | ||
keywords='zest.releaser release automation setuptools_scm git', | ||
url='https://github.com/jamadden/icrs.releaser', | ||
project_urls={ | ||
'Documentation': 'https://icrsreleaser.readthedocs.io/en/latest/', | ||
}, | ||
classifiers=[ | ||
'Intended Audience :: Developers', | ||
'Natural Language :: English', | ||
'Operating System :: OS Independent', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.8', | ||
'Programming Language :: Python :: 3.9', | ||
'Programming Language :: Python :: 3.10', | ||
'Programming Language :: Python :: 3.11', | ||
'Programming Language :: Python :: 3.12', | ||
'Programming Language :: Python :: Implementation :: CPython', | ||
'Programming Language :: Python :: Implementation :: PyPy', | ||
'Development Status :: 1 - Planning', | ||
], | ||
zip_safe=False, | ||
packages=find_namespace_packages(where='src'), | ||
package_dir={'': 'src'}, | ||
namespace_packages=['icrs'], | ||
install_requires=[ | ||
# Placeholder | ||
'zest.releaser >= 9.1.1', | ||
], | ||
entry_points=entry_points, | ||
include_package_data=True, | ||
extras_require={ | ||
'test': TESTS_REQUIRE, | ||
'docs': [ | ||
'Sphinx', | ||
'furo', | ||
'sphinxcontrib-programoutput', | ||
] + TESTS_REQUIRE, | ||
'recommended': [ | ||
'zest.releaser[recommended]', | ||
], | ||
}, | ||
python_requires=">=3.8", | ||
) |
Oops, something went wrong.