Browse Source

also bump version ref in setup.py

shut-new-model
Niklas Rosenstein 9 months ago
parent
commit
d97cbfb9bd
No known key found for this signature in database GPG Key ID: 6D269B33D25F6C6
1 changed files with 12 additions and 8 deletions
  1. + 12
    - 8
      src/shut/renderers/setuptools.py

+ 12
- 8
src/shut/renderers/setuptools.py

@ -387,15 +387,19 @@ class SetuptoolsRenderer(Renderer[PackageModel]):
files.add_static(os.path.join(directory, 'py.typed'), '')
def get_version_refs(self, package: PackageModel) -> Iterable[VersionRef]:
def _regex_refs(filename: Optional[str], regex: str) -> Iterable[VersionRef]:
if filename and os.path.isfile(filename):
with open(filename) as fp:
text = fp.read()
match = re.search(regex, text, re.M)
if match:
yield VersionRef(filename, match.start(1), match.end(1), match.group(1))
filename = os.path.join(package.get_directory(), 'setup.py')
yield from _regex_refs(filename, r'^\s*version\s*=\s*[\'"]([^\'"]+)[\'"]')
filename = package.get_python_package_metadata().filename
if not filename or not os.path.isfile(filename):
return; yield
regex = '__version__\s*=\s*[\'"]([^\'"]+)[\'"]'
with open(filename) as fp:
match = re.search(regex, fp.read())
if match:
yield VersionRef(filename, match.start(1), match.end(1), match.group(1))
yield from _regex_refs(filename, r'^__version__\s*=\s*[\'"]([^\'"]+)[\'"]')
register_renderer(PackageModel, SetuptoolsRenderer)

Loading…
Cancel
Save