Skip to content

Commit

Permalink
Add gh actions and config (#3)
Browse files Browse the repository at this point in the history
* Add gh actions and config

* reformat

* Move codecov to right folder

* Add dist and clean commands

* add wheel to reqs

* Fix wheel paths
  • Loading branch information
pjbull committed Mar 6, 2021
1 parent 8b7d147 commit ca1e650
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 32 deletions.
19 changes: 19 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
codecov:
require_ci_to_pass: yes

coverage:
precision: 1
round: down
range: "70...100"
status:
project: # Coverage of whole project
default:
target: auto # Coverage target to pass; auto is base commit
threshold: 2% # Allow coverage to drop by this much vs. base and still pass
patch: # Coverage of lines in this change
default:
target: 80% # Coverage target to pass
threshold: 20% # Allow coverage to drop by this much vs. base and still pass

comment:
layout: "diff,flags,tree"
46 changes: 46 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: tests

on:
push:
branches: [master]
pull_request:
schedule:
# Run every Sunday
- cron: "0 0 * * 0"

jobs:
build:
name: ${{ matrix.os }}, Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Run lint and test
run: |
make test
- name: Build distribution and test installation
shell: bash
run: |
make dist
python -m pip install dist/pandas_path-*.whl --no-deps --force-reinstall
python -m pip install dist/pandas_path-*.tar.gz --no-deps --force-reinstall
- name: Upload coverage to codecov
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
fail_ci_if_error: true
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
*.pyc
*.pyc

*.egg-info/

.vscode/

htmlcov/
.coverage
coverage*
39 changes: 29 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
reqs:
requirements:
pip install -r requirements-dev.txt

test: lint
py.test -vv pandas_path/tests.py

lint:
black .
black --check .
flake8 .

clean_pycache:
find . -name *.pyc -delete && find . -name __pycache__ -delete
format:
black .

clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts

clean-build: ## remove build artifacts
rm -fr build/
rm -fr dist/
rm -fr .eggs/
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +

clean-pyc: ## remove Python file artifacts
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +

clean: clean_pycache
rm -rf dist
rm -rf pandas_path.egg-info
clean-test: ## remove test and coverage artifacts
rm -fr .tox/
rm -f .coverage
rm -fr htmlcov/
rm -fr .pytest_cache

package: clean
dist: clean ## builds source and wheel package
python setup.py sdist
python setup.py bdist_wheel
ls -l dist

distribute_pypitest: package
distribute_pypitest: dist
twine upload --repository pypitest dist/*.tar.gz

distribute_pypi: package
distribute_pypi: dist
twine upload --repository pypi dist/*.tar.gz
10 changes: 3 additions & 7 deletions pandas_path/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@pd.api.extensions.register_series_accessor("path")
@pd.api.extensions.register_index_accessor("path")
class PathAccessor:
""" Adds a `.path` accessor to Series and Index objects so that all of the methods
"""Adds a `.path` accessor to Series and Index objects so that all of the methods
from pathlib.Path are available.
Register with pandas by importing. No other changes necessary.
Expand All @@ -35,9 +35,7 @@ def _validate(obj):
[Path(x) for x in obj.values]

def __getattr__(self, attr):
apply_series = (
self._obj.to_series() if isinstance(self._obj, pd.Index) else self._obj
)
apply_series = self._obj.to_series() if isinstance(self._obj, pd.Index) else self._obj

# check the type of this attribute on a Path object
attr_type = getattr(type(Path()), attr, None)
Expand Down Expand Up @@ -105,9 +103,7 @@ def _to_apply(this_elem, other_elem):
return elementwise_result

def _path_join(self, other, side):
if isinstance(
other, (list, tuple, np.ndarray, pd.Series, pd.Index, PathAccessor)
):
if isinstance(other, (list, tuple, np.ndarray, pd.Series, pd.Index, PathAccessor)):
return self._elementwise(other, side)
else:
return self.__getattr__(side)(other)
Expand Down
8 changes: 2 additions & 6 deletions pandas_path/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ def test_operators(sample_series, sample_paths):
sample_series.path.parent.path / "new_folder" / "new_file"

# chaining - explicit
expected = [
str(Path(f).parent / "new_sub_folder" / "new_file.txt") for f in sample_paths
]
expected = [str(Path(f).parent / "new_sub_folder" / "new_file.txt") for f in sample_paths]
assert (
(sample_series.path.parent.path / "new_sub_folder").path / "new_file.txt"
).tolist() == expected
Expand All @@ -117,9 +115,7 @@ def test_elementwise(pd, sample_series, sample_paths):
assert (sample_series.path.parent.path / to_append).tolist() == expected
assert (sample_series.path.parent.path / np.array(to_append)).tolist() == expected
assert (sample_series.path.parent.path / pd.Series(to_append)).tolist() == expected
assert (
sample_series.path.parent.path / pd.Series(to_append).path
).tolist() == expected
assert (sample_series.path.parent.path / pd.Series(to_append).path).tolist() == expected

expected = [str(p / Path(f)) for f, p in zip(sample_paths, to_prepend)]
assert (to_prepend / sample_series.path).tolist() == expected
Expand Down
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tool.black]
line-length = 99
target-version = ['py36', 'py37', 'py38']
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.venv
)
'''
4 changes: 3 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
black
flake8
pytest
twine
pytest-cov
twine
wheel
23 changes: 16 additions & 7 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
[metadata]
description-file = README.md
[aliases]
# Define setup.py command aliases here
test = pytest

[flake8]
ignore = E731,E266,E501,C901,W503
ignore = E731,E266,E501,C901,W503,E203
max-line-length = 99
exclude = .git
exclude =
.git

[pep8]
max-line-length = 99
exclude = .git
[mypy]
ignore_missing_imports = True
allow_redefinition = True

[tool:pytest]
testpaths = pandas_path/tests.py
addopts = --cov=pandas_path --cov-report=term --cov-report=html --cov-report=xml

[coverage:report]
include = pandas_path/**.py

0 comments on commit ca1e650

Please sign in to comment.