Skip to content

Cria deprecated_sps_pkg_name para manter acessível a versão anterior do nome do pacote#1065

Merged
robertatakenaka merged 3 commits intoscieloorg:masterfrom
robertatakenaka:renomeia_versao_antiga_de_sps_pkg_name_
Jan 19, 2026
Merged

Cria deprecated_sps_pkg_name para manter acessível a versão anterior do nome do pacote#1065
robertatakenaka merged 3 commits intoscieloorg:masterfrom
robertatakenaka:renomeia_versao_antiga_de_sps_pkg_name_

Conversation

@robertatakenaka
Copy link
Copy Markdown
Member

Adiciona deprecated_sps_pkg_name para manter compatibilidade com versão anterior do nome do pacote

Descrição

Cria a propriedade deprecated_sps_pkg_name e propriedades auxiliares (deprecated_sps_pkg_name_suppl, deprecated_sps_pkg_name_fpage) para preservar o acesso à lógica anterior de geração do nome do pacote SPS.

Motivação

A propriedade sps_pkg_name foi modificada com novas regras de formatação:

  • Suplemento: formato alterado de "1" para "s1"
  • Fpage: quando fpage == lpage e existe v2, adiciona sufixo dos últimos 5 caracteres do v2

Essas mudanças podem impactar sistemas que dependem do formato anterior do nome do pacote. Para garantir compatibilidade retroativa e permitir migração gradual, foram criadas as versões deprecated_*.

Mudanças

Propriedade Versão atual Versão deprecated
sps_pkg_name_suppl "s1" "1"
sps_pkg_name_suppl (zero) "suppl" "suppl"
sps_pkg_name_fpage (fpage==lpage com v2) "123_00123" "123"

Testes

Adicionados testes unitários cobrindo:

  • sps_pkg_name_suppl e deprecated_sps_pkg_name_suppl
  • sps_pkg_name_fpage e deprecated_sps_pkg_name_fpage
  • sps_pkg_name e deprecated_sps_pkg_name
  • Cenários com e sem suplemento, fpage, fpage_seq, v2

- Add deprecated_sps_pkg_name_fpage: formats fpage without underscore before seq
- Add deprecated_sps_pkg_name_suppl: returns raw suppl value (not prefixed with 's')
- Add deprecated_sps_pkg_name: builds package name using deprecated format
Copilot AI review requested due to automatic review settings January 19, 2026 16:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds deprecated properties (deprecated_sps_pkg_name, deprecated_sps_pkg_name_suppl, deprecated_sps_pkg_name_fpage) to maintain backward compatibility with the previous SPS package naming format. The changes were made because sps_pkg_name was modified with new formatting rules: supplements changed from "1" to "s1", and fpage now includes a v2 suffix when fpage equals lpage.

Changes:

  • Added deprecated_sps_pkg_name_fpage, deprecated_sps_pkg_name_suppl, and deprecated_sps_pkg_name properties to XMLWithPre class
  • Exposed deprecated_sps_pkg_name in PidProviderXMLAdapter
  • Created comprehensive test suite for both new and deprecated naming conventions

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

File Description
tests/sps/pid_provider/test_xml_sps_lib.py New test file with comprehensive tests for SPS package name properties, including deprecated versions
packtools/sps/pid_provider/xml_sps_lib.py Added deprecated property implementations for backward-compatible package naming
packtools/sps/pid_provider/xml_sps_adapter.py Exposed deprecated_sps_pkg_name property through the adapter interface

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

def sps_pkg_name(self):
return self.xml_with_pre.sps_pkg_name

@property
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The deprecated_sps_pkg_name property should be decorated with @cached_property instead of @property to match the caching behavior of sps_pkg_name (line 18-20) and the underlying implementation in xml_sps_lib.py where it is also a cached property. This inconsistency will cause the deprecated package name to be recomputed on every access, potentially impacting performance.

Suggested change
@property
@cached_property

Copilot uses AI. Check for mistakes.
Comment on lines +2 to +3
from unittest.mock import MagicMock, PropertyMock, patch
from lxml import etree
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

Unused imports detected. The imports MagicMock, PropertyMock, and patch from unittest.mock, as well as etree from lxml, are not used anywhere in this test file. Consider removing them to keep the imports clean.

