Skip to content

Commit

Permalink
Merge pull request #580 from RonnyPfannschmidt/git-archives-full-support
Browse files Browse the repository at this point in the history
Git archives full support
  • Loading branch information
RonnyPfannschmidt authored Jun 21, 2022
2 parents 5ae39d4 + 6707c4f commit 07270fc
Show file tree
Hide file tree
Showing 49 changed files with 1,392 additions and 940 deletions.
4 changes: 4 additions & 0 deletions .git_archival.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe)$
ref-names: $Format:%D$
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.git_archival.txt export-subst
14 changes: 7 additions & 7 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ jobs:
strategy:
fail-fast: false
matrix:
python_version: [ '3.6', '3.7', '3.8', '3.9', '3.10', 'pypy-3.6' ]
python_version: ['3.7', '3.8', '3.9', '3.10', '3.11.0-alpha - 3.11.0', 'pypy-3.8' ]
os: [windows-latest, ubuntu-latest] #, macos-latest]
include:
- os: windows-latest
python_version: 'msys2'

name: ${{ matrix.os }} - Python ${{ matrix.python_version }}
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- name: Setup python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
if: matrix.python_version != 'msys2'
with:
python-version: ${{ matrix.python_version }}
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: "3.6"
python-version: "3.7"
architecture: x64
- run: pip install -e .[toml,test] pytest virtualenv
- run: pytest --test-legacy testing/test_setuptools_support.py || true # ignore fail flaky on ci
Expand All @@ -92,11 +92,11 @@ jobs:
strategy:
fail-fast: false
matrix:
python_version: [ '3.6', '3.9', 'pypy-3.6' ]
python_version: [ '3.7', '3.9', 'pypy-3.8' ]
installer: ["pip install"]
name: check self install - Python ${{ matrix.python_version }} via ${{ matrix.installer }}
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- name: Setup python
uses: actions/setup-python@v2
with:
Expand All @@ -105,7 +105,7 @@ jobs:
# self install testing needs some clarity
# so its being executed without any other tools running
# setuptools smaller 52 is needed to do easy_install
- run: pip install -U "setuptools<52" tomli packaging
- run: pip install -U "setuptools<52" tomli packaging typing_extensions importlib_metadata
- run: python setup.py egg_info
- run: python setup.py sdist
- run: ${{ matrix.installer }} dist/*
Expand Down
17 changes: 11 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
default_language_version:
python: python3.9
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/asottile/reorder_python_imports
rev: v3.0.1
rev: v3.1.0
hooks:
- id: reorder-python-imports
args: [ "--application-directories=.:src" , --py3-plus]
args: [ "--application-directories=.:src" , --py37-plus, --add-import, 'from __future__ import annotations']
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
Expand All @@ -21,19 +23,22 @@ repos:
hooks:
- id: flake8
- repo: https://github.com/asottile/pyupgrade
rev: v2.32.0
rev: v2.32.1
hooks:
- id: pyupgrade
args: [--py36-plus]
args: [--py37-plus]
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.20.1
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.942'
rev: 'v0.960'
hooks:
- id: mypy
args: [--strict]
language_version: "3.10"
additional_dependencies:
- types-setuptools
- tokenize-rt==3.2.0
- pytest == 6.2.5
- pytest == 7.1
- importlib_metadata
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v7.0.0
=======

* drop python 3.6 support
* include git archival support


v6.4.3
======

Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
exclude *.nix
exclude .pre-commit-config.yaml
exclude .git_archival.txt
include *.py
include testing/*.py
include tox.ini
Expand Down
4 changes: 2 additions & 2 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[mypy]
python_version = 3.6
python_version = 3.7
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
# strict = true
strict = true
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
requires = [
"setuptools>=45",
"tomli>=1.0",
"packaging>=20.0"
"packaging>=20.0",
"typing_extensions",
"importlib_metadata",
]
build-backend = "setuptools.build_meta"
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ classifiers =
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Expand All @@ -31,7 +30,8 @@ install_requires =
packaging>=20.0
setuptools
tomli>=1.0.0 # keep in sync
python_requires = >=3.6
typing-extensions
python_requires = >=3.7
package_dir =
=src
zip_safe = true
Expand Down Expand Up @@ -59,6 +59,7 @@ setuptools_scm.parse_scm =
.git = setuptools_scm.git:parse
setuptools_scm.parse_scm_fallback =
.hg_archival.txt = setuptools_scm.hg:parse_archival
.git_archival.txt = setuptools_scm.git:parse_archival
PKG-INFO = setuptools_scm.hacks:parse_pkginfo
pip-egg-info = setuptools_scm.hacks:parse_pip_egg_info
setup.py = setuptools_scm.hacks:fallback_version
Expand Down
24 changes: 7 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,15 @@
pip usage is recommended
"""
from __future__ import annotations

import os
import sys

import setuptools
from setuptools.command.bdist_egg import bdist_egg as original_bdist_egg


class bdist_egg(original_bdist_egg):
def run(self):
raise SystemExit(
"%s is forbidden, "
"please update to setuptools>=45 which uses pip" % type(self).__name__
)


def scm_version():

if sys.version_info < (3, 6):
raise RuntimeError(
"support for python < 3.6 has been removed in setuptools_scm>=6.0.0"
)
def scm_version() -> str:
here = os.path.dirname(os.path.abspath(__file__))
src = os.path.join(here, "src")

Expand All @@ -40,8 +28,11 @@ def scm_version():
from setuptools_scm import git
from setuptools_scm import hg
from setuptools_scm.version import guess_next_dev_version, get_local_node_and_date
from setuptools_scm.config import Configuration

from setuptools_scm.version import ScmVersion

def parse(root, config):
def parse(root: str, config: Configuration) -> ScmVersion | None:
try:
return parse_pkginfo(root, config)
except OSError:
Expand All @@ -64,5 +55,4 @@ def parse(root, config):
],
"test": ["pytest>=6.2", "virtualenv>20"],
},
cmdclass={"bdist_egg": bdist_egg},
)
4 changes: 4 additions & 0 deletions src/setuptools_scm/.git_archival.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe)$
ref-names: $Format:%D$
65 changes: 34 additions & 31 deletions src/setuptools_scm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
:copyright: 2010-2015 by Ronny Pfannschmidt
:license: MIT
"""
from __future__ import annotations

import os
import warnings
from typing import Optional
from typing import Any
from typing import Callable
from typing import TYPE_CHECKING

from . import _types
from . import _types as _t
from ._entrypoints import _call_entrypoint_fn
from ._entrypoints import _version_from_entrypoints
from ._overrides import _read_pretended_version_for
Expand Down Expand Up @@ -36,14 +39,14 @@
# coding: utf-8
# file generated by setuptools_scm
# don't change, don't track in version control
version = {version!r}
version_tuple = {version_tuple!r}
__version__ = version = {version!r}
__version_tuple__ = version_tuple = {version_tuple!r}
""",
".txt": "{version}",
}


def version_from_scm(root):
def version_from_scm(root: _t.PathT) -> ScmVersion | None:
warnings.warn(
"version_from_scm is deprecated please use get_version",
category=DeprecationWarning,
Expand All @@ -54,11 +57,11 @@ def version_from_scm(root):


def dump_version(
root: _types.PathT,
root: _t.PathT,
version: str,
write_to: _types.PathT,
template: "str | None" = None,
):
write_to: _t.PathT,
template: str | None = None,
) -> None:
assert isinstance(version, str)
target = os.path.normpath(os.path.join(root, write_to))
ext = os.path.splitext(target)[1]
Expand All @@ -76,7 +79,7 @@ def dump_version(
fp.write(template.format(version=version, version_tuple=version_tuple))


def _do_parse(config: Configuration) -> "ScmVersion|None":
def _do_parse(config: Configuration) -> ScmVersion | None:
pretended = _read_pretended_version_for(config)
if pretended is not None:
return pretended
Expand All @@ -85,9 +88,9 @@ def _do_parse(config: Configuration) -> "ScmVersion|None":
parse_result = _call_entrypoint_fn(config.absolute_root, config, config.parse)
if isinstance(parse_result, str):
raise TypeError(
"version parse result was a string\nplease return a parsed version"
f"version parse result was {str!r}\nplease return a parsed version"
)
version: Optional[ScmVersion]
version: ScmVersion | None
if parse_result:
assert isinstance(parse_result, ScmVersion)
version = parse_result
Expand All @@ -102,7 +105,7 @@ def _do_parse(config: Configuration) -> "ScmVersion|None":
return version


def _version_missing(config) -> "NoReturn":
def _version_missing(config: Configuration) -> NoReturn:
raise LookupError(
f"setuptools-scm was unable to detect version for {config.absolute_root}.\n\n"
"Make sure you're either building from a fully intact git repository "
Expand All @@ -116,23 +119,23 @@ def _version_missing(config) -> "NoReturn":


def get_version(
root=".",
version_scheme=DEFAULT_VERSION_SCHEME,
local_scheme=DEFAULT_LOCAL_SCHEME,
write_to=None,
write_to_template=None,
relative_to=None,
tag_regex=DEFAULT_TAG_REGEX,
parentdir_prefix_version=None,
fallback_version=None,
fallback_root=".",
parse=None,
git_describe_command=None,
dist_name=None,
version_cls=None,
normalize=True,
search_parent_directories=False,
):
root: str = ".",
version_scheme: Callable[[ScmVersion], str] | str = DEFAULT_VERSION_SCHEME,
local_scheme: Callable[[ScmVersion], str] | str = DEFAULT_LOCAL_SCHEME,
write_to: _t.PathT | None = None,
write_to_template: str | None = None,
relative_to: str | None = None,
tag_regex: str = DEFAULT_TAG_REGEX,
parentdir_prefix_version: str | None = None,
fallback_version: str | None = None,
fallback_root: _t.PathT = ".",
parse: Any | None = None,
git_describe_command: Any | None = None,
dist_name: str | None = None,
version_cls: Any | None = None,
normalize: bool = True,
search_parent_directories: bool = False,
) -> str:
"""
If supplied, relative_to should be a file from which root may
be resolved. Typically called by a script or module that is not
Expand All @@ -147,7 +150,7 @@ def get_version(
return maybe_version


def _get_version(config: Configuration) -> "str|None":
def _get_version(config: Configuration) -> str | None:
parsed_version = _do_parse(config)
if parsed_version is None:
return None
Expand Down
Loading

0 comments on commit 07270fc

Please sign in to comment.