Skip to content

Commit 8583d7f

Browse files
authored
Merge pull request #39 from nexB/update-skeleton
Update skeleton
2 parents fa13562 + bfdc6ff commit 8583d7f

32 files changed

+5007
-42
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
/Lib
1313
/pip-selfcheck.json
1414
/tmp
15+
/venv
1516
.Python
1617
/include
1718
/Include

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ python:
1919
install: ./configure --dev
2020

2121
# Scripts to run at script stage
22-
script: tmp/bin/pytest
22+
script: venv/bin/pytest

README.rst

Lines changed: 135 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ A Simple Python Project Skeleton
22
================================
33
This repo attempts to standardize our python repositories using modern python
44
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
5+
repository will serve as the base for all new python projects and will be adopted to all
66
our existing ones as well.
77

88
.. _blog post: https://blog.jaraco.com/a-project-skeleton-for-python-projects/
@@ -33,18 +33,148 @@ Update an existing project
3333
3434
This is also the workflow to use when updating the skeleton files in any given repository.
3535

36-
3736
Customizing
3837
-----------
3938

4039
You typically want to perform these customizations:
4140

4241
- remove or update the src/README.rst and tests/README.rst files
42+
- set project info and dependencies in setup.cfg
4343
- check the configure and configure.bat defaults
4444

45+
Initializing a project
46+
----------------------
47+
48+
All projects using the skeleton will be expected to pull all of it dependencies
49+
from thirdparty.aboutcode.org/pypi or the local thirdparty directory, using
50+
requirements.txt and/or requirements-dev.txt to determine what version of a
51+
package to collect. By default, PyPI will not be used to find and collect
52+
packages from.
53+
54+
In the case where we are starting a new project where we do not have
55+
requirements.txt and requirements-dev.txt and whose dependencies are not yet on
56+
thirdparty.aboutcode.org/pypi, we run the following command after adding and
57+
customizing the skeleton files to your project:
58+
59+
.. code-block:: bash
60+
61+
./configure --init
62+
63+
This will initialize the virtual environment for the project, pull in the
64+
dependencies from PyPI and add them to the virtual environment.
65+
66+
Generating requirements.txt and requirements-dev.txt
67+
----------------------------------------------------
68+
69+
After the project has been initialized, we can generate the requirements.txt and
70+
requirements-dev.txt files.
71+
72+
Ensure the virtual environment is enabled.
73+
74+
.. code-block:: bash
75+
76+
source venv/bin/activate
77+
78+
To generate requirements.txt:
79+
80+
.. code-block:: bash
81+
82+
python etc/scripts/gen_requirements.py -s venv/lib/python<version>/site-packages/
83+
84+
Replace \<version\> with the version number of the Python being used, for example: ``venv/lib/python3.6/site-packages/``
85+
86+
To generate requirements-dev.txt after requirements.txt has been generated:
87+
88+
.. code-block:: bash
89+
./configure --init --dev
90+
python etc/scripts/gen_requirements_dev.py -s venv/lib/python<version>/site-packages/
91+
92+
Note: on Windows, the ``site-packages`` directory is located at ``venv\Lib\site-packages\``
93+
94+
.. code-block:: bash
95+
96+
python .\\etc\\scripts\\gen_requirements.py -s .\\venv\\Lib\\site-packages\\
97+
.\configure --init --dev
98+
python .\\etc\\scripts\\gen_requirements_dev.py -s .\\venv\\Lib\\site-packages\\
99+
100+
Collecting and generating ABOUT files for dependencies
101+
------------------------------------------------------
102+
103+
Ensure that the dependencies used by ``etc/scripts/bootstrap.py`` are installed:
104+
105+
.. code-block:: bash
106+
107+
pip install -r etc/scripts/requirements.txt
108+
109+
Once we have requirements.txt and requirements-dev.txt, we can fetch the project
110+
dependencies as wheels and generate ABOUT files for them:
111+
112+
.. code-block:: bash
113+
114+
python etc/scripts/bootstrap.py -r requirements.txt -r requirements-dev.txt --with-deps
115+
116+
There may be issues with the generated ABOUT files, which will have to be
117+
corrected. You can check to see if your corrections are valid by running:
118+
119+
.. code-block:: bash
120+
121+
python etc/scripts/check_thirdparty.py -d thirdparty
122+
123+
Once the wheels are collected and the ABOUT files are generated and correct,
124+
upload them to thirdparty.aboutcode.org/pypi by placing the wheels and ABOUT
125+
files from the thirdparty directory to the pypi directory at
126+
https://github.com/nexB/thirdparty-packages
127+
128+
129+
Usage after project initialization
130+
----------------------------------
131+
132+
Once the ``requirements.txt`` and ``requirements-dev.txt`` have been generated
133+
and the project dependencies and their ABOUT files have been uploaded to
134+
thirdparty.aboutcode.org/pypi, you can configure the project without using the
135+
``--init`` option.
136+
137+
If the virtual env for the project becomes polluted, or you would like to remove
138+
it, use the ``--clean`` option:
139+
140+
.. code-block:: bash
141+
142+
./configure --clean
143+
144+
Then you can run ``./configure`` again to set up the project virtual environment.
145+
146+
To set up the project for development use:
147+
148+
.. code-block:: bash
149+
150+
./configure --dev
151+
152+
To update the project dependencies (adding, removing, updating packages, etc.),
153+
update the dependencies in ``setup.cfg``, then run:
154+
155+
.. code-block:: bash
156+
157+
./configure --clean # Remove existing virtual environment
158+
./configure --init # Create project virtual environment, pull in new dependencies
159+
source venv/bin/activate # Ensure virtual environment is activated
160+
python etc/scripts/gen_requirements.py -s venv/lib/python<version>/site-packages/ # Regenerate requirements.txt
161+
python etc/scripts/gen_requirements_dev.py -s venv/lib/python<version>/site-packages/ # Regenerate requirements-dev.txt
162+
pip install -r etc/scripts/requirements.txt # Install dependencies needed by etc/scripts/bootstrap.py
163+
python etc/scripts/bootstrap.py -r requirements.txt -r requirements-dev.txt --with-deps # Collect dependency wheels and their ABOUT files
164+
165+
Ensure that the generated ABOUT files are valid, then take the dependency wheels
166+
and ABOUT files and upload them to thirdparty.aboutcode.org/pypi.
45167