Suggested change
from unittest.mock import MagicMock, PropertyMock, patch
from lxml import etree

Copilot uses AI. Check for mistakes.
self.volume,
self.number and self.number.zfill(2),
self.deprecated_sps_pkg_name_suppl,
self.sps_pkg_name_suffix or self.alternative_sps_pkg_name_suffix,
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The deprecated_sps_pkg_name function is using self.sps_pkg_name_suffix which internally calls the NEW sps_pkg_name_fpage logic. This defeats the purpose of providing backward compatibility. A new property deprecated_sps_pkg_name_suffix should be created that uses deprecated_sps_pkg_name_fpage instead of sps_pkg_name_fpage, and it should be used here. Otherwise, when fpage equals lpage and v2 exists, the deprecated version will incorrectly include the v2 suffix.

Copilot uses AI. Check for mistakes.
Comment on lines +160 to +174
def test_deprecated_sps_pkg_name_fpage_none(self):
xml_with_pre = self._make_xml(vol="10", num="2", elocation="e123")
self.assertIsNone(xml_with_pre.deprecated_sps_pkg_name_fpage)

def test_deprecated_sps_pkg_name_fpage_zero(self):
xml_with_pre = self._make_xml(vol="10", num="2", fpage="0", lpage="0")
self.assertIsNone(xml_with_pre.deprecated_sps_pkg_name_fpage)

def test_deprecated_sps_pkg_name_fpage_simple(self):
xml_with_pre = self._make_xml(vol="10", num="2", fpage="123", lpage="130")
self.assertEqual(xml_with_pre.deprecated_sps_pkg_name_fpage, "123")

def test_deprecated_sps_pkg_name_fpage_with_seq(self):
xml_with_pre = self._make_xml(vol="10", num="2", fpage="123", fpage_seq="a", lpage="130")
self.assertEqual(xml_with_pre.deprecated_sps_pkg_name_fpage, "123a")
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

Missing test case for deprecated_sps_pkg_name_fpage when fpage equals lpage and v2 is present. According to the PR description, this is a key difference: the deprecated version should return just the fpage (e.g., "123") while the new version returns fpage with v2 suffix (e.g., "123_00123"). Add a test case similar to test_sps_pkg_name_fpage_same_fpage_lpage_with_v2 but for the deprecated version to verify it returns just "123" without the v2 suffix.

Copilot uses AI. Check for mistakes.
Comment on lines +220 to +242
def test_deprecated_sps_pkg_name_with_suppl(self):
xml_with_pre = self._make_xml(
issn_epub="1234-5678",
acron="abc",
vol="10",
num="2",
suppl="1",
fpage="100",
lpage="110",
)
self.assertEqual(xml_with_pre.deprecated_sps_pkg_name, "1234-5678-abc-10-02-1-100")

def test_deprecated_sps_pkg_name_suppl_zero(self):
xml_with_pre = self._make_xml(
issn_epub="1234-5678",
acron="abc",
vol="10",
num="2",
suppl="0",
fpage="100",
lpage="110",
)
self.assertEqual(xml_with_pre.deprecated_sps_pkg_name, "1234-5678-abc-10-02-suppl-100")
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

Missing test case for the complete deprecated_sps_pkg_name with fpage==lpage and v2 scenario. This would ensure the entire deprecated package name is correctly generated without the v2 suffix, verifying the fix for the bug in the implementation where sps_pkg_name_suffix is incorrectly used instead of a deprecated version.

Copilot uses AI. Check for mistakes.
Comment on lines +294 to +295
import unittest
unittest.main() No newline at end of file
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

Module 'unittest' is imported with both 'import' and 'import from'.

Suggested change
import unittest
unittest.main()
from unittest import main
main()

Copilot uses AI. Check for mistakes.
try:
if int(fpage) == 0:
return None
except (TypeError, ValueError):
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

'except' clause does nothing but pass and there is no explanatory comment.

Copilot uses AI. Check for mistakes.
try:
if int(suppl) == 0:
return "suppl"
except (TypeError, ValueError):
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

'except' clause does nothing but pass and there is no explanatory comment.

Copilot uses AI. Check for mistakes.
@robertatakenaka robertatakenaka merged commit e9fa179 into scieloorg:master Jan 19, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants