Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 587 file finding no commit #4

Closed
wants to merge 109 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
6efd9ba
Use slimmer and more modern APIs
flying-sheep Jan 20, 2021
acc0eff
Style and deps
flying-sheep Jan 20, 2021
4c328c7
add packaging to build system dependencies
flying-sheep Jan 20, 2021
c8c82c3
Support working on a Git repository with hg-git
paugier Mar 16, 2021
fcff025
Simplify git.parse
paugier Mar 16, 2021
dc1006e
update workflows
RonnyPfannschmidt Mar 17, 2021
48c40e7
Clean up hg
paugier Mar 17, 2021
603b3bb
More clean up git (buggy)
paugier Mar 17, 2021
b029703
Fix broken git parser
paugier Mar 18, 2021
4d49d54
hg-git: fix corner case git commit not exported
paugier Mar 18, 2021
a2a2a2b
Refactoring git, hg and hg-git
paugier Mar 18, 2021
982fee5
Match in hg-git describe + addre TODOs
paugier Mar 18, 2021
0046129
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 18, 2021
ebd205f
hg-git: fix 2 corner cases
paugier Mar 23, 2021
184a52e
hg-git: test like git + fixes
paugier Mar 23, 2021
770cf6d
Better testing hg-git
paugier Mar 25, 2021
2ae4efe
Restore python-tests.yml
flying-sheep Apr 5, 2021
a5ffde4
Merge branch 'main' into no-setuptools
flying-sheep Apr 5, 2021
580e83b
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Apr 5, 2021
f01df54
Merge pull request #552 from pypa/pre-commit-ci-update-config
RonnyPfannschmidt Apr 5, 2021
63ad053
Merge pull request #514 from flying-sheep/no-setuptools
RonnyPfannschmidt Apr 5, 2021
87f40f9
README: remove incorrect mention of pkg_resources
sbraz Apr 10, 2021
8335602
Merge pull request #553 from sbraz/importlib_readme
RonnyPfannschmidt Apr 10, 2021
7818106
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Apr 12, 2021
060e893
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 12, 2021
b366d8b
Merge pull request #556 from pypa/pre-commit-ci-update-config
RonnyPfannschmidt Apr 12, 2021
69b5575
Fix #557
kkirsche Apr 15, 2021
87ac86b
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Apr 19, 2021
5ed3cf6
Merge pull request #559 from pypa/pre-commit-ci-update-config
RonnyPfannschmidt Apr 19, 2021
06ef8d8
Merge pull request #558 from kkirsche/bug/557
RonnyPfannschmidt Apr 22, 2021
83e5902
enhance docs and old python erroring
RonnyPfannschmidt Mar 18, 2021
e110406
gitignore hypothesis
RonnyPfannschmidt Apr 5, 2021
3e7b6dc
Merge pull request #544 from RonnyPfannschmidt/error-on-dead-python
RonnyPfannschmidt Apr 23, 2021
08dbabf
Merge pull request #539 from RonnyPfannschmidt/workflows
RonnyPfannschmidt Apr 23, 2021
db96f76
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Apr 26, 2021
f950168
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 26, 2021
43839cf
Merge pull request #562 from pypa/pre-commit-ci-update-config
RonnyPfannschmidt Apr 26, 2021
0016bf9
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] May 3, 2021
c3b3aac
Merge pull request #563 from pypa/pre-commit-ci-update-config
RonnyPfannschmidt May 3, 2021
fd6be16
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] May 10, 2021
d03dec0
Merge pull request #565 from pypa/pre-commit-ci-update-config
RonnyPfannschmidt May 10, 2021
67f8794
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] May 17, 2021
28976d4
Merge pull request #566 from pypa/pre-commit-ci-update-config
RonnyPfannschmidt May 17, 2021
ad1e40f
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] May 24, 2021
fd0559d
Merge pull request #570 from pypa/pre-commit-ci-update-config
RonnyPfannschmidt May 24, 2021
79a1a81
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] May 31, 2021
bedd4f5
Merge pull request #572 from pypa/pre-commit-ci-update-config
RonnyPfannschmidt May 31, 2021
37be7e0
Accept branches start with 'v' as being a release branch.
QuLogic Jun 1, 2021
41f3cf4
docs: recommend _version.py as a nicer default
henryiii Jun 1, 2021
f4fb031
Merge pull request #576 from henryiii/henryiii/docs/_version
RonnyPfannschmidt Jun 1, 2021
3bb3275
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jun 8, 2021
f2ad45b
Merge pull request #579 from pypa/pre-commit-ci-update-config
RonnyPfannschmidt Jun 8, 2021
29f0745
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jun 14, 2021
5f5ef0e
Merge pull request #581 from pypa/pre-commit-ci-update-config
RonnyPfannschmidt Jun 16, 2021
b680e37
Merge pull request #573 from QuLogic/v-prefix
RonnyPfannschmidt Jun 16, 2021
fbadf5b
First step towards #524
Jun 17, 2021
f7c636d
Merge branch 'main' of https://github.com/pypa/setuptools_scm into fe…
Jun 18, 2021
c06b58a
Added a `normalize` boolean flag and a `NonNormalizedVersion` class. …
Jun 18, 2021
20bc3de
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 18, 2021
d6da17e
Flake8
Jun 18, 2021
59c029d
Merge branch 'feature/custom_version_cls' of https://github.com/smari…
Jun 18, 2021
50cc767
flake8
Jun 18, 2021
8e15642
Removed the f string
Jun 18, 2021
67e2b57
As per code review: reorganized a bit + the NonNormalizedVersion now …
Jun 18, 2021
b746720
Exposing `NonNormalizedVersion` at the root level now that it moved t…
Jun 18, 2021
4c7015e
`version_cls` can now receive a string too. Added a test for setuptoo…
Jun 18, 2021
b9b4384
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 18, 2021
794357b
Added an __all__ entry so that "official" public package-level symbol…
Jun 18, 2021
59a6392
Fixed doc
Jun 18, 2021
ae76c48
Merge branch 'feature/custom_version_cls' of https://github.com/smari…
Jun 18, 2021
456b8c9
flake8
Jun 18, 2021
663f9e2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 18, 2021
27afe9d
Minor tests improvement
Jun 18, 2021
9794ae4
Readme fix.
Jun 18, 2021
1db0fe7
Fixed changelog
Jun 18, 2021
ffab6ed
Merge branch 'feature/custom_version_cls' of https://github.com/smari…
Jun 18, 2021
645f73b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 18, 2021
7d07d9f
Update src/setuptools_scm/config.py
smarie Jun 18, 2021
ece87b2
Merge pull request #584 from smarie/feature/custom_version_cls
RonnyPfannschmidt Jun 25, 2021
0b2b66f
fix #585: switch to tomli
RonnyPfannschmidt Jun 25, 2021
3b5c099
fix #585: switch to tomli
RonnyPfannschmidt Jun 25, 2021
5c54817
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jul 5, 2021
6219b9d
Merge pull request #588 from pypa/pre-commit-ci-update-config
RonnyPfannschmidt Jul 6, 2021
b1e4634
Merge main branch into hg-git branch
paugier Jul 6, 2021
d9463c2
Use UTF-8 encoding when reading pyproject.toml
domdfcoding Jul 11, 2021
3060fa3
Lint
domdfcoding Jul 11, 2021
3eded96
Use os.mkdir rather than subprocess.Popen
domdfcoding Jul 11, 2021
1f335af
Merge pull request #589 from domdfcoding/toml-utf8
RonnyPfannschmidt Jul 11, 2021
93c65c0
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jul 12, 2021
7a89fb5
Trying Github Actions config with simple quotes
paugier Jul 13, 2021
437b5f3
Merge pull request #590 from pypa/pre-commit-ci-update-config
RonnyPfannschmidt Jul 13, 2021
50024f3
Install pip2 on Github Actions for Mercurial hg-git
paugier Jul 13, 2021
087c32b
Merge pull request #532 from paugier/hg-git
RonnyPfannschmidt Jul 13, 2021
2543273
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jul 19, 2021
470fc3a
Merge pull request #592 from pypa/pre-commit-ci-update-config
RonnyPfannschmidt Jul 20, 2021
fef87ba
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jul 26, 2021
b0b46fd
Merge pull request #594 from pypa/pre-commit-ci-update-config
RonnyPfannschmidt Jul 26, 2021
796db1d
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Aug 2, 2021
dfb4bea
Merge pull request #596 from pypa/pre-commit-ci-update-config
RonnyPfannschmidt Aug 2, 2021
060e528
Adding search_parent_directories to recursively search parent directo…
tdegeus Aug 5, 2021
2f40274
split hg_git support to better invoke the helpers
RonnyPfannschmidt Aug 7, 2021
407730c
apply reorder-python-imports
RonnyPfannschmidt Aug 7, 2021
a85790e
begin mypy usage - addresses part of #501
RonnyPfannschmidt Aug 7, 2021
e942610
Merge pull request #599 from RonnyPfannschmidt/ronny/reorder-imports
RonnyPfannschmidt Aug 7, 2021
988732a
drop pre-commit action as we use pre-commit.ci
RonnyPfannschmidt Jun 9, 2021
18085da
Merge pull request #600 from RonnyPfannschmidt/drop-pre-commit-action
RonnyPfannschmidt Aug 10, 2021
d485ef7
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Aug 23, 2021
e214250
Merge pull request #601 from pypa/pre-commit-ci-update-config
RonnyPfannschmidt Aug 24, 2021
54c5b81
fix #587 - stop file finding on missing commits
RonnyPfannschmidt Aug 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .github/workflows/pre-commit.yml

