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

Make setup.py OS-agnostic and replace fcntl with an OS-agnostic alternative #1670

Closed
Andrew-S-Rosen opened this issue May 26, 2023 · 1 comment · Fixed by #1719
Closed

Make setup.py OS-agnostic and replace fcntl with an OS-agnostic alternative #1670

Andrew-S-Rosen opened this issue May 26, 2023 · 1 comment · Fixed by #1719
Labels
feature New feature addition

Comments

@Andrew-S-Rosen
Copy link
Contributor

Andrew-S-Rosen commented May 26, 2023

What should we add?

Setting aside some potential UI challenges, if you want to make Covalent Electron objects compatible with Windows (e.g. to use as regular functions), I don't think it's all that difficult.


The first change is to modify open("README.md").read() to be open("README.md", encoding="utf8").read() below so the Windows user can pip install covalent.

"long_description": open("README.md").read(),

Edit: This was merged in #1685.


The second change is to use an OS-agnostic locking mechanism in place of fcntl below so the config file can be properly written. Portalocker is one such option, which is basically a drop-in replacement of fcntl.lockf(f, fcntl.LOCK_EX) with portalocker.lock(f, portalocker.LOCK_EX).

with open(self.config_file, "r+") as f:
fcntl.lockf(f, fcntl.LOCK_EX)
file_config = toml.load(f)
update_nested_dict(self.config_data, file_config)
if new_entries:
update_nested_dict(self.config_data, new_entries, override_existing)
# Writing it back to the file
self.write_config()
def read_config(self) -> None:
"""
Read the configuration from file.
Args:
None
Returns:
None
"""
self.config_data = toml.load(self.config_file)
def write_config(self) -> None:
"""
Write the configuration to file.
Args:
None
Returns:
None
"""
with open(self.config_file, "w") as f:
fcntl.lockf(f, fcntl.LOCK_EX)
toml.dump(self.config_data, f)


Once those two changes are made, you can import/use Electron objects as normal functions on Windows.

Describe alternatives you've considered.

No response

@Andrew-S-Rosen Andrew-S-Rosen added the feature New feature addition label May 26, 2023
@Andrew-S-Rosen Andrew-S-Rosen changed the title Initial attempts at some degree of Windows compatibility Make setup.py OS-agnostic and replace fcntl with an OS-agnostic alternative May 26, 2023
@Andrew-S-Rosen Andrew-S-Rosen reopened this Jul 4, 2023
@kessler-frost kessler-frost linked a pull request Aug 1, 2023 that will close this issue
3 tasks
@sgbaird
Copy link

sgbaird commented Jan 15, 2024

covalent start on Windows 11 for me results in:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\sterg\miniconda3\envs\self-driving-lab-demo\Scripts\covalent.exe\__main__.py", line 4, in <module>
  File "C:\Users\sterg\miniconda3\envs\self-driving-lab-demo\Lib\site-packages\covalent_dispatcher\__init__.py", line 17, in <module>    
    from .entry_point import cancel_running_dispatch, run_dispatcher
  File "C:\Users\sterg\miniconda3\envs\self-driving-lab-demo\Lib\site-packages\covalent_dispatcher\entry_point.py", line 24, in <module> 
    from covalent._shared_files import logger
  File "C:\Users\sterg\miniconda3\envs\self-driving-lab-demo\Lib\site-packages\covalent\__init__.py", line 22, in <module>
    from . import executor, leptons  # nopycln: import
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\sterg\miniconda3\envs\self-driving-lab-demo\Lib\site-packages\covalent\executor\__init__.py", line 32, in <module>      
    from .._shared_files import logger
  File "C:\Users\sterg\miniconda3\envs\self-driving-lab-demo\Lib\site-packages\covalent\_shared_files\logger.py", line 24, in <module>   
    from .config import get_config
  File "C:\Users\sterg\miniconda3\envs\self-driving-lab-demo\Lib\site-packages\covalent\_shared_files\config.py", line 199, in <module>  
    _config_manager = ConfigManager()
                      ^^^^^^^^^^^^^^^
  File "C:\Users\sterg\miniconda3\envs\self-driving-lab-demo\Lib\site-packages\covalent\_shared_files\config.py", line 42, in __init__   
    DEFAULT_CONFIG = asdict(DefaultConfig())
                            ^^^^^^^^^^^^^^^
  File "<string>", line 3, in __init__
  File "C:\Users\sterg\miniconda3\envs\self-driving-lab-demo\Lib\site-packages\covalent\_shared_files\defaults.py", line 45, in get_default_sdk_config
    or (os.environ["HOME"] + "/.config/covalent")
        ~~~~~~~~~~^^^^^^^^
  File "<frozen os>", line 679, in __getitem__
KeyError: 'HOME'

where a possible fix would be:

from os import path
home_dir = os.environ.get('HOME') or os.environ.get('USERPROFILE')
path.join(home_dir, ".config/covalent")

A workaround is:

You can set the HOME environment variable to be the same as USERPROFILE in PowerShell with the following command:

[Environment]::SetEnvironmentVariable("HOME", $env:USERPROFILE, "User")

This command sets the HOME environment variable for the current user. The change will take effect in new PowerShell sessions. If you want the change to be visible in the current session as well, you can also set it directly in the session:

$env:HOME = $env:USERPROFILE

Please note that these changes are temporary and will not persist across sessions. If you want to make a permanent change, you would need to set the environment variable at the system level, which typically requires administrative privileges.

I realize Windows isn't officially supported, but wanted to leave this here for provenance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature addition
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants