Skip to content

Commit

Permalink
Fixed release issue and added a build session so as to detect it earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain MARIE committed Sep 26, 2024
1 parent 6fd4c3c commit 714fe1f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ jobs:
uses: codecov/codecov-action@v4.0.1
with:
files: ./docs/reports/coverage/coverage.xml
- name: \[not on TAG\] Build wheel and sdist
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads')
run: nox -s build

# -------------- only on Ubuntu + TAG PUSH (no pull request) -----------

Expand Down
6 changes: 5 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Changelog

### 1.15.5 - compatibility fix
### 1.15.6 - compatibility fix

- Fixed issue with legacy python 2.7 and 3.5. Fixes [#110](https://github.com/smarie/python-makefun/issues/110)

### 1.15.5 - yanked version

- This version was yanked as the fix declared in the changelog was not actually active on the version deployed on PyPi

### 1.15.4 - Python 3.13 official support

- Python 3.13 is now supported. PR [#108](https://github.com/smarie/python-makefun/pull/108) and PR
Expand Down
38 changes: 32 additions & 6 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


# set the default activated sessions, minimal for CI
nox.options.sessions = ["tests", "flake8", "docs"] # , "docs", "gh_pages"
nox.options.sessions = ["tests", "flake8", "docs", "build"] # , "docs", "gh_pages"
nox.options.error_on_missing_interpreters = True
nox.options.reuse_existing_virtualenvs = True # this can be done using -r
# if platform.system() == "Windows": >> always use this for better control
Expand Down Expand Up @@ -208,11 +208,9 @@ def publish(session):
# session.run2('codecov -t %s -f %s' % (codecov_token, Folders.coverage_xml))


@nox.session(python=PY39)
def release(session):
"""Create a release on github corresponding to the latest tag"""

install_reqs(session, phase="setup.py#dist", phase_reqs=["setuptools_scm"])
def _build(session):
"""Common code used by build and release sessions"""
install_reqs(session, setup=True, phase="setup.py#dist", phase_reqs=["setuptools_scm"])

# Get current tag using setuptools_scm and make sure this is not a dirty/dev one
from setuptools_scm import get_version # (note that this import is not from the session env but the main nox env)
Expand All @@ -222,12 +220,40 @@ def release(session):
def my_scheme(version_):
version.append(version_)
return guess_next_dev_version(version_)

current_tag = get_version(".", version_scheme=my_scheme)

# create the package
rm_folder(Folders.dist)

session.run("python", "setup.py", "sdist", "bdist_wheel")

# Make sure that the generated _version.py file exists and is compliant with python 2.7
version_py = Path(f"src/{pkg_name}/_version.py")
if not version_py.exists():
raise ValueError("Error with setuptools_scm: _version.py file not generated")

if ":" in version_py.read_text():
raise ValueError("Error with setuptools_scm: _version.py file contains annotations")

return current_tag, version


@nox.session(python=PY39)
def build(session):
"""Same as release but just builds"""

current_tag, version = _build(session)
print(f"current tag: {current_tag}")
print(f"version: {version}")


@nox.session(python=PY39)
def release(session):
"""Create a release on github corresponding to the latest tag"""

current_tag, version = _build(session)

if version[0].dirty or not version[0].exact:
raise ValueError("You need to execute this action on a clean tag version with no local changes.")

Expand Down
8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@
# Use the 'version_file_template' directive if possible to avoid type hints and annotations (python <3.8)
from packaging.version import Version
setuptools_scm_version = pkg_resources.get_distribution("setuptools_scm").version
if Version(setuptools_scm_version) >= Version('8.1.0'):
if Version(setuptools_scm_version) >= Version('6'):
# template_arg_name = "version_file_template" if Version(setuptools_scm_version) >= Version('8.1') else "write_to_template"
# print(Version(setuptools_scm_version))
# print(template_arg_name)

# Note that it was named 'write_to_template' earlier. But at that time it was not generating annotations so no need.
args["version_file_template"] = """# file generated by setuptools_scm
args["write_to_template"] = """# file generated by setuptools_scm and customized
# don't change, don't track in version control
__version__ = version = '{version}'
__version_tuple__ = version_tuple = {version_tuple}
Expand Down

0 comments on commit 714fe1f

Please sign in to comment.