Skip to content

Commit 26a27ee

Browse files
authored
Merge pull request #24 from BeyondEvil/use-pre-commit
black styling and pre-commit changes
2 parents fcbe0a9 + 0d65778 commit 26a27ee

File tree

11 files changed

+292
-122
lines changed

11 files changed

+292
-122
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ __pycache__
22
.cache
33
.DS_Store
44
.tox
5+
.eggs
6+
.vscode
57
build
68
dist
79
*.egg-info
810
*.pyc
11+
Pipfile.lock

.pre-commit-config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
repos:
2+
3+
- repo: https://github.com/psf/black
4+
rev: stable
5+
hooks:
6+
- id: black
7+
args: [--safe, --quiet]
8+
language_version: python3
9+
10+
- repo: https://gitlab.com/pycqa/flake8
11+
rev: 3.7.7
12+
hooks:
13+
- id: flake8
14+
exclude: docs
15+
language_version: python3

.travis.yml

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
11
language: python
2-
python:
3-
- 2.7
4-
- 3.4
5-
- 3.5
6-
- 3.6
7-
- pypy
8-
- pypy3
9-
- nightly
102
jobs:
113
include:
12-
- stage:
4+
- stage: Tests
5+
name: Linting
6+
python: 3.7
7+
dist: xenial
8+
sudo: required
9+
env: TOXENV=linting
10+
11+
-
12+
python: 2.7
13+
env: TOXENV=py27
14+
15+
-
1316
python: 3.6
14-
env: TOXENV=flake8
17+
env: TOXENV=py36
18+
19+
-
20+
python: 3.7
21+
dist: xenial
22+
sudo: required
23+
env: TOXENV=py37
24+
25+
-
26+
python: pypy
27+
env: TOXENV=pypy
28+
29+
-
30+
python: pypy3
31+
env: TOXENV=pypy3
32+
1533
- stage: deploy
16-
python: 3.6
34+
python: 3.7
35+
dist: xenial
36+
sudo: required
1737
install: skip
1838
script: skip
1939
deploy:
@@ -25,7 +45,9 @@ jobs:
2545
on:
2646
tags: true
2747
repo: pytest-dev/pytest-variables
28-
cache:
29-
pip: true
30-
install: pip install tox-travis
48+
49+
cache: pip
50+
51+
install: pip install tox
52+
3153
script: tox

Pipfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
pytest = "*"
8+
tox = "*"
9+
flake8 = "*"
10+
black = "*"
11+
pre-commit = "*"
12+
13+
[packages]
14+
pytest-variables = {editable = true,extras = ["hjson", "yaml"],path = "."}

README.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ languages. To install YAML support:
6363
6464
$ pip install pytest-variables[yaml]
6565
66+
Contributing
67+
------------
68+
69+
We welcome contributions.
70+
71+
To learn more, see `Development <https://github.com/pytest-dev/pytest-variables/blob/master/development.rst>`_
72+
6673
Specifying variables
6774
--------------------
6875

