Distribution Utilities partis.pyproj.dist_file#
dist_base#
- class dist_base(outname, outdir=None, tmpdir=None, logger=None, named_dirs=None)[source]#
Bases:
ABCBuilder for file distribution
- Parameters:
outdir¶ (str | pathlib.Path) – Path to directory where the file should be copied after completing build.
tmpdir¶ (None | str | pathlib.Path) – If not None, uses the given directory to place the temporary file(s) before copying to final location. May be the same as outdir.
named_dirs¶ (None | Dict[ str, str | pathlib.PurePosixPath ]) – Mapping of specially named directories within the distribution. By default a named directory { ‘root’ : ‘.’ } will be added, unless overridden with another directory name.
logger¶ (None | logging.Logger) – Logger to which any status information is to be logged.
- outpath#
Path to final output file location
- Type:
- named_dirs#
Mapping of specially named directories within the distribution
- Type:
Dict[ str, pathlib.PurePosixPath ]
- records#
Recorded list of path, hash, and size (bytes) of files added to distribution
- Type:
List[ Tuple[ pathlib.PurePosixPath, str, int ] ]
- record_hash#
Final hash value of the record after being finalized
Note
Not all distribution implementations will create a hash of the record
- Type:
None | str
- makedirs(dst, mode=None, exist_ok=False, record=True)[source]#
Behaviour similar to os.makedirs into the distribution file
- Parameters:
Note
Some archive file types do not need to explicitly create directories, but this is given in case an implementation needs to create a directory before creating files within the directory.
- copyfile(src, dst, mode=None, exist_ok=False, record=True)[source]#
Behaviour similar to shutil.copyfile into the distribution file
- copytree(src, dst, ignore=None, exist_ok=False, record=True)[source]#
Behaviour similar to shutil.copytree into the distribution file
- Parameters:
src¶ (str | pathlib.Path) –
dst¶ (str | pathlib.PurePosixPath) –
ignore¶ (None | callable) –
If not None,
callable(src, names) -> ignored_names
- record(dst, data)[source]#
Creates a record for an added file
This produces an sha256 hash of the data and associates a record with the item
- abstract create_distfile()[source]#
Creates and opens a temporary distribution file into which files are copied
dist_targz#
- class dist_targz(outname, outdir=None, tmpdir=None, named_dirs=None, logger=None)[source]#
Bases:
dist_baseBuilds a tar-file with gz compression
Example
import tempfile with tempfile.TemporaryDirectory() as tmpdir: import os import os.path pkg_dir = os.path.join( tmpdir, 'src', 'my_package' ) out_dir = os.path.join( tmpdir, 'build' ) os.makedirs( pkg_dir ) with open( os.path.join( pkg_dir, 'module.py' ), 'w' ) as fp: fp.write("print('hello')") from partis.pyproj import ( dist_targz ) with dist_targz( outname = 'my_dist.tar.gz', outdir = out_dir ) as dist: dist.copytree( src = pkg_dir, dst = 'my_package' )
- create_distfile()[source]#
Creates and opens a temporary distribution file into which files are copied
dist_zip#
- class dist_zip(outname, outdir=None, tmpdir=None, named_dirs=None, logger=None)[source]#
Bases:
dist_baseBuilds a zip file
Example
import tempfile with tempfile.TemporaryDirectory() as tmpdir: import os import os.path pkg_dir = os.path.join( tmpdir, 'src', 'my_package' ) out_dir = os.path.join( tmpdir, 'build' ) os.makedirs( pkg_dir ) with open( os.path.join( pkg_dir, 'module.py' ), 'w' ) as fp: fp.write("print('hello')") from partis.pyproj import ( dist_zip ) with dist_zip( outname = 'my_dist.zip', outdir = out_dir ) as dist: dist.copytree( src = pkg_dir, dst = 'my_package' )
- create_distfile()[source]#
Creates and opens a temporary distribution file into which files are copied
dist_source_targz#
- class dist_source_targz(pkg_info, outdir=None, tmpdir=None, logger=None)[source]#
Bases:
dist_targzBuild a source distribution
*.tar.gzfile- Parameters:
outdir¶ (None | str | pathlib.Path) – Path to directory where the wheel file should be copied after completing build.
tmpdir¶ (None | str | pathlib.Path) – If not None, uses the given directory to place the temporary wheel file before copying to final location. My be the same as outdir.
logger¶ (None |
logging.Logger) – Logger to use.
Example
import tempfile with tempfile.TemporaryDirectory() as tmpdir: import os import os.path pkg_dir = os.path.join( tmpdir, 'src', 'my_package' ) out_dir = os.path.join( tmpdir, 'build' ) os.makedirs( pkg_dir ) with open( os.path.join( pkg_dir, 'module.py' ), 'w' ) as fp: fp.write("print('hello')") from partis.pyproj import ( PkgInfo, dist_source_targz ) pkg_info = PkgInfo( project = dict( name = 'my-package', version = '1.0' ) ) with dist_source_targz( pkg_info = pkg_info, outdir = out_dir ) as sdist: sdist.copytree( src = './src', dst = os.path.join( sdist.base_path, 'src' ) )
dist_binary_wheel#
- class dist_binary_wheel(*, pkg_info, build='', compat=None, outdir=None, tmpdir=None, logger=None, gen_name=None)[source]#
Bases:
dist_zipBuild a binary distribution PEP 427, PEP 491 wheel file
*.whl- Parameters:
build¶ (str) – Build tag. Must start with a digit, or be an empty string.
compat¶ (List[ Tuple[str,str,str] ] | List[
CompatibilityTags]) – List of build compatability tuples of the form ( py_tag, abi_tag, plat_tag ). e.g. ( ‘py3’, ‘abi3’, ‘linux_x86_64’ )outdir¶ (str) – Path to directory where the wheel file should be copied after completing build.
tmpdir¶ (None | str) – If not None, uses the given directory to place the temporary wheel file before copying to final location. My be the same as outdir.
logger¶ (None |
logging.Logger) – Logger to use.gen_name¶ (str) – Name to use as the ‘Generator’ of the wheel file
Example
import tempfile with tempfile.TemporaryDirectory() as tmpdir: import os import os.path pkg_dir = os.path.join( tmpdir, 'src', 'my_package' ) out_dir = os.path.join( tmpdir, 'build' ) os.makedirs( pkg_dir ) with open( os.path.join( pkg_dir, 'module.py' ), 'w' ) as fp: fp.write("print('hello')") from partis.pyproj import ( PkgInfo, dist_binary_wheel ) pkg_info = PkgInfo( project = dict( name = 'my-package', version = '1.0' ) ) with dist_binary_wheel( pkg_info = pkg_info, outdir = out_dir ) as bdist: bdist.copytree( src = pkg_dir, dst = 'my_package' )
See also