This file was deleted.

7 changes: 7 additions & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
tags:
- "v*"
release:
types: [published]

jobs:
test:
Expand Down Expand Up @@ -40,6 +41,12 @@ jobs:
- run: pip install -U setuptools
if: matrix.python_version != 'msys2'
- run: pip install -e .[toml] pytest
# pip2 is needed because Mercurial uses python2 on Ubuntu 20.04
- run: |
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
sudo python2 get-pip.py
$(hg debuginstall --template "{pythonexe}") -m pip install hg-git --user
if: matrix.os == 'ubuntu-latest'
- run: pytest

check_selfinstall:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ htmlcov/
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Sphinx documentation
docs/_build/
22 changes: 17 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
repos:
- repo: https://github.com/psf/black
rev: 20.8b1
rev: 21.7b0
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.6.0
hooks:
- id: reorder-python-imports
args: [ "--application-directories=.:src" , --py3-plus]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.0
- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
- repo: https://github.com/asottile/pyupgrade
rev: v2.11.0
rev: v2.24.0
hooks:
- id: pyupgrade
args: [--py36-plus]
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.17.0
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.910'
hooks:
- id: mypy
additional_dependencies:
- types-setuptools
- tokenize-rt==3.2.0
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
In progress
===========

* fix #587: don't fail file finders when distribution is not given
* fix #524: new parameters ``normalize`` and ``version_cls`` to customize the version normalization class.
* fix #585: switch from toml to tomli