development.rst

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
Development
2+
===========
3+
4+
To contribute to `pytest-variables` you can use `Pipenv`_ to manage
5+
a python virtual environment and `pre-commit <https://pre-commit.com/>`_ to help you with
6+
styling and formatting.
7+
8+
To setup the virtual environment and pre-commit, run:
9+
10+
.. code-block:: bash
11+
12+
$ pipenv install --dev
13+
$ pipenv run pre-commit install
14+
15+
If you're not using `Pipenv`_, to install `pre-commit`, run:
16+
17+
.. code-block:: bash
18+
19+
$ pip install pre-commit
20+
$ pre-commit install
21+
22+
Automated Testing
23+
-----------------
24+
25+
All pull requests and merges are tested in `Travis CI <https://travis-ci.org/>`_
26+
based on the ``.travis.yml`` file.
27+
28+
Usually, a link to your specific travis build appears in pull requests, but if
29+
not, you can find it on the
30+
`pull requests page <https://travis-ci.org/pytest-dev/pytest-variables/pull_requests>`_
31+
32+
The only way to trigger Travis CI to run again for a pull request, is to submit
33+
another change to the pull branch.
34+
35+
You can do this with `git commit --allow-empty`
36+
37+
Running Tests
38+
-------------
39+
40+
You will need `Tox <http://tox.testrun.org/>`_ installed to run the tests
41+
against the supported Python versions. If you're using `Pipenv`_ it will be
42+
installed for you.
43+
44+
With `Pipenv`_, run:
45+
46+
.. code-block:: bash
47+
48+
$ pipenv run tox
49+
50+
Otherwise, to install and run, do:
51+
52+
.. code-block:: bash
53+
54+
$ pip install tox
55+
$ tox
56+
57+
Releasing a new version
58+
-----------------------
59+
60+
Follow these steps to release a new version of the project:
61+
62+
1. Update your local master with the upstream master (``git pull --rebase upstream master``)
63+
2. Create a new branch and update ``CHANGES.rst`` with the new version, today's date, and all changes/new features
64+
3. Commit and push the new branch and then create a new pull request
65+
4. Wait for tests and reviews and then merge the branch
66+
5. Once merged, update your local master again (``git pull --rebase upstream master``)
67+
6. Tag the release with the new release version (``git tag v<new tag>``)
68+
7. Push the tag (``git push upstream --tags``)
69+
8. Done. You can monitor the progress on `Travis <https://travis-ci.org/pytest-dev/pytest-variables/>`_

pytest_variables/errors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55

66
class ValueError(Exception):
77
"""pytest-variables usage error."""
8+
89
pass

pytest_variables/plugin.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,45 @@
1414

1515

1616
def default(module, path):
17-
with io.open(path, 'r', encoding='utf8') as f:
17+
with io.open(path, "r", encoding="utf8") as f:
1818
return module.load(f)
1919

2020

2121
parser_table = {
22-
'json': ('json', default),
23-
'hjson': ('hjson', default),
24-
'yml': ('yaml', default),
25-
'yaml': ('yaml', default)}
22+
"json": ("json", default),
23+
"hjson": ("hjson", default),
24+
"yml": ("yaml", default),
25+
"yaml": ("yaml", default),
26+
}
2627

2728

2829
def import_parser(path, import_type, parser_func):
2930
try:
3031
__import__(import_type)
3132
mod = sys.modules[import_type]
3233
except ImportError:
33-
sys.exit('{0} import error, please make sure that {0} is '
34-
'installed'.format(import_type))
34+
sys.exit(
35+
"{0} import error, please make sure that {0} is "
36+
"installed".format(import_type)
37+
)
3538
return parser_func(mod, path)
3639

3740

3841
def pytest_addoption(parser):
39-
group = parser.getgroup('debugconfig')
42+
group = parser.getgroup("debugconfig")
4043
group.addoption(
41-
'--variables',
42-
action='append',
44+
"--variables",
45+
action="append",
4346
default=[],
44-
metavar='path',
45-
help='path to variables file.')
47+
metavar="path",
48+
help="path to variables file.",
49+
)
4650

4751