46168
Release Notes
47-
-------------
169+
=============
170+
171+
- 2021-09-03:
172+
- ``configure`` now requires pinned dependencies via the use of ``requirements.txt`` and ``requirements-dev.txt``
173+
- ``configure`` can now accept multiple options at once
174+
- Add utility scripts from scancode-toolkit/etc/release/ for use in generating project files
175+
- Rename virtual environment directory from ``tmp`` to ``venv``
176+
- Update README.rst with instructions for generating ``requirements.txt`` and ``requirements-dev.txt``,
177+
as well as collecting dependencies as wheels and generating ABOUT files for them.
48178

49-
- 2021-05-11: adopt new configure scripts from ScanCode TK that allows correct
50-
configuration of which Python version is used.
179+
- 2021-05-11:
180+
- Adopt new configure scripts from ScanCode TK that allows correct configuration of which Python version is used.

azure-pipelines.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,52 +13,52 @@ jobs:
1313
image_name: ubuntu-16.04
1414
python_versions: ['3.6', '3.7', '3.8', '3.9']
1515
test_suites:
16-
all: tmp/bin/pytest -vvs
16+
all: venv/bin/pytest -vvs
1717

1818
- template: etc/ci/azure-posix.yml
1919
parameters:
2020
job_name: ubuntu18_cpython
2121
image_name: ubuntu-18.04
2222
python_versions: ['3.6', '3.7', '3.8', '3.9']
2323
test_suites:
24-
all: tmp/bin/pytest -n 2 -vvs
24+
all: venv/bin/pytest -n 2 -vvs
2525

2626
- template: etc/ci/azure-posix.yml
2727
parameters:
2828
job_name: ubuntu20_cpython
2929
image_name: ubuntu-20.04
3030
python_versions: ['3.6', '3.7', '3.8', '3.9']
3131
test_suites:
32-
all: tmp/bin/pytest -n 2 -vvs
32+
all: venv/bin/pytest -n 2 -vvs
3333