v6.0.1
=======

Expand Down
53 changes: 41 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@ to be supplied to ``get_version()``. For example:
# pyproject.toml

[tool.setuptools_scm]
write_to = "pkg/version.py"
write_to = "pkg/_version.py"


``setup.py`` usage
------------------
``setup.py`` usage (deprecated)
-------------------------------

.. warning::

``setup_requires`` has been deprecated in favor of ``pyproject.toml``

The following settings are considered legacy behavior and
superseded by the ``pyproject.toml`` usage, but for maximal
Expand Down Expand Up @@ -129,8 +133,8 @@ You can confirm the version number locally via ``setup.py``:
not defined in ``setup.cfg``.


``setup.cfg`` usage
-------------------
``setup.cfg`` usage (deprecated)
------------------------------------

as ``setup_requires`` is deprecated in favour of ``pyproject.toml``
usage in ``setup.cfg`` is considered deprecated,
Expand All @@ -147,7 +151,7 @@ than the project's root, you can use:
from setuptools_scm import get_version
version = get_version(root='..', relative_to=__file__)

See `setup.py Usage`_ above for how to use this within ``setup.py``.
See `setup.py Usage (deprecated)`_ above for how to use this within ``setup.py``.


Retrieving package version at runtime
Expand All @@ -169,7 +173,7 @@ or the `importlib_metadata`_ backport:
pass

Alternatively, you can use ``pkg_resources`` which is included in
``setuptools``:
``setuptools`` (but has a significant runtime cost):

.. code:: python

Expand All @@ -192,13 +196,14 @@ Usage from Sphinx
-----------------

It is discouraged to use ``setuptools_scm`` from Sphinx itself,
instead use ``pkg_resources`` after editable/real installation:
instead use ``importlib.metadata`` after editable/real installation:

.. code:: python

# contents of docs/conf.py
from importlib.metadata import version

release = version("package-name")
release = version('myproject')
# for example take major/minor
version = '.'.join(release.split('.')[:2])

The underlying reason is, that services like *Read the Docs* sometimes change
Expand Down Expand Up @@ -311,7 +316,7 @@ The currently supported configuration keys are:

:write_to:
A path to a file that gets replaced with a file containing the current
version. It is ideal for creating a ``version.py`` file within the
version. It is ideal for creating a ``_version.py`` file within the
package, typically used to avoid using `pkg_resources.get_distribution`
(which adds some overhead).

Expand Down Expand Up @@ -371,6 +376,30 @@ The currently supported configuration keys are:
Defaults to the value set by ``setuptools_scm.git.DEFAULT_DESCRIBE``
(see `git.py <src/setuptools_scm/git.py>`_).

:normalize:
A boolean flag indicating if the version string should be normalized.
Defaults to ``True``. Setting this to ``False`` is equivalent to setting
``version_cls`` to ``setuptools_scm.version.NonNormalizedVersion``

:version_cls:
An optional class used to parse, verify and possibly normalize the version
string. Its constructor should receive a single string argument, and its
``str`` should return the normalized version string to use.
This option can also receive a class qualified name as a string.

This defaults to ``packaging.version.Version`` if available. If
``packaging`` is not installed, ``pkg_resources.packaging.version.Version``
is used. Note that it is known to modify git release candidate schemes.

