Best Python code snippet using tempest_python
bump_versions.py
Source:bump_versions.py
...14"""Regular expression for capturing version."""15VERSION_RE = r"[\w.]+"16def log(*args):17 print(*args, file=sys.stderr)18def replace_version(target_version, path, match_re=None):19 """Set version to ``target_version`` in ``path``.20 :param match_re: If provided, replace capture group 1 that matches match_re21 """22 if match_re is None:23 log(f"{path}: {target_version}")24 with open(path, 'w') as f:25 f.write(target_version + "\n")26 return27 match_re = re.compile(match_re)28 with fileinput.FileInput(files=(path.as_posix(),), inplace=True) as f:29 match_found = False30 for line in f:31 match = match_re.search(line)32 if match is not None:33 match_found = True34 start, end = match.span(1)35 replace_line_with = line36 replace_line_with = (replace_line_with[:start] + target_version37 + replace_line_with[end:])38 log(f"{path}: {line.strip()} => {replace_line_with.strip()}")39 # In file input context, stdout writes to the file.40 sys.stdout.write(replace_line_with)41 else:42 sys.stdout.write(line)43 assert match_found, f"Match not found for {path}"44def replace_version_toml(filename, mutations):45 """Apply ``mutations`` to TOML formatted ``filename``.46 :param mutations: Mutations is a dictionary describing keys and values47 in the TOML file to update. Keys are specified as a ``.``48 separated path.49 """50 with open(filename, "r") as f:51 contents_str = f.read()52 contents = tomlkit.parse(contents_str)53 for (path, update) in mutations.items():54 parts = path.split(".")55 o = contents56 for part in parts[:-1]:57 o = o[part]58 log(f"{filename}: {path} => {update}")59 o[parts[-1]] = update60 with open(filename, "w") as f:61 write_str = tomlkit.dumps(contents)62 f.write(write_str)63def bump_oso_version(version):64 replace_version(version, BASE / "VERSION")65 replace_version(version,66 BASE / "languages/java/oso/pom.xml",67 fr"<!-- oso_version --><version>({VERSION_RE})<\/version>")68 replace_version(version,69 BASE / "docs/examples/Makefile",70 fr"JAVA_PACKAGE_JAR_PATH := .*\/oso-({VERSION_RE})\.jar")71 replace_version(version,72 BASE / "languages/js/package.json",73 fr'"version": "({VERSION_RE})"')74 replace_version(version,75 BASE / "languages/python/docs/conf.py",76 fr'version = "({VERSION_RE})"')77 replace_version(version,78 BASE / "languages/python/docs/conf.py",79 fr'release = "({VERSION_RE})"')80 replace_version(version,81 BASE / "languages/python/oso/oso/oso.py",82 fr'__version__ = "({VERSION_RE})"')83 replace_version(version,84 BASE / "languages/ruby/Gemfile.lock",85 fr'oso-oso \(({VERSION_RE})\)')86 replace_version(version,87 BASE / "languages/ruby/lib/oso/version.rb",88 fr"VERSION = '({VERSION_RE})'")89 replace_version_toml(BASE / "languages/rust/oso-derive/Cargo.toml",90 {91 "package.version": version92 })93 replace_version_toml(BASE / "languages/rust/oso/Cargo.toml",94 {95 "package.version": version,96 "dependencies.oso-derive.version": f"={version}",97 "dependencies.polar-core.version": f"={version}",98 "dev-dependencies.oso-derive.version": f"={version}",99 })100 replace_version_toml(BASE / "polar-c-api/Cargo.toml",101 {102 "package.version": version,103 "dependencies.polar-core.version": f"={version}",104 })105 replace_version_toml(BASE / "polar-core/Cargo.toml",106 {107 "package.version": version,108 })109 replace_version_toml(BASE / "polar-wasm-api/Cargo.toml",110 {111 "package.version": version,112 "dependencies.polar-core.version": f"={version}",113 })114 replace_version_toml(BASE / "polar-language-server/Cargo.toml",115 {116 "package.version": version,117 "dependencies.polar-core.version": f"={version}",118 })119 replace_version(version,120 BASE / ".github/workflows/publish-docs.yml",121 fr'default: "({VERSION_RE})" # oso_version')122 replace_version(version,123 BASE / "vscode/oso/package.json",124 fr'"version": "({VERSION_RE})"')125def oso_python_dependency_version(version):126 """Get oso version that Python dependencies should pin to.127 0.14.5 => 0.14.0128 """129 parsed = parse_version(version)130 return ".".join((str(parsed.major), str(parsed.minor), str(0)))131def bump_sqlalchemy_version(version, oso_version):132 replace_version(version,133 BASE / "languages/python/sqlalchemy-oso/sqlalchemy_oso/__init__.py",134 fr'__version__ = "({VERSION_RE})"')135 replace_version(oso_python_dependency_version(oso_version),136 BASE / "languages/python/sqlalchemy-oso/requirements.txt",137 fr'oso~=({VERSION_RE})')138 replace_version(version,139 BASE / ".github/workflows/publish-docs.yml",140 fr'default: "({VERSION_RE})" # sqlalchemy_oso_version')141def bump_flask_version(version, oso_version):142 replace_version(version,143 BASE / "languages/python/flask-oso/flask_oso/__init__.py",144 fr'__version__ = "({VERSION_RE})"')145 replace_version(oso_python_dependency_version(oso_version),146 BASE / "languages/python/flask-oso/requirements.txt",147 fr'oso~=({VERSION_RE})')148 replace_version(version,149 BASE / ".github/workflows/publish-docs.yml",150 fr'default: "({VERSION_RE})" # flask_oso_version')151def bump_django_version(version, oso_version):152 replace_version(version,153 BASE / "languages/python/django-oso/django_oso/__init__.py",154 fr'__version__ = "({VERSION_RE})"')155 replace_version(oso_python_dependency_version(oso_version),156 BASE / "languages/python/django-oso/requirements.txt",157 fr'oso~=({VERSION_RE})')158 replace_version(version,159 BASE / ".github/workflows/publish-docs.yml",160 fr'default: "({VERSION_RE})" # django_oso_version')161def bump_versions(oso_version=None, sqlalchemy_version=None,162 flask_version=None, django_version=None):163 if oso_version is not None:164 bump_oso_version(oso_version)165 if sqlalchemy_version is not None:166 assert oso_version is not None, "--oso_version must be provided"167 bump_sqlalchemy_version(sqlalchemy_version, oso_version)168 if flask_version is not None:169 assert oso_version is not None, "--oso_version must be provided"170 bump_flask_version(flask_version, oso_version)171 if django_version is not None:172 assert oso_version is not None, "--oso_version must be provided"...
update_version.py
Source:update_version.py
1"""2Automatically update the version number3"""4import json5import os6import re7from datetime import date, datetime8from dateutil.relativedelta import relativedelta9import pybamm10def update_version():11 """12 Opens file and updates the version number13 """14 current_year = datetime.now().strftime("%y")15 current_month = datetime.now().month16 release_version = f"{current_year}.{current_month}"17 last_day_of_month = date.today() + relativedelta(day=31)18 # pybamm/version.py19 with open(os.path.join(pybamm.root_dir(), "pybamm", "version.py"), "r+") as file:20 output = file.read()21 replace_version = re.sub(22 '(?<=__version__ = ")(.+)(?=")', release_version, output23 )24 file.truncate(0)25 file.seek(0)26 file.write(replace_version)27 # docs/conf.py28 with open(os.path.join(pybamm.root_dir(), "docs", "conf.py"), "r+") as file:29 output = file.read()30 replace_version = re.sub('(?<=version = ")(.+)(?=")', release_version, output)31 file.truncate(0)32 file.seek(0)33 file.write(replace_version)34 # CITATION.cff35 with open(os.path.join(pybamm.root_dir(), "CITATION.cff"), "r+") as file:36 output = file.read()37 replace_version = re.sub('(?<=version: ")(.+)(?=")', release_version, output)38 file.truncate(0)39 file.seek(0)40 file.write(replace_version)41 # vcpkg.json42 with open(os.path.join(pybamm.root_dir(), "vcpkg.json"), "r+") as file:43 output = file.read()44 json_version_string = json.loads(output)["version-string"]45 replace_version = output.replace(json_version_string, release_version)46 file.truncate(0)47 file.seek(0)48 file.write(replace_version)49 # Get latest commit id from pybamm-team/sundials-vcpkg-registry50 cmd = "git ls-remote https://github.com/pybamm-team/sundials-vcpkg-registry | grep refs/heads/main | cut -f 1 | tr -d '\n'" # noqa: E50151 latest_commit_id = os.popen(cmd).read()52 # vcpkg-configuration.json53 with open(54 os.path.join(pybamm.root_dir(), "vcpkg-configuration.json"), "r+"55 ) as file:56 output = file.read()57 json_commit_id = json.loads(output)["registries"][0]["baseline"]58 replace_commit_id = output.replace(json_commit_id, latest_commit_id)59 file.truncate(0)60 file.seek(0)61 file.write(replace_commit_id)62 changelog_line1 = "# [Unreleased](https://github.com/pybamm-team/PyBaMM/)\n"63 changelog_line2 = f"# [v{release_version}](https://github.com/pybamm-team/PyBaMM/tree/v{release_version}) - {last_day_of_month}\n\n" # noqa: E50164 # CHANGELOG.md65 with open(os.path.join(pybamm.root_dir(), "CHANGELOG.md"), "r+") as file:66 output_list = file.readlines()67 output_list[0] = changelog_line168 output_list.insert(2, changelog_line2)69 file.truncate(0)70 file.seek(0)71 file.writelines(output_list)72def get_changelog():73 """74 Opens CHANGELOG.md and overrides the changelog with the latest version.75 Used in GitHub workflow to create the changelog for the GitHub release.76 """77 # This month78 now = datetime.now()79 current_year = now.strftime("%y")80 current_month = now.month81 # Previous month82 previous_date = datetime.now() + relativedelta(months=-1)83 previous_year = previous_date.strftime("%y")84 previous_month = previous_date.month85 current_version = re.escape(f"# [v{current_year}.{current_month}]")86 previous_version = re.escape(f"# [v{previous_year}.{previous_month}]")87 # Open CHANGELOG.md and keep the relevant lines88 with open(os.path.join(pybamm.root_dir(), "CHANGELOG.md"), "r+") as file:89 output = file.read()90 re_changelog = f"{current_version}.*?(##.*)(?={previous_version})"91 release_changelog = re.findall(re_changelog, output, re.DOTALL)[0]92 print(release_changelog)93 file.truncate(0)94 file.seek(0)95 file.write(release_changelog)96if __name__ == "__main__":...
release.py
Source:release.py
...4parser.add_argument('--old', help='version for the release', action="store")5parser.add_argument('--new', help='version for the release', action="store")6args = parser.parse_args()7def bump_version():8 replace_version('Mixpanel-swift.podspec', args.old, args.new)9 replace_version('Sources/Info.plist', args.old, args.new)10 replace_version('Sources/AutomaticProperties.swift', args.old, args.new)11 replace_version('./scripts/generate_docs.sh', args.old, args.new)12 subprocess.call('git add Mixpanel-swift.podspec', shell=True)13 subprocess.call('git add Sources/Info.plist', shell=True)14 subprocess.call('git add Sources/AutomaticProperties.swift', shell=True)15 subprocess.call('git add ./scripts/generate_docs.sh', shell=True)16 subprocess.call('git commit -m "Version {}"'.format(args.new), shell=True)17 subprocess.call('git push', shell=True)18def replace_version(file_name, old_version, new_version):19 with open(file_name) as f:20 file_str = f.read()21 assert(old_version in file_str)22 file_str = file_str.replace(old_version, new_version)23 with open(file_name, "w") as f:24 f.write(file_str)25def generate_docs():26 subprocess.call('./scripts/generate_docs.sh', shell=True)27 subprocess.call('git add docs', shell=True)28 subprocess.call('git commit -m "Update docs"', shell=True)29 subprocess.call('git push', shell=True)30def add_tag():31 subprocess.call('git tag -a v{} -m "version {}"'.format(args.new, args.new), shell=True)32 subprocess.call('git push origin --tags', shell=True)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!