Skip to content

feat(nano): use decorator to export a Blueprint#1395

Merged
jansegre merged 1 commit intomasterfrom
feat/nano/blueprint-export-decorator
Sep 10, 2025
Merged

feat(nano): use decorator to export a Blueprint#1395
jansegre merged 1 commit intomasterfrom
feat/nano/blueprint-export-decorator

Conversation

@jansegre
Copy link
Member

@jansegre jansegre commented Sep 8, 2025

Motivation

The current method of assigning to __blueprint__ has some drawbacks. This proposal uses a decorator which should already be familiar because of @view and @public decorators.

Acceptance Criteria

  • Move hathor.nanocontracts.on_chain_blueprints.BLUEPRINT_CLASS_NAME to hathor.nanocontracts.types.BLUEPRINT_EXPORT_NAME
  • Introduce hathor.nanocontracts.export which just sets __blueprint__ at the module where it is called, which means it is backwards compatible:
    @export
    class Foo(Blueprint):
        pass
    Has the same runtime effect of:
    class Foo(Blueprint):
        pass
    __blueprint__ = Foo

Checklist

  • If you are requesting a merge into master, confirm this code is production-ready and can be included in future releases as soon as it gets merged

@jansegre jansegre requested review from glevco and msbrogli September 8, 2025 13:19
@jansegre jansegre self-assigned this Sep 8, 2025
@jansegre jansegre moved this from Todo to In Progress (WIP) in Hathor Network Sep 8, 2025
@jansegre jansegre force-pushed the feat/nano/blueprint-export-decorator branch 2 times, most recently from 1a13e0d to 663c694 Compare September 8, 2025 13:28
@github-actions
Copy link

github-actions bot commented Sep 8, 2025

🐰 Bencher Report

Branchfeat/nano/blueprint-export-decorator
Testbedubuntu-22.04
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
minutes (m)
(Result Δ%)
Lower Boundary
minutes (m)
(Limit %)
Upper Boundary
minutes (m)
(Limit %)
sync-v2 (up to 20000 blocks)📈 view plot
🚷 view threshold
1.84 m
(+9.18%)Baseline: 1.68 m
1.51 m
(82.43%)
2.02 m
(90.98%)
🐰 View full continuous benchmarking report in Bencher

@jansegre jansegre force-pushed the feat/nano/blueprint-export-decorator branch from 663c694 to e1cd544 Compare September 8, 2025 13:54
@codecov
Copy link

codecov bot commented Sep 8, 2025

Codecov Report

❌ Patch coverage is 81.63265% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.86%. Comparing base (9d0e7dd) to head (eb235f2).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
hathor/verification/on_chain_blueprint_verifier.py 78.78% 5 Missing and 2 partials ⚠️
hathor/nanocontracts/types.py 83.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1395      +/-   ##
==========================================
- Coverage   85.87%   85.86%   -0.02%     
==========================================
  Files         431      431              
  Lines       32700    32733      +33     
  Branches     5096     5102       +6     
==========================================
+ Hits        28082    28105      +23     
- Misses       3598     3608      +10     
  Partials     1020     1020              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jansegre jansegre moved this from In Progress (WIP) to In Progress (Done) in Hathor Network Sep 8, 2025
@jansegre jansegre force-pushed the feat/nano/blueprint-export-decorator branch from e1cd544 to 156555c Compare September 8, 2025 15:01
Comment on lines +281 to +308
def export(cls: B) -> B:
"""Decorator to export the main Blueprint of a Python module."""
current_frame = inspect.currentframe()
assert current_frame is not None
module_frame = current_frame.f_back
assert module_frame is not None
module_globals = module_frame.f_globals
if BLUEPRINT_EXPORT_NAME in module_globals:
raise TypeError('A Blueprint has already been registered')
module_globals[BLUEPRINT_EXPORT_NAME] = cls
return cls
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using global or globals() doesn't work?

Copy link
Member Author

@jansegre jansegre Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work because it would refer to the hathor.nanocontracts.types's globals, not the module that uses @export's globals.

msbrogli
msbrogli previously approved these changes Sep 8, 2025
@jansegre jansegre moved this from In Progress (Done) to In Review (Done) in Hathor Network Sep 8, 2025
@jansegre jansegre force-pushed the feat/nano/blueprint-export-decorator branch 2 times, most recently from df2898c to 492dcf5 Compare September 9, 2025 13:50
@jansegre jansegre force-pushed the feat/nano/blueprint-export-decorator branch from 492dcf5 to eb235f2 Compare September 10, 2025 16:45
@github-project-automation github-project-automation bot moved this from In Review (Done) to In Review (WIP) in Hathor Network Sep 10, 2025
@jansegre jansegre moved this from In Review (WIP) to In Review (Done) in Hathor Network Sep 10, 2025
@jansegre jansegre merged commit afa0f10 into master Sep 10, 2025
7 checks passed
@jansegre jansegre deleted the feat/nano/blueprint-export-decorator branch September 10, 2025 17:20
@github-project-automation github-project-automation bot moved this from In Review (Done) to Waiting to be deployed in Hathor Network Sep 10, 2025
@jansegre jansegre moved this from Waiting to be deployed to Done in Hathor Network Sep 18, 2025
@jansegre jansegre mentioned this pull request Sep 24, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants