diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7d41c64ae9..1355ab29de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,8 +61,8 @@ jobs: - name: Install dependencies run: | - python -m pip install --upgrade pip - pip install --upgrade tox coveralls + python3 -m pip install --upgrade pip + python3 -m pip install --upgrade tox coveralls - name: Run tox (${{ env.TOXENV }}) # See TOXENV environment variable for the testenv to be executed here @@ -99,6 +99,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - python -m pip install --upgrade pip - pip install --upgrade coveralls + python3 -m pip install --upgrade pip + python3 -m pip install --upgrade coveralls coveralls --finish diff --git a/docs/CLI.md b/docs/CLI.md index 6b2b5a3bee..a91d41cb0e 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -3,7 +3,7 @@ The TUF command-line interface (CLI) requires a full [TUF installation](INSTALLATION.rst). Be sure to include the installation of extra dependencies and C extensions ( -```pip install securesystemslib[crypto,pynacl]```). +```python3 -m pip install securesystemslib[crypto,pynacl]```). The use of the CLI is documented with examples below. @@ -279,12 +279,6 @@ Enter a password for the encrypted key (tufkeystore/mykey): Serve the repo ```Bash -$ cd tufrepo/ -$ python -m SimpleHTTPServer 8001 -``` - -If running python 3: -```Bash $ python3 -m http.server 8001 ``` @@ -412,12 +406,6 @@ $ repo.py --add README.txt --role role_x --sign tufkeystore/key_x tufkeystore/ke Serve the repo ```Bash -$ cd tufrepo/ -$ python -m SimpleHTTPServer 8001 -``` - -If running python 3: -```Bash $ python3 -m http.server 8001 ``` diff --git a/docs/CONTRIBUTORS.rst b/docs/CONTRIBUTORS.rst index 74abd39e19..31119a507a 100644 --- a/docs/CONTRIBUTORS.rst +++ b/docs/CONTRIBUTORS.rst @@ -79,7 +79,7 @@ and instructions for installing locally from source are provided here: $ curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-15.0.3.tar.gz $ tar xvfz virtualenv-15.0.3.tar.gz $ cd virtualenv-15.0.3 - $ python virtualenv.py myVE + $ python3 virtualenv.py myVE Development Installation @@ -102,7 +102,7 @@ To work on the TUF project, it's best to perform a development install. :: - $ pip install -r requirements-dev.txt + $ python3 -m pip install -r requirements-dev.txt Auto-formatting @@ -134,15 +134,15 @@ dependencies must already be installed (see above). :: $ cd tests - $ python aggregate_tests.py + $ python3 aggregate_tests.py Individual tests can also be executed. Optional '-v' flags can be added to increase log level up to DEBUG ('-vvvv'). :: - $ python test_updater.py # run a specific test file - $ python test_updater.py TestUpdater.test_4_refresh # run a specific test - $ python test_updater.py -vvvv TestUpdater.test_4_refresh # run test with DEBUG log level + $ python3 test_updater.py # run a specific test file + $ python3 test_updater.py TestUpdater.test_4_refresh # run a specific test + $ python3 test_updater.py -vvvv TestUpdater.test_4_refresh # run test with DEBUG log level All of the log levels and the corresponding options that could be used for testing are: @@ -180,9 +180,9 @@ a *venv*), and then install ``securesystemslib`` in editable mode too (in the sa :: $ cd path/to/tuf - $ pip install -r requirements-dev.txt + $ python3 -m pip install -r requirements-dev.txt $ cd path/to/securesystemslib - $ pip install -r requirements-dev.txt + $ python3 -m pip install -r requirements-dev.txt With `tox `_ the test suite can be executed in a diff --git a/docs/INSTALLATION.rst b/docs/INSTALLATION.rst index 0bb3f9dccf..a0a4200d7c 100644 --- a/docs/INSTALLATION.rst +++ b/docs/INSTALLATION.rst @@ -41,10 +41,10 @@ If you are only using ed25519-based cryptography, you can employ a pure-Python installation, done simply with one of the following commands: Installing from Python Package Index (https://pypi.python.org/pypi). -(Note: Please use "pip install --no-use-wheel tuf" if your version +(Note: Please use "python3 -m pip install --no-use-wheel tuf" if your version of pip <= 1.5.6) :: - $ pip install tuf + $ python3 -m pip install tuf **Alternatively**, if you wish to install from a GitHub release you've already @@ -52,11 +52,11 @@ downloaded, or a package you obtained in another way, you can instead: Install from a local source archive: :: - $ pip install + $ python3 -m pip install Or install from the root directory of the unpacked archive: :: - $ pip install . + $ python3 -m pip install . @@ -70,7 +70,7 @@ securesystemslib. **Note**: that may require non-Python dependencies, so if you encounter an error attempting this pip command, see `more instructions below <#non-python-dependencies>`_). :: - $ pip install securesystemslib[crypto,pynacl] tuf + $ python3 -m pip install securesystemslib[crypto,pynacl] tuf @@ -96,5 +96,5 @@ Fedora-based distributions can instead install these libraries with dnf. OS X users can install these header libraries with the `Homebrew `_ package manager, among other options. :: - $ brew install python + $ brew install python3 $ brew install libffi diff --git a/docs/QUICKSTART.md b/docs/QUICKSTART.md index c8c44e5180..3cbc8d0711 100644 --- a/docs/QUICKSTART.md +++ b/docs/QUICKSTART.md @@ -15,7 +15,7 @@ how TUF works, however. It will serve as a very basic update system. Make sure that TUF is installed, along with some of the optional cryptographic libraries and C extensions. Try this command to do that: -`pip install securesystemslib[colors,crypto,pynacl] tuf` +`python3 -m pip install securesystemslib[colors,crypto,pynacl] tuf` If you run into errors during that pip command, please consult the more detailed [TUF Installation Instructions](INSTALLATION.rst). (There are some @@ -81,10 +81,6 @@ repository's metadata. ```Bash $ cd "tufrepo/" $ python3 -m http.server 8001 - -# or, if you are using Python2: -$ python -m SimpleHTTPServer 8001 - ``` **Step (4)** - Obtain and verify the `testfile` update on a client. diff --git a/docs/TUTORIAL.md b/docs/TUTORIAL.md index ad0b6c1ad7..d8659e7213 100644 --- a/docs/TUTORIAL.md +++ b/docs/TUTORIAL.md @@ -674,11 +674,6 @@ repository example created earlier in this document. ## Test TUF Locally ## Run the local TUF repository server. ```Bash -$ cd "repository/"; python -m SimpleHTTPServer 8001 -``` - -If running Python 3: -```Bash $ cd "repository/"; python3 -m http.server 8001 ``` diff --git a/requirements.txt b/requirements.txt index ed3328659f..84e209f3ed 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,9 +26,9 @@ # 1. Use this script to create a pinned requirements file for each Python # version # ``` -# for v in 2.7 3.6 3.7 3.8 3.9; do +# for v in 3.6 3.7 3.8 3.9; do # mkvirtualenv tuf-env-${v} -p python${v}; -# pip install pip-tools; +# python3 -m pip install pip-tools; # pip-compile --no-header -o requirements-${v}.txt requirements.txt; # deactivate; # rmvirtualenv tuf-env-${v}; diff --git a/setup.py b/setup.py index 0b5b35592a..6e78ee7238 100755 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ distributed to other users. The packaged source is saved to the 'dist' folder in the current directory. - $ python setup.py sdist + $ python3 setup.py sdist INSTALLATION OPTIONS @@ -31,18 +31,18 @@ pip - installing and managing Python packages (recommended): # Installing from Python Package Index (https://pypi.python.org/pypi). - $ pip install tuf + $ python3 -m pip install tuf # Installing from local source archive. - $ pip install + $ python3 -m pip install # Or from the root directory of the unpacked archive. - $ pip install . + $ python3 -m pip install . # Installing optional requirements (i.e., after installing tuf). # Support for creation of Ed25519 signatures and support for RSA and ECDSA # signatures in general requires optional dependencies: - $ pip install securesystemslib[crypto,pynacl] + $ python3 -m pip install securesystemslib[crypto,pynacl] Alternate installation options: @@ -51,13 +51,13 @@ run one of the following shell commands: Install to the global site-packages directory. - $ python setup.py install + $ python3 setup.py install Install to the user site-packages directory. - $ python setup.py install --user + $ python3 setup.py install --user Install to a chosen directory. - $ python setup.py install --home= + $ python3 setup.py install --home= Note: The last two installation options may require modification of @@ -96,7 +96,6 @@ 'Operating System :: POSIX :: Linux', 'Operating System :: MacOS :: MacOS X', 'Operating System :: Microsoft :: Windows', - 'Programming Language :: Python', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', diff --git a/tests/repository_data/README.md b/tests/repository_data/README.md index 50ceb0114b..a91b97da5e 100644 --- a/tests/repository_data/README.md +++ b/tests/repository_data/README.md @@ -13,7 +13,7 @@ Or by invoking `aggregate_tests.py` from the directory. ``` -$ python aggregate_tests.py +$ python3 aggregate_tests.py ``` Note: integration tests end in `_integration.py`. @@ -22,13 +22,13 @@ If you wish to run a particular unit test, navigate to the tests directory and run that specific unit test. For example: ``` -$ python test_updater.py +$ python3 test_updater.py ``` It it also possible to run the test cases of a unit test. For instance: ``` -$ python -m unittest test_updater.TestMultiRepoUpdater.test_get_one_valid_targetinfo +$ python3 -m unittest test_updater.TestMultiRepoUpdater.test_get_one_valid_targetinfo ``` ## Setup diff --git a/tests/test_tutorial.py b/tests/test_tutorial.py index 40f2fd2285..fcdee24bba 100755 --- a/tests/test_tutorial.py +++ b/tests/test_tutorial.py @@ -389,9 +389,6 @@ def test_tutorial(self): # TODO: Run subprocess to simulate the following bash instructions: - # $ cd "repository/"; python -m SimpleHTTPServer 8001 - # If running Python 3: - # $ cd "repository/"; python3 -m http.server 8001 # We next retrieve targets from the TUF repository and save them to client/. The client.py script is available to download metadata and files from a specified repository. In a different command-line prompt . . . diff --git a/tox.ini b/tox.ini index 94d0d0683f..234a8626f3 100644 --- a/tox.ini +++ b/tox.ini @@ -14,9 +14,9 @@ skipsdist = true changedir = tests commands = - python --version - python -m coverage run aggregate_tests.py - python -m coverage report -m --fail-under 97 + python3 --version + python3 -m coverage run aggregate_tests.py + python3 -m coverage report -m --fail-under 97 deps = -r{toxinidir}/requirements-test.txt @@ -24,7 +24,7 @@ deps = # installation (see `skipsdist`), to get relative paths in coverage reports --editable {toxinidir} -install_command = pip install {opts} {packages} +install_command = python3 -m pip install {opts} {packages} # Develop test env to run tests against securesystemslib's master branch # Must to be invoked explicitly with, e.g. `tox -e with-sslib-master` @@ -35,8 +35,8 @@ deps = --editable {toxinidir} commands = - python -m coverage run aggregate_tests.py - python -m coverage report -m + python3 -m coverage run aggregate_tests.py + python3 -m coverage report -m [testenv:lint] changedir = {toxinidir} diff --git a/tuf/ATTACKS.md b/tuf/ATTACKS.md index 10a7636eca..eff02fcbda 100644 --- a/tuf/ATTACKS.md +++ b/tuf/ATTACKS.md @@ -42,7 +42,7 @@ $ rm -rf "client/targets/" "client/metadata/current/timestamp.json" The client now performs an update and should detect the invalid target file... Note: The following command should be executed in the "client/" directory. ```Bash -$ python basic_client.py --repo http://localhost:8001 +$ python3 basic_client.py --repo http://localhost:8001 Error: No working mirror was found: localhost:8001: BadHashError() ``` @@ -80,7 +80,7 @@ indicates when metadata should no longer be trusted. In the following simulation, the client first tries to perform an update. ```Bash -$ python basic_client.py --repo http://localhost:8001 +$ python3 basic_client.py --repo http://localhost:8001 ``` According to the logger (`tuf.log` file in the current working directory), @@ -95,7 +95,7 @@ should no longer be trusted. $ sudo date -s '2080-12-25 12:34:56' Wed Dec 25 12:34:56 EST 2080 -$ python basic_client.py --repo http://localhost:8001 +$ python3 basic_client.py --repo http://localhost:8001 Error: No working mirror was found: u'localhost:8001': ExpiredMetadataError(u"Metadata u'root' expired on Tue Jan 1 00:00:00 2030 (UTC).",) ``` @@ -119,7 +119,7 @@ $ cp repository/metadata/timestamp.json /tmp We should next generate a new Timestamp file on the repository side. ```Bash -$ python +$ python3 >>> from tuf.repository_tool import * >>> repository = load_repository('repository') >>> repository.timestamp.version @@ -138,12 +138,12 @@ $ cp repository/metadata.staged/* repository/metadata Now start the HTTP server from the directory containing the 'repository' subdirectory. ```Bash -$ python -m SimpleHTTPServer 8001 +$ python3 -m SimpleHTTPServer 8001 ``` And perform an update so that the client retrieves the updated timestamp.json. ```Bash -$ python basic_client.py --repo http://localhost:8001 +$ python3 basic_client.py --repo http://localhost:8001 ``` Finally, move the previous timestamp.json file to the current live repository @@ -151,12 +151,12 @@ and have the client try to download the outdated version. The client should reject it! ```Bash $ cp /tmp/timestamp.json repository/metadata/ -$ cd repository; python -m SimpleHTTPServer 8001 +$ cd repository; python3 -m SimpleHTTPServer 8001 ``` On the client side, perform an update... ```Bash -$ python basic_client.py --repo http://localhost:8001 +$ python3 basic_client.py --repo http://localhost:8001 Error: No working mirror was found: u'localhost:8001': ReplayedMetadataError() ``` @@ -180,7 +180,7 @@ requested target file (according to what is listed in trusted TUF metadata). ```Bash $ cp repository/targets/file1.txt /tmp -$ python -c "print 'a' * 1000" >> repository/targets/file1.txt +$ python3 -c "print 'a' * 1000" >> repository/targets/file1.txt ``` Now delete the local metadata and target files on the client side so @@ -195,7 +195,7 @@ expected size, and no more. The target file available on the software repository does contain more data than expected, though. ```Bash -$ python basic_client.py --repo http://localhost:8001 +$ python3 basic_client.py --repo http://localhost:8001 ``` At this point, part of the "file1.txt" file should have been fetched. That is, @@ -243,7 +243,7 @@ keys. The client should reject the partially signed snapshot file served by the repository (or imagine that it is a compromised software repository). ```Bash -$ python +$ python3 >>> from tuf.repository_tool import * >>> repository = load_repository('repository') >>> version = repository.root.version @@ -273,7 +273,7 @@ The client now attempts to refresh the top-level metadata and the partially written snapshot.json, which should be rejected. ```Bash -$ python basic_client.py --repo http://localhost:8001 +$ python3 basic_client.py --repo http://localhost:8001 Error: No working mirror was found: u'localhost:8001': BadSignatureError() ``` @@ -296,7 +296,7 @@ which to launch it. ```Bash # Before launching the slow retrieval server, copy 'slow_retrieval_server.py' # to the 'repository/' directory and run it from that directory as follows: -$ python slow_retrieval_server.py 8002 mode_2 +$ python3 slow_retrieval_server.py 8002 mode_2 ``` The client may now make a request to the slow retrieval server on port 8002. @@ -307,7 +307,7 @@ This should make it so that the client detects the slow retrieval server's delayed streaming. ```Bash -$ python basic_client.py --verbose 1 --repo http://localhost:8002 +$ python3 basic_client.py --verbose 1 --repo http://localhost:8002 Error: No working mirror was found: u'localhost:8002': SlowRetrievalError() ``` diff --git a/tuf/developer_tool.py b/tuf/developer_tool.py index e900651492..3e578b54fc 100755 --- a/tuf/developer_tool.py +++ b/tuf/developer_tool.py @@ -1018,6 +1018,6 @@ def _strip_prefix_from_targets_metadata(targets_metadata, prefix): if __name__ == '__main__': # The interactive sessions of the documentation strings can # be tested by running 'developer_tool.py' as a standalone module: - # $ python developer_tool.py + # $ python3 developer_tool.py import doctest doctest.testmod() diff --git a/tuf/formats.py b/tuf/formats.py index ace8a99fb7..ca304ca9e4 100755 --- a/tuf/formats.py +++ b/tuf/formats.py @@ -1004,6 +1004,6 @@ def check_signable_object_format(signable): if __name__ == '__main__': # The interactive sessions of the documentation strings can # be tested by running formats.py as a standalone module. - # python -B formats.py + # python3 -B formats.py import doctest doctest.testmod() diff --git a/tuf/log.py b/tuf/log.py index 485d2391df..62def62e83 100755 --- a/tuf/log.py +++ b/tuf/log.py @@ -57,8 +57,8 @@ multiple threads in a single process is also thread-safe. The logging module is NOT thread-safe when logging to a single file across multiple processes: - http://docs.python.org/2/library/logging.html#thread-safety - http://docs.python.org/2/howto/logging-cookbook.html + http://docs.python.org/library/logging.html#thread-safety + http://docs.python.org/howto/logging-cookbook.html """ import logging @@ -88,7 +88,7 @@ # Ask all Formatter instances to talk GMT. Set the 'converter' attribute of # 'logging.Formatter' so that all formatters use Greenwich Mean Time. -# http://docs.python.org/2/library/logging.html#logging.Formatter.formatTime +# http://docs.python.org/library/logging.html#logging.Formatter.formatTime # The 2nd paragraph in the link above contains the relevant information. # GMT = UTC (Coordinated Universal Time). TUF metadata stores timestamps in UTC. # We previously displayed the local time but this lead to confusion when @@ -144,8 +144,8 @@ def filter(self, record): http://stackoverflow.com/q/6177520 http://stackoverflow.com/q/5875225 http://bugs.python.org/issue6435 - http://docs.python.org/2/howto/logging-cookbook.html#filters-contextual - http://docs.python.org/2/library/logging.html#logrecord-attributes + http://docs.python.org/howto/logging-cookbook.html#filters-contextual + http://docs.python.org/library/logging.html#logrecord-attributes record: @@ -169,7 +169,7 @@ def filter(self, record): # with too much data. Assuming that this filter is not applied to the # file logging handler, the user may always consult the file log for the # original exception traceback. The exc_info is explained here: - # http://docs.python.org/2/library/sys.html#sys.exc_info + # http://docs.python.org/library/sys.html#sys.exc_info exc_type, _, _ = record.exc_info # Simply set the class name as the exception text. diff --git a/tuf/repository_tool.py b/tuf/repository_tool.py index 7ab22463e6..0c1ac272d7 100755 --- a/tuf/repository_tool.py +++ b/tuf/repository_tool.py @@ -629,7 +629,7 @@ def get_filepaths_in_directory(files_directory, recursive_walk=False, # FIXME: We need a way to tell Python 2, but not Python 3, to return # filenames in Unicode; see #61 and: - # http://docs.python.org/2/howto/unicode.html#unicode-filenames + # http://docs.python.org/howto/unicode.html#unicode-filenames for dirpath, dirnames, filenames in os.walk(files_directory, followlinks=followlinks): for filename in filenames: @@ -3286,6 +3286,6 @@ def append_signature(signature, metadata_filepath): if __name__ == '__main__': # The interactive sessions of the documentation strings can # be tested by running repository_tool.py as a standalone module: - # $ python repository_tool.py. + # $ python3 repository_tool.py. import doctest doctest.testmod() diff --git a/tuf/scripts/repo.py b/tuf/scripts/repo.py index 34eab998d7..0b61b2bc59 100755 --- a/tuf/scripts/repo.py +++ b/tuf/scripts/repo.py @@ -23,7 +23,7 @@ developer_tool.py. Note: - 'pip install securesystemslib[crypto,pynacl]' is required by the CLI, + 'python3 -m pip install securesystemslib[crypto,pynacl]' is required by the CLI, which installs the 3rd-party dependencies: cryptography and pynacl.