Commit Graph

107 Commits

Author SHA1 Message Date
Jon Dufresne 089bbcb939 Remove unnecessary type override NamedTemporaryFileResult
The object returned by NamedTemporaryFile delegates all functions calls
to the underlying file so can avoid the type override by relying on IO
methods.
2020-12-27 17:19:28 -08:00
Pradyun Gedam 86afa89043
Merge pull request #9361 from jdufresne/f-strings
Use f-strings for simple string formatting
2020-12-26 10:24:18 +00:00
Jon Dufresne cdcf74fb8e Use f-strings for simple string formatting
Use pyupgrade to convert simple string formatting to use f-string
syntax. pyupgrade is intentionally timid and will not create an f-string
if it would make the expression longer or if the substitution parameters
are anything but simple names or dotted names.
2020-12-25 16:21:20 -08:00
Jon Dufresne 09b3d3a50b Remove object from class definitions
Unnecessary since dropping Python 2 support. In Python 3, all classes
are new style classes.
2020-12-25 15:48:11 -08:00
Jon Dufresne c148bcc1aa Use short Python3 super() syntax 2020-12-24 15:11:51 -08:00
Jon Dufresne f32adaf09b Remove __future__ imports
Unnecessary since dropping Python 2.
2020-12-24 08:38:09 -08:00
Jon Dufresne 53234e578f Remove obsolete "# type: ignore" comments
Obsolete since dropping Python 2 support.

Add the mypy setting "warn_unused_ignores = True" to catch these
earlier.
2020-12-23 15:42:48 -08:00
Hugo van Kemenade 817ee23051 Remove redundant Python 2.7 code 2020-12-22 09:06:26 +02:00
Pradyun Gedam 58c594c06b
Prepare isort for black 2020-09-23 21:47:47 +05:30
Pradyun Gedam 25ab172b55
Update linter: isort 2020-09-23 19:52:28 +05:30
Tzu-ping Chung a12e2f1479 PEP 427 mandates UTF-8, we don't need the fallback 2020-08-03 15:00:58 +08:00
Tzu-ping Chung d4995cb89e Implement heuristics to get non-ASCII ZIP entries 2020-08-03 09:29:19 +08:00
Chris Hunt 3f9b326c11 Provide a reasonable error on invalid scheme keys
Originally we would throw an `AttributeError` if a bad scheme key was
used. After refactoring we would throw a `KeyError`, which isn't much
better. Now we call out the wheel being processed, scheme key we didn't
recognize, and provide a list of the valid scheme keys. This would
likely be useful for people developing/testing the wheel.
2020-07-29 22:24:09 -04:00
Chris Hunt 864f0e0efa Explicitly handle incorrect .data paths during wheel install
Previously our wheel installation process allowed wheels which contained
non-conforming contents in a contained .data directory.

After the refactoring to enable direct-from-wheel installation, pip
throws an exception when encountering these wheels, but does not include
any helpful information to pinpoint the cause.

Now if we encounter such a wheel, we trace an error that includes the
name of the requirement we're trying to install, the path to the wheel
file, the path we didn't understand, and a hint about what we expect.
2020-07-29 18:12:16 -04:00
Nguyễn Gia Phong f8b06a3906 Enable flake8-logging-format 2020-07-17 14:33:19 +07:00
Chris Hunt 677b4e7f11 Remove redundant try ... except 2020-07-11 15:34:06 -04:00
Chris Hunt 145b7add7e Move error message construction into MissingCallableSuffix
Now, we are free to throw MissingCallableSuffix from anywhere and don't
have to worry about catching it in the middle of our processing.
2020-07-11 15:34:06 -04:00
Chris Hunt f48c44e203 Add req description to error in install_wheel
Moving this value up from `_install_wheel` means that we do not need to
pass `req_description` anymore. This will also let us move our
entrypoint error handling around without worrying about losing the
context from the previous message.
2020-07-11 15:34:06 -04:00
Chris Hunt d13ec25361 Prevent path traversal when installing wheels directly 2020-07-09 21:21:35 -04:00
Chris Hunt 4605b32c49 Don't unpack wheel before installing 2020-07-09 18:25:11 -04:00
Chris Hunt 483213a318 Drop unused wheeldir parameter 2020-07-09 18:25:11 -04:00
Chris Hunt df92f25079 Don't use wheeldir for pyc record paths 2020-07-09 18:25:11 -04:00
Chris Hunt 4bdb8bcd7e Extract files directly from wheel 2020-07-09 18:25:10 -04:00
Chris Hunt f9432790de Get list of files directly from wheel
One less dependency on the wheel being extracted.
2020-07-09 18:24:33 -04:00
Chris Hunt e0f95f12b6 Get non-root scheme files from paths, not disk
Now we rely solely on the list of RECORD-like paths derived from the
filesystem, and can easily trade out the implementation for one that
comes from the wheel file directly.
2020-07-09 18:24:30 -04:00
Chris Hunt 8221aac105 Get paths and make files separately
At the beginning of our wheel processing we are going to have the list
of contained files. By splitting this into its own function, and
deriving it from disk in the same way it will appear in the zip, we can
incrementally refactor our approach using the same interface that will
be available at that time.

