Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use flake8 for fast lintint. #58

Merged
merged 1 commit into from Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Expand Up @@ -18,6 +18,7 @@ repos:
- id: check-copyright-headers
name: Check python modules for appropriate copyright headers
files: ^.*\.py$
exclude: setup\.py
entry: python .pre-commit-hooks/copyright_headers.py
language: system
# <---- Local Hooks ------------------------------------------------------------------------------------------------
Expand All @@ -31,3 +32,15 @@ repos:
rev: 22.6.0
hooks:
- id: black

# ----- Code Analysis --------------------------------------------------------------------------------------------->
- repo: https://github.com/pycqa/flake8
rev: '5.0.4'
hooks:
- id: flake8
exclude: ^(\.pre-commit-hooks/.*\.py)$
additional_dependencies:
- flake8-mypy-fork
- flake8-docstrings
- flake8-typing-imports
# <---- Code Analysis ---------------------------------------------------------------------------------------------
2 changes: 1 addition & 1 deletion noxfile.py
@@ -1,7 +1,7 @@
# Copyright 2022 VMware, Inc.
# SPDX-License-Identifier: Apache-2
"""
Nox session definitions
Nox session definitions.
"""
import datetime
import os
Expand Down
4 changes: 2 additions & 2 deletions relenv/__main__.py
@@ -1,7 +1,7 @@
# Copyright 2022 VMware, Inc.
# SPDX-License-Identifier: Apache-2
"""
The entrypoint into relenv
The entrypoint into relenv.
"""

from argparse import ArgumentParser
Expand Down Expand Up @@ -38,7 +38,7 @@ def setup_cli():

def main():
"""
Run the relenv cli and disbatch to subcommands
Run the relenv cli and disbatch to subcommands.
"""
parser = setup_cli()
args = parser.parse_args()
Expand Down
3 changes: 3 additions & 0 deletions relenv/build/__init__.py
Expand Up @@ -13,6 +13,9 @@


def platform_module():
"""
Return the right module based on `sys.platform`.
"""
if sys.platform == "darwin":
return darwin
elif sys.platform == "linux":
Expand Down
58 changes: 32 additions & 26 deletions relenv/build/common.py
@@ -1,8 +1,10 @@
# Copyright 2022 VMware, Inc.
# SPDX-License-Identifier: Apache-2
"""
Build process common methods.
"""
import logging
import os.path
import codecs
import hashlib
import pathlib
import glob
Expand Down Expand Up @@ -31,7 +33,6 @@
get_toolchain,
get_triplet,
runcmd,
work_root,
work_dirs,
)
from relenv.relocate import main as relocate_main
Expand Down Expand Up @@ -415,7 +416,7 @@ def valid_hash(self):
@staticmethod
def validate_signature(archive, signature):
"""
True when the archive's signature is valid
True when the archive's signature is valid.

:param archive: The path to the archive to validate
:type archive: str
Expand Down Expand Up @@ -638,7 +639,7 @@ def __init__(

def set_arch(self, arch):
"""
Set the architecture for the build
Set the architecture for the build.

:param arch: The arch to build
:type arch: str
Expand Down Expand Up @@ -838,7 +839,7 @@ def build(self, steps=None, cleanup=True):
:type steps: list, optional
:param cleanup: Whether to clean up or not, defaults to True
:type cleanup: bool, optional
"""
""" # noqa: D400
fails = []
events = {}
waits = {}
Expand Down Expand Up @@ -924,8 +925,9 @@ def build(self, steps=None, cleanup=True):

def check_prereqs(self):
"""
Check pre-requsists for build. This method verifies all requrements for
a successful build are satisfied.
Check pre-requsists for build.

This method verifies all requrements for a successful build are satisfied.

:return: Returns a list of string describing failed checks
:rtype: list
Expand Down Expand Up @@ -983,6 +985,8 @@ def __call__(

def install_sysdata(mod, destfile, buildroot, toolchain):
"""
Create a Relenv Python environment's sysconfigdata.

Helper method used by the `finalize` build method to create a Relenv
Python environment's sysconfigdata.

Expand All @@ -996,22 +1000,23 @@ def install_sysdata(mod, destfile, buildroot, toolchain):
:type toolchain: str
"""
data = {}
fbuildroot = lambda _: _.replace(str(buildroot), "{BUILDROOT}")
ftoolchain = lambda _: _.replace(str(toolchain), "{TOOLCHAIN}")
keymap = {
"BINDIR": (fbuildroot,),
"BINLIBDEST": (fbuildroot,),
"CFLAGS": (fbuildroot, ftoolchain),
"CPPLAGS": (fbuildroot, ftoolchain),
"CXXFLAGS": (fbuildroot, ftoolchain),
"datarootdir": (fbuildroot,),
"exec_prefix": (fbuildroot,),
"LDFLAGS": (fbuildroot, ftoolchain),
"LDSHARED": (fbuildroot, ftoolchain),
"LIBDEST": (fbuildroot,),
"prefix": (fbuildroot,),
"SCRIPTDIR": (fbuildroot,),
}
fbuildroot = lambda _: _.replace(str(buildroot), "{BUILDROOT}") # noqa: E731
ftoolchain = lambda _: _.replace(str(toolchain), "{TOOLCHAIN}") # noqa: E731
# XXX: keymap is not used, remove it?
# keymap = {
# "BINDIR": (fbuildroot,),
# "BINLIBDEST": (fbuildroot,),
# "CFLAGS": (fbuildroot, ftoolchain),
# "CPPLAGS": (fbuildroot, ftoolchain),
# "CXXFLAGS": (fbuildroot, ftoolchain),
# "datarootdir": (fbuildroot,),
# "exec_prefix": (fbuildroot,),
# "LDFLAGS": (fbuildroot, ftoolchain),
# "LDSHARED": (fbuildroot, ftoolchain),
# "LIBDEST": (fbuildroot,),
# "prefix": (fbuildroot,),
# "SCRIPTDIR": (fbuildroot,),
# }
for key in sorted(mod.build_time_vars):
val = mod.build_time_vars[key]
if isinstance(val, str):
Expand All @@ -1031,7 +1036,7 @@ def install_sysdata(mod, destfile, buildroot, toolchain):

def find_sysconfigdata(pymodules):
"""
Find sysconfigdata directory for python installation
Find sysconfigdata directory for python installation.

:param pymodules: Path to python modules (e.g. lib/python3.10)
:type pymodules: str
Expand All @@ -1047,8 +1052,9 @@ def find_sysconfigdata(pymodules):

def finalize(env, dirs, logfp):
"""
Run after we've fully built python. This method enhances the newly created
python with Relenv's runtime hacks.
Run after we've fully built python.

This method enhances the newly created python with Relenv's runtime hacks.

:param env: The environment dictionary
:type env: dict
Expand Down
4 changes: 3 additions & 1 deletion relenv/build/linux.py
@@ -1,8 +1,10 @@
# Copyright 2022 VMware, Inc.
# SPDX-License-Identifier: Apache-2
"""
The linux build process.
"""
from .common import *
from ..common import arches, LINUX
import textwrap

ARCHES = arches[LINUX]

Expand Down
3 changes: 3 additions & 0 deletions relenv/build/windows.py
@@ -1,5 +1,8 @@
# Copyright 2022 VMware, Inc.
# SPDX-License-Identifier: Apache-2
"""
The windows build process.
"""
import glob
import shutil
import sys
Expand Down
20 changes: 13 additions & 7 deletions relenv/common.py
@@ -1,7 +1,7 @@
# Copyright 2022 VMware, Inc.
# SPDX-License-Identifier: Apache-2
"""
Common classes and values used around relenv
Common classes and values used around relenv.
"""
import os
import pathlib
Expand Down Expand Up @@ -46,11 +46,14 @@

class RelenvException(Exception):
"""
Base class for exeptions generated from relenv
Base class for exeptions generated from relenv.
"""


def build_arch():
"""
Return the current machine.
"""
machine = platform.machine()
return machine.lower()

Expand Down Expand Up @@ -199,7 +202,7 @@ def get_triplet(machine=None, plat=None):
elif plat == "linux":
return f"{machine}-linux-gnu"
else:
raise RelenvException("Unknown platform {}".format(platform))
raise RelenvException(f"Unknown platform {plat}")


def archived_build(triplet=None):
Expand All @@ -220,7 +223,7 @@ def archived_build(triplet=None):

def extract_archive(to_dir, archive):
"""
Extract an archive to a specific location
Extract an archive to a specific location.

:param to_dir: The directory to extract to
:type to_dir: str
Expand Down Expand Up @@ -256,8 +259,9 @@ def get_download_location(url, dest):

def download_url(url, dest, verbose=True):
"""
Download the url to the provided destination. This method assumes the last
part of the url is a filename. (https://foo.com/bar/myfile.tar.xz)
Download the url to the provided destination.

This method assumes the last part of the url is a filename. (https://foo.com/bar/myfile.tar.xz)

:param url: The url to download
:type url: str
Expand Down Expand Up @@ -292,7 +296,7 @@ def download_url(url, dest, verbose=True):
block = fin.read(10240)
fin.close()
fout.close()
except:
except Exception:
try:
os.unlink(local)
except OSError:
Expand All @@ -303,6 +307,8 @@ def download_url(url, dest, verbose=True):

def runcmd(*args, **kwargs):
"""
Run a command.

Run the provided command, raising an Exception when the command finishes
with a non zero exit code. Arguments are passed through to ``subprocess.run``

Expand Down
7 changes: 5 additions & 2 deletions relenv/create.py
Expand Up @@ -10,7 +10,7 @@
import sys
import tarfile

from .common import MODULE_DIR, RelenvException, arches, archived_build, build_arch
from .common import RelenvException, arches, archived_build, build_arch


@contextlib.contextmanager
Expand Down Expand Up @@ -44,7 +44,10 @@ def setup_parser(subparsers):
"""
create_subparser = subparsers.add_parser(
"create",
description="Create a Relenv environment. This will create a directory of the given name with newly created Relenv environment.",
description=(
"Create a Relenv environment. This will create a directory of the given "
"name with newly created Relenv environment.",
),
)
create_subparser.set_defaults(func=main)
create_subparser.add_argument("name", help="The name of the directory to create")
Expand Down
3 changes: 1 addition & 2 deletions relenv/fetch.py
Expand Up @@ -5,7 +5,6 @@
"""

import os
import sys

from .build import platform_module
from .common import DATA_DIR, build_arch, download_url, get_triplet, work_dir
Expand Down Expand Up @@ -42,4 +41,4 @@ def main(args):
url = f"https://woz.io/relenv/{version}/build/{triplet}.tar.xz"
builddir = work_dir("build", DATA_DIR)
os.makedirs(builddir, exist_ok=True)
archive = download_url(url, builddir)
download_url(url, builddir)
8 changes: 4 additions & 4 deletions relenv/relocate.py
Expand Up @@ -45,7 +45,7 @@

def is_macho(path):
"""
Determines whether the given file is a macho file
Determines whether the given file is a macho file.

:param path: The path to the file to check
:type path: str
Expand All @@ -61,7 +61,7 @@ def is_macho(path):

def is_elf(path):
"""
Determines whether the given file is an ELF file
Determines whether the given file is an ELF file.

:param path: The path to the file to check
:type path: str
Expand Down Expand Up @@ -229,7 +229,7 @@ def is_in_dir(filepath, directory):

def patch_rpath(path, new_rpath, only_relative=True):
"""
Patch the rpath of a given ELF file
Patch the rpath of a given ELF file.

:param path: The path to an ELF file
:type path: str
Expand Down Expand Up @@ -264,7 +264,7 @@ def patch_rpath(path, new_rpath, only_relative=True):

def handle_elf(path, libs, rpath_only, root=None):
"""
Handle the parsing and pathcing of an ELF file
Handle the parsing and pathcing of an ELF file.

:param path: The path of the ELF file
:type path: str
Expand Down