question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fix build command on Windows

See original GitHub issue

DESIRED BEHAVIOR

My team uses django-bakery in a couple of places. We want builds on Windows to just work without workarounds. However, right now we need some workarounds because of limitations that prevent builds on Windows.

WORKAROUND

In my environment so far, two changes are needed to allow builds on Windows to proceed.

First, make sure the BUILD_DIR is free of a colon, which fails validation by python-fs:

__build_dir = os.environ.get('BUILD_DIR', os.path.join(BASE_DIR, 'build'))
if sys.platform == 'win32':
    __build_dir = __build_dir.replace('\\', '/')[2:]
BUILD_DIR = __build_dir

Second, override the build method of BuildableTemplateView to correct for the use of os.path.join:

from bakery.views import BuildableTemplateView as BaseBuildableTemplateView


class BuildableTemplateView(BaseBuildableTemplateView):
    def build(self):
        logger.debug("Building %s" % self.template_name)
        build_path = self.get_build_path()
        self.request = self.create_request(build_path)
        path = fs.path.combine(settings.BUILD_DIR, build_path)
        self.prep_directory(build_path)
        self.build_file(path, self.get_content())

SHORT-TERM FIX

A short-term fix is to simply promote at least the 1-line change to build into the package. 3 lines in the local or development settings file is acceptably dry. I’ll admit that our work-around for the BUILD_DIR is not a complete solution - you need the drive specification on Windows.

I will work on a pull request for the short-term fix, but I think there will need to be discussion around the longer term fix.

LONG-TERM FIX

Using python-fs is really not that great now that Python 3 supports the pathlib module. It might be possible to migrate to the pathlib module.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
danizencommented, Mar 1, 2022

I have tested with Django 3.2 and added it to the build matrix. I am stopped from a good pull request by two things:

  • Travis-CI.org shutdown awhile ago, and so I would have to go through a lot to test that Python 2.7 still works. Dropping support for Python 2.7 and Django 1.11 would make me confident - without them I would want a build bot.

  • A better fix would not require a work-around on Windows for BUILD_DIR setting. So, I want to understand an OSFS is supposed to work on Windows. My intuition is that the BUILD_ROOT should be validated with os.path and then opened as a filesystem itself, and the relative path is what should be validated. However, I am not certain and want to wait for PyFilesystem/pyfilesystem2#526

0reactions
danizencommented, Feb 28, 2022

I see. The intention is to define AWS_ACCESS_KEY_ID and so on to make sure that we are not mutating any real environment, as described in moto documentation.

The issue is resolved for me with small changes to the tests, I think deriving from changes in how the moto API works - it patches now on client or resource creation I think. The boto API has also changed a little and I also had to use kwargs only in a couple of places in tests. Might not have needed to do if I got the mocking right first.

https://github.com/danizen/django-bakery/commit/4b655d83046ed5d3f7f083aa6d816a4d2404e58d

I am testing now only with Django 2.2, but I saw there were some issues with Django 4. I will give more recent versions of Django a try tomorrow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Repair Windows 10 Using Command Prompt - YouTube
How to Repair Windows 10 Using Command Prompt▻▻▻SUBSCRIBE for more: https://www.youtube.com/user/Britec09?sub_confirmation=1So your ...
Read more >
Windows 10 Pro Insider Preview Build 14316 CMD (Command
I try to repair build cos some problems and "dism.exe /online ... Press Windows + R keys from the keyboard to open Run...
Read more >
How Fix Error " Build Not Recognized ..." when use VS 2019 ...
Tools -> Command Line -> Developer powershell . And try using the command msbuild instead of build . Share. Share a link to...
Read more >
Build & serve commands fail on Windows · Issue #255 - GitHub
When following the README steps to run the project locally on a Windows machine, after a successful npm install, npm run serve and...
Read more >
Java and the Windows Command Prompt
You will use the Java compiler javac to compile your Java programs and the Java interpreter java to run them. You should skip...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found