We start with the root-scheme paths (that end up in lib_dir) first.
2020-07-09 18:23:17 -04:00
Chris Hunt a3b977330a Separate RECORD path from source file path
When we start processing files directly from the wheel, all we will have
are the files with their zip path (which should match a `RECORD`
entry). Separating this from the source file path (used for copying)
and annotating it with our `RecordPath` type makes it clear what the
format of this public property is, and that it should match what is in
`RECORD`.
2020-07-09 18:23:17 -04:00
Chris Hunt 239accb1b6 Inline clobber 2020-07-09 18:23:17 -04:00
Chris Hunt f2239b5488 Combine processing of root- and data-scheme files
With this approach, we can add the rest of our generated files into the
same iterable and they can undergo the same processing.
2020-07-09 18:23:17 -04:00
Chris Hunt e8382871ad Filter files outside of file-finding function
Simplifying the file-finding function will make it easier to drive our
whole wheel installation from a single list of files later.
2020-07-09 18:23:17 -04:00
Chris Hunt f1e906d166 Move script fixing into separate class
This makes `clobber` much simpler, and aligns the interface of
root_scheme files and data_scheme files, so we can process them in the
same way.
2020-07-09 18:23:17 -04:00
Chris Hunt 50f6f8d69b Simplify return type for fix_script
We always pass a file path to this function, so assert as much. We want
the return type to be consistent so we can assign the result to
non-Optional types.
2020-07-09 18:23:17 -04:00
Chris Hunt bf45bd77be Extract "getting files" outside `clobber`
"getting files" is one of the places that requires files to be on disk.
By extracting this out of `clobber` we can make it simpler and then
trade it out for a zip-based implementation.
2020-07-08 21:43:40 -04:00
Chris Hunt aa8dd9cecc Add File class to represent a file to install
Hiding the file-specific implementation we currently use will let us
trade out the implementation for a zip-backed one later. We can also use
this interface to represent the other kinds of files that we have to
generate as part of wheel installation.

We use a Protocol instead of a base class because there's no need for
shared behavior right now, and using Protocol is less verbose.
2020-07-08 20:41:53 -04:00
Chris Hunt 6b26ac911a Derive parent directory from destination path
By removing this dependency of the "file installation" part of `clobber`
on the "file finding" part of `clobber`, we can more easily factor out
the "file installation" part.
2020-07-08 20:41:43 -04:00
Chris Hunt 64dd286d88 Don't unconditionally create destination directory
Dropping the top-level directory creation allows us to make the
processing completely dependent on files to be installed, and not on the
top-level directory they happen to be installed in.

We already create the parent directory in the loop below, so this call
should be redundant for files that get installed.
2020-07-08 17:31:59 -04:00
Chris Hunt 5e4c1a96a2 Remove unused argument 2020-07-05 20:16:36 -04:00
Chris Hunt 452e683eda Move byte-compilation after installing wheel files
There are a few changes here:

1. The byte-compilation now occurs after we copy the root-scheme files
   and files from any wheel data dirs
