Skip to content

Commit 194896d

Browse files
committed
New fine_python_setuptools_scm extension with handler of get_src_artifact_version. Add possibility to replace all action handlers or disable single handlers.
1 parent 8a96371 commit 194896d

20 files changed

Lines changed: 487 additions & 30 deletions

File tree

extensions/fine_python_package_info/fine_python_package_info/publish_artifact_to_registry_py_handler.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
@dataclasses.dataclass
1818
class PublishArtifactToRegistryPyHandlerConfig(code_action.ActionHandlerConfig):
19-
...
19+
username: str | None = None
20+
password: str | None = None
2021

2122

2223
class PublishArtifactToRegistryPyHandler(
@@ -69,6 +70,8 @@ async def run(
6970
skip_existing=not payload.force,
7071
non_interactive=True,
7172
verbose=False,
73+
username=self.config.username,
74+
password=self.config.password
7275
)
7376

7477
# Run twine upload in executor to avoid blocking
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.venvs
2+
build/
3+
*.egg-info/
4+
__pycache__
5+
finecode_config_dump/
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from .get_src_artifact_version_setuptools_scm_handler import (
2+
GetSrcArtifactVersionSetuptoolsScmHandler,
3+
GetSrcArtifactVersionSetuptoolsScmHandlerConfig,
4+
)
5+
6+
__all__ = [
7+
"GetSrcArtifactVersionSetuptoolsScmHandler",
8+
"GetSrcArtifactVersionSetuptoolsScmHandlerConfig",
9+
]
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import dataclasses
2+
3+
from setuptools_scm import Configuration
4+
from setuptools_scm._get_version_impl import _get_version
5+
6+
from finecode_extension_api import code_action
7+
from finecode_extension_api.actions import (
8+
get_src_artifact_version as get_src_artifact_version_action,
9+
)
10+
from finecode_extension_api.interfaces import iprojectinfoprovider, ilogger
11+
12+
13+
@dataclasses.dataclass
14+
class GetSrcArtifactVersionSetuptoolsScmHandlerConfig(
15+
code_action.ActionHandlerConfig
16+
): ...
17+
18+
19+
class GetSrcArtifactVersionSetuptoolsScmHandler(
20+
code_action.ActionHandler[
21+
get_src_artifact_version_action.GetSrcArtifactVersionAction,
22+
GetSrcArtifactVersionSetuptoolsScmHandlerConfig,
23+
]
24+
):
25+
def __init__(
26+
self,
27+
config: GetSrcArtifactVersionSetuptoolsScmHandlerConfig,
28+
project_info_provider: iprojectinfoprovider.IProjectInfoProvider,
29+
logger: ilogger.ILogger
30+
) -> None:
31+
self.config = config
32+
self.project_info_provider = project_info_provider
33+
self.logger = logger
34+
35+
async def run(
36+
self,
37+
payload: get_src_artifact_version_action.GetSrcArtifactVersionRunPayload,
38+
run_context: get_src_artifact_version_action.GetSrcArtifactVersionRunContext,
39+
) -> get_src_artifact_version_action.GetSrcArtifactVersionRunResult:
40+
src_artifact_def_path = payload.src_artifact_def_path
41+
42+
src_artifact_raw_def = (
43+
await self.project_info_provider.get_project_raw_config(
44+
project_def_path=src_artifact_def_path
45+
)
46+
)
47+
48+
# Check that version is dynamic
49+
dynamic_fields = src_artifact_raw_def.get("project", {}).get("dynamic", [])
50+
if "version" not in dynamic_fields:
51+
raise code_action.ActionFailedException(
52+
f"Version is not dynamic in {src_artifact_def_path}, "
53+
"this handler only supports dynamic versions via setuptools_scm"
54+
)
55+
56+
# from setuptools_scm._cli:main
57+
pyproject = src_artifact_def_path.as_posix()
58+
59+
try:
60+
# could be optimized by providing config from project_info_provider instead
61+
# of reading file each time
62+
config = Configuration.from_file(
63+
pyproject,
64+
root=None
65+
)
66+
except (LookupError, FileNotFoundError) as ex:
67+
# no pyproject.toml OR no [tool.setuptools_scm]
68+
self.logger.warning(
69+
f"Warning: could not use {pyproject},"
70+
" using default configuration.\n"
71+
f" Reason: {ex}."
72+
)
73+
config = Configuration(root=src_artifact_def_path.parent.as_posix())
74+
75+
version = _get_version(
76+
config
77+
)
78+
if version is None:
79+
raise code_action.ActionFailedException("ERROR: no version found")
80+
81+
# from setuptools_scm._cli:main end
82+
83+
return get_src_artifact_version_action.GetSrcArtifactVersionRunResult(
84+
version=version
85+
)

extensions/fine_python_setuptools_scm/fine_python_setuptools_scm/py.typed

Whitespace-only changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[project]
2+
name = "fine_python_setuptools_scm"
3+
version = "0.1.0a0"
4+
description = ""
5+
authors = [{ name = "Vladyslav Hnatiuk", email = "aders1234@gmail.com" }]
6+
readme = "README.md"
7+
requires-python = ">=3.11, <= 3.14"
8+
dependencies = ["finecode_extension_api~=0.4.0a0", "setuptools-scm>=8"]
9+
10+
[dependency-groups]
11+
dev_workspace = ["finecode~=0.4.0a0", "finecode_dev_common_preset~=0.3.0a0"]
12+
13+
[tool.finecode]
14+
presets = [{ source = "finecode_dev_common_preset" }]
15+
16+
[tool.finecode.env.dev_workspace.dependencies]
17+
finecode_dev_common_preset = { path = "../../finecode_dev_common_preset", editable = true }
18+
finecode = { path = "../../", editable = true }
19+
finecode_extension_runner = { path = "../../finecode_extension_runner", editable = true }
20+
finecode_extension_api = { path = "../../finecode_extension_api", editable = true }
21+
finecode_jsonrpc = { path = "../../finecode_jsonrpc", editable = true }
22+
finecode_builtin_handlers = { path = "../../finecode_builtin_handlers", editable = true }
23+
fine_python_recommended = { path = "../../presets/fine_python_recommended", editable = true }
24+
fine_python_lint = { path = "../../presets/fine_python_lint", editable = true }
25+
fine_python_format = { path = "../../presets/fine_python_format", editable = true }
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import atexit
2+
import shutil
3+
import sys
4+
import tempfile
5+
6+
from setuptools import setup
7+
from setuptools.command.build import build
8+
from setuptools.command.build_ext import build_ext
9+
from setuptools.command.build_py import build_py
10+
from setuptools.command.egg_info import egg_info
11+
12+
# Create a single temp directory for all build operations
13+
_TEMP_BUILD_DIR = None
14+
15+
16+
def get_temp_build_dir(pkg_name):
17+
global _TEMP_BUILD_DIR
18+
if _TEMP_BUILD_DIR is None:
19+
_TEMP_BUILD_DIR = tempfile.mkdtemp(prefix=f"{pkg_name}_build_")
20+
atexit.register(lambda: shutil.rmtree(_TEMP_BUILD_DIR, ignore_errors=True))
21+
return _TEMP_BUILD_DIR
22+
23+
24+
class TempDirBuildMixin:
25+
def initialize_options(self):
26+
super().initialize_options()
27+
temp_dir = get_temp_build_dir(self.distribution.get_name())
28+
self.build_base = temp_dir
29+
30+
31+
class TempDirEggInfoMixin:
32+
def initialize_options(self):
33+
super().initialize_options()
34+
temp_dir = get_temp_build_dir(self.distribution.get_name())
35+
self.egg_base = temp_dir
36+
37+
38+
class CustomBuild(TempDirBuildMixin, build):
39+
pass
40+
41+
42+
class CustomBuildPy(TempDirBuildMixin, build_py):
43+
pass
44+
45+
46+
class CustomBuildExt(TempDirBuildMixin, build_ext):
47+
pass
48+
49+
50+
class CustomEggInfo(TempDirEggInfoMixin, egg_info):
51+
def initialize_options(self):
52+
# Don't use temp dir for editable installs
53+
if "--editable" in sys.argv or "-e" in sys.argv:
54+
egg_info.initialize_options(self)
55+
else:
56+
super().initialize_options()
57+
58+
59+
setup(
60+
name="fine_python_setuptools_scm",
61+
cmdclass={
62+
"build": CustomBuild,
63+
"build_py": CustomBuildPy,
64+
"build_ext": CustomBuildExt,
65+
"egg_info": CustomEggInfo,
66+
},
67+
)

finecode_dev_common_preset/src/finecode_dev_common_preset/preset.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,7 @@ handlers = [
102102
{ name = 'build_and_publish_artifact', source = 'finecode_dev_extensions.BuildAndPublishArtifactHandler', env = "dev_no_runtime", dependencies = [
103103
"finecode_dev_extensions~=0.2.0a0",
104104
] },
105+
{ name = 'copy_distributables', source = 'finecode_dev_extensions.BuildAndPublishArtifactCopyDistributablesHandler', env = "dev_no_runtime", dependencies = [
106+
"finecode_dev_extensions~=0.2.0a0",
107+
] },
105108
]

finecode_extension_api/src/finecode_extension_api/actions/group_src_artifact_files_by_lang.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ def __init__(
2424
run_id: int,
2525
initial_payload: GroupSrcArtifactFilesByLangRunPayload,
2626
meta: code_action.RunActionMeta,
27+
info_provider: code_action.RunContextInfoProvider
2728
) -> None:
28-
super().__init__(run_id=run_id, initial_payload=initial_payload, meta=meta)
29+
super().__init__(run_id=run_id, initial_payload=initial_payload, meta=meta, info_provider=info_provider)
2930

3031

3132
@dataclasses.dataclass

finecode_extension_runner/pyproject.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,11 @@ layers = [
6161
version_file = "src/finecode_extension_runner/_version.py"
6262
root = ".."
6363

64-
[tool.finecode.env.dev_no_runtime]
65-
# runner.debug = true
64+
[tool.finecode.action.get_src_artifact_version]
65+
source = "finecode_extension_api.actions.get_src_artifact_version.GetSrcArtifactVersionAction"
66+
handlers_mode = "replace"
67+
handlers = [
68+
{ name = 'get_src_artifact_version_setuptools_scm', source = 'fine_python_setuptools_scm.GetSrcArtifactVersionSetuptoolsScmHandler', env = "dev_no_runtime", dependencies = [
69+
"fine_python_setuptools_scm~=0.1.0a1",
70+
] },
71+
]

0 commit comments

Comments
 (0)