diff options
author | Ronny Pfannschmidt <opensource@ronnypfannschmidt.de> | 2019-12-14 00:23:40 +0100 |
---|---|---|
committer | Ronny Pfannschmidt <ronny.pfannschmidt@redhat.com> | 2020-05-01 22:26:47 +0200 |
commit | b536c087bf5fc76febff44ea38315928beb0e168 (patch) | |
tree | d1d668710f3b8c53d925076da9c2144a5e5809f7 | |
parent | c534e8a6dadb0b8830cc79203e62b6a1a966acaf (diff) | |
download | setuptools-scm-b536c087bf5fc76febff44ea38315928beb0e168.tar.gz |
add python testsworkflows
port testsuite to pathlib, and try to resolve windows short paths
trace git toplevel mismatch (observed on win32 name shortening)
exclude python2 on windows
remove the appveyor config, its broken
drop most travis envs that we have in github workflows now
add actions for creating egg artifacts/wheels/sdists
WIP: experiment with act
WIP: fix workflow typo
WIP: add missed runs-on
fix typoed excludes
fixup: upload actuall wheel/sdist in the build step
style fixes for the actions config
-rw-r--r-- | .github/workflows/python-tests.yml | 94 | ||||
-rw-r--r-- | .travis.yml | 40 | ||||
-rw-r--r-- | appveyor.yml | 43 | ||||
-rw-r--r-- | setup.py | 2 | ||||
-rw-r--r-- | src/setuptools_scm/file_finder_git.py | 3 | ||||
-rw-r--r-- | testing/conftest.py | 17 | ||||
-rw-r--r-- | testing/test_file_finder.py | 68 | ||||
-rw-r--r-- | testing/test_git.py | 31 | ||||
-rw-r--r-- | testing/test_mercurial.py | 18 |
9 files changed, 173 insertions, 143 deletions
diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml new file mode 100644 index 0000000..4822766 --- /dev/null +++ b/.github/workflows/python-tests.yml @@ -0,0 +1,94 @@ +name: python tests+artifacts+release + +on: + pull_request: + push: + branches: [master] + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + python_version: [ '2.7', '3.5', '3.6', '3.7', '3.8', 'pypy2', 'pypy3' ] + os: [windows-latest, ubuntu-latest] #, macos-latest] + exclude: + - os: windows-latest + python_version: "2.7" + - os: windows-latest + python_version: "pypy2" + name: ${{ matrix.os }} - Python ${{ matrix.python_version }} + steps: + - uses: actions/checkout@v1 + - name: Setup python + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python_version }} + architecture: x64 + - run: pip install -e .[toml] pytest + - run: pytest + + + eggs: + runs-on: ubuntu-latest + + needs: [build] + name: Python ${{ matrix.python_version }} eggs + strategy: + matrix: + python_version: ['2.7', '3.5', '3.6', '3.7', '3.8'] + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python_version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install --upgrade wheel setuptools + - name: Build package + run: | + python setup.py bdist_egg + - uses: actions/upload-artifact@v2 + with: + name: dist + path: dist + + dist: + runs-on: ubuntu-latest + + needs: [build] + name: Python bdist/wheel + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-python@v1 + with: + python-version: "3.8" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install --upgrade wheel setuptools + - name: Build package + run: | + python setup.py bdist_wheel sdist + - uses: actions/upload-artifact@v2 + with: + name: dist + path: dist + + dist_upload: + + runs-on: ubuntu-latest + if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') && github.repository == 'pypa/setuptools_scm' + needs: [eggs, dist] + steps: + - uses: actions/download-artifact@v2 + with: + name: dist + - name: Publish package to PyPI + uses: pypa/gh-action-pypi-publish@master + with: + user: __token__ + password: ${{ secrets.pypi_token }} diff --git a/.travis.yml b/.travis.yml index 75c3c0e..fa22d9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,11 +19,7 @@ credentials: tags: yes python: - '2.7' -- '3.4' -- '3.5' -- '3.6' - '3.7' -- '3.8-dev' dist: xenial # needed for 3.7+ env: - TOXENV=py-test @@ -34,9 +30,6 @@ jobs: name: check readme python: '3.6' env: TOXENV=check_readme - # - stage: test - # python: '3.7' - # dist: xenial - stage: test python: '2.7' env: SELFINSTALL=1 @@ -44,16 +37,6 @@ jobs: python: '3.6' env: SELFINSTALL=1 - - stage: linting - python: '3.6' - name: validate pre-commit - env: - install: - - pip install pre-commit - - pre-commit install-hooks - script: - - pre-commit run --all-files - - &deploy stage: deploy name: "modern distributions" @@ -65,29 +48,6 @@ jobs: <<: *pypi distributions: "sdist bdist_wheel" - - &bdist_egg - <<: *deploy - name: "python eggs 2.7" - python: '2.7' - deploy: - <<: *pypi - distributions: "bdist_egg" - - <<: *bdist_egg - name: "python eggs 3.4" - python: '3.4' - - <<: *bdist_egg - name: "python eggs 3.5" - python: '3.5' - - <<: *bdist_egg - name: "python eggs 3.6" - python: '3.6' - - <<: *bdist_egg - name: "python eggs 3.7" - python: '3.7' - - <<: *bdist_egg - name: "python eggs 3.8" - python: '3.8-dev' - cache: directories: - $HOME/.cache/pip diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 5319f7c..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,43 +0,0 @@ -environment:
- matrix:
- - PYTHON: "C:\\Python27"
- TOXENV: "py-test"
-
- - PYTHON: "C:\\Python27-x64"
- TOXENV: "py-test"
-
- - PYTHON: "C:\\Python34"
- TOXENV: "py-test"
-
- - PYTHON: "C:\\Python34-x64"
- TOXENV: "py-test"
-
-init:
- - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
-
- - ECHO "Updating Environment"
- - python -m pip install -U pip
- - python -m pip install -U pep517
- - python -m pip install -U --upgrade-strategy=eager tox
-
-
-install:
- # Check that we have the expected version and architecture for Python
- - python -c "import sys, os;sys.stdout.write(str(sys.version) + os.linesep)"
- - "python -c \"import struct; print(struct.calcsize('P') * 8)\""
- - python -m pip list
-
-build: false # Not a C# project, build stuff at the test step instead.
-
-test_script:
- # Build the compiled extension and run the project tests
- - python -m tox
-
-after_test:
- # If tests are successful, create a whl package for the project.
- - python -m pep517.build --binary .
- - ps: "ls dist"
-
-artifacts:
- # Archive the generated wheel package in the ci.appveyor.com build report.
- - path: dist\*
@@ -115,7 +115,7 @@ arguments = dict( "Topic :: Utilities", ], python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", - extras_require=dict(toml=["toml"]), + extras_require=dict(toml=["toml", "setuptools>=42"]), ) if __name__ == "__main__": diff --git a/src/setuptools_scm/file_finder_git.py b/src/setuptools_scm/file_finder_git.py index 8b81d2c..9aa6245 100644 --- a/src/setuptools_scm/file_finder_git.py +++ b/src/setuptools_scm/file_finder_git.py @@ -62,5 +62,8 @@ def git_find_files(path=""): toplevel = _git_toplevel(path) if not toplevel: return [] + fullpath = os.path.abspath(os.path.normpath(path)) + if not fullpath.startswith(toplevel): + trace("toplevel mismatch", toplevel, fullpath) git_files, git_dirs = _git_ls_files_and_dirs(toplevel) return scm_find_files(path, git_files, git_dirs) diff --git a/testing/conftest.py b/testing/conftest.py index 0d34731..5cb65f6 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -1,6 +1,7 @@ import os import itertools import pytest +import six os.environ["SETUPTOOLS_SCM_DEBUG"] = "1" VERSION_PKGS = ["setuptools", "setuptools_scm"] @@ -21,6 +22,9 @@ class Wd(object): commit_command = None add_command = None + def __repr__(self): + return "<WD {cwd}>".format(cwd=self.cwd) + def __init__(self, cwd): self.cwd = cwd self.__counter = itertools.count() @@ -33,10 +37,13 @@ class Wd(object): return do(cmd, self.cwd) def write(self, name, value, **kw): - filename = self.cwd.join(name) + filename = self.cwd / name if kw: value = value.format(**kw) - filename.write(value) + if isinstance(value, six.text_type): + filename.write_text(value) + else: + filename.write_bytes(value) return filename def _reason(self, given_reason): @@ -83,5 +90,7 @@ def debug_mode(): @pytest.fixture -def wd(tmpdir): - return Wd(tmpdir.ensure("wd", dir=True)) +def wd(tmp_path): + target_wd = tmp_path.resolve() / "wd" + target_wd.mkdir() + return Wd(target_wd) diff --git a/testing/test_file_finder.py b/testing/test_file_finder.py index 825f1c3..c9409c4 100644 --- a/testing/test_file_finder.py +++ b/testing/test_file_finder.py @@ -7,7 +7,7 @@ from setuptools_scm.integration import find_files @pytest.fixture(params=["git", "hg"]) -def inwd(request, wd): +def inwd(request, wd, monkeypatch): if request.param == "git": wd("git init") wd("git config user.email test@example.com") @@ -18,14 +18,16 @@ def inwd(request, wd): wd("hg init") wd.add_command = "hg add ." wd.commit_command = 'hg commit -m test-{reason} -u test -d "0 0"' - (wd.cwd / "file1").ensure(file=True) - adir = (wd.cwd / "adir").ensure(dir=True) - (adir / "filea").ensure(file=True) - bdir = (wd.cwd / "bdir").ensure(dir=True) - (bdir / "fileb").ensure(file=True) + (wd.cwd / "file1").touch() + adir = wd.cwd / "adir" + adir.mkdir() + (adir / "filea").touch() + bdir = wd.cwd / "bdir" + bdir.mkdir() + (bdir / "fileb").touch() wd.add_and_commit() - with wd.cwd.as_cwd(): - yield wd + monkeypatch.chdir(wd.cwd) + yield wd def _sep(paths): @@ -39,14 +41,14 @@ def test_basic(inwd): def test_whitespace(inwd): - (inwd.cwd / "adir" / "space file").ensure(file=True) + (inwd.cwd / "adir" / "space file").touch() inwd.add_and_commit() assert set(find_files("adir")) == _sep({"adir/space file", "adir/filea"}) def test_case(inwd): - (inwd.cwd / "CamelFile").ensure(file=True) - (inwd.cwd / "file2").ensure(file=True) + (inwd.cwd / "CamelFile").touch() + (inwd.cwd / "file2").touch() inwd.add_and_commit() assert set(find_files()) == _sep( {"CamelFile", "file2", "file1", "adir/filea", "bdir/fileb"} @@ -55,14 +57,14 @@ def test_case(inwd): @pytest.mark.skipif(sys.platform == "win32", reason="symlinks to dir not supported") def test_symlink_dir(inwd): - (inwd.cwd / "adir" / "bdirlink").mksymlinkto("../bdir") + (inwd.cwd / "adir" / "bdirlink").symlink_to("../bdir") inwd.add_and_commit() assert set(find_files("adir")) == _sep({"adir/filea", "adir/bdirlink/fileb"}) @pytest.mark.skipif(sys.platform == "win32", reason="symlinks to dir not supported") def test_symlink_dir_source_not_in_scm(inwd): - (inwd.cwd / "adir" / "bdirlink").mksymlinkto("../bdir") + (inwd.cwd / "adir" / "bdirlink").symlink_to("../bdir") assert set(find_files("adir")) == _sep({"adir/filea"}) @@ -70,7 +72,7 @@ def test_symlink_dir_source_not_in_scm(inwd): sys.platform == "win32", reason="symlinks to files not supported on windows" ) def test_symlink_file(inwd): - (inwd.cwd / "adir" / "file1link").mksymlinkto("../file1") + (inwd.cwd / "adir" / "file1link").symlink_to("../file1") inwd.add_and_commit() assert set(find_files("adir")) == _sep( {"adir/filea", "adir/file1link"} @@ -81,28 +83,28 @@ def test_symlink_file(inwd): sys.platform == "win32", reason="symlinks to files not supported on windows" ) def test_symlink_file_source_not_in_scm(inwd): - (inwd.cwd / "adir" / "file1link").mksymlinkto("../file1") + (inwd.cwd / "adir" / "file1link").symlink_to("../file1") assert set(find_files("adir")) == _sep({"adir/filea"}) @pytest.mark.skipif(sys.platform == "win32", reason="symlinks to dir not supported") def test_symlink_loop(inwd): - (inwd.cwd / "adir" / "loop").mksymlinkto("../adir") + (inwd.cwd / "adir" / "loop").symlink_to("../adir") inwd.add_and_commit() assert set(find_files("adir")) == _sep({"adir/filea", "adir/loop"}) # -> ../adir @pytest.mark.skipif(sys.platform == "win32", reason="symlinks to dir not supported") def test_symlink_loop_outside_path(inwd): - (inwd.cwd / "bdir" / "loop").mksymlinkto("../bdir") - (inwd.cwd / "adir" / "bdirlink").mksymlinkto("../bdir") + (inwd.cwd / "bdir" / "loop").symlink_to("../bdir") + (inwd.cwd / "adir" / "bdirlink").symlink_to("../bdir") inwd.add_and_commit() assert set(find_files("adir")) == _sep({"adir/filea", "adir/bdirlink/fileb"}) @pytest.mark.skipif(sys.platform == "win32", reason="symlinks to dir not supported") def test_symlink_dir_out_of_git(inwd): - (inwd.cwd / "adir" / "outsidedirlink").mksymlinkto(os.path.join(__file__, "..")) + (inwd.cwd / "adir" / "outsidedirlink").symlink_to(os.path.join(__file__, "..")) inwd.add_and_commit() assert set(find_files("adir")) == _sep({"adir/filea"}) @@ -111,23 +113,23 @@ def test_symlink_dir_out_of_git(inwd): sys.platform == "win32", reason="symlinks to files not supported on windows" ) def test_symlink_file_out_of_git(inwd): - (inwd.cwd / "adir" / "outsidefilelink").mksymlinkto(__file__) + (inwd.cwd / "adir" / "outsidefilelink").symlink_to(__file__) inwd.add_and_commit() assert set(find_files("adir")) == _sep({"adir/filea"}) def test_empty_root(inwd): subdir = inwd.cwd / "cdir" / "subdir" - subdir.ensure(dir=True) - (subdir / "filec").ensure(file=True) + subdir.mkdir(parents=True) + (subdir / "filec").touch() inwd.add_and_commit() assert set(find_files("cdir")) == _sep({"cdir/subdir/filec"}) def test_empty_subdir(inwd): subdir = inwd.cwd / "adir" / "emptysubdir" / "subdir" - subdir.ensure(dir=True) - (subdir / "xfile").ensure(file=True) + subdir.mkdir(parents=True) + (subdir / "xfile").touch() inwd.add_and_commit() assert set(find_files("adir")) == _sep( {"adir/filea", "adir/emptysubdir/subdir/xfile"} @@ -136,10 +138,10 @@ def test_empty_subdir(inwd): @pytest.mark.skipif(sys.platform == "win32", reason="symlinks not supported on windows") def test_double_include_through_symlink(inwd): - (inwd.cwd / "data").ensure(dir=True) - (inwd.cwd / "data" / "datafile").ensure(file=True) - (inwd.cwd / "adir" / "datalink").mksymlinkto("../data") - (inwd.cwd / "adir" / "filealink").mksymlinkto("filea") + (inwd.cwd / "data").mkdir() + (inwd.cwd / "data" / "datafile").touch() + (inwd.cwd / "adir" / "datalink").symlink_to("../data") + (inwd.cwd / "adir" / "filealink").symlink_to("filea") inwd.add_and_commit() assert set(find_files()) == _sep( { @@ -155,17 +157,17 @@ def test_double_include_through_symlink(inwd): @pytest.mark.skipif(sys.platform == "win32", reason="symlinks not supported on windows") def test_symlink_not_in_scm_while_target_is(inwd): - (inwd.cwd / "data").ensure(dir=True) - (inwd.cwd / "data" / "datafile").ensure(file=True) + (inwd.cwd / "data").mkdir() + (inwd.cwd / "data" / "datafile").touch() inwd.add_and_commit() - (inwd.cwd / "adir" / "datalink").mksymlinkto("../data") - (inwd.cwd / "adir" / "filealink").mksymlinkto("filea") + (inwd.cwd / "adir" / "datalink").symlink_to("../data") + (inwd.cwd / "adir" / "filealink").symlink_to("filea") assert set(find_files()) == _sep( { "file1", "adir/filea", # adir/datalink and adir/afilelink not included - # because the symlink themselves are not in scm + # because the symlink_to themselves are not in scm "bdir/fileb", "data/datafile", } diff --git a/testing/test_git.py b/testing/test_git.py index 8416571..ac45b5b 100644 --- a/testing/test_git.py +++ b/testing/test_git.py @@ -34,9 +34,10 @@ def test_parse_describe_output(given, tag, number, node, dirty): def test_root_relative_to(tmpdir, wd, monkeypatch): monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG") - p = wd.cwd.ensure("sub/package", dir=1) - p.join("setup.py").write( - """from setuptools import setup + p = wd.cwd.joinpath("sub/package") + p.mkdir(parents=True) + p.joinpath("setup.py").write_text( + u"""from setuptools import setup setup(use_scm_version={"root": "../..", "relative_to": __file__}) """ @@ -159,8 +160,10 @@ def test_git_shallow_autocorrect(shallow_wd, recwarn): def test_find_files_stop_at_root_git(wd): wd.commit_testfile() - wd.cwd.ensure("project/setup.cfg") - assert integration.find_files(str(wd.cwd / "project")) == [] + project = wd.cwd / "project" + project.mkdir() + project.joinpath("setup.cfg").touch() + assert integration.find_files(str(project)) == [] @pytest.mark.issue(128) @@ -175,7 +178,7 @@ def test_alphanumeric_tags_match(wd): assert wd.version.startswith("0.1.dev1+g") -def test_git_archive_export_ignore(wd): +def test_git_archive_export_ignore(wd, monkeypatch): wd.write("test1.txt", "test") wd.write("test2.txt", "test") wd.write( @@ -186,28 +189,28 @@ def test_git_archive_export_ignore(wd): ) wd("git add test1.txt test2.txt") wd.commit() - with wd.cwd.as_cwd(): - assert integration.find_files(".") == [opj(".", "test1.txt")] + monkeypatch.chdir(wd.cwd) + assert integration.find_files(".") == [opj(".", "test1.txt")] @pytest.mark.issue(228) -def test_git_archive_subdirectory(wd): +def test_git_archive_subdirectory(wd, monkeypatch): wd("mkdir foobar") wd.write("foobar/test1.txt", "test") wd("git add foobar") wd.commit() - with wd.cwd.as_cwd(): - assert integration.find_files(".") == [opj(".", "foobar", "test1.txt")] + monkeypatch.chdir(wd.cwd) + assert integration.find_files(".") == [opj(".", "foobar", "test1.txt")] @pytest.mark.issue(251) -def test_git_archive_run_from_subdirectory(wd): +def test_git_archive_run_from_subdirectory(wd, monkeypatch): wd("mkdir foobar") wd.write("foobar/test1.txt", "test") wd("git add foobar") wd.commit() - with (wd.cwd / "foobar").as_cwd(): - assert integration.find_files(".") == [opj(".", "test1.txt")] + monkeypatch.chdir(wd.cwd / "foobar") + assert integration.find_files(".") == [opj(".", "test1.txt")] def test_git_feature_branch_increments_major(wd): diff --git a/testing/test_mercurial.py b/testing/test_mercurial.py index 40f9409..c20c2fd 100644 --- a/testing/test_mercurial.py +++ b/testing/test_mercurial.py @@ -38,15 +38,17 @@ def test_archival_to_version(expected, data): ) -def test_find_files_stop_at_root_hg(wd): +def test_find_files_stop_at_root_hg(wd, monkeypatch): wd.commit_testfile() - wd.cwd.ensure("project/setup.cfg") + project = wd.cwd / "project" + project.mkdir() + project.joinpath("setup.cfg").touch() # setup.cfg has not been committed - assert integration.find_files(str(wd.cwd / "project")) == [] + assert integration.find_files(str(project)) == [] # issue 251 wd.add_and_commit() - with (wd.cwd / "project").as_cwd(): - assert integration.find_files() == ["setup.cfg"] + monkeypatch.chdir(project) + assert integration.find_files() == ["setup.cfg"] # XXX: better tests for tag prefixes @@ -81,7 +83,7 @@ def test_version_from_hg_id(wd): def test_version_from_archival(wd): # entrypoints are unordered, # cleaning the wd ensure this test wont break randomly - wd.cwd.join(".hg").remove() + wd.cwd.joinpath(".hg").rename(wd.cwd / ".nothg") wd.write(".hg_archival.txt", "node: 000000000000\n" "tag: 0.1\n") assert wd.version == "0.1" @@ -144,8 +146,8 @@ def test_version_bump_from_merge_commit(wd): def test_version_bump_from_commit_including_hgtag_mods(wd): """ Test the case where a commit includes changes to .hgtags and other files """ - with wd.cwd.join(".hgtags").open("a") as tagfile: - tagfile.write("0 0\n") + with wd.cwd.joinpath(".hgtags").open("ab") as tagfile: + tagfile.write(b"0 0\n") wd.write("branchfile", "branchtext") wd(wd.add_command) assert wd.version.startswith("1.0.1.dev1+") # bump from dirty version |