Skip to content

Commit 03d4799

Browse files
committed
Do not depend on click. Use argparse.
These boostrap scripts cannot depend on click. Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 1e4d3bc commit 03d4799

File tree

3 files changed

+86
-67
lines changed

3 files changed

+86
-67
lines changed

docs/skeleton-usage.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ customizing the skeleton files to your project:
4949

5050
.. code-block:: bash
5151
52-
./configure --init
52+
./configure
5353
5454
This will initialize the virtual environment for the project, pull in the
5555
dependencies from PyPI and add them to the virtual environment.
@@ -77,7 +77,7 @@ Replace \<version\> with the version number of the Python being used, for exampl
7777
To generate requirements-dev.txt after requirements.txt has been generated:
7878

7979
.. code-block:: bash
80-
./configure --init --dev
80+
./configure --dev
8181
python etc/scripts/gen_requirements_dev.py -s venv/lib/python<version>/site-packages/
8282
8383
Note: on Windows, the ``site-packages`` directory is located at ``venv\Lib\site-packages\``
@@ -88,10 +88,11 @@ Note: on Windows, the ``site-packages`` directory is located at ``venv\Lib\site-
8888
.\configure --init --dev
8989
python .\\etc\\scripts\\gen_requirements_dev.py -s .\\venv\\Lib\\site-packages\\
9090
91+
9192
Collecting and generating ABOUT files for dependencies
9293
------------------------------------------------------
9394

94-
Ensure that the dependencies used by ``etc/scripts/bootstrap.py`` are installed:
95+
Ensure that the dependencies used by ``etc/scripts/fetch_thirdparty.py`` are installed:
9596

9697
.. code-block:: bash
9798
@@ -102,7 +103,7 @@ dependencies as wheels and generate ABOUT files for them:
102103

103104
.. code-block:: bash
104105
105-
python etc/scripts/bootstrap.py -r requirements.txt -r requirements-dev.txt --with-deps
106+
python etc/scripts/fetch_thirdparty.py -r requirements.txt -r requirements-dev.txt
106107
107108
There may be issues with the generated ABOUT files, which will have to be
108109
corrected. You can check to see if your corrections are valid by running:
@@ -122,8 +123,8 @@ Usage after project initialization
122123

123124
Once the ``requirements.txt`` and ``requirements-dev.txt`` have been generated
124125
and the project dependencies and their ABOUT files have been uploaded to
125-
thirdparty.aboutcode.org/pypi, you can configure the project without using the
126-
``--init`` option.
126+
thirdparty.aboutcode.org/pypi, you can configure the project as needed, typically
127+
when you update dependencies or use a new checkout.
127128

128129
If the virtual env for the project becomes polluted, or you would like to remove
129130
it, use the ``--clean`` option:
@@ -146,12 +147,11 @@ update the dependencies in ``setup.cfg``, then run:
146147
.. code-block:: bash
147148
148149
./configure --clean # Remove existing virtual environment
149-
./configure --init # Create project virtual environment, pull in new dependencies
150150
source venv/bin/activate # Ensure virtual environment is activated
151151
python etc/scripts/gen_requirements.py -s venv/lib/python<version>/site-packages/ # Regenerate requirements.txt
152152
python etc/scripts/gen_requirements_dev.py -s venv/lib/python<version>/site-packages/ # Regenerate requirements-dev.txt
153153
pip install -r etc/scripts/requirements.txt # Install dependencies needed by etc/scripts/bootstrap.py
154-
python etc/scripts/bootstrap.py -r requirements.txt -r requirements-dev.txt --with-deps # Collect dependency wheels and their ABOUT files
154+
python etc/scripts/fetch_thirdparty.py -r requirements.txt -r requirements-dev.txt # Collect dependency wheels and their ABOUT files
155155
156156
Ensure that the generated ABOUT files are valid, then take the dependency wheels
157157
and ABOUT files and upload them to thirdparty.aboutcode.org/pypi.

etc/scripts/gen_requirements.py

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,48 @@
88
# See https://github.com/nexB/skeleton for support or download.
99
# See https://aboutcode.org for more information about nexB OSS projects.
1010
#
11-
import click
11+
import argparse
12+
import pathlib
13+
1214
import utils_requirements
1315

16+
"""
17+
Utilities to manage requirements files.
18+
NOTE: this should use ONLY the standard library and not import anything else
19+
because this is used for boostrapping with no requirements installed.
20+
"""
1421

