File: project.py

package info (click to toggle)
sip5 5.5.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,380 kB
  • sloc: ansic: 37,043; yacc: 6,670; python: 2,107; lex: 823; makefile: 18; cpp: 4
file content (52 lines) | stat: -rw-r--r-- 1,793 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from sipbuild import Option, Project, PyProjectOptionException


class CoreProject(Project):
    """ A project that adds an additional configuration option and introspects
    the system to determine its value.
    """

    def get_options(self):
        """ Return the sequence of configurable options. """

        # Get the standard options.
        options = super().get_options()

        # Add our new option.
        options.append(Option('platform'))

        return options

    def apply_nonuser_defaults(self, tool):
        """ Apply any non-user defaults. """

        if self.platform is None:
            # The option wasn't specified in pyproject.toml so we introspect
            # the system.

            from sys import platform

            if platform == 'linux':
                self.platform = 'Linux'
            elif platform == 'darwin':
                self.platform = 'macOS'
            elif platform == 'win32':
                self.platform = 'Windows'
            else:
                raise PyProjectOptionException('platform',
                        "the '{0}' platform is not supported".format(platform))
        else:
            # The option was set in pyproject.toml so we just verify the value.
            if self.platform not in ('Linux', 'macOS', 'Windows'):
                raise PyProjectOptionException('platform',
                        "'{0}' is not a valid platform".format(self.platform))

        # Apply the defaults for the standard options.
        super().apply_nonuser_defaults(tool)

    def update(self, tool):
        """ Update the project configuration. """

        # Get the 'core' bindings and add the platform to the list of tags.
        core_bindings = self.bindings['core']
        core_bindings.tags.append(self.platform)