Skip to content

Build

  • APP BUILD SCRIPT

DST: Path = Path(SRC, 'dist') module-attribute

HANDLING APP FILES

build_app(version=None, beta=False, console=False, raw=False)

Build Proxyshop as an executable release.

Source code in src/utils/build.py
207
208
209
210
211
212
213
214
@build_cli.command()
@click.argument('version', required=False)
@click.option('-B', '--beta', is_flag=True, default=False, help="Build app as a Beta release.")
@click.option('-C', '--console', is_flag=True, default=False, help="Build app with console enabled.")
@click.option('-R', '--raw', is_flag=True, default=False, help="Build app without creating ZIP.")
def build_app(version: Optional[str] = None, beta: bool = False, console: bool = False, raw: bool = False):
    """Build Proxyshop as an executable release."""
    build_app(version=version, beta=beta, console=console, zipped=not raw)

build_cli()

App build tools CLI.

Source code in src/utils/build.py
201
202
203
204
@click.group()
def build_cli():
    """App build tools CLI."""
    pass

build_zip(filename)

Create a zip of this release. @filename: Filename to use on zip archive.

Source code in src/utils/build.py
142
143
144
145
146
147
148
149
150
151
152
def build_zip(filename: str) -> None:
    """
    Create a zip of this release.
    @filename: Filename to use on zip archive.
    """
    ZIP_SRC = osp.join(SRC, filename)
    with zipfile.ZipFile(ZIP_SRC, "w", zipfile.ZIP_DEFLATED) as zipf:
        for fp in glob(osp.join(DST, "**/*"), recursive=True):
            zipf.write(fp, arcname=fp.replace(
                osp.commonpath([DST, fp]), ""))
    move(ZIP_SRC, osp.join(DST, filename))

clear_build_files(clear_dist=True)

Clean out pycache and venv cache, remove previous build files. @param clear_dist: Remove previous dist directory if True, otherwise skip.

Source code in src/utils/build.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
def clear_build_files(clear_dist: bool = True) -> None:
    """
    Clean out __pycache__ and venv cache, remove previous build files.
    @param clear_dist: Remove previous dist directory if True, otherwise skip.
    """
    # Run pyclean on main directory and venv
    os.system("pyclean -v .")
    if osp.exists(osp.join(SRC, '.venv')):
        os.system("pyclean -v .venv")

    # Remove build directory
    with suppress(Exception):
        rmtree(osp.join(SRC, 'build'))

    # Optionally remove dist directory
    if clear_dist:
        with suppress(Exception):
            rmtree(osp.join(SRC, 'dist'))

copy_app_files(config)

Copy necessary app files and directories. @param config: TOML config data.

Source code in src/utils/build.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
def copy_app_files(config: dict[str, Any]) -> None:
    """
    Copy necessary app files and directories.
    @param config: TOML config data.
    """
    for _, DIR in config.get('copy', {}).items():
        # Copy directories
        for path in DIR.get('paths', []):
            copy_directory(
                src=osp.join(SRC, path),
                dst=osp.join(DST, path),
                x_files=DIR.get('exclude_files', []),
                x_dirs=DIR.get('exclude_dirs', []),
                x_ext=DIR.get('exclude_ext', []),
                recursive=bool(DIR.get('recursive', True)))
        # Copy files
        for file in DIR.get('files', []):
            copy2(
                src=osp.join(SRC, file),
                dst=osp.join(DST, file))

copy_directory(src, dst, x_files, x_dirs, x_ext=None, recursive=True)

Copy a directory from src to dst. @param src: Source directory to copy this directory from. @param dst: Destination directory to copy this directory to. @param x_files: Excluded file names. @param x_dirs: Excluded directory names. @param x_ext: Excluded extensions. @param recursive: Will exclude all subdirectories if False.

Source code in src/utils/build.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
def copy_directory(
    src: str, dst: str,
    x_files: list[str],
    x_dirs: list[str],
    x_ext: Optional[list[str]] = None,
    recursive: bool = True
) -> None:
    """
    Copy a directory from src to dst.
    @param src: Source directory to copy this directory from.
    @param dst: Destination directory to copy this directory to.
    @param x_files: Excluded file names.
    @param x_dirs: Excluded directory names.
    @param x_ext: Excluded extensions.
    @param recursive: Will exclude all subdirectories if False.
    """
    # Set empty lists for None value
    x_files = x_files or []
    x_dirs = x_dirs or []
    x_ext = x_ext or []

    def _ignore(path: str, names: list[str]):
        """
        Return a list of files to ignore based on our exclusion criteria.
        @param path: Path to these files.
        @names: Names of these files.
        """
        ignored: list[str] = []
        for name in names:
            # Ignore certain names and extensions
            p = Path(path, name)
            if name in x_files or p.suffix in x_ext:
                ignored.append(name)
            # Ignore certain directories
            elif (name in x_dirs or not recursive) and osp.isdir(osp.join(path, name)):
                ignored.append(name)
        return set(ignored)

    # Copy the directory
    copytree(src, dst, ignore=_ignore)

make_directories(config)

Make sure necessary directories exist. @param config: TOML config data.

Source code in src/utils/build.py
38
39
40
41
42
43
44
45
def make_directories(config: dict[str, Any]) -> None:
    """
    Make sure necessary directories exist.
    @param config: TOML config data.
    """
    DST.mkdir(mode=711, parents=True, exist_ok=True)
    for path in config['make']['paths']:
        Path(DST, path).mkdir(mode=711, parents=True, exist_ok=True)