15-
@click.command()
16-
@click.option(
17-
"-s",
18-
"--site-packages-dir",
19-
type=click.Path(exists=True, readable=True, path_type=str, file_okay=False, resolve_path=True),
20-
required=True,
21-
metavar="DIR",
22-
help='Path to the "site-packages" directory where wheels are installed such as lib/python3.6/site-packages',
23-
)
24-
@click.option(
25-
"-r",
26-
"--requirements-file",
27-
type=click.Path(path_type=str, dir_okay=False),
28-
metavar="FILE",
29-
default="requirements.txt",
30-
show_default=True,
31-
help="Path to the requirements file to update or create.",
32-
)
33-
@click.help_option("-h", "--help")
34-
def gen_requirements(site_packages_dir, requirements_file):
35-
"""
22+
23+
def gen_requirements():
24+
description = """
3625
Create or replace the `--requirements-file` file FILE requirements file with all
3726
locally installed Python packages.all Python packages found installed in `--site-packages-dir`
3827
"""
28+
parser = argparse.ArgumentParser(description=description)
29+
30+
parser.add_argument(
31+
"-s",
32+
"--site-packages-dir",
33+
dest="site_packages_dir",
34+
type=pathlib.Path,
35+
required=True,
36+
metavar="DIR",
37+
help="Path to the 'site-packages' directory where wheels are installed such as lib/python3.6/site-packages",
38+
)
39+
parser.add_argument(
40+
"-r",
41+
"--requirements-file",
42+
type=pathlib.Path,
43+
metavar="FILE",
44+
default="requirements.txt",
45+
help="Path to the requirements file to update or create.",
46+
)
47+
48+
args = parser.parse_args()
49+
3950
utils_requirements.lock_requirements(
40-
requirements_file=requirements_file,
41-
site_packages_dir=site_packages_dir,
51+
site_packages_dir=args.site_packages_dir,
52+
requirements_file=args.requirements_file,
4253
)
4354

4455

etc/scripts/gen_requirements_dev.py

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,59 @@
88
# See https://github.com/nexB/skeleton for support or download.
99
# See https://aboutcode.org for more information about nexB OSS projects.
1010
#
11-
import click
11+
import argparse
12+
import pathlib
13+
1214
import utils_requirements
1315

16+
"""
17+
Utilities to manage requirements files.
18+
NOTE: this should use ONLY the standard library and not import anything else
19+
because this is used for boostrapping with no requirements installed.
20+
"""
1421

15-
@click.command()
16-
@click.option(
17-
"-s",
18-
"--site-packages-dir",
19-
type=click.Path(exists=True, readable=True, path_type=str, file_okay=False, resolve_path=True),
20-
required=True,
21-
metavar="DIR",
22-
help='Path to the "site-packages" directory where wheels are installed such as lib/python3.6/site-packages',
23-
)
24-
@click.option(
25-
"-d",
26-
"--dev-requirements-file",
27-
type=click.Path(path_type=str, dir_okay=False),
28-
metavar="FILE",
29-
default="requirements-dev.txt",
30-
show_default=True,
31-
help="Path to the dev requirements file to update or create.",
32-
)
33-
@click.option(
34-
"-r",
35-
"--main-requirements-file",
36-
type=click.Path(path_type=str, dir_okay=False),
37-
default="requirements.txt",
38-
metavar="FILE",
39-
show_default=True,
40-
help="Path to the main requirements file. Its requirements will be excluded "
41-
"from the generated dev requirements.",
42-
)
43-
@click.help_option("-h", "--help")
44-
def gen_dev_requirements(site_packages_dir, dev_requirements_file, main_requirements_file):
45-
"""
22+
23+
def gen_dev_requirements():
24+
description = """
4625
Create or overwrite the `--dev-requirements-file` pip requirements FILE with
4726
all Python packages found installed in `--site-packages-dir`. Exclude
4827
package names also listed in the --main-requirements-file pip requirements
4928
FILE (that are assume to the production requirements and therefore to always
5029
be present in addition to the development requirements).
5130
"""
31+
parser = argparse.ArgumentParser(description=description)
32+
33+
parser.add_argument(
34+
"-s",
35+
"--site-packages-dir",
36+
type=pathlib.Path,
37+
required=True,
38+
metavar="DIR",
39+
help='Path to the "site-packages" directory where wheels are installed such as lib/python3.6/site-packages',
40+
)
41+
parser.add_argument(
42+
"-d",
43+
"--dev-requirements-file",
44+
type=pathlib.Path,
45+
metavar="FILE",
46+
default="requirements-dev.txt",
47+
help="Path to the dev requirements file to update or create.",
48+
)
49+
parser.add_argument(
50+
"-r",
51+
"--main-requirements-file",
52+
type=pathlib.Path,
53+
default="requirements.txt",
54+
metavar="FILE",
55+
help="Path to the main requirements file. Its requirements will be excluded "
56+
"from the generated dev requirements.",
57+
)
58+
args = parser.parse_args()
59+
5260
utils_requirements.lock_dev_requirements(
53-
dev_requirements_file=dev_requirements_file,
54-
main_requirements_file=main_requirements_file,
55-
site_packages_dir=site_packages_dir,
61+
dev_requirements_file=args.dev_requirements_file,
62+
main_requirements_file=args.main_requirements_file,
63+
site_packages_dir=args.site_packages_dir,
5664
)
5765

5866

0 commit comments

Comments
 (0)