Skip to content

Commit ae3be3a

Browse files
committed
Upgrade Makefile and install instructions and remove old unneeded stuff
1 parent 3187407 commit ae3be3a

File tree

8 files changed

+142
-75
lines changed

8 files changed

+142
-75
lines changed

CONTRIBUTING.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ Ready to contribute? Here's how to set up `Copulas` for local development.
6969

7070
$ mkvirtualenv Copulas
7171
$ cd Copulas/
72-
$ pip install -e .
73-
$ pip install -r requirements_dev.txt
72+
$ make install-develop
7473

7574
4. Create a branch for local development::
7675

@@ -181,14 +180,16 @@ The process of releasing a new version involves several steps combining both ``g
181180
these changes are committed and available in ``master`` branch.
182181
Normally this is just a list of the Pull Requests that have been merged since the latest version.
183182

184-
Once this is done, just run the following commands::
183+
Once this is done, run of the following commands:
184+
185+
1. If you are releasing a patch version::
185186

186-
git checkout stable
187-
git merge --no-ff master # This creates a merge commit
188-
bumpversion release # This creates a new commit and a TAG
189-
git push --tags origin stable
190187
make release
191-
git checkout master
192-
git merge stable
193-
bumpversion --no-tag patch
194-
git push
188+
189+
2. If you are releasing a minor version::
190+
191+
make release-minor
192+
193+
3. If you are releasing a major version::
194+
195+
make release-major

Makefile

Lines changed: 105 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
.PHONY: clean clean-test clean-pyc clean-build clean-docs docs help
21
.DEFAULT_GOAL := help
32

43
define BROWSER_PYSCRIPT
@@ -26,38 +25,71 @@ export PRINT_HELP_PYSCRIPT
2625

2726
BROWSER := python -c "$$BROWSER_PYSCRIPT"
2827

28+
.PHONY: help
2929
help:
3030
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
3131

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

33+
# CLEAN TARGETS
34+
35+
.PHONY: clean-build
3436
clean-build: ## remove build artifacts
3537
rm -fr build/
3638
rm -fr dist/
3739
rm -fr .eggs/
3840
find . -name '*.egg-info' -exec rm -fr {} +
3941
find . -name '*.egg' -exec rm -f {} +
4042

43+
.PHONY: clean-pyc
4144
clean-pyc: ## remove Python file artifacts
4245
find . -name '*.pyc' -exec rm -f {} +
4346
find . -name '*.pyo' -exec rm -f {} +
4447
find . -name '*~' -exec rm -f {} +
4548
find . -name '__pycache__' -exec rm -fr {} +
4649

50+
.PHONY: clean-docs
51+
clean-docs: ## remove previously built docs
52+
-$(MAKE) -C docs clean 2>/dev/null # this fails if sphinx is not yet installed
53+
54+
.PHONY: clean-coverage
4755
clean-coverage: ## remove coverage artifacts
4856
rm -f .coverage
4957
rm -f .coverage.*
5058
rm -fr htmlcov/
5159

52-
clean-test: ## remove test and coverage artifacts
60+
.PHONY: clean-test
61+
clean-test: ## remove test artifacts
5362
rm -fr .tox/
5463
rm -fr .pytest_cache
5564

65+
.PHONY: clean
66+
clean: clean-build clean-pyc clean-test clean-coverage clean-docs ## remove all build, test, coverage, docs and Python artifacts
67+
68+
69+
# INSTALL TARGETS
70+
71+
.PHONY: install
72+
install: clean-build clean-pyc ## install the package to the active Python's site-packages
73+
pip install .
74+
75+
.PHONY: install-test
76+
install-test: clean-build clean-pyc ## install the package and test dependencies
77+
pip install .[test]
78+
79+
.PHONY: install-develop
80+
install-develop: clean-build clean-pyc ## install the package in editable mode and dependencies for development
81+
pip install -e .[dev]
82+
83+
84+
# LINT TARGETS
85+
86+
.PHONY: lint
5687
lint: ## check style with flake8 and isort
5788
flake8 copulas tests examples
5889
isort -c --recursive copulas tests examples
5990

60-
fixlint: ## fix lint issues using autoflake, autopep8, and isort
91+
.PHONY: fix-lint
92+
fix-lint: ## fix lint issues using autoflake, autopep8, and isort
6193
find copulas -name '*.py' | xargs autoflake --in-place --remove-all-unused-imports --remove-unused-variables
6294
autopep8 --in-place --recursive --aggressive copulas
6395
isort --apply --atomic --recursive copulas
@@ -70,45 +102,97 @@ fixlint: ## fix lint issues using autoflake, autopep8, and isort
70102
autopep8 --in-place --recursive --aggressive examples
71103
isort --apply --atomic --recursive examples
72104

