Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #306 from nikitalita/extra
Browse files Browse the repository at this point in the history
  • Loading branch information
lorengordon authored Aug 2, 2021
2 parents 1b3abd0 + 4ad6a5b commit cd52d2c
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[bumpversion]
current_version = 0.3.67
commit = False
current_version = 0.4.0
commit = True
tag = False
tag_name = v{new_version}

Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGE LOG
==========

0.4.0 - 2021.08.02
-------------------
* [FEATURE] Add option to include/exclude extras_require from required packages,
using `get_required(include_extras_require=False)`.

0.3.17 - 2020.02.27
-------------------
* [FIX] Remove standard packages from setup.cfg install requires.
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ This is a sample usage of Pyppyn from a Python script.
# Load config, install dependencies and import a module from the package
p.process_config()
print("Package requires:", p.get_required())
print("Package requires:", p.get_required(include_extras_require=False))
Contribute
==========
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- script: |
call $(venvDirectory)/Scripts/activate.bat
python -m pip install --editable .
displayName: install gravitybee
displayName: install pyppyn
- script: |
call $(venvDirectory)/Scripts/activate.bat
python -m pip list
Expand Down
29 changes: 24 additions & 5 deletions pyppyn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import uuid
import zipfile

__version__ = "0.3.67"
__version__ = "0.4.0"

__EXITOKAY__ = 0
FILE_DIR = ".pyppyn"
Expand Down Expand Up @@ -145,7 +145,14 @@ def __init__(self, **kwargs):
self.python_version = sys.version_info[0] + (sys.version_info[1] / 10)

# requirements
self.reqs = {"os": [], "other": [], "base": [], "python": [], "unparsed": []}
self.reqs = {
"os": [],
"other": [],
"base": [],
"python": [],
"unparsed": [],
"extra": [],
}

# suffix for renaming build/dist directories
self._rename_end = None
Expand Down Expand Up @@ -361,6 +368,8 @@ def _parse_marker(self, package=None, marker=None):
):
self.reqs["python"].append(package)

elif marker_parts[0] == "extra":
self.reqs["extra"].append(package)
else:
self.reqs["unparsed"].append(package)

Expand Down Expand Up @@ -433,21 +442,31 @@ def install_packages(self):

return self._status["did_load"] == self._status["should_load"]

def get_required(self):
"""Return required packages based on configuration."""
def get_required(self, include_extras_require=True):
"""Return required packages based on configuration.
Args:
include_extras_require: Boolean. If False, skip
packages tagged as "extra" in return.
"""
if (
self._status["state"] != ConfigRep.STATE_LOAD
and self._status["state"] != ConfigRep.STATE_INSTALLED
):
self.load_config()

return (
required = (
self.reqs["base"]
+ self.reqs["os"]
+ self.reqs["python"]
+ self.reqs["unparsed"]
)

if include_extras_require:
required = required + self.reqs["extra"]

return required

def get_config_attr(self, key, element=0):
"""Return value associated with a key in the configuration.
Expand Down
8 changes: 8 additions & 0 deletions tests/minipippy/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,11 @@ addopts =
--doctest-modules
--doctest-glob=\*.md
--tb=short

[options.extras_require]
test =
pytest
check =
flake8
docs =
sphinx
27 changes: 25 additions & 2 deletions tests/test_pyppyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,36 @@ def test_process_config(configrep):


def test_get_required(configrep):
"""Test getting list of requirements."""
"""Test getting list of requirements, including extra packages
(such as those marked with "test", "check", "docs")."""
if platform.system().lower() == "windows":
assert set(configrep.get_required()) == set(
["backoff", "click", "pyyaml", "defusedxml", "pypiwin32", "six"]
[
"backoff",
"click",
"pyyaml",
"defusedxml",
"pypiwin32",
"six",
"pytest",
"flake8",
"sphinx",
]
)
else:
assert set(configrep.get_required()) == set(
["backoff", "click", "six", "pyyaml", "pytest", "flake8", "sphinx"]
)


def test_get_required_no_extras(configrep):
"""Test getting list of requirements."""
if platform.system().lower() == "windows":
assert set(configrep.get_required(include_extras_require=False)) == set(
["backoff", "click", "pyyaml", "defusedxml", "pypiwin32", "six"]
)
else:
assert set(configrep.get_required(include_extras_require=False)) == set(
["backoff", "click", "six", "pyyaml"]
)

Expand Down

0 comments on commit cd52d2c

Please sign in to comment.