Skip to content

Commit

Permalink
48 - Add dependency version constraints (#53)
Browse files Browse the repository at this point in the history
* Add minimum versions for runtime dependencies, also update gitignore

* Fix minimum version

* Add generate_requirements.py script and remove manually added files

* Add commit hook to the repo, add usage instructions and update docs

* Add newlines to generated requiremetns

* Remove blank requirements.txt

* Review comments
- Run black on generate_requirements.py
- Add to lint targets
- Roll back requests-negotiate-sspi to pypi latest release
- Make hook somewhat tolerant to differences in python installation names
  • Loading branch information
da1910 authored Jan 10, 2022
1 parent 32b8e57 commit d255054
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 13 deletions.
36 changes: 36 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
#
# A pre-commit hook to automatically generate requirements files
# from the install_requires and extra_requires entries in the
# setup.cfg file.
# These are only present to allow github's dependabot tool to actually
# monitor our packages

# Redirect output to stderr.
exec 1>&2

pythonAliases=("python3" "py" "python")
hasPython=0

for alias in "${pythonAliases[@]}"; do
if command -v "$alias"; then
pythonAlias="$alias"
hasPython=1
break
fi
done

if [ -z "$hasPython" ]; then
echo "No python was detected, ensure it is available on your path as one of:"
echo "${pythonAliases[*]}"
exit 1
fi

ROOT_DIR=$(git rev-parse --show-toplevel)
pushd "$ROOT_DIR/requires" || exit 1
"$pythonAlias" ./generate_requirements.py
if test -f "./.updated"; then
rm ./.updated
git add ./*_requirements.txt
fi
popd || exit 0
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,18 @@ _autosummary
.coverage
*,cover
test-output.xml
/.tox
/htmlcov

\#*
.\#*
/.ipynb_checkpoints

# IDE Specific Files #
######################
/.idea


# Virtual Environments #
########################
/venv
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Install openapi-common with:
pip install ansys-openapi-common
Alternatively, clone and install in development mode with:
Alternatively, clone and install with:

.. code::
git clone https://github.com/pyansys/openapi-common
cd openapi-common
pip install -e .
pip install .
Usage
Expand Down
1 change: 1 addition & 0 deletions doc/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and install the latest version by running:
git clone https://github.com/pyansys/openapi-common
cd openapi-common
pip install .
git config core.hooksPath .githooks
Questions
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ deps =
{[testenv]deps}
commands =
black --check ./tests ./src
black --check ./tests ./src ./requires
mypy ./src
"""
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

58 changes: 58 additions & 0 deletions requires/generate_requirements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import os
import shutil
import sys

from setuptools.config import read_configuration


def item_generator(things):
for item in things:
yield item
yield "\n"


setup_info = read_configuration("../setup.cfg")

install_requires = []
extras_require = {}

if "options" in setup_info:
info_options = setup_info["options"]
if "install_requires" in info_options:
install_requires = info_options["install_requires"]
if "extras_require" in info_options:
extras_require = info_options["extras_require"]

# Copy all existing requirements.txt files to allow us to roll-back if something goes wrong
for file in os.listdir("./"):
if file.endswith("requirements.txt"):
shutil.move(file, f"./{file}.orig")

try:
with open("./package_requirements.txt", "w", encoding="utf8") as fp:
print("Writing package requirements to package_requirements.txt")
fp.writelines(item_generator(install_requires))

for extra, requirements in extras_require.items():
file_name = f"{extra}_requirements.txt"
print(f"Writing extra requirements for {extra} to {file_name}")
with open(file_name, "w", encoding="utf8") as fp:
fp.writelines(item_generator(requirements))

with open("./.updated", "w") as fp:
fp.write("updated")

for file in os.listdir("./"):
if file.endswith(".orig"):
os.remove(file)

except (IOError, OSError) as excinfo:
print("An error occurred:")
print(excinfo)

for file in os.listdir("./"):
if file.endswith(".orig"):
shutil.move(file, file[:-5])

print("Rolled back to original state, aborting")
sys.exit(1)
1 change: 1 addition & 0 deletions requires/linux_kerberos_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests-kerberos >= 0.13.0; sys_platform == "linux"
2 changes: 2 additions & 0 deletions requires/oidc_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests_oauthlib >= 1.2
keyring >= 22.0
6 changes: 6 additions & 0 deletions requires/package_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
requests >= 2.26
requests-negotiate-sspi >= 0.5.2; sys_platform == "win32"
requests-ntlm >= 1.1.0
pyparsing >= 3.0
python-dateutil >= 2.6.1
typing-extensions >= 3.7; python_version < '3.8'
18 changes: 9 additions & 9 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ package_dir =
=src
packages = find_namespace:
install_requires =
requests
requests-negotiate-sspi; sys_platform == "win32"
requests-ntlm
pyparsing
python-dateutil
typing-extensions; python_version < '3.8'
requests >= 2.26
requests-negotiate-sspi >= 0.5.2; sys_platform == "win32"
requests-ntlm >= 1.1.0
pyparsing >= 3.0
python-dateutil >= 2.6.1
typing-extensions >= 3.7; python_version < '3.8'
tests_require =
pytest
uvicorn
Expand All @@ -50,7 +50,7 @@ where = src

[options.extras_require]
oidc =
requests_oauthlib
keyring
requests_oauthlib >= 1.2
keyring >= 22.0
linux-kerberos =
requests-kerberos; sys_platform == "linux"
requests-kerberos >= 0.13.0; sys_platform == "linux"

0 comments on commit d255054

Please sign in to comment.