Do main VCS-independent setup function for installing Versioneer.
()
| 2074 | |
| 2075 | |
| 2076 | def do_setup(): |
| 2077 | """Do main VCS-independent setup function for installing Versioneer.""" |
| 2078 | root = get_root() |
| 2079 | try: |
| 2080 | cfg = get_config_from_root(root) |
| 2081 | except (OSError, configparser.NoSectionError, configparser.NoOptionError) as e: |
| 2082 | if isinstance(e, (OSError, configparser.NoSectionError)): |
| 2083 | print("Adding sample versioneer config to setup.cfg", file=sys.stderr) |
| 2084 | with open(os.path.join(root, "setup.cfg"), "a") as f: |
| 2085 | f.write(SAMPLE_CONFIG) |
| 2086 | print(CONFIG_ERROR, file=sys.stderr) |
| 2087 | return 1 |
| 2088 | |
| 2089 | print(" creating %s" % cfg.versionfile_source) |
| 2090 | with open(cfg.versionfile_source, "w") as f: |
| 2091 | LONG = LONG_VERSION_PY[cfg.VCS] |
| 2092 | f.write( |
| 2093 | LONG |
| 2094 | % { |
| 2095 | "DOLLAR": "$", |
| 2096 | "STYLE": cfg.style, |
| 2097 | "TAG_PREFIX": cfg.tag_prefix, |
| 2098 | "PARENTDIR_PREFIX": cfg.parentdir_prefix, |
| 2099 | "VERSIONFILE_SOURCE": cfg.versionfile_source, |
| 2100 | } |
| 2101 | ) |
| 2102 | |
| 2103 | ipy = os.path.join(os.path.dirname(cfg.versionfile_source), "__init__.py") |
| 2104 | if os.path.exists(ipy): |
| 2105 | try: |
| 2106 | with open(ipy, "r") as f: |
| 2107 | old = f.read() |
| 2108 | except OSError: |
| 2109 | old = "" |
| 2110 | module = os.path.splitext(os.path.basename(cfg.versionfile_source))[0] |
| 2111 | snippet = INIT_PY_SNIPPET.format(module) |
| 2112 | if OLD_SNIPPET in old: |
| 2113 | print(" replacing boilerplate in %s" % ipy) |
| 2114 | with open(ipy, "w") as f: |
| 2115 | f.write(old.replace(OLD_SNIPPET, snippet)) |
| 2116 | elif snippet not in old: |
| 2117 | print(" appending to %s" % ipy) |
| 2118 | with open(ipy, "a") as f: |
| 2119 | f.write(snippet) |
| 2120 | else: |
| 2121 | print(" %s unmodified" % ipy) |
| 2122 | else: |
| 2123 | print(" %s doesn't exist, ok" % ipy) |
| 2124 | ipy = None |
| 2125 | |
| 2126 | # Make VCS-specific changes. For git, this means creating/changing |
| 2127 | # .gitattributes to mark _version.py for export-subst keyword |
| 2128 | # substitution. |
| 2129 | do_vcs_install(cfg.versionfile_source, ipy) |
| 2130 | return 0 |
| 2131 | |
| 2132 | |
| 2133 | def scan_setup_py(): |
no test coverage detected
searching dependent graphs…