3434
- template: etc/ci/azure-posix.yml
3535
parameters:
3636
job_name: macos1014_cpython
3737
image_name: macos-10.14
3838
python_versions: ['3.6', '3.7', '3.8', '3.9']
3939
test_suites:
40-
all: tmp/bin/pytest -n 2 -vvs
40+
all: venv/bin/pytest -n 2 -vvs
4141

4242
- template: etc/ci/azure-posix.yml
4343
parameters:
4444
job_name: macos1015_cpython
4545
image_name: macos-10.15
4646
python_versions: ['3.6', '3.7', '3.8', '3.9']
4747
test_suites:
48-
all: tmp/bin/pytest -n 2 -vvs
48+
all: venv/bin/pytest -n 2 -vvs
4949

5050
- template: etc/ci/azure-win.yml
5151
parameters:
5252
job_name: win2016_cpython
5353
image_name: vs2017-win2016
5454
python_versions: ['3.6', '3.7', '3.8', '3.9']
5555
test_suites:
56-
all: tmp\Scripts\pytest -n 2 -vvs
56+
all: venv\Scripts\pytest -n 2 -vvs
5757

5858
- template: etc/ci/azure-win.yml
5959
parameters:
6060
job_name: win2019_cpython
6161
image_name: windows-2019
6262
python_versions: ['3.6', '3.7', '3.8', '3.9']
6363
test_suites:
64-
all: tmp\Scripts\pytest -n 2 -vvs
64+
all: venv\Scripts\pytest -n 2 -vvs

configure

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ CLI_ARGS=$1
2626
################################
2727

2828
# Requirement arguments passed to pip and used by default or with --dev.
29-
REQUIREMENTS="--editable ."
30-
DEV_REQUIREMENTS="--editable .[testing]"
29+
REQUIREMENTS="--editable . --constraint requirements.txt"
30+
DEV_REQUIREMENTS="--editable .[testing] --constraint requirements.txt --constraint requirements-dev.txt"
3131

3232
# where we create a virtualenv
33-
VIRTUALENV_DIR=tmp
33+
VIRTUALENV_DIR=venv
3434

3535
# Cleanable files and directories with the --clean option
3636
CLEANABLE="
3737
build
38-
tmp"
38+
venv"
3939

4040
# extra arguments passed to pip
4141
PIP_EXTRA_ARGS=" "
@@ -50,8 +50,9 @@ 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-
# Find packages from the local thirdparty directory or from pypi
54-
PIP_EXTRA_ARGS="--find-links $CFG_ROOT_DIR/thirdparty"
53+
# Find packages from the local thirdparty directory or from thirdparty.aboutcode.org
54+
PIP_EXTRA_ARGS="--find-links $CFG_ROOT_DIR/thirdparty --find-links https://thirdparty.aboutcode.org/pypi"
55+
5556

5657
################################
5758
# Set the quiet flag to empty if not defined
@@ -80,10 +81,14 @@ cli_help() {
8081
echo " usage: ./configure [options]"
8182
echo
8283
echo The default is to configure for regular use. Use --dev for development.
84+
echo Use the --init option if starting a new project and the project
85+
echo dependencies are not available on thirdparty.aboutcode.org/pypi/
86+
echo and requirements.txt and/or requirements-dev.txt has not been generated.
8387
echo
8488
echo The options are:
8589
echo " --clean: clean built and installed files and exit."
8690
echo " --dev: configure the environment for development."
91+
echo " --init: pull dependencies from PyPI. Used when first setting up a project."
8792
echo " --help: display this help message and exit."
8893
echo
8994
echo By default, the python interpreter version found in the path is used.
@@ -157,12 +162,22 @@ install_packages() {
157162
# Main command line entry point
158163
CFG_DEV_MODE=0
159164
CFG_REQUIREMENTS=$REQUIREMENTS
160-
161-
case "$CLI_ARGS" in
162-
--help) cli_help;;
163-
--clean) clean;;
164-
--dev) CFG_REQUIREMENTS="$DEV_REQUIREMENTS" && CFG_DEV_MODE=1;;
165-
esac
165+
NO_INDEX="--no-index"
166+
167+
# We are using getopts to parse option arguments that start with "-"
168+
while getopts :-: optchar; do
169+
case "${optchar}" in
170+
-)
171+
case "${OPTARG}" in
172+
help ) cli_help;;
173+
clean ) clean;;
174+
dev ) CFG_REQUIREMENTS="$DEV_REQUIREMENTS" && CFG_DEV_MODE=1;;
175+
init ) NO_INDEX="";;
176+
esac;;
177+
esac
178+
done
179+
180+
PIP_EXTRA_ARGS="$PIP_EXTRA_ARGS $NO_INDEX"
166181