The ``setuptools_scm.NonNormalizedVersion`` convenience class is
provided to disable the normalization step done by
``packaging.version.Version``. If this is used while ``setuptools_scm``
is integrated in a setuptools packaging process, the non-normalized
version number will appear in all files (see ``write_to``) BUT note
that setuptools will still normalize it to create the final distribution,
so as to stay compliant with the python packaging standards.


To use ``setuptools_scm`` in other Python code you can use the ``get_version``
function:

Expand All @@ -390,7 +419,7 @@ Example configuration in ``setup.py`` format:

setup(
use_scm_version={
'write_to': 'version.py',
'write_to': '_version.py',
'write_to_template': '__version__ = "{version}"',
'tag_regex': r'^(?P<prefix>v)?(?P<version>[^\+]+)(?P<suffix>.*)?$',
}
Expand Down
9 changes: 9 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[mypy]
python_version = 3.6
warn_return_any = True
warn_unused_configs = True
mypy_path = $MYPY_CONFIG_FILE_DIR/src

[mypy-setuptools_scm.*]
# disabled as it will take a bit
# disallow_untyped_defs = True
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ setuptools_scm.version_scheme =

[options.extras_require]
toml =
toml
tomli~=1.0.0
10 changes: 10 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,31 @@
"""
import os
import sys

import setuptools


def scm_config():

if sys.version_info < (3, 6):
raise RuntimeError(
"support for python < 3.6 has been removed in setuptools_scm>=6.0.0"
)

here = os.path.dirname(os.path.abspath(__file__))
src = os.path.join(here, "src")
egg_info = os.path.join(src, "setuptools_scm.egg-info")
has_entrypoints = os.path.isdir(egg_info)
import pkg_resources

pkg_resources.require("setuptools>=45")

sys.path.insert(0, src)
pkg_resources.working_set.add_entry(src)
# FIXME: remove debug
print(src)
print(pkg_resources.working_set)

from setuptools_scm.hacks import parse_pkginfo
from setuptools_scm.git import parse as parse_git
from setuptools_scm.version import guess_next_dev_version, get_local_node_and_date
Expand Down
46 changes: 36 additions & 10 deletions src/setuptools_scm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
import os
import warnings

try:
from packaging.version import parse
except ImportError:
from pkg_resources import parse_version as parse

from .config import (
Configuration,
DEFAULT_VERSION_SCHEME,
DEFAULT_LOCAL_SCHEME,
DEFAULT_TAG_REGEX,
NonNormalizedVersion,
)
from .utils import function_has_arg, trace
from .version import format_version, meta
Expand Down Expand Up @@ -61,7 +67,8 @@ def _version_from_entrypoints(config, fallback=False):
else:
entrypoint = "setuptools_scm.parse_scm"
root = config.absolute_root
for ep in iter_matching_entrypoints(root, entrypoint):

for ep in iter_matching_entrypoints(root, entrypoint, config):
version = _call_entrypoint_fn(root, config, ep.load())

if version:
Expand All @@ -83,15 +90,12 @@ def dump_version(root, version, write_to, template=None):
)
)

# version_tuple: each field is converted to an int if possible or kept as string
fields = tuple(version.split("."))
version_fields = []
for field in fields:
try:
v = int(field)
except ValueError:
v = field
version_fields.append(v)
parsed_version = parse(version)
version_fields = parsed_version.release
if parsed_version.dev is not None:
version_fields += (f"dev{parsed_version.dev}",)
if parsed_version.local is not None:
version_fields += (parsed_version.local,)

with open(target, "w") as fp:
fp.write(template.format(version=version, version_tuple=tuple(version_fields)))
Expand Down Expand Up @@ -157,6 +161,9 @@ def get_version(
parse=None,
git_describe_command=None,
dist_name=None,
version_cls=None,
normalize=True,
search_parent_directories=False,
):
"""
If supplied, relative_to should be a file from which root may
Expand Down Expand Up @@ -186,3 +193,22 @@ def _get_version(config):
)

return version_string


# Public API
__all__ = [
"get_version",
"dump_version",
"version_from_scm",
"Configuration",
"NonNormalizedVersion",
"DEFAULT_VERSION_SCHEME",
"DEFAULT_LOCAL_SCHEME",
"DEFAULT_TAG_REGEX",
# TODO: are the symbols below part of public API ?
"function_has_arg",
"trace",
"format_version",
"meta",
"iter_matching_entrypoints",
]
3 changes: 2 additions & 1 deletion src/setuptools_scm/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import sys

from setuptools_scm import get_version
from setuptools_scm.integration import find_files


def main():
def main() -> None:
print("Guessed Version", get_version())
if "ls" in sys.argv:
for fname in find_files("."):
Expand Down
Loading