Skip to content

Commit

Permalink
[#69] Version.take_name has been renamed to Version.variant_name.
Browse files Browse the repository at this point in the history
  • Loading branch information
eoyilmaz committed Nov 11, 2024
1 parent ce55ff0 commit 403f2e4
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 188 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
Stalker Changes
===============

1.0.0
=====

* `Version.take_name` has been renamed to `Version.variant_name` to follow the industry
standard.
* `Task.depends` renmaed to `Task.depends_on`.
* `TaskDependency.task_depends_to` renamed to `TaskDependency.task_depends_on`.
* Stalker now supports Python versions from 3.8 to 3.13.
* Added GitHub actions for CI/CD practices.
* Updated validation messages to make them more consistently displaying the current
type and the value of the validated attribute.
* Added Makefile workflow to help creating a virtualenv, building, installing, releasing
etc. actions much more easier.
* Modernised Stalker as a Python project. It is now fully PEP 517 compliant.
* Renamed OSX to macOS anywhere it is mentioned.

0.2.27
======

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Rename Version.take_name to Version.variant_name
Revision ID: ec1eb2151bb9
Revises: 019378697b5b
Create Date: 2024-11-01 16:37:18.048904
"""

from alembic import op

import sqlalchemy as sa



# revision identifiers, used by Alembic.
revision = 'ec1eb2151bb9'
down_revision = '019378697b5b'


def upgrade():
"""Upgrade the tables."""
op.alter_column(
"Versions", "take_name", new_column_name="variant_name"
)


def downgrade():
"""Downgrade the tables."""
op.alter_column(
"Versions", "variant_name", new_column_name="take_name"
)
2 changes: 1 addition & 1 deletion docs/source/_static/images/stalker_design.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,7 @@
<shape arcwidth="20.0" archeight="20.0" xsi:type="roundRect"/>
</child>
<child ID="1365"
label="take_name | STRING, DEFAULT=&quot;Main&quot;"
label="variant_name | STRING, DEFAULT=&quot;Main&quot;"
created="1275345214943" x="34.0" y="43.25" width="228.0"
height="23.0" strokeWidth="1.0" autoSized="true" xsi:type="node">
<fillColor>#F2AE45</fillColor>
Expand Down
8 changes: 4 additions & 4 deletions docs/source/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ Variables which can be set in ``config.py`` are as follows:

key = "stalker_default_key"

.. confval:: version_take_name
.. confval:: version_variant_name

The default take name for :class:`~stalker.models.version.Version`
The default variant name for :class:`~stalker.models.version.Version`
instances. Default value is::

version_take_name = "Main"
version_variant_name = "Main"

.. confval:: status_bg_color

Expand Down Expand Up @@ -555,7 +555,7 @@ Variables which can be set in ``config.py`` are as follows:
:class:`~stalker.models.version.Version` instances. This value is not used
yet. Default value is::

filename_template = '{{task.entity_type}}_{{task.id}}_{{version.take_name}}_v{{"%03d"|format(version.version_number)}}'
filename_template = '{{task.entity_type}}_{{task.id}}_{{version.variant_name}}_v{{"%03d"|format(version.version_number)}}'

.. confval:: sequence_format

Expand Down
6 changes: 3 additions & 3 deletions examples/flat_project_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
name="Flat Task Template",
target_entity_type="Task",
path="{{project.code}}", # everything will be under the same folder
filename="{{task.nice_name}}_{{version.take_name}}"
filename="{{task.nice_name}}_{{version.variant_name}}"
'_v{{"%03d"|format(version.version_number)}}{{extension}}'
# you can customize this as you wish, you can even use a uuid4
# as the file name
Expand Down Expand Up @@ -109,7 +109,7 @@
target_entity_type="Task",
path="{{project.code}}/{%- for parent_task in parent_tasks -%}"
"{{parent_task.nice_name}}/{%- endfor -%}", # all in different folder
filename="{{task.nice_name}}_{{version.take_name}}"
filename="{{task.nice_name}}_{{version.variant_name}}"
'_v{{"%03d"|format(version.version_number)}}{{extension}}',
)

Expand Down Expand Up @@ -163,7 +163,7 @@
db.DBSession.add(shot1) # this should be enough to add the rest

# now create new maya files for them
comp_v1 = Version(task=comp, take_name="Test")
comp_v1 = Version(task=comp, variant_name="Test")
comp_v1.update_paths()
comp_v1.extension = ".ma"

Expand Down
4 changes: 2 additions & 2 deletions src/stalker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class Config(ConfigBase):
admin_group_name="admins",
# the default keyword which is going to be used in password scrambling
key="stalker_default_key",
version_take_name="Main",
version_variant_name="Main",
actions=["Create", "Read", "Update", "Delete", "List"], # CRUDL
# Tickets
ticket_label="Ticket",
Expand Down Expand Up @@ -434,7 +434,7 @@ class Config(ConfigBase):
}""",
tj_command="tj3" if sys.platform == "win32" else "/usr/local/bin/tj3",
path_template="{{project.code}}/{%- for parent_task in parent_tasks -%}{{parent_task.nice_name}}/{%- endfor -%}", # noqa: B950
filename_template='{{task.entity_type}}_{{task.id}}_{{version.take_name}}_v{{"%03d"|format(version.version_number)}}', # noqa: B950
filename_template='{{task.entity_type}}_{{task.id}}_{{version.variant_name}}_v{{"%03d"|format(version.version_number)}}', # noqa: B950
# --------------------------------------------
# the following settings came from oyProjectManager
sequence_format="%h%p%t %R",
Expand Down
76 changes: 39 additions & 37 deletions src/stalker/models/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class Version(Link, DAGMixin):
$REPO{{project.repository.id}}/{{project.code}}/{%- for parent_task in parent_tasks -%}{{parent_task.nice_name}}/{%- endfor -%}
Args:
take_name (str): A short string holding the current take name. Takes in Stalker
are used solely for grouping individual versions together. Versions with the
same ``take_name`` (of the same Task) are numbered together. It can be any
variant_name (str): A short string holding the current variant name. Variants in
Stalker are used for creating variants versions. Versions with the same
``variant_name`` (of the same Task) are numbered together. It can be any
alphanumeric value (a-zA-Z0-9_). The default is the string "Main". When
skipped it will use the default value. It can not start with a number. It
can not have white spaces.
Expand Down Expand Up @@ -105,11 +105,11 @@ class Version(Link, DAGMixin):
back_populates="versions",
)