105+
# TEST TARGETS
106+
107+
.PHONY: test
73108
test: ## run tests quickly with the default Python
74-
pytest
109+
python -m pytest --cov=copulas
75110

111+
.PHONY: test-all
76112
test-all: ## run tests on every Python version with tox
77113
tox
78114

79-
coverage: clean-coverage ## check code coverage quickly with the default Python
115+
.PHONY: coverage
116+
coverage: ## check code coverage quickly with the default Python
80117
coverage run --source copulas -m pytest
81118
coverage report -m
82119
coverage html
83120
$(BROWSER) htmlcov/index.html
84121

85-
clean-docs: ## remove previously built docs
86-
rm -f docs/copulas.rst
87-
rm -f docs/copulas.*.rst
88-
rm -f docs/modules.rst
89-
$(MAKE) -C docs clean
90122

123+
# DOCS TARGETS
124+
125+
.PHONY: docs
91126
docs: clean-docs ## generate Sphinx HTML documentation, including API docs
92-
sphinx-apidoc -o docs/ copulas
93127
$(MAKE) -C docs html
94128
touch docs/_build/html/.nojekyll
95129

96-
viewdocs: docs ## view docs in browser
130+
.PHONY: view-docs
131+
view-docs: docs ## view docs in browser
97132
$(BROWSER) docs/_build/html/index.html
98133

99-
servedocs: docs ## compile the docs watching for changes
100-
watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D .
134+
.PHONY: serve-docs
135+
serve-docs: view-docs ## compile the docs watching for changes
136+
watchmedo shell-command -W -R -D -p '*.rst;*.md' -c '$(MAKE) -C docs html' docs
101137