167182
create_virtualenv "$VIRTUALENV_DIR"
168183
install_packages "$CFG_REQUIREMENTS"

configure.bat

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
@rem ################################
2525

2626
@rem # Requirement arguments passed to pip and used by default or with --dev.
27-
set "REQUIREMENTS=--editable ."
28-
set "DEV_REQUIREMENTS=--editable .[testing]"
27+
set "REQUIREMENTS=--editable . --constraint requirements.txt"
28+
set "DEV_REQUIREMENTS=--editable .[testing] --constraint requirements.txt --constraint requirements-dev.txt"
2929

3030
@rem # where we create a virtualenv
31-
set "VIRTUALENV_DIR=tmp"
31+
set "VIRTUALENV_DIR=venv"
3232

3333
@rem # Cleanable files and directories to delete with the --clean option
34-
set "CLEANABLE=build tmp"
34+
set "CLEANABLE=build venv"
3535

3636
@rem # extra arguments passed to pip
3737
set "PIP_EXTRA_ARGS= "
@@ -49,7 +49,7 @@ set "CFG_BIN_DIR=%CFG_ROOT_DIR%\%VIRTUALENV_DIR%\Scripts"
4949

5050
@rem ################################
5151
@rem # Thirdparty package locations and index handling
52-
set "PIP_EXTRA_ARGS=--find-links %CFG_ROOT_DIR%\thirdparty"
52+
set "PIP_EXTRA_ARGS=--find-links %CFG_ROOT_DIR%\thirdparty --find-links https://thirdparty.aboutcode.org/pypi" & %INDEX_ARG%
5353
@rem ################################
5454

5555

@@ -64,19 +64,26 @@ if not defined CFG_QUIET (
6464
@rem # Main command line entry point
6565
set CFG_DEV_MODE=0
6666
set "CFG_REQUIREMENTS=%REQUIREMENTS%"
67-
68-
if "%1" EQU "--help" (goto cli_help)
69-
if "%1" EQU "--clean" (goto clean)
70-
if "%1" EQU "--dev" (
71-
set "CFG_REQUIREMENTS=%DEV_REQUIREMENTS%"
72-
set CFG_DEV_MODE=1
73-
)
74-
if "%1" EQU "--python" (
75-
echo "The --python option is now DEPRECATED. Use the PYTHON_EXECUTABLE environment"
76-
echo "variable instead. Run configure --help for details."
77-
exit /b 0
67+
set "NO_INDEX=--no-index"
68+
69+
:again
70+
if not "%1" == "" (
71+
if "%1" EQU "--help" (goto cli_help)
72+
if "%1" EQU "--clean" (goto clean)
73+
if "%1" EQU "--dev" (
74+
set "CFG_REQUIREMENTS=%DEV_REQUIREMENTS%"
75+
set CFG_DEV_MODE=1
76+
)
77+
if "%1" EQU "--init" (
78+
set "NO_INDEX= "
79+
)
80+
shift
81+
goto again
7882
)
7983

84+
set "PIP_EXTRA_ARGS=%PIP_EXTRA_ARGS% %NO_INDEX%"
85+
86+
8087
@rem ################################
8188
@rem # find a proper Python to run
8289
@rem # Use environment variables or a file if available.
@@ -165,10 +172,14 @@ exit /b 0
165172
echo " usage: configure [options]"
166173
echo " "
167174
echo The default is to configure for regular use. Use --dev for development.
175+
echo Use the --init option if starting a new project and the project
176+
echo dependencies are not available on thirdparty.aboutcode.org/pypi/
177+
echo and requirements.txt and/or requirements-dev.txt has not been generated.
168178
echo " "
169179
echo The options are:
170180
echo " --clean: clean built and installed files and exit."
171181
echo " --dev: configure the environment for development."
182+
echo " --init: pull dependencies from PyPI. Used when first setting up a project."
172183
echo " --help: display this help message and exit."
173184
echo " "
174185
echo By default, the python interpreter version found in the path is used.

0 commit comments

Comments
 (0)