4852
def _merge(a, b, path=None):
4953
""" merges b and a configurations.
5054
Based on http://bit.ly/2uFUHgb
51-
"""
55+
"""
5256
if path is None:
5357
path = []
5458

@@ -68,29 +72,31 @@ def _merge(a, b, path=None):
6872

6973
def pytest_configure(config):
7074
config._variables = {}
71-
paths = config.getoption('variables')
75+
paths = config.getoption("variables")
7276
for path in paths:
73-
ext = os.path.splitext(path)[1][1:].lower() or 'json'
77+
ext = os.path.splitext(path)[1][1:].lower() or "json"
7478
try:
7579
variables = import_parser(path, *parser_table[ext])
7680
except KeyError:
77-
warnings.warn(UserWarning(
78-
"Could not find a parser for the file extension '{0}'. "
79-
'Supported extensions are: {1}'.format(
80-
ext, ', '.join(sorted(parser_table.keys())))))
81-
variables = import_parser(path, *parser_table['json'])
81+
warnings.warn(
82+
UserWarning(
83+
"Could not find a parser for the file extension '{0}'. "
84+
"Supported extensions are: {1}".format(
85+
ext, ", ".join(sorted(parser_table.keys()))
86+
)
87+
)
88+
)
89+
variables = import_parser(path, *parser_table["json"])
8290
except ValueError as e:
83-
raise errors.ValueError('Unable to parse {0}: {1}'.format(
84-
path, e))
91+
raise errors.ValueError("Unable to parse {0}: {1}".format(path, e))
8592

8693
if not isinstance(variables, dict):
87-
raise errors.ValueError('Unable to parse {0}'.format(
88-
path))
94+
raise errors.ValueError("Unable to parse {0}".format(path))
8995

9096
reduce(_merge, [config._variables, variables])
9197

9298

93-
@pytest.fixture(scope='session')
99+
@pytest.fixture(scope="session")
94100
def variables(pytestconfig):
95101
"""Provide test variables from a specified file"""
96102
return pytestconfig._variables

setup.py

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
from setuptools import setup
22

3-
setup(name='pytest-variables',
4-
use_scm_version=True,
5-
description='pytest plugin for providing variables to tests/fixtures',
6-
long_description=open('README.rst').read(),
7-
author='Dave Hunt',
8-
author_email='[email protected]',
9-
url='https://github.com/pytest-dev/pytest-variables',
10-
packages=['pytest_variables'],
11-
entry_points={'pytest11': ['variables = pytest_variables.plugin']},
12-
install_requires=['pytest>=2.4.2'],
13-
setup_requires=['setuptools_scm'],
14-
extras_require={
15-
'hjson': ['hjson'],
16-
'yaml': ['PyYAML']},
17-
license='Mozilla Public License 2.0 (MPL 2.0)',
18-
keywords='py.test pytest json variables',
19-
classifiers=[
20-
'Development Status :: 5 - Production/Stable',
21-
'Framework :: Pytest',
22-
'Intended Audience :: Developers',
23-
'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
24-
'Operating System :: POSIX',
25-
'Operating System :: Microsoft :: Windows',
26-
'Operating System :: MacOS :: MacOS X',
27-
'Topic :: Software Development :: Quality Assurance',
28-
'Topic :: Software Development :: Testing',
29-
'Topic :: Utilities',
30-
'Programming Language :: Python',
31-
'Programming Language :: Python :: 2.7',
32-
'Programming Language :: Python :: 3.6'])
3+
setup(
4+
name="pytest-variables",
5+
use_scm_version=True,
6+
description="pytest plugin for providing variables to tests/fixtures",
7+
long_description=open("README.rst").read(),
8+
author="Dave Hunt",
9+
author_email="[email protected]",
10+
url="https://github.com/pytest-dev/pytest-variables",
11+
packages=["pytest_variables"],
12+
entry_points={"pytest11": ["variables = pytest_variables.plugin"]},
13+
install_requires=["pytest>=2.4.2"],
14+
setup_requires=["setuptools_scm"],
15+
extras_require={"hjson": ["hjson"], "yaml": ["PyYAML"]},
16+
license="Mozilla Public License 2.0 (MPL 2.0)",
17+
keywords="py.test pytest json variables",
18+
classifiers=[
19+
"Development Status :: 5 - Production/Stable",
20+
"Framework :: Pytest",
21+
"Intended Audience :: Developers",
22+
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
23+
"Operating System :: POSIX",
24+
"Operating System :: Microsoft :: Windows",
25+
"Operating System :: MacOS :: MacOS X",
26+
"Topic :: Software Development :: Quality Assurance",
27+
"Topic :: Software Development :: Testing",
28+
"Topic :: Utilities",
29+
"Programming Language :: Python",
30+
"Programming Language :: Python :: 2.7",
31+
"Programming Language :: Python :: 3.6",
32+
"Programming Language :: Python :: 3.7",
33+
],
34+
)

0 commit comments

Comments
 (0)