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

POC Python profiles with django settings inspired syntax #8547

Closed
wants to merge 10 commits into from

Conversation

danimtb
Copy link
Member

@danimtb danimtb commented Feb 24, 2021

Coming from #7922

See django settings docs: https://docs.djangoproject.com/en/3.1/topics/settings/

@danimtb danimtb self-assigned this Feb 24, 2021

class PythonProfilesTest(unittest.TestCase):

def setUp(self):
Copy link
Member

Choose a reason for hiding this comment

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

Please start using modern pytest syntax with fixtures.

Copy link
Member Author

Choose a reason for hiding this comment

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

moved tests to pytest


options.shared = True

env.env_var = "bar"
Copy link
Member

Choose a reason for hiding this comment

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

Lets aim to use the Environment composition defined in #8534

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 have added a similar test with append, prepend, delete and so syntax to the env object

Copy link
Member

Choose a reason for hiding this comment

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

This can wait until #8534 moves forward. You can leave it as is by now, but it would be good to use the same interface, the same that will be used in recipes defined in #8534 in Environment.

self.client = TestClient()
self.pr1_content = textwrap.dedent("""
import os
from conans import settings, options, env
Copy link
Member

Choose a reason for hiding this comment

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

This import of a global object, and the way the object is re-initialized for each profile doesn't look good.

It would be cleaner to do something like:

from conan.profiles import Settings, Options  # To be define where it is, definitely in the new ``conan.`` scope, but not in the root
from conan.tools.env import Environment # the new one

settings = Settings()
settings.os = "Windows"

env = Environment()
env.append_path("PATH", os.getenv("MyLocalPathVar"))

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 agree, the re-initilialization is not very elegant that way but wanted to try the clean syntax of not having to initialize a new object in the profile file.

I think it is easier to just have seettings initialized and you can apply the values without having to "compose" the "Settings()" object. You only load the files in the given order and just apply pure python rules.

Copy link
Member

Choose a reason for hiding this comment

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

Not worth if we incur in such code anti-pattern, this access to global objects is bad, and we have also had very bad experience with it.

@@ -10,6 +12,64 @@
from conans.util.files import load


class ProfileOptions(defaultdict):
Copy link
Member

Choose a reason for hiding this comment

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

These classes cannot be here, this is too global of scope. Better move them to conan.profile

return {key: item.value() for key, item in self._data.items()}


settings = ProfileSettings()
Copy link
Member

Choose a reason for hiding this comment

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

Remove these global objects, this is an anti-pattern.


@staticmethod
def _init_profile():
import conans
Copy link
Member

Choose a reason for hiding this comment

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

Continuation of the anti-pattern of the global objects, please avoid it.


@pytest.fixture
def client():
return TestClient()
Copy link
Member

Choose a reason for hiding this comment

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

A fixture of 1 line provides no value, they are for initialization reuse, but 1 liner is not worth (actually counter productive, losing locality is bad for reading tests). You can put all 3 fixtures in just 1, if you are always using them together: (client, pr1_content, pr2_content):. Also include the client.save() in the fixture.

@memsharded
Copy link
Member

Superseded by #9147

@memsharded memsharded closed this Jun 23, 2021
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.

None yet

2 participants