take_name = Column(
variant_name = Column(
String(256),
default=defaults.version_take_name,
doc="""Takes in Versions are used solely for grouping individual
versions together.""",
default=defaults.version_variant_name,
doc="""Variants in Versions are used for representing different variants of the
same version.""",
)

version_number = Column(
Expand Down Expand Up @@ -150,7 +150,7 @@ class Version(Link, DAGMixin):
def __init__(
self,
task=None,
take_name=defaults.version_take_name,
variant_name=defaults.version_variant_name,
inputs=None,
outputs=None,
parent=None,
Expand All @@ -164,7 +164,7 @@ def __init__(

DAGMixin.__init__(self, parent=parent)

self.take_name = take_name
self.variant_name = variant_name
self.task = task
self.version_number = None
if inputs is None:
Expand Down Expand Up @@ -196,59 +196,61 @@ def __repr__(self) -> str:
)

@classmethod
def _format_take_name(cls, take_name: str) -> str:
"""Format the given take_name value.
def _format_variant_name(cls, variant_name: str) -> str:
"""Format the given variant_name value.
Args:
take_name (str): The take name value to be formatted.
variant_name (str): The variant name value to be formatted.
Returns:
str: The formatted take name value.
str: The formatted variant name value.
"""
# remove unnecessary characters
take_name = re.sub(r"([^a-zA-Z0-9\s_\-@]+)", r"", take_name).strip()
variant_name = re.sub(r"([^a-zA-Z0-9\s_\-@]+)", r"", variant_name).strip()

# replace empty spaces with underscores
take_name = re.sub(r"[\s]+", "_", take_name)
variant_name = re.sub(r"[\s]+", "_", variant_name)

# replace multiple underscores with only one
# take_name = re.sub(r'([_]+)', r'_', take_name)
# variant_name = re.sub(r'([_]+)', r'_', variant_name)

# remove any non allowed characters from the start
take_name = re.sub(r"^[^a-zA-Z0-9]+", r"", take_name)
variant_name = re.sub(r"^[^a-zA-Z0-9]+", r"", variant_name)

return take_name
return variant_name

@validates("take_name")
def _validate_take_name(self, key: str, take_name: str) -> str:
"""Validate the given take_name value.
@validates("variant_name")
def _validate_variant_name(self, key: str, variant_name: str) -> str:
"""Validate the given variant_name value.
Args:
key (str): The name of the validated column.
take_name (str): The take name value to be validated.
variant_name (str): The variant name value to be validated.
Raises:
TypeError: If the take name value is not a string.
ValueError: If the take name value is an empty string.
TypeError: If the variant name value is not a string.
ValueError: If the variant name value is an empty string.
Returns:
str: The validated take name value.
str: The validated variant name value.
"""
if not isinstance(take_name, string_types):
if not isinstance(variant_name, string_types):
raise TypeError(
"{}.take_name should be a string, not {}: '{}'".format(
self.__class__.__name__, take_name.__class__.__name__, take_name
"{}.variant_name should be a string, not {}: '{}'".format(
self.__class__.__name__,
variant_name.__class__.__name__,
variant_name,
)
)

take_name = self._format_take_name(take_name)
variant_name = self._format_variant_name(variant_name)

if take_name == "":
if variant_name == "":
raise ValueError(
f"{self.__class__.__name__}.take_name can not be an empty string"
f"{self.__class__.__name__}.variant_name can not be an empty string"
)

return take_name
return variant_name

@property
def latest_version(self) -> "Version":
Expand All @@ -262,7 +264,7 @@ def latest_version(self) -> "Version":
with DBSession.no_autoflush:
last_version = (
Version.query.filter(Version.task == self.task)
.filter(Version.take_name == self.take_name)
.filter(Version.variant_name == self.variant_name)
.order_by(Version.version_number.desc())
.first()
)
Expand Down Expand Up @@ -522,7 +524,7 @@ def latest_published_version(self) -> "Version":
"""
return (
Version.query.filter_by(task=self.task)
.filter_by(take_name=self.take_name)
.filter_by(variant_name=self.variant_name)
.filter_by(is_published=True)
.order_by(Version.version_number.desc())
.first()
Expand Down Expand Up @@ -563,14 +565,14 @@ def __eq__(self, other):
Returns:
bool: True if the other object is equal to this one as an Entity, is a
Version instance, has the same task, same take_name and same
Version instance, has the same task, same variant_name and same
version_number.
"""
return (
super(Version, self).__eq__(other)
and isinstance(other, Version)
and self.task == other.task
and self.take_name == other.take_name
and self.variant_name == other.variant_name
and self.version_number == other.version_number
)

Expand Down Expand Up @@ -624,7 +626,7 @@ def nice_name(self) -> str:
naming_parents = self.naming_parents
return self._format_nice_name(
"{}_{}".format(
"_".join(map(lambda x: x.nice_name, naming_parents)), self.take_name
"_".join(map(lambda x: x.nice_name, naming_parents)), self.variant_name
)
)

Expand Down
16 changes: 8 additions & 8 deletions tests/db/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3468,7 +3468,7 @@ def test_persistence_of_structure(setup_postgresql_db):
name="Character Asset Template",
description="This is the template for character assets",
path="Assets/{{asset_type.name}}/{{pipeline_step.code}}",
filename="{{asset.name}}_{{take.name}}_{{asset_type.name}}_\
filename="{{asset.name}}_{{version.variant_name}}_{{asset_type.name}}_\
v{{version.version_number}}",
target_entity_type="Asset",
type=v_type,
Expand Down Expand Up @@ -4390,7 +4390,7 @@ def test_persistence_of_version(setup_postgresql_db):
test_version = Version(
name="version for task modeling",
task=test_task,
take="MAIN",
variant_name="MAIN",
full_path="M:/Shows/Proj1/Seq1/Shots/SH001/Lighting"
"/Proj1_Seq1_Sh001_MAIN_Lighting_v001.ma",
outputs=[
Expand All @@ -4410,7 +4410,7 @@ def test_persistence_of_version(setup_postgresql_db):
test_version_2 = Version(
name="version for task modeling",
task=test_task,
take="MAIN",
variant_name="MAIN",
full_path="M:/Shows/Proj1/Seq1/Shots/SH001/Lighting"
"/Proj1_Seq1_Sh001_MAIN_Lighting_v001.ma",
inputs=[test_version],
Expand All @@ -4429,7 +4429,7 @@ def test_persistence_of_version(setup_postgresql_db):
is_published = test_version.is_published
full_path = test_version.full_path
tags = test_version.tags
take_name = test_version.take_name
variant_name = test_version.variant_name
# tickets = test_version.tickets
type_ = test_version.type
updated_by = test_version.updated_by
Expand All @@ -4453,7 +4453,7 @@ def test_persistence_of_version(setup_postgresql_db):
assert test_version_db.is_published == is_published
assert test_version_db.full_path == full_path
assert test_version_db.tags == tags
assert test_version_db.take_name == take_name
assert test_version_db.variant_name == variant_name
assert test_version_db.type == type_
assert test_version_db.updated_by == updated_by
assert test_version_db.version_number == version_number
Expand All @@ -4471,7 +4471,7 @@ def test_persistence_of_version(setup_postgresql_db):
test_version_3 = Version(
name="version for task modeling",
task=test_task,
take="MAIN",
variant_name="MAIN",
full_path="M:/Shows/Proj1/Seq1/Shots/SH001/Lighting"
"/Proj1_Seq1_Sh001_MAIN_Lighting_v003.ma",
)
Expand Down Expand Up @@ -4499,7 +4499,7 @@ def test_persistence_of_version(setup_postgresql_db):
# create a new version append it to version_3.children and then delete
# version_3
test_version_4 = Version(
name="version for task modeling", task=test_task, take="MAIN"
name="version for task modeling", task=test_task, variant_name="MAIN"
)
test_version_3.children.append(test_version_4)
DBSession.save(test_version_4)
Expand Down Expand Up @@ -4537,7 +4537,7 @@ def test_persistence_of_version(setup_postgresql_db):
assert test_version_4_db.parent is None

# create a new version and assign it as a child of version_5
test_version_5 = Version(task=test_task, take="MAIN")
test_version_5 = Version(task=test_task, variant_name="MAIN")
DBSession.save(test_version_5)
test_version_4.children = [test_version_5]
DBSession.commit()
Expand Down
4 changes: 2 additions & 2 deletions tests/models/test_filename_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def setup_filename_template_tests():
name="Test Type", code="tt", target_entity_type="FilenameTemplate"
),
"path": "ASSETS/{{asset.code}}/{{task.type.code}}/",
"filename": "{{asset.code}}_{{version.take}}_{{task.type.code}}_"
"filename": "{{asset.code}}_{{version.variant_name}}_{{task.type.code}}_"
"{{version.version}}_{{user.initials}}",
"output_path": "",
"target_entity_type": "Asset",
Expand Down Expand Up @@ -315,7 +315,7 @@ def test_naming_case(setup_postgresql_db):
{%- endif -%}
{%- endfor -%}
{%- set fx = parent_tasks[-2] -%}
_{{fx.name}}_{{version.take_name}}_v{{"%02d"|format(version.version_number)}}""",
_{{fx.name}}_{{version.variant_name}}_v{{"%02d"|format(version.version_number)}}""",
)
DBSession.add(ft)

Expand Down
Loading

0 comments on commit 403f2e4

Please sign in to comment.