Python

Room rules: sopython.com/chatroom Code formatting guide: tinyu...
Jan 31, 2023 15:18
write a client that calls the api's and check for the expected result would be one option
Jan 31, 2023 15:09
use the inbuild testing utils until you reach a point where you feel to need more: docs.python.org/3/library/unittest.html
Jan 30, 2023 14:55
def __remove_root_folder_from_path(self, path: str) -> str:
        return os.path.relpath(path, self.template_root_path[:-1])
Jan 30, 2023 14:54
nah I have to remove the root_folder, because jinja2 is using a FileSystemLoader that already takes the template_root_path
Jan 30, 2023 14:29
seems to be a valid option for my usecase, thanks!
Jan 30, 2023 14:28
ah good hint, wasn't aware of this
Jan 30, 2023 14:26
the code basically copies the files inside the folders
Jan 30, 2023 14:26
import shutil

template_files: list[str] = list(
    glob.iglob(self.template_root_path + "**/*.*", recursive=True)
)
template_dot_files: list[str] = list(
    glob.iglob(self.template_root_path + "**/.**", recursive=True)
)

files: list[str] = template_files + template_dot_files

for file_path in files:
    target_file_path: str = file_path.replace(
        self.template_root_path[:-1], self.output_path
    )
    if file_path.endswith(".j2"):
        target_file_path: str = target_file_path.split(".j2")[0]
Jan 30, 2023 14:23
but I cannot use copytree or something similar, because I have to evaluate each file on its own
Jan 30, 2023 14:23
then the folder will be created upfront and afterwards the file will be copied. But this does not seem to work for folders like .vscode
Jan 30, 2023 14:22
os.makedirs(os.path.dirname(target_file_path), exist_ok=True)
shutil.copy(file_path, target_file_path)
Jan 30, 2023 14:22
it works in this order
Jan 30, 2023 14:20
its windows
Jan 30, 2023 14:19
ah got my issue. Actually I´m trying to copy a mixture of files and folders and I even have some folders that start with a dot. Only the folders make the programm run into this issue
Jan 30, 2023 14:16
ok, maybe the issue is somewhere else
Jan 30, 2023 14:16
hm
Jan 30, 2023 14:15
that right sir
Jan 30, 2023 14:15
i want to copy it and I´m on windows. Any other file that does not start with a "." works perfectly
Jan 30, 2023 14:14
shutil.copy(file_path, target_file_path)
Jan 30, 2023 14:13
my file..
Jan 30, 2023 14:13
'template\\aws-cdk-python\\.gitignore'
Jan 30, 2023 14:12
PermissionError: [Errno 13] Permission denied:
Jan 30, 2023 14:07
How can I copy files that start with a dot, like .gitignore? Using shutil.move => works, but shutil.copy results in a permisson issue. Any ideas that do not make the code to complicated and work for python 3.9?
Sep 14, 2022 12:21
thanks a lot, I´ll take a look <3
Sep 14, 2022 12:17
@sahasrara62 any link/ documention I can follow on this?
Sep 14, 2022 11:51
@NordineLotfi Thanks for the answer, I´ll check if this might be a workaround
Sep 14, 2022 11:51
@Kevin I will run into "SSL: CERTIFICATE_VERIFY_FAILED"
Sep 14, 2022 11:47
except adding an upstream to pypi.org in my self hosted artifact repository
Sep 14, 2022 11:45
One more Q. As I´m working behind ZScaler in my Company... when I want to download a package from pypi.org I need to set a certificate in pip-config in order to be allowed to do the request. But When I´m using CodeArtifact there is an exception in our Company (ALL AWS services) and therefore I dont need a Certificate to do the request. Is there a better way than always comment in & out in the config file the cert="" option?
Sep 14, 2022 11:42
ah ok, thanks.
Sep 14, 2022 11:37
Might be a stupid Q, but I don't find any good information about this. How can I COMFORTABLE install packages with pip from different sources. Lets say I want to download a package from "pypi.org" and another package that I have created and hosted in AWS CodeArtifact. Is there a way to comfortable link this in a requirements.txt so that pip knows which package to download from which source?
 

JavaScript

Topic: Anything JavaScript, ECMAScript including Node, React, ...
Jul 28, 2021 14:14
Hi, does someone know how to force a http request retry within a hook when using the got lib? A retry is not triggered when the http request returns statusCode 404. But under certain conditions I need to force a retry here. Any ideas?
Oct 1, 2020 11:35
the working example was just an expression (could be a oneline without formatting), but when using a try-catch plus a functionCall it required a functional scope and is no longer an expression
Oct 1, 2020 11:33
ah ok, i think i understood it now. Thanks for the help
Oct 1, 2020 11:29
:D ok thanks!
Oct 1, 2020 11:26
of course it´s pseudo code
Oct 1, 2020 11:26
@MisterSirCode jsfiddle.net/fdnxrwk9/1
Oct 1, 2020 11:25
expression expected
Oct 1, 2020 11:23
ah ok, i was missing that word. But why does a try-catch break the code then if it is a function
Oct 1, 2020 11:20
//Works
    const fetchHEAD = () => (
        got.head(url, Object.assign({ }, opts, {
          retry: { retries: 0 }
        }))
          .then((res) => ({
            status: 'alive',
            statusCode: res.statusCode
          }))
      )

      return fetchHEAD();

      //Does not work
    const fetchHEAD = () => (

        try {
            const result = got.head(url, opts, {
                retry: { retries: 0 }
              });

        } catch (error) {

        }
      )

      return fetchHEAD();
Oct 1, 2020 11:20
I don´t understand that notation, fetchHEAD is a function, right? Can some one explain or provide me some resource to understand it?
Sep 11, 2020 12:57
thanks for pointing me in the right direction!
Sep 11, 2020 12:56
@JBis ahhh got it. Within one of my IF I returned nothing.... so just changed it to something now its gone
Sep 11, 2020 12:54
but isnt it at the very bottom so that it is return always? Should i declare users empyt at the top to solve this or didnt i got your point?
Sep 11, 2020 12:50
I just implemented to return user, before nothing
Sep 11, 2020 12:50
@JBis the code inside my actual function quite complex and executing several async operations
Sep 11, 2020 12:48
probably my eslint is already in weekend or I missed something O.o
Sep 11, 2020 12:46
because it seems to be just a normal function i wrote 100 times