1. Instead of iterating over the files in the unpacked wheel directory,
   we iterate over the installed files as they exist in the installation
   path
2. In addition to asserting that pyc files were created, we also add
   them to the list of installed files, so they will be included in RECORD

By compiling after installation, we no longer depend on a separate
temporary directory - this brings us closer to installing directly from
wheel files.

By compiling with source files as they exist in the installation output
directory, we no longer generate pyc files with an embedded randomized
temp directory - this means that wheel installs can be deterministic.
2020-07-05 09:38:35 -04:00
Chris Hunt 2ece73cc86 Confirm that pyc files are written during installation
In order to add generated pyc files to the RECORD file for our package,
we need to know their path! To raise confidence that we're doing this
correctly, we assert the existence of the expected 'pyc' files while
still using the old installation logic.

Some valid reasons why pyc files may not be generated:

1. Syntax error in the installed Python files
2. There is already a pyc file in-place that isn't writable by the
   current user

We don't fail installation in those cases today, and we wouldn't want to
change our behavior here, so we only assert that the pyc file was
created if `compileall.compile_file` indicates success.
2020-07-05 09:38:07 -04:00
Chris Hunt 4cb6f729ab Filter to files actually processed by compileall.compile_file
`compileall.compile_file` returns a success parameter, but can return
"successful" without actually generating a pyc file if the input file
was filtered out and compilation was not attempted.

In our file processing we mirror that logic, to ensure that a truthy
success returned by `compileall.compile_file` actually indicates a file
was written.
2020-07-05 09:37:47 -04:00
Chris Hunt 0a3a558e38 Use compileall.compile_file instead of compileall.compile_dir
We want to move towards having more control over the generation of pyc
files, which will allow us to provide deterministic installs and
generate pyc files without relying on an already-extracted wheel.

To that end, here we are stripping away one layer of abstraction,
`compileall.compile_dir`. `compileall.compile_dir` essentially recurses
through the provided directories and passes the files and args verbatim
to `compileall.compile_file`, so removing that layer means that we
directly call `compileall.compile_file`.

We make the assumption that we can successfully walk over the
source file tree, since we just wrote it, and omit the per-directory
traversal error handling done by `compileall.compile_dir`.
2020-07-05 09:37:45 -04:00
Christopher Hunt feb2a24f14
Merge pull request #8537 from chrahunt/refactor/read-record-from-wheel
Read RECORD from wheel file directly during install
2020-07-03 22:00:34 -04:00
Christopher Hunt 196f5487f9
Merge pull request #8535 from chrahunt/refactor/extract-console-script-spec-source
Extract console script spec calculation from install_unpacked_wheel
2020-07-03 21:58:57 -04:00
Chris Hunt d7b5a776b3 Move record_path closer to first use 2020-07-03 20:53:56 -04:00
Chris Hunt d441f9518b Get wheel RECORD directly from wheel file
This reduces our dependence on disk files, and removes some complexity
around Python 2/3 compatibility with the csv module.
2020-07-03 20:49:16 -04:00
Chris Hunt 0433200135 Move dest_info_dir construction closer to first use
Reducing the scope of variables makes it easier to refactor, since
we can extract whole contiguous chunks of code later.
2020-07-03 19:46:45 -04:00
Chris Hunt 3930e4b063 Drop unused argument 2020-07-03 19:46:45 -04:00
Chris Hunt 479154b4ae Get Wheel entrypoints from Distribution instead of file
Since the Distribution pulls its data directly from the Wheel file,
without extracting intermediate files to disk, this brings us closer to
installing from Wheels without extracting everything.
2020-07-03 19:46:45 -04:00
Chris Hunt d49d97f19f Pass Wheel distribution to install.wheel.get_entrypoints
Right now we're just wiring up the arguments. Next we will actually use
them.
2020-07-03 19:46:45 -04:00
Chris Hunt 94421cfb1a Extract console script spec calculation from install_wheel
This big chunk of code was independent of the rest of our wheel
installation process. Moving it out enforces that there are no
dependencies between it and the original function, and makes it easier
to read the original function.
2020-07-03 17:43:33 -04:00