From c93feb6c81fc6e0b72146ed90ed60df99adf2b2d Mon Sep 17 00:00:00 2001 From: jreiberkyle Date: Wed, 3 Mar 2021 13:26:08 -0800 Subject: [PATCH 1/7] move tests, linting, and coverage to nox from make and tox --- Makefile | 7 ----- noxfile.py | 45 +++++++++++++++++++++++++++++ planet/api/_fatomic.py | 60 --------------------------------------- requirements-dev.txt | 4 --- setup.cfg | 17 +++++++++++ setup.py | 15 ++-------- tests/unit/test_atomic.py | 53 ---------------------------------- tox.ini | 13 --------- 8 files changed, 64 insertions(+), 150 deletions(-) create mode 100644 noxfile.py delete mode 100644 planet/api/_fatomic.py delete mode 100644 requirements-dev.txt delete mode 100644 tests/unit/test_atomic.py delete mode 100644 tox.ini diff --git a/Makefile b/Makefile index 71ec81be1..07a8c53b2 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,5 @@ GH_PAGES_SOURCES = planet docs Makefile -check: - py.test --doctest-modules planet tests - flake8 planet tests - -coverage: - py.test --doctest-modules --cov planet --cov-report=html:htmlcov tests planet/api - pex: # disable-cache seemed required or the older version would be used pex . -o dist/planet -e planet.scripts:main --disable-cache diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 000000000..58431e97f --- /dev/null +++ b/noxfile.py @@ -0,0 +1,45 @@ +import nox + +nox.options.stop_on_first_error = True +nox.options.reuse_existing_virtualenvs = True +# nox.options.keywords = "test + check" + +source_files = ("planet", "tests", "setup.py", "noxfile.py") +test_reqs = ("pytest", "pytest-asyncio==0.14.0", "pytest-cov", "respx==0.16.3") +lint_reqs = ("flake8", ) +# docs_requirements = ("mkdocs", "mkdocs-material", "mkautodoc>=0.1.0") + + +@nox.session(python=["3.7", "3.8", "3.9"]) +def test(session): + session.install(*test_reqs) + session.install("-e", ".") + + options = session.posargs + if "-x" in options: + options.append("--no-cov") + + session.run("pytest", "-v", *options) + + +@nox.session +def check(session): + session.install(*lint_reqs) + session.install("-e", ".") + + session.run("flake8", *source_files) + +# @nox.session +# def docs(session): +# session.install("--upgrade", *docs_requirements) +# session.install("-e", ".") +# +# session.run("mkdocs", "build") +# +# +# @nox.session(reuse_venv=True) +# def watch(session): +# session.install("--upgrade", *docs_requirements) +# session.install("-e", ".") +# +# session.run("mkdocs", "serve") diff --git a/planet/api/_fatomic.py b/planet/api/_fatomic.py deleted file mode 100644 index 5d2949c78..000000000 --- a/planet/api/_fatomic.py +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright 2015 Planet Labs, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -''' Provide atomic file support - a subset of `fatomic` included here -(https://github.com/abarnert/fatomic) as upstream is not in pypi -''' -import contextlib -import errno -import os -import shutil -import tempfile -import types - - -@contextlib.contextmanager -def atomic_open(filename, mode, *args, **kwargs): - if mode[0] not in 'wxa' or len(mode) > 1 and mode[1] == '+': - raise ValueError("invalid mode: '{}'".format(mode)) - f = tempfile.NamedTemporaryFile(mode=mode, - prefix=os.path.basename(filename), - dir=os.path.dirname(filename), - suffix='.tmp', - delete=False) - # track: explicitly discarded, normal/abnormal completion - _discard = [None] - try: - if mode[0] == 'a': - try: - with open(filename, 'r'+mode[1:], *args, **kwargs) as fin: - shutil.copyfileobj(fin, f) - except (OSError, IOError) as e: - if e.errno == errno.ENOENT: - pass - - def discard(self, _discard=_discard): - # explicit discard - _discard[0] = True - f.discard = types.MethodType(discard, f) - yield f - # normal completion - if not _discard[0]: - _discard[0] = False - # block and force discarding - finally: - f.close() - # if we didn't complete or were aborted, delete - if _discard[0] is None or _discard[0]: - os.unlink(f.name) - else: - os.replace(f.name, filename) diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index c7129f646..000000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,4 +0,0 @@ -pytest-asyncio==0.14.0 -respx==0.16.3 -sphinx-autobuild==2020.9.1 -tox==3.20.1 diff --git a/setup.cfg b/setup.cfg index 5a8e9329c..fc457e155 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,3 +3,20 @@ universal: 1 [metadata] license_file: LICENSE + +[tool:pytest] +addopts = + --cov=planet + --cov=tests + --cov-report=term-missing + --cov-report=xml + --cov-fail-under 95.69 + -rxXs + +[coverage:run] +source = planet,tests +branch = True + +[coverage:report] +skip_covered = True +show_missing = True diff --git a/setup.py b/setup.py index 775652d10..631817fb8 100644 --- a/setup.py +++ b/setup.py @@ -11,21 +11,10 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from pathlib import Path -from codecs import open as codecs_open from setuptools import setup, find_packages - -# Get the long description from the relevant file -# TODO: consider moving to markdown from rst at this point -try: - with codecs_open('README.rst', encoding='utf-8') as f: - long_description = f.read() -except: - # @todo for now, fall back to this - pex fails to resolve the README - long_description = '' - - with open('planet/api/__version__.py') as f: for line in f: if line.find("__version__") >= 0: @@ -53,7 +42,7 @@ setup(name='planet', version=version, description=u"Planet API Client", - long_description=long_description, + long_description=Path("README.md").read_text("utf-8"), classifiers=[ 'Development Status :: 2 - Pre-Alpha', 'Environment :: Console', diff --git a/tests/unit/test_atomic.py b/tests/unit/test_atomic.py deleted file mode 100644 index 63b1234c7..000000000 --- a/tests/unit/test_atomic.py +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright 2015 Planet Labs, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -from planet.api._fatomic import atomic_open - - -def test_atomic_open(tmpdir): - outfile = str(tmpdir.join('foo')) - - def lsdir(): - return os.listdir(str(tmpdir)) - - def assert_content_is(expected): - with open(outfile, 'r') as fp: - assert fp.read() == expected - - # success case - with atomic_open(outfile, 'w') as fp: - fp.write('bar') - assert_content_is('bar') - # no tmp files remain - assert ['foo'] == lsdir() - - # exception during write, assert file remains untouched - try: - with atomic_open(outfile, 'w') as fp: - fp.write('bazzy') - raise Exception('drat') - except Exception: - assert_content_is('bar') - else: - assert False - # no tmp files remain - assert ['foo'] == lsdir() - - # manual discarding - with atomic_open(outfile, 'w') as fp: - fp.write('bazzy') - fp.discard() - assert_content_is('bar') - # no tmp files remain - assert ['foo'] == lsdir() diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 66963ede2..000000000 --- a/tox.ini +++ /dev/null @@ -1,13 +0,0 @@ -# Tox (https://tox.readthedocs.io/) is a tool for running tests -# in multiple virtualenvs. This configuration file will run the -# test suite on all supported python versions. To use it, "pip install tox" -# and then run "tox" from this directory. - -[tox] -envlist = py37, py38, py39 - -[testenv] -deps = pytest -commands = - pip install -e .[dev] - pytest {posargs} From 404118cad285f4c77b356b4e725d0631a0ee0ff2 Mon Sep 17 00:00:00 2001 From: jreiberkyle Date: Wed, 3 Mar 2021 15:53:59 -0800 Subject: [PATCH 2/7] remove redundancy in specifying dev requirements --- noxfile.py | 10 +++------- setup.py | 24 ++++++++++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/noxfile.py b/noxfile.py index 58431e97f..f488ac12d 100644 --- a/noxfile.py +++ b/noxfile.py @@ -5,18 +5,15 @@ # nox.options.keywords = "test + check" source_files = ("planet", "tests", "setup.py", "noxfile.py") -test_reqs = ("pytest", "pytest-asyncio==0.14.0", "pytest-cov", "respx==0.16.3") -lint_reqs = ("flake8", ) # docs_requirements = ("mkdocs", "mkdocs-material", "mkautodoc>=0.1.0") @nox.session(python=["3.7", "3.8", "3.9"]) def test(session): - session.install(*test_reqs) - session.install("-e", ".") + session.install("-e", ".[test]") options = session.posargs - if "-x" in options: + if "-k" or "-x" in options: options.append("--no-cov") session.run("pytest", "-v", *options) @@ -24,8 +21,7 @@ def test(session): @nox.session def check(session): - session.install(*lint_reqs) - session.install("-e", ".") + session.install("-e", ".[dev]") session.run("flake8", *source_files) diff --git a/setup.py b/setup.py index 631817fb8..13245a76f 100644 --- a/setup.py +++ b/setup.py @@ -24,21 +24,29 @@ continue +install_requires = [ + 'httpx>=0.16', + 'tqdm>=4.56', + 'pywin32 >= 1.0;platform_system=="Windows"' +] + test_requires = [ 'pytest', 'pytest-asyncio', - 'respx' + 'pytest-cov', + 'respx==0.16.3' ] -dev_requires = [ +lint_requires = [ 'flake8', - 'setuptools', - 'pex', - 'pytest-cov', - 'sphinx', - 'wheel', + # 'setuptools', + # 'pex', + # 'pytest-cov', + # 'sphinx', + # 'wheel', ] + setup(name='planet', version=version, description=u"Planet API Client", @@ -71,7 +79,7 @@ ], extras_require={ 'test': test_requires, - 'dev': test_requires + dev_requires, + 'dev': test_requires + lint_requires, }, entry_points=""" [console_scripts] From 73d87523a2f7d01e0aa27f136471ca6896a43eaa Mon Sep 17 00:00:00 2001 From: jreiberkyle Date: Wed, 3 Mar 2021 17:31:51 -0800 Subject: [PATCH 3/7] remove commented deps --- setup.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/setup.py b/setup.py index 13245a76f..3a1736bc8 100644 --- a/setup.py +++ b/setup.py @@ -39,11 +39,6 @@ lint_requires = [ 'flake8', - # 'setuptools', - # 'pex', - # 'pytest-cov', - # 'sphinx', - # 'wheel', ] From c9a7f6b390d2b3f14f3e36511f724d5d02e8dcd1 Mon Sep 17 00:00:00 2001 From: jreiberkyle Date: Thu, 4 Mar 2021 12:14:23 -0800 Subject: [PATCH 4/7] update travis to run tests and docs through nox instead of make --- .travis.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index e066820c8..860f32b1e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,7 @@ python: cache: directories: - $HOME/.cache/pip -before_install: - - pip install setuptools pip pytest --upgrade install: - - pip install -e .[dev] + - pip install pip nox --upgrade script: - - make check html-docs + - nox From 19fb748c15a24dcb6ecb5ae53f7d5ef0a4d4d746 Mon Sep 17 00:00:00 2001 From: jreiberkyle Date: Thu, 4 Mar 2021 15:06:50 -0800 Subject: [PATCH 5/7] use github actions for ci testing --- .github/workflows/test.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..776e6c0f1 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,31 @@ +name: test + +on: [push, pull_request] + +jobs: + test: + name: Test Python ${{ matrix.python-version }} + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: [3.7, 3.8, 3.9] + + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Pip cache + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip + restore-keys: | + ${{ runner.os }}-pip + - name: Test + run: | + pip install --upgrade nox + nox -s test-${{ matrix.python-version }} From 83aba758f773c390244dfdc97ecca66ef6a5c670 Mon Sep 17 00:00:00 2001 From: jreiberkyle Date: Thu, 4 Mar 2021 15:09:29 -0800 Subject: [PATCH 6/7] remove travis ci --- .travis.yml | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 860f32b1e..000000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: python -python: - - "3.7" - - "3.8" - - "3.9" -cache: - directories: - - $HOME/.cache/pip -install: - - pip install pip nox --upgrade -script: - - nox From 2124249e9ba14c3a60559ae235c5574f6dcb9c2f Mon Sep 17 00:00:00 2001 From: jreiberkyle Date: Thu, 4 Mar 2021 15:20:16 -0800 Subject: [PATCH 7/7] only test on pr, add lint check --- .github/workflows/test.yml | 28 +++++++++++++++++++++++++++- noxfile.py | 2 +- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 776e6c0f1..0106142e3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,6 @@ name: test -on: [push, pull_request] +on: [pull_request] jobs: test: @@ -29,3 +29,29 @@ jobs: run: | pip install --upgrade nox nox -s test-${{ matrix.python-version }} + + lint: + name: Check Linting + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.7 + - name: Pip cache + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip + restore-keys: | + ${{ runner.os }}-pip + - name: Lint + run: | + pip install --upgrade nox + nox -s lint + + + + diff --git a/noxfile.py b/noxfile.py index f488ac12d..8ce7a4f4b 100644 --- a/noxfile.py +++ b/noxfile.py @@ -20,7 +20,7 @@ def test(session): @nox.session -def check(session): +def lint(session): session.install("-e", ".[dev]") session.run("flake8", *source_files)