Skip to content

Commit d255054

Browse files
authored
48 - Add dependency version constraints (#53)
* 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
1 parent 32b8e57 commit d255054

11 files changed

+126
-13
lines changed

.githooks/pre-commit

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
#
3+
# A pre-commit hook to automatically generate requirements files
4+
# from the install_requires and extra_requires entries in the
5+
# setup.cfg file.
6+
# These are only present to allow github's dependabot tool to actually
7+
# monitor our packages
8+
9+
# Redirect output to stderr.
10+
exec 1>&2
11+
12+
pythonAliases=("python3" "py" "python")
13+
hasPython=0
14+
15+
for alias in "${pythonAliases[@]}"; do
16+
if command -v "$alias"; then
17+
pythonAlias="$alias"
18+
hasPython=1
19+
break
20+
fi
21+
done
22+
23+
if [ -z "$hasPython" ]; then
24+
echo "No python was detected, ensure it is available on your path as one of:"
25+
echo "${pythonAliases[*]}"
26+
exit 1
27+
fi
28+
29+
ROOT_DIR=$(git rev-parse --show-toplevel)
30+
pushd "$ROOT_DIR/requires" || exit 1
31+
"$pythonAlias" ./generate_requirements.py
32+
if test -f "./.updated"; then
33+
rm ./.updated
34+
git add ./*_requirements.txt
35+
fi
36+
popd || exit 0

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,18 @@ _autosummary
3838
.coverage
3939
*,cover
4040
test-output.xml
41+
/.tox
42+
/htmlcov
4143

4244
\#*
4345
.\#*
4446
/.ipynb_checkpoints
4547

48+
# IDE Specific Files #
49+
######################
50+
/.idea
51+
52+
53+
# Virtual Environments #
54+
########################
55+
/venv

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ Install openapi-common with:
1717
1818
pip install ansys-openapi-common
1919
20-
Alternatively, clone and install in development mode with:
20+
Alternatively, clone and install with:
2121

2222
.. code::
2323
2424
git clone https://github.com/pyansys/openapi-common
2525
cd openapi-common
26-
pip install -e .
26+
pip install .
2727
2828
2929
Usage

doc/source/contributing.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and install the latest version by running:
2424
git clone https://github.com/pyansys/openapi-common
2525
cd openapi-common
2626
pip install .
27+
git config core.hooksPath .githooks
2728
2829
2930
Questions

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ deps =
4646
{[testenv]deps}
4747
4848
commands =
49-
black --check ./tests ./src
49+
black --check ./tests ./src ./requires
5050
mypy ./src
5151
"""

requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

requires/generate_requirements.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import os
2+
import shutil
3+
import sys
4+
5+
from setuptools.config import read_configuration
6+
7+
8+
def item_generator(things):
9+
for item in things:
10+
yield item
11+
yield "\n"
12+
13+
14+
setup_info = read_configuration("../setup.cfg")
15+
16+
install_requires = []
17+
extras_require = {}
18+
19+
if "options" in setup_info:
20+
info_options = setup_info["options"]
21+
if "install_requires" in info_options:
22+
install_requires = info_options["install_requires"]
23+
if "extras_require" in info_options:
24+
extras_require = info_options["extras_require"]
25+
26+
# Copy all existing requirements.txt files to allow us to roll-back if something goes wrong
27+
for file in os.listdir("./"):
28+
if file.endswith("requirements.txt"):
29+
shutil.move(file, f"./{file}.orig")
30+
31+
try:
32+
with open("./package_requirements.txt", "w", encoding="utf8") as fp:
33+
print("Writing package requirements to package_requirements.txt")
34+
fp.writelines(item_generator(install_requires))
35+
36+
for extra, requirements in extras_require.items():
37+
file_name = f"{extra}_requirements.txt"
38+
print(f"Writing extra requirements for {extra} to {file_name}")
39+
with open(file_name, "w", encoding="utf8") as fp:
40+
fp.writelines(item_generator(requirements))
41+
42+
with open("./.updated", "w") as fp:
43+
fp.write("updated")
44+
45+
for file in os.listdir("./"):
46+
if file.endswith(".orig"):
47+
os.remove(file)
48+
49+
except (IOError, OSError) as excinfo:
50+
print("An error occurred:")
51+
print(excinfo)
52+
53+
for file in os.listdir("./"):
54+
if file.endswith(".orig"):
55+
shutil.move(file, file[:-5])
56+
57+
print("Rolled back to original state, aborting")
58+
sys.exit(1)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests-kerberos >= 0.13.0; sys_platform == "linux"

requires/oidc_requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
requests_oauthlib >= 1.2
2+
keyring >= 22.0

requires/package_requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
requests >= 2.26
2+
requests-negotiate-sspi >= 0.5.2; sys_platform == "win32"
3+
requests-ntlm >= 1.1.0
4+
pyparsing >= 3.0
5+
python-dateutil >= 2.6.1
6+
typing-extensions >= 3.7; python_version < '3.8'

0 commit comments

Comments
 (0)