Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: ♻️ switch create_package_structure() to make properties only #1047

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

lwjohnst86
Copy link
Member

Description

The create_package_structure() was no longer relevant, so I refactored it to the create_package_properties(). This function takes properties and a path as input and creates the datapackage.json file as well as the folder for the data package.

I had to comment out several docstring examples since they depended on the global structure rather than the "local-first" approach.

Closes #1033
Closes #958

This PR needs an in-depth review.

Checklist

  • Added or updated tests
  • Updated documentation
  • Ran just run-all

@lwjohnst86 lwjohnst86 requested a review from a team as a code owner February 12, 2025 22:40
Copy link
Member

@signekb signekb left a comment

Choose a reason for hiding this comment

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

Very nice. I like this 👍 Just some small things.

seedcase_sprout/core/create_package_properties.py Outdated Show resolved Hide resolved
seedcase_sprout/core/create_package_properties.py Outdated Show resolved Hide resolved
seedcase_sprout/core/create_package_properties.py Outdated Show resolved Hide resolved
seedcase_sprout/core/create_package_properties.py Outdated Show resolved Hide resolved
seedcase_sprout/core/edit_package_properties.py Outdated Show resolved Hide resolved
seedcase_sprout/core/edit_package_properties.py Outdated Show resolved Hide resolved
seedcase_sprout/core/create_package_properties.py Outdated Show resolved Hide resolved
seedcase_sprout/core/create_package_properties.py Outdated Show resolved Hide resolved
Copy link
Member Author

Choose a reason for hiding this comment

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

It's annoying that this is interpreted as a completely new file, when I only revised the older file. 😠

seedcase_sprout/core/create_package_properties.py Outdated Show resolved Hide resolved
seedcase_sprout/core/create_package_properties.py Outdated Show resolved Hide resolved
seedcase_sprout/core/create_package_properties.py Outdated Show resolved Hide resolved
@lwjohnst86 lwjohnst86 requested a review from signekb February 13, 2025 11:02
Copy link
Contributor

@martonvago martonvago left a comment

Choose a reason for hiding this comment

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

Very nice, just some comments 😊

seedcase_sprout/core/create_package_properties.py Outdated Show resolved Hide resolved
)
```
"""
default_properties = PackageProperties.default()
Copy link
Contributor

Choose a reason for hiding this comment

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

The way we have the default method now, this makes sense, but it makes me wonder if the default method is something we should keep around. If this is the only place where we want to access these default values, maybe it would make it simpler to set them on the incoming properties directly? And maybe set them only if properties doesn't already have them set, so as not to rewrite them?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure I understand. Could you give an example in code?

Copy link
Contributor

Choose a reason for hiding this comment

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

I just meant like this

properties.id = properties.id or str(uuid4())
properties.version = properties.version or "0.1.0"
properties.created = properties.created or get_iso_timestamp()

But I only thought of this because both here and for the example package properties, it felt like default was not very nice to code around, having to convert and update when all we want to do is set some attributes.

"""
default_properties = PackageProperties.default()
properties = properties.compact_dict
properties.update(default_properties.compact_dict)
Copy link
Contributor

Choose a reason for hiding this comment

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

This rewrites any id, created or version set on properties, right? Are we sure we want that?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think anyone wants to manually create these properties, I know I wouldn't! Do you have a use case that might highlight that need?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe if the package exists already (not necessarily as a formal data package) and has a version or an earlier created date? Of course they can still edit all that if they don't want to use the default. But to keep any explicitly set values, we would just need to switch it around to default_properties.update(properties) -- and then there are no "silent" rewrites.

Comment on lines +57 to +58
# The path should already exist as a directory.
check_is_dir(path)
Copy link
Contributor

@martonvago martonvago Feb 13, 2025

Choose a reason for hiding this comment

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

Suggested change
# The path should already exist as a directory.
check_is_dir(path)
# The path should already exist as a directory.
check_is_dir(path)

Defaults to the working directory.

Returns:
A path to the created folder and `datapackage.json` file.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
A path to the created folder and `datapackage.json` file.
The path to the `datapackage.json` file in the created folder.

To make it clear that it returns one path

Comment on lines +19 to +20
to edit the `datapackage.json` properties, use this function to ensure the
properties are correctly structured before it's written. It only edits the
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
to edit the `datapackage.json` properties, use this function to ensure the
properties are correctly structured before it's written. It only edits the
to edit the `datapackage.json` file, use this function to ensure the
properties are correctly structured before they're written. It only edits the

Use this any time you want to edit the package's properties. When you need
to edit the `datapackage.json` properties, use this function to ensure the
properties are correctly structured before it's written. It only edits the
properties of the package itself, not on the data resources contained within
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
properties of the package itself, not on the data resources contained within
properties of the package itself, not of the data resources contained within

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a test around the behaviour of default attributes, what rewrites what

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
3 participants