<commit_before>import os
import logging
from fusesoc.utils import unique_dirs
from fusesoc.vlnv import Vlnv

logger = logging.getLogger(__name__)


class File(object):
    """File objects consist of a mandatory file name, with path relative to
the core root. Extra options can be specified as a comma-separated list
enclosed in [] after the file name. Options are either boolean (option) or has a
value (option=value). No white-space is allowed anywhere in the file object

The following options are defined:

* *file_type :* Value can be any type defined in <<FileTypes, File types>>

* *is_include_file :* Boolean value to indicate this should be treated as an include file

* *logical_name :* Indicate that the file belongs to a logical unit (e.g. VHDL Library) with the name set by the value
* *copyto :* Indicate that the file should be copied to a new location relative to the work root.

Example: rtl/verilog/uart_defines.v[file_type=verilogSource,is_include_file]

Example: data/mem_init_file.bin[copyto=out/boot.bin]

"""

    FILE_TYPES = [
        "PCF",
        "QIP",
        "SDC",
        "UCF",
        "BMM",
        "tclSource",
        "user",
        "verilogSource",
        "verilogSource-95",
        "verilogSource-2001",
        "verilogSource-2005",
        "systemVerilogSource",
        "systemVerilogSource-3.0",
        "systemVerilogSource-3.1",
        "systemVerilogSource-3.1a",
        "vhdlSource",
        "vhdlSource-87",
        "vhdlSource-93",
        "vhdlSource-2008",
        "xci",
        "xdc",
    ]
    name = ""
    copyto = ""
    file_type = ""
    is_include_file = False
    logical_name = ""

    def __init__(self, s):
        self.is_include_file = False
        if s[-1:] == "]":
            _tmp = s[:-1].split("[")
            if len(_tmp) != 2:
                raise SyntaxError("Expected '['")
            self.name = _tmp[0]
            for _arg in [x.strip() for x in _tmp[1].split(",")]:
                if _arg == "is_include_file":
                    self.is_include_file = True
                elif "=" in _arg:
                    _tmp = [x.strip() for x in _arg.split("=")]
                    if _tmp[0] == "file_type" and _tmp[1] not in self.FILE_TYPES:
                        _s = "Unknown file type '{}'. Allowed file types are {}"
                        raise SyntaxError(
                            _s.format(_tmp[1], ", ".join(self.FILE_TYPES))
                        )
                    if _tmp[0] in ["copyto", "file_type", "logical_name"]:
                        setattr(self, _tmp[0], _tmp[1])
                else:
                    raise SyntaxError("Unexpected argument '" + _arg + "'")
        else:
            self.name = s


class Error(Exception):
    pass


class NoSuchItemError(Error):
    pass


class UnknownSection(Error):
    pass


class StringList(list):
    """Space-separated list of strings"""

    def __new__(cls, *args, **kwargs):
        if not args:
            return list()
        else:
            return list(args[0].split())


class PathList(StringList):
    """Space-separated list of paths

Each element in the list is subjected to expansion of environment variables and
 ~ to home directories
"""

    def __new__(cls, *args, **kwargs):
        if not args:
            return list()
        else:
            return [os.path.expandvars(p) for p in args[0].split()]


class FileList(PathList):
    """Space-separated list of <<File>>

Each element in the list is first subjected to the expansion according to
<<PathList>> and then parsed as a <<File>>
"""

    def __new__(clk, *args, **kwargs):
        if not args:
            return list()
        else:
            return [File(p) for p in PathList(args[0])]


class VlnvList(StringList):
    """Space-separated list of VLNV tags

Each element is treated as a VLNV element with an optional version range

Example: librecores.org:peripherals:uart16550:1.5 >=::simple_spi:1.6 mor1kx =::i2c:1.14
"""

    def __new__(clk, *args, **kwargs):
        if not args:
            return list()
        else:
            return [Vlnv(p) for p in StringList(args[0])]


class EnumList(list):
    def __new__(cls, *args, **kwargs):
        if not args:
            return super(EnumList, cls).__new__(cls)
        else:
            values = kwargs["values"]
            _args = args[0].split()<commit_msg>Cleanup: Replace list() with []<commit_after>import os
import logging
from fusesoc.utils import unique_dirs
from fusesoc.vlnv import Vlnv

logger = logging.getLogger(__name__)


class File(object):
    """File objects consist of a mandatory file name, with path relative to
the core root. Extra options can be specified as a comma-separated list
enclosed in [] after the file name. Options are either boolean (option) or has a
value (option=value). No white-space is allowed anywhere in the file object

The following options are defined:

* *file_type :* Value can be any type defined in <<FileTypes, File types>>

* *is_include_file :* Boolean value to indicate this should be treated as an include file

* *logical_name :* Indicate that the file belongs to a logical unit (e.g. VHDL Library) with the name set by the value
* *copyto :* Indicate that the file should be copied to a new location relative to the work root.

Example: rtl/verilog/uart_defines.v[file_type=verilogSource,is_include_file]

Example: data/mem_init_file.bin[copyto=out/boot.bin]

"""

    FILE_TYPES = [
        "PCF",
        "QIP",
        "SDC",
        "UCF",
        "BMM",
        "tclSource",
        "user",
        "verilogSource",
        "verilogSource-95",
        "verilogSource-2001",
        "verilogSource-2005",
        "systemVerilogSource",
        "systemVerilogSource-3.0",
        "systemVerilogSource-3.1",
        "systemVerilogSource-3.1a",
        "vhdlSource",
        "vhdlSource-87",
        "vhdlSource-93",
        "vhdlSource-2008",
        "xci",
        "xdc",
    ]
    name = ""
    copyto = ""
    file_type = ""
    is_include_file = False
    logical_name = ""

    def __init__(self, s):
        self.is_include_file = False
        if s[-1:] == "]":
            _tmp = s[:-1].split("[")
            if len(_tmp) != 2:
                raise SyntaxError("Expected '['")
            self.name = _tmp[0]
            for _arg in [x.strip() for x in _tmp[1].split(",")]:
                if _arg == "is_include_file":
                    self.is_include_file = True
                elif "=" in _arg:
                    _tmp = [x.strip() for x in _arg.split("=")]
                    if _tmp[0] == "file_type" and _tmp[1] not in self.FILE_TYPES:
                        _s = "Unknown file type '{}'. Allowed file types are {}"
                        raise SyntaxError(
                            _s.format(_tmp[1], ", ".join(self.FILE_TYPES))
                        )
                    if _tmp[0] in ["copyto", "file_type", "logical_name"]:
                        setattr(self, _tmp[0], _tmp[1])
                else:
                    raise SyntaxError("Unexpected argument '" + _arg + "'")
        else:
            self.name = s


class Error(Exception):
    pass


class NoSuchItemError(Error):
    pass


class UnknownSection(Error):
    pass


class StringList(list):
    """Space-separated list of strings"""

    def __new__(cls, *args, **kwargs):
        if not args:
            return []
        else:
            return args[0].split()


class PathList(StringList):
    """Space-separated list of paths

Each element in the list is subjected to expansion of environment variables and
 ~ to home directories
"""

    def __new__(cls, *args, **kwargs):
        if not args:
            return []
        else:
            return [os.path.expandvars(p) for p in args[0].split()]


class FileList(PathList):
    """Space-separated list of <<File>>

Each element in the list is first subjected to the expansion according to
<<PathList>> and then parsed as a <<File>>
"""

    def __new__(clk, *args, **kwargs):
        if not args:
            return []
        else:
            return [File(p) for p in PathList(args[0])]


class VlnvList(StringList):
    """Space-separated list of VLNV tags

Each element is treated as a VLNV element with an optional version range

Example: librecores.org:peripherals:uart16550:1.5 >=::simple_spi:1.6 mor1kx =::i2c:1.14
"""

    def __new__(clk, *args, **kwargs):
        if not args:
            return []
        else:
            return [Vlnv(p) for p in StringList(args[0])]


class EnumList(list):
    def __new__(cls, *args, **kwargs):
        if not args:
            return super(EnumList, cls).__new__(cls)
        else:
            values = kwargs["values"]
            _args = args[0].split()
{'fraction_non_alphanumeric': 0.11615930418860151, 'fraction_numerical': 0.012359807736324101, 'mean_word_length': 2.1469211379186173, 'pattern_counts': {'":': 4, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6578502', 'n_tokens_mistral': 2743, 'n_tokens_neox': 2633, 'n_words': 805}