102-
release: dist ## package and upload a release
103-
twine upload dist/*
104138

105-
test-release: dist ## package and upload a release on TestPyPI
106-
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
139+
# RELEASE TARGETS
107140

141+
.PHONY: dist
108142
dist: clean ## builds source and wheel package
109143
python setup.py sdist
110144
python setup.py bdist_wheel
111145
ls -l dist
112146

113-
install: clean ## install the package to the active Python's site-packages
114-
python setup.py install
147+
.PHONY: test-publish
148+
test-publish: dist ## package and upload a release on TestPyPI
149+
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
150+
151+
.PHONY: publish
152+
publish: dist ## package and upload a release
153+
twine upload dist/*
154+
155+
.PHONY: bumpversion-release
156+
bumpversion-release: ## Merge master to stable and bumpversion release
157+
git checkout stable
158+
git merge --no-ff master -m"make release-tag: Merge branch 'master' into stable"
159+
bumpversion release
160+
git push --tags origin stable
161+
162+
.PHONY: bumpversion-patch
163+
bumpversion-patch: ## Merge stable to master and bumpversion patch
164+
git checkout master
165+
git merge stable
166+
bumpversion --no-tag patch
167+
git push
168+
169+
.PHONY: bumpversion-minor
170+
bumpversion-minor: ## Bump the version the next minor skipping the release
171+
bumpversion --no-tag minor
172+
173+
.PHONY: bumpversion-major
174+
bumpversion-major: ## Bump the version the next major skipping the release
175+
bumpversion --no-tag major
176+
177+
CURRENT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
178+
CHANGELOG_LINES := $(shell git diff HEAD..stable HISTORY.md | wc -l)
179+
180+
.PHONY: check-release
181+
check-release: ## Check if the release can be made
182+
ifneq ($(CURRENT_BRANCH),master)
183+
$(error Please make the release from master branch\n)
184+
endif
185+
ifeq ($(CHANGELOG_LINES),0)
186+
$(error Please insert the release notes in HISTORY.md before releasing)
187+
else
188+
@echo "A new release can be made"
189+
endif
190+
191+
.PHONY: release
192+
release: check-release bumpversion-release publish bumpversion-patch
193+
194+
.PHONY: release-minor
195+
release-minor: check-release bumpversion-minor release
196+
197+
.PHONY: release-major
198+
release-major: check-release bumpversion-major release

docs/installation.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ You can either clone the public repository:
3232

3333
.. code-block:: console
3434
35-
$ git clone git://github.com/DAI-Lab/copulas
35+
$ git clone git://github.com/DAI-Lab/Copulas
3636
3737
Or download the `tarball`_:
3838

3939
.. code-block:: console
4040
41-
$ curl -OL https://github.com/DAI-Lab/copulas/tarball/master
41+
$ curl -OL https://github.com/DAI-Lab/Copulas/tarball/master
4242
4343
Once you have a copy of the source, you can install it with:
4444

4545
.. code-block:: console
4646
47-
$ python setup.py install
47+
$ make install
4848
4949
50-
.. _Github repo: https://github.com/DAI-Lab/copulas
51-
.. _tarball: https://github.com/DAI-Lab/copulas/tarball/master
50+
.. _Github repo: https://github.com/DAI-Lab/Copulas
51+
.. _tarball: https://github.com/DAI-Lab/Copulas/tarball/master

requirements_dev.txt

Lines changed: 0 additions & 26 deletions
This file was deleted.

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
tests_require = [
3939
'pytest>=3.4.2',
40+
'pytest-cov>=2.6.0',
4041
]
4142

4243
setup_requires = [

tests/copulas/bivariate/test_base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ def test_to_dict(self):
7272
# Check
7373
assert result == expected_result
7474

75+
@mock.patch("builtins.open")
7576
@mock.patch('copulas.bivariate.base.json.dump')
76-
def test_save(self, json_mock):
77+
def test_save(self, json_mock, open_mock):
7778
"""Save stores the internal dictionary as a json in a file."""
7879
# Setup
7980
instance = Bivariate('frank')
@@ -89,12 +90,13 @@ def test_save(self, json_mock):
8990
instance.save('test.json')
9091

9192
# Check
93+
assert open_mock.called_once_with('test.json', 'w')
9294
assert json_mock.called
9395
compare_nested_dicts(json_mock.call_args[0][0], expected_content)
9496

95-
@mock.patch('builtins.open', new_callable=mock.mock_open)
97+
@mock.patch('builtins.open')
9698
@mock.patch('copulas.bivariate.base.json.load')
97-
def test_load_from_file(self, json_mock, file_mock):
99+
def test_load_from_file(self, json_mock, open_mock):
98100
"""Load can recreate an instance from a saved file."""
99101
# Setup
100102
json_mock.return_value = {
@@ -107,6 +109,7 @@ def test_load_from_file(self, json_mock, file_mock):
107109
instance = Bivariate.load('somefile.json')
108110

109111
# Check
112+
assert open_mock.called_once_with('test.json', 'r')
110113
instance.copula_type == CopulaTypes.FRANK
111114
instance.tau == -0.33333333333333337
112115
instance.theta == -3.305771759329249

tests/copulas/multivariate/test_gaussian_copula.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,9 @@ def test_from_dict(self):
372372
# This isn't to check the sampling, but that the copula is able to run.
373373
assert copula.sample(10).all().all()
374374

375+
@mock.patch("builtins.open")
375376
@mock.patch('copulas.multivariate.base.json.dump')
376-
def test_save(self, json_mock):
377+
def test_save(self, json_mock, open_mock):
377378
"""Save stores the internal dictionary as a json in a file."""
378379
# Setup
379380
instance = GaussianMultivariate()
@@ -423,11 +424,12 @@ def test_save(self, json_mock):
423424
instance.save('test.json')
424425

425426
# Check
427+
assert open_mock.called_once_with('test.json', 'w')
426428
compare_nested_dicts(json_mock.call_args[0][0], expected_content)
427429

428-
@mock.patch('builtins.open', new_callable=mock.mock_open)
430+
@mock.patch('builtins.open')
429431
@mock.patch('copulas.bivariate.base.json.load')
430-
def test_load(self, json_mock, file_mock):
432+
def test_load(self, json_mock, open_mock):
431433
"""Load can recreate an instance from a saved file."""
432434
# Setup
433435
covariance = [
@@ -470,7 +472,7 @@ def test_load(self, json_mock, file_mock):
470472
}
471473

472474
# Run
473-
instance = GaussianMultivariate.load('somefile.json')
475+
instance = GaussianMultivariate.load('test.json')
474476

475477
# Check
476478
assert (instance.covariance == np.array([
@@ -482,3 +484,5 @@ def test_load(self, json_mock, file_mock):
482484

483485
for name, distrib in instance.distribs.items():
484486
assert instance.distribs[name].to_dict() == json_mock.return_value['distribs'][name]
487+
488+
assert open_mock.called_once_with('test.json', 'r')

tox.ini

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ python =
99

1010

1111
[testenv]
12+
passenv = CI TRAVIS TRAVIS_*
1213
setenv =
1314
PYTHONPATH = {toxinidir}
15+
extras = test
1416
commands =
15-
/usr/bin/env python setup.py test
17+
/usr/bin/env python -m pytest --cov=copulas
1618

1719

1820
[testenv:lint]
1921
skipsdist = true
20-
deps =
21-
-r{toxinidir}/requirements_dev.txt
22+
extras = dev
2223
commands =
2324
/usr/bin/env make lint
2425

2526

2627
[testenv:docs]
2728
skipsdist = true
28-
deps =
29-
-r{toxinidir}/requirements_dev.txt
29+
extras = dev
3030
commands =
3131
/usr/bin/env make docs

0 commit comments

Comments
 (0)