Skip to content

Commit 907e540

Browse files
authored
Merge pull request #62 from nexB/better-tpp-scripts
Better tpp scripts
2 parents ae73ce3 + b272e3b commit 907e540

16 files changed

+1349
-2602
lines changed

Diff for: README.rst

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
A Simple Python Project Skeleton
22
================================
3-
This repo attempts to standardize our python repositories using modern python
4-
packaging and configuration techniques. Using this `blog post`_ as inspiration, this
5-
repository will serve as the base for all new python projects and will be adopted to all
6-
our existing ones as well.
3+
This repo attempts to standardize the structure of the Python-based project's
4+
repositories using modern Python packaging and configuration techniques.
5+
Using this `blog post`_ as inspiration, this repository serves as the base for
6+
all new Python projects and is mergeable in existing repositories as well.
77

88
.. _blog post: https://blog.jaraco.com/a-project-skeleton-for-python-projects/
99

10+
1011
Usage
1112
=====
1213

@@ -36,9 +37,16 @@ This is also the workflow to use when updating the skeleton files in any given r
3637

3738
More usage instructions can be found in ``docs/skeleton-usage.rst``.
3839

40+
3941
Release Notes
4042
=============
4143

44+
- 2022-03-04:
45+
- Synchronize configure and configure.bat scripts for sanity
46+
- Update CI operating system support with latest Azure OS images
47+
- Streamline utility scripts in etc/scripts/ to create, fetch and manage third-party dependencies
48+
There are now fewer scripts. See etc/scripts/README.rst for details
49+
4250
- 2021-09-03:
4351
- ``configure`` now requires pinned dependencies via the use of ``requirements.txt`` and ``requirements-dev.txt``
4452
- ``configure`` can now accept multiple options at once

Diff for: azure-pipelines.yml

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ jobs:
3131
test_suites:
3232
all: venv/bin/pytest -n 2 -vvs
3333

34+
- template: etc/ci/azure-posix.yml
35+
parameters:
36+
job_name: macos11_cpython
37+
image_name: macos-11
38+
python_versions: ['3.6', '3.7', '3.8', '3.9', '3.10']
39+
test_suites:
40+
all: venv/bin/pytest -n 2 -vvs
41+
3442
- template: etc/ci/azure-win.yml
3543
parameters:
3644
job_name: win2019_cpython

Diff for: configure

+84-71
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ set -e
1616
# Source this script for initial configuration
1717
# Use configure --help for details
1818
#
19+
# NOTE: please keep in sync with Windows script configure.bat
20+
#
1921
# This script will search for a virtualenv.pyz app in etc/thirdparty/virtualenv.pyz
2022
# Otherwise it will download the latest from the VIRTUALENV_PYZ_URL default
2123
################################
@@ -32,10 +34,8 @@ DEV_REQUIREMENTS="--editable .[testing] --constraint requirements.txt --constrai
3234
# where we create a virtualenv
3335
VIRTUALENV_DIR=venv
3436

35-
# Cleanable files and directories with the --clean option
36-
CLEANABLE="
37-
build
38-
venv"
37+
# Cleanable files and directories to delete with the --clean option
38+
CLEANABLE="build venv"
3939

4040
# extra arguments passed to pip
4141
PIP_EXTRA_ARGS=" "
@@ -50,11 +50,14 @@ VIRTUALENV_PYZ_URL=https://bootstrap.pypa.io/virtualenv.pyz
5050
CFG_ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5151
CFG_BIN_DIR=$CFG_ROOT_DIR/$VIRTUALENV_DIR/bin
5252

53+
54+
################################
55+
# Thirdparty package locations and index handling
5356
# Find packages from the local thirdparty directory or from thirdparty.aboutcode.org
5457
if [ -f "$CFG_ROOT_DIR/thirdparty" ]; then
55-
PIP_EXTRA_ARGS="--find-links $CFG_ROOT_DIR/thirdparty "
58+
PIP_EXTRA_ARGS="--find-links $CFG_ROOT_DIR/thirdparty"
5659
fi
57-
PIP_EXTRA_ARGS="$PIP_EXTRA_ARGS --find-links https://thirdparty.aboutcode.org/pypi"
60+
PIP_EXTRA_ARGS="$PIP_EXTRA_ARGS --find-links https://thirdparty.aboutcode.org/pypi/simple/links.html"
5861

5962

6063
################################
@@ -65,56 +68,50 @@ fi
6568

6669

6770
################################
68-
# find a proper Python to run
69-
# Use environment variables or a file if available.
70-
# Otherwise the latest Python by default.
71-
if [[ "$PYTHON_EXECUTABLE" == "" ]]; then
72-
# check for a file named PYTHON_EXECUTABLE
73-
if [ -f "$CFG_ROOT_DIR/PYTHON_EXECUTABLE" ]; then
74-
PYTHON_EXECUTABLE=$(cat "$CFG_ROOT_DIR/PYTHON_EXECUTABLE")
75-
else
76-
PYTHON_EXECUTABLE=python3
77-
fi
78-
fi
71+
# Main command line entry point
72+
main() {
73+
CFG_REQUIREMENTS=$REQUIREMENTS
74+
NO_INDEX="--no-index"
75+
76+
# We are using getopts to parse option arguments that start with "-"
77+
while getopts :-: optchar; do
78+
case "${optchar}" in
79+
-)
80+
case "${OPTARG}" in
81+
help ) cli_help;;
82+
clean ) find_python && clean;;
83+
dev ) CFG_REQUIREMENTS="$DEV_REQUIREMENTS";;
84+
init ) NO_INDEX="";;
85+
esac;;
86+
esac
87+
done
7988

89+
PIP_EXTRA_ARGS="$PIP_EXTRA_ARGS $NO_INDEX"
8090

81-
################################
82-
cli_help() {
83-
echo An initial configuration script
84-
echo " usage: ./configure [options]"
85-
echo
86-
echo The default is to configure for regular use. Use --dev for development.
87-
echo Use the --init option if starting a new project and the project
88-
echo dependencies are not available on thirdparty.aboutcode.org/pypi/
89-
echo and requirements.txt and/or requirements-dev.txt has not been generated.
90-
echo
91-
echo The options are:
92-
echo " --clean: clean built and installed files and exit."
93-
echo " --dev: configure the environment for development."
94-
echo " --init: pull dependencies from PyPI. Used when first setting up a project."
95-
echo " --help: display this help message and exit."
96-
echo
97-
echo By default, the python interpreter version found in the path is used.
98-
echo Alternatively, the PYTHON_EXECUTABLE environment variable can be set to
99-
echo configure another Python executable interpreter to use. If this is not
100-
echo set, a file named PYTHON_EXECUTABLE containing a single line with the
101-
echo path of the Python executable to use will be checked last.
102-
set +e
103-
exit
91+
find_python
92+
create_virtualenv "$VIRTUALENV_DIR"
93+
install_packages "$CFG_REQUIREMENTS"
94+
. "$CFG_BIN_DIR/activate"
10495
}
10596

10697

107-
clean() {
108-
# Remove cleanable file and directories and files from the root dir.
109-
echo "* Cleaning ..."
110-
for cln in $CLEANABLE;
111-
do rm -rf "${CFG_ROOT_DIR:?}/${cln:?}";
112-
done
113-
set +e
114-
exit
98+
################################
99+
# Find a proper Python to run
100+
# Use environment variables or a file if available.
101+
# Otherwise the latest Python by default.
102+
find_python() {
103+
if [[ "$PYTHON_EXECUTABLE" == "" ]]; then
104+
# check for a file named PYTHON_EXECUTABLE
105+
if [ -f "$CFG_ROOT_DIR/PYTHON_EXECUTABLE" ]; then
106+
PYTHON_EXECUTABLE=$(cat "$CFG_ROOT_DIR/PYTHON_EXECUTABLE")
107+
else
108+
PYTHON_EXECUTABLE=python3
109+
fi
110+
fi
115111
}
116112

117113

114+
################################
118115
create_virtualenv() {
119116
# create a virtualenv for Python
120117
# Note: we do not use the bundled Python 3 "venv" because its behavior and
@@ -145,6 +142,7 @@ create_virtualenv() {
145142
}
146143

147144

145+
################################
148146
install_packages() {
149147
# install requirements in virtualenv
150148
# note: --no-build-isolation means that pip/wheel/setuptools will not
@@ -162,28 +160,43 @@ install_packages() {
162160

163161

164162
################################
165-
# Main command line entry point
166-
CFG_DEV_MODE=0
167-
CFG_REQUIREMENTS=$REQUIREMENTS
168-
NO_INDEX="--no-index"
169-
170-
# We are using getopts to parse option arguments that start with "-"
171-
while getopts :-: optchar; do
172-
case "${optchar}" in
173-
-)
174-
case "${OPTARG}" in
175-
help ) cli_help;;
176-
clean ) clean;;
177-
dev ) CFG_REQUIREMENTS="$DEV_REQUIREMENTS" && CFG_DEV_MODE=1;;
178-
init ) NO_INDEX="";;
179-
esac;;
180-
esac
181-
done
182-
183-
PIP_EXTRA_ARGS="$PIP_EXTRA_ARGS $NO_INDEX"
184-
185-
create_virtualenv "$VIRTUALENV_DIR"
186-
install_packages "$CFG_REQUIREMENTS"
187-
. "$CFG_BIN_DIR/activate"
163+
cli_help() {
164+
echo An initial configuration script
165+
echo " usage: ./configure [options]"
166+
echo
167+
echo The default is to configure for regular use. Use --dev for development.
168+
echo Use the --init option if starting a new project and the project
169+
echo dependencies are not available on thirdparty.aboutcode.org/pypi/
170+
echo and requirements.txt and/or requirements-dev.txt has not been generated.
171+
echo
172+
echo The options are:
173+
echo " --clean: clean built and installed files and exit."
174+
echo " --dev: configure the environment for development."
175+
echo " --init: pull dependencies from PyPI. Used when first setting up a project."
176+
echo " --help: display this help message and exit."
177+
echo
178+
echo By default, the python interpreter version found in the path is used.
179+
echo Alternatively, the PYTHON_EXECUTABLE environment variable can be set to
180+
echo configure another Python executable interpreter to use. If this is not
181+
echo set, a file named PYTHON_EXECUTABLE containing a single line with the
182+
echo path of the Python executable to use will be checked last.
183+
set +e
184+
exit
185+
}
186+
187+
188+
################################
189+
clean() {
190+
# Remove cleanable file and directories and files from the root dir.
191+
echo "* Cleaning ..."
192+
for cln in $CLEANABLE;
193+
do rm -rf "${CFG_ROOT_DIR:?}/${cln:?}";
194+
done
195+
set +e
196+
exit
197+
}
198+
199+
200+
main
188201

189202
set +e

Diff for: configure.bat

+13-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
@rem # Source this script for initial configuration
1515
@rem # Use configure --help for details
1616

17+
@rem # NOTE: please keep in sync with POSIX script configure
18+
1719
@rem # This script will search for a virtualenv.pyz app in etc\thirdparty\virtualenv.pyz
1820
@rem # Otherwise it will download the latest from the VIRTUALENV_PYZ_URL default
1921
@rem ################################
@@ -49,10 +51,11 @@ set "CFG_BIN_DIR=%CFG_ROOT_DIR%\%VIRTUALENV_DIR%\Scripts"
4951

5052
@rem ################################
5153
@rem # Thirdparty package locations and index handling
54+
@rem # Find packages from the local thirdparty directory or from thirdparty.aboutcode.org
5255
if exist "%CFG_ROOT_DIR%\thirdparty" (
5356
set PIP_EXTRA_ARGS=--find-links "%CFG_ROOT_DIR%\thirdparty"
5457
)
55-
set "PIP_EXTRA_ARGS=%PIP_EXTRA_ARGS% --find-links https://thirdparty.aboutcode.org/pypi" & %INDEX_ARG%
58+
set "PIP_EXTRA_ARGS=%PIP_EXTRA_ARGS% --find-links https://thirdparty.aboutcode.org/pypi/simple/links.html"
5659

5760

5861
@rem ################################
@@ -64,7 +67,6 @@ if not defined CFG_QUIET (
6467

6568
@rem ################################
6669
@rem # Main command line entry point
67-
set CFG_DEV_MODE=0
6870
set "CFG_REQUIREMENTS=%REQUIREMENTS%"
6971
set "NO_INDEX=--no-index"
7072

@@ -74,7 +76,6 @@ if not "%1" == "" (
7476
if "%1" EQU "--clean" (goto clean)
7577
if "%1" EQU "--dev" (
7678
set "CFG_REQUIREMENTS=%DEV_REQUIREMENTS%"
77-
set CFG_DEV_MODE=1
7879
)
7980
if "%1" EQU "--init" (
8081
set "NO_INDEX= "
@@ -87,7 +88,7 @@ set "PIP_EXTRA_ARGS=%PIP_EXTRA_ARGS% %NO_INDEX%"
8788

8889

8990
@rem ################################
90-
@rem # find a proper Python to run
91+
@rem # Find a proper Python to run
9192
@rem # Use environment variables or a file if available.
9293
@rem # Otherwise the latest Python by default.
9394
if not defined PYTHON_EXECUTABLE (
@@ -99,6 +100,8 @@ if not defined PYTHON_EXECUTABLE (
99100
)
100101
)
101102

103+
104+
@rem ################################
102105
:create_virtualenv
103106
@rem # create a virtualenv for Python
104107
@rem # Note: we do not use the bundled Python 3 "venv" because its behavior and
@@ -143,6 +146,7 @@ if %ERRORLEVEL% neq 0 (
143146
)
144147

145148

149+
@rem ################################
146150
:install_packages
147151
@rem # install requirements in virtualenv
148152
@rem # note: --no-build-isolation means that pip/wheel/setuptools will not
@@ -157,6 +161,9 @@ if %ERRORLEVEL% neq 0 (
157161
%PIP_EXTRA_ARGS% ^
158162
%CFG_REQUIREMENTS%
159163

164+
165+
@rem ################################
166+
:create_bin_junction
160167
@rem # Create junction to bin to have the same directory between linux and windows
161168
if exist "%CFG_ROOT_DIR%\%VIRTUALENV_DIR%\bin" (
162169
rmdir /s /q "%CFG_ROOT_DIR%\%VIRTUALENV_DIR%\bin"
@@ -171,7 +178,6 @@ exit /b 0
171178

172179

173180
@rem ################################
174-
175181
:cli_help
176182
echo An initial configuration script
177183
echo " usage: configure [options]"
@@ -195,11 +201,12 @@ exit /b 0
195201
exit /b 0
196202

197203

204+
@rem ################################
198205
:clean
199206
@rem # Remove cleanable file and directories and files from the root dir.
200207
echo "* Cleaning ..."
201208
for %%F in (%CLEANABLE%) do (
202209
rmdir /s /q "%CFG_ROOT_DIR%\%%F" >nul 2>&1
203210
del /f /q "%CFG_ROOT_DIR%\%%F" >nul 2>&1
204211
)
205-
exit /b 0
212+
exit /b 0

0 commit comments

